NAME

Developer::Dashboard::Guide::Namespacing - module namespacing and built-in command help

DESCRIPTION

Module namespacing: the shared runtime parts, the transient web token policy, user CLI extensions, built-in command help, and the open-file and data query commands.

This guide is part of the Developer::Dashboard manual. The main page is the front door for the whole set.

All project modules are scoped under the Developer::Dashboard:: namespace to prevent pollution of the CPAN ecosystem. Core helper modules are available under this namespace:

  • Developer::Dashboard::File

    File I/O helpers with alias support for older bookmark compatibility.

  • Developer::Dashboard::Folder

    Folder path resolution and discovery with runtime registry support.

  • Developer::Dashboard::DataHelper

    JSON encoding and decoding helpers for older bookmark code.

  • Developer::Dashboard::Zipper

    Token encoding and Ajax command building for transient URL construction.

  • Developer::Dashboard::Runtime::Result

    Hook result environment variable decoding and access for command runners.

Project-owned modules now live only under the Developer::Dashboard:: namespace so the distribution does not pollute the CPAN ecosystem with generic package names. The bookmark CODE runtime imports the short JSON helper names from Developer::Dashboard::DataHelper automatically for every block. The shared JSON wrapper lazily reuses its fixed-configuration canonical encoder and UTF-8 decoder within each Perl interpreter; calls requiring different encoder options construct their own configured encoder.

A diagram of the Developer::Dashboard namespace: one root box for Developer::Dashboard above four family boxes, Engines, Web layer, CLI helpers and the Guide pods.

One root module, and the four families that live beneath it.

Main Concepts

The runtime has a few shared parts:

  • Path and file registries

    Resolve the layered home, project, and skill locations used for configuration, pages, logs, collectors, and other runtime data.

  • Pages and actions

    Store saved pages, render browser views, and run configured actions with their working directory, environment, and timeout settings.

  • Collectors and indicators

    Run scheduled or on-demand checks, save their results, and expose concise status to the browser and shell prompt.

  • Web and command interfaces

    Provide the local browser UI and the d2 command line entry point over the same runtime data.

  • Skills and extensions

    Add isolated commands, pages, configuration, and collectors that can be layered with the shared and project runtimes.

The implementation modules are under the Developer::Dashboard:: namespace. The command guides below describe supported user-facing behaviour; module references are most useful when embedding or extending the system.

Transient Web Token Policy

Transient page tokens still exist for CLI workflows such as d2 page encode and d2 page decode, but browser routes that execute a transient payload from token= or atoken= are disabled by default.

That means links such as:

  • http://127.0.0.1:7890/?token=...

  • http://127.0.0.1:7890/action?atoken=...

  • http://127.0.0.1:7890/ajax?token=...

return a 403 unless DEVELOPER_DASHBOARD_ALLOW_TRANSIENT_URLS is enabled. Saved bookmark-file routes such as /app/index and /app/index/action/... continue to work without that flag.

Saved bookmark editor pages also stay on their named /app/<id>/edit and /app/<id> routes when you save from the browser, so editing an existing bookmark file does not fall back to transient token= URLs under the default deny policy.

Ajax helper calls inside saved bookmark CODE* blocks should use an explicit file => 'name.json' argument. When a saved page supplies that name, the helper stores the Ajax Perl code under the saved dashboard ajax tree and emits a stable saved-bookmark endpoint such as /ajax/name.json?type=text.

Skill pages use the same helper contract. Without extra skill route metadata the generated saved endpoint is namespaced under the longest matching skill route, for example /ajax/example-skill/name.json?type=text or /ajax/example-skill/sub-skill/name.json?type=text.

The runtime config tree and installed skills can both ship config/routes.json to declare canonical custom paths for normal saved app pages, skill-local app pages, Ajax handlers, JavaScript assets, CSS assets, and other public assets. The schema is a JSON object whose keys are the public custom paths and whose values are either one smart local route string or an object with to plus an optional type, for example

{
   "/java" : "/app/learn.ai",
   "/v1/status" : {
      "to" : "/ajax/status",
      "type" : "json"
   },
   "/hello/world" : "/app/hello/world",
   "/main.css" : "/css/hello/world.css",
   "/hey.js" : "/js/hey/how/are/you.js",
   "/what/are/you" : "/others/hello/world/you.html"
}

When that file is present, skill pages emit the declared canonical ajax path such as /v1/status instead of the default /ajax/... url, and runtime-level aliases such as /java can point at normal saved bookmark ids such as /app/learn.ai without treating the dot as skill notation. The same manifest also makes the declared custom /app, /js, /css, and /others paths requestable.

The smart longest-prefix routes remain the parent resolvers: /app/example-skill/..., /ajax/example-skill/..., /js/example-skill/..., /css/example-skill/..., and /others/example-skill/... are always checked first, and any declared custom path is checked only after the normal smart route misses.

Runtime-level custom paths from the active config/routes.json layer chain follow the same fallback rule against the built-in /app, /ajax, /js, /css, and /others route handlers. If neither the smart route nor the custom path resolves, the request falls through to the normal 404 response.

Ajax custom routes default to json when no explicit type is present, and the optional type value can also be html, text, or an arbitrary raw mime type such as application/vnd.example+json. Those saved Ajax handlers run the stored file as a real process, defaulting to Perl unless the file starts with a shebang, and stream both stdout and stderr back to the browser as they happen.

That keeps bookmark Ajax workflows usable even while transient token URLs stay disabled by default, and it means bookmark Ajax code can rely on normal print, warn, die, system, and exec process behaviour instead of a buffered JSON wrapper. The same layered runtime config chain and installed-skill config trees can now ship config/api.json files that authorise selected /ajax/... routes for machine-to-machine callers without forcing a helper login form.

The schema is a JSON object keyed by API client name.

Each entry must provide a stored SHA-256 hex digest under secret plus an ajax array of exact saved Ajax route paths such as /ajax/stream.txt or /ajax/example-skill/status.json. When a non-admin remote request targets one of those registered /ajax/... paths, the caller can send X-DD-API-Key: NAME and X-DD-API-Secret: RAW-SECRET.

Developer Dashboard hashes the raw secret with SHA-256, compares it to the stored digest, and executes the saved Ajax handler when they match.

Missing or wrong credentials for a registered API route return 403 with the JSON body {"status":"forbidden"}.

Existing helper-session auth still works on the same saved Ajax routes, so browser workflows and machine callers can coexist on one handler without adding a second copy of the route. Like the rest of DD-OOP-LAYERS, runtime config/api.json files merge from home to the deepest active child layer, and installed skills contribute their own layered config/api.json fragments for skill-local saved Ajax routes.

The built-in d2 api command is the supported way to inspect or update the writable runtime layer for that registry.

An entry carrying "disabled": true (or the same flag under _disabled) is dropped from the registry; a JSON literal false there keeps the key visible, including values such as "disabled": 0 or "disabled": "no".

Saved bookmark Ajax handlers default to text/plain when no explicit type => ... argument is supplied, and the generated Perl wrapper now enables autoflush on both STDOUT and STDERR so long-running handlers show incremental output in the browser instead of stalling behind process buffers.

If a saved handler also needs refresh-safe process reuse, pass singleton => 'NAME' in the Ajax helper.

The generated URL carries the singleton name, and the worker runs as d2 ajax: NAME. A refreshed request replaces the older matching worker.

d2 stop and d2 restart also stop singleton Ajax workers. Closing a browser tab sends a pagehide cleanup request to /ajax/singleton/stop?singleton=NAME.

If code => ... is omitted, Ajax(file => 'name') targets the existing executable at dashboards/ajax/name instead of rewriting it. Static files referenced by saved bookmarks are resolved from the effective runtime public tree first and then from the saved bookmark root.

The web layer also provides a built-in bundled /js/jquery.js asset that serves the local copy of jQuery 4.0.0, with /js/jquery-4.0.0.min.js kept as a compatibility alias for the same shipped payload even when no runtime file has been copied into dashboard/public/js yet.

The bundled browser tab icon works the same way: browsers request /favicon.ico on their own for every page load, so that route is served outside the authorisation gate, on every trust tier and before any helper login, from the bundled 16x16 icon. Dropping your own dashboard/public/others/favicon.ico into any runtime layer overrides it.

Skills can ship the same classes of assets under their own dashboard tree: dashboards/ajax/* resolves at /ajax/<repo-name>/... or /ajax/<repo-name>/<sub-skill>/..., and dashboards/public/js/*, dashboards/public/css/*, and dashboards/public/others/* resolve at /js/<repo-name>/..., /css/<repo-name>/..., and /others/<repo-name>/... with the same nested-skill extension, for example /js/<repo-name>/<sub-skill>/path/file.js.

If a request such as /js/<repo-name>/foo/bar.js or /js/<repo-name>/<sub-skill>/foo/bar.js does not exist in the skill-local public tree, the web layer falls back to the normal nested saved-bookmark asset path dashboards/public/js/... or saved Ajax file path dashboards/ajax/... instead of assuming the leading path segments must belong to a skill.

Saved bookmark editor and view-source routes also protect literal inline script content from breaking the browser bootstrap. If a bookmark body contains HTML such as /script, the editor now escapes the inline JSON assignment used to reload the source text, so the browser keeps the full bookmark source inside the editor instead of spilling raw text below the page.

Saved browser workspaces can also show a request-specific token form above the editor whenever the current request uses {{token}} placeholders, carrying those token values across matching placeholders in the same workflow so later requests can reuse the operator-supplied values without manual copy-and-paste.

Bookmark rendering now emits saved set_chain_value() bindings after the bookmark body HTML, so pages that declare var endpoints = {} and then call helpers from $(document).ready(...) receive their saved /ajax/... endpoint URLs without throwing a play-route JavaScript ReferenceError.

Bookmark pages now also expose fetch_value(url, target, options, formatter), stream_value(url, target, options, formatter), and stream_data(url, target, options, formatter) helpers so a bookmark can bind saved Ajax endpoints into DOM targets without hand-writing the fetch and render boilerplate. stream_data() and stream_value() now use XMLHttpRequest progress events for browser-visible incremental updates, so a saved /ajax/... endpoint that prints early output updates the DOM before the request finishes.

Those helpers support plain text, JSON, and HTML output. Saved Ajax bindings are available after the page declares its endpoint root, so $(document).ready(...) callbacks can call helpers such as fetch_value(endpoints.foo, '#foo') on first render.

For response inspection panels, place the Response Body and Response Headers tabs below the response pre box. This keeps the main response visible while the details remain accessible.

User CLI Extensions

Unknown top-level subcommands can be provided by executable files under the current working directory's ./.developer-dashboard/cli first, then the nearest git-backed project runtime ./.developer-dashboard/cli when it is a different directory, and then ~/.developer-dashboard/cli. For example, d2 foobar a b will exec the first matching cli/foobar with a b as argv, while preserving stdin, stdout, and stderr.

A direct custom command can also be stored as an executable cli/<command>.pl, cli/<command>.py, cli/<command>.js, cli/<command>.go, cli/<command>.java, cli/<command>.sh, cli/<command>.bash, cli/<command>.ps1, cli/<command>.cmd, or cli/<command>.bat, and d2 <command> resolves the same logical command name to those files.

Concrete source-backed examples:

d2 hi
d2 foo

If cli/hi.go is executable, d2 hi runs it through go run. If cli/report.py is executable, d2 report runs it through python.

If cli/webhook.js is executable, d2 webhook runs it through node. If cli/foo.java is executable, d2 foo compiles it with javac into an isolated temp directory and then runs the declared main class with java.

To demonstrate a custom update command with a hook, create both files in a runtime CLI layer and then invoke the switchboard:

mkdir -p ~/.developer-dashboard/cli/update.d
printf '#!/usr/bin/env perl\nprint "custom update\\n";\n' > ~/.developer-dashboard/cli/update
chmod +x ~/.developer-dashboard/cli/update
printf '#!/bin/sh\nprintf "before update\\n"\n' > ~/.developer-dashboard/cli/update.d/01-log
chmod +x ~/.developer-dashboard/cli/update.d/01-log
perl -Ilib bin/d2 update

The command file is user-provided, not a built-in. The hook runs before it; project-local runtime layers take precedence over the home layer.

If a user mistypes a command, dashboard now prints an explicit unknown-command error together with the closest matching public command before the usual usage summary. The same guidance also applies to dotted skill commands, so d2 alpha-skill.run-tset suggests the nearest installed dotted skill command instead of only dumping generic help.

Built-in command help and completion

Every dashboard-managed built-in command and its public actions use one help catalogue. Request help with --help, -h, or a trailing help, for example d2 api add --help, d2 api add help, or the global form d2 help docker development enable.

The public version command also supports d2 version --help and global d2 help version. Bare d2 help, d2 --help, and d2 -h print a concise index of public built-in commands instead of the full module manual.

Top-level TAB completion lists commands and dotted skill commands; path aliases are offered in the d2 workspace <alias> position instead of being mixed into the command list. Help is returned before the built-in command body runs, while the normal main and per-command hook order is preserved. The global help form and command help include actionable usage and the available action/options where applicable.

The same catalogue supplies TAB candidates for public commands, nested actions, and supported option flags. Bash and zsh call the live d2 complete helper, so their candidates stay aligned with the command catalogue rather than maintaining separate shell-side action lists. Existing dynamic completions for skills, workspace sessions, collectors, and workspace path aliases remain available.

When a skill with the same name exists in project and home runtime layers, its dotted command candidates are merged from every participating layer and duplicate command names appear once; execution still uses the normal deepest-layer lookup.

cdr TAB completion lists aliases and direct child directories. Each entered narrowing term descends one matching directory level before suggesting the next child, avoiding recursive scans of unrelated repository and dependency trees. When a command has a default action, the root help and completion also expose that action's options; for example, d2 api --key helper-bot -o json lists API keys without requiring the explicit ls action.

DD-OOP-LAYERS is now the runtime contract for the whole local ecosystem. Starting at the home directory and walking down through every parent directory until the current working directory, every existing .developer-dashboard/ and .d2/ runtime directory participates. When both names exist at the same depth, both are searched independently; .developer-dashboard/ has priority over .d2/ at that depth and remains the write target.

The deepest available runtime root is the write target, but bookmarks, nav/*.tt, config, collectors, indicators, auth/session state lookups, runtime local/lib/perl5, Docker Compose service folders, skills, and custom CLI hooks are inherited across the full chain instead of only a single project-or-home split.

Per-command hooks can live in cli/<command> or cli/<command>.d at each runtime layer, from home to the current directory.

Executable hooks run in sorted order within each layer. Layers run from home to the deepest active directory, and non-executable files are skipped.

Hook output streams to the terminal and is also accumulated as JSON in RESULT.

If that JSON grows too large for a safe exec() environment, d2 spills it into RESULT_FILE and Developer::Dashboard::Runtime::Result reads the same logical payload from there so later hooks and the final command still see the same result set without tripping Argument list too long. Built-in commands such as d2 jq use the same hook directory.

A directory-backed custom command can provide its real executable as ~/.developer-dashboard/cli/<command>/run, and that runner receives the final RESULT plus LAST_RESULT environment variables.

After each hook finishes, the updated RESULT JSON is written back into the environment before the next sorted hook starts, and LAST_RESULT is rewritten to the structured result for the hook that just ran, so later hook scripts can react to earlier hook output and also inspect the immediate previous hook in a stable shape. LAST_RESULT carries file, exit, STDOUT, and STDERR.

Only an explicit [[STOP]] marker in one hook's stderr stops the remaining hook files for that command. A non-zero exit code alone is still recorded, but it does not skip later hooks.

Executable .py hook files and direct .py custom commands run through python. Executable .js hook files and direct .js custom commands run through node.

Executable .go hook files and direct .go custom commands run through go run. Executable .java hook files and direct .java custom commands are compiled with javac into an isolated temp directory and then run through java using the declared main class from the source file.

Perl hook code can use Runtime::Result to decode RESULT safely, read the immediate last_result, and inspect per-hook stdout, stderr, exit codes, or the last recorded hook entry. If a Perl-backed command wants a compact final summary after its hook files run, it can also call Developer::Dashboard::Runtime::Result->report() to print a simple success/error report for each sorted hook file.

Open File Commands

d2 of is the shorthand name for d2 open-file.

These commands support:

  • direct file paths

  • file:line references

  • Perl module names such as My::Module, resolved against every directory in the running Perl's @INC

  • Java class names such as com.example.App or javax.jws.WebService

  • recursive regex searches inside a resolved directory alias or path

  • recursive content searches with d2 of grep -nr <pattern> <directory>

Without --print, d2 of and d2 open-file now behave like the older picker workflow again: one unique match opens directly in --editor, VISUAL, EDITOR, or vim as the final fallback, and multiple matches render a numbered prompt. At that prompt you can press Enter to open all matches with vim -p, type one number to open one file, type comma-separated numbers such as 1,3, or use a range such as 2-5.

Scoped searches also rank exact helper/script names before broader regex hits, so d2 of . jq lists jq and jq.js ahead of jquery.js.

Every scoped search token is treated as a case-insensitive regex, so d2 of . 'Ok\.js$' matches ok.js but not ok.json. Content grep passes arguments directly to the system grep executable (no shell expansion), adds filename and line-number output for reliable file selection, then opens the unique matching files using the same chooser. Add --print before grep to print the unique paths without opening an editor.

Java class lookup first checks live .java files under the current project, workspace roots, and @INC-adjacent source trees. If no live source file exists, it also searches local source archives such as -sources.jar, -src.jar, src.zip, war, and jar files under the current roots, ~/.m2/repository, Gradle caches, and JAVA_HOME.

When a local archive still does not provide the requested class, the helper can fetch a matching Maven source jar, cache it under ~/.developer-dashboard/cache/open-file/, and then open the extracted Java source.

Data Query Commands

These built-in commands parse structured text and can then either extract a dotted path or evaluate a Perl expression against the decoded document through $d:

  • d2 jq [path] [file] for JSON

  • d2 yq [path] [file] for YAML

  • d2 tomq [path] [file] for TOML

  • d2 propq [path] [file] for Java properties

  • d2 iniq [path] [file] for INI

  • d2 csvq [path] [file] for CSV

  • d2 xmlq [path] [file] for XML

If the selected value is a hash or array, the command prints canonical JSON. If the selected value is a scalar, it prints the scalar plus a trailing newline.

The file path and query text are order-independent, and $d selects the whole parsed document. For example, cat file.json | d2 jq '$d' and d2 jq file.json '$d' return the same result.

If the query text uses $d inside a Perl expression, the command evaluates that expression against the decoded document. For example, echo '{"foo":[1],"bar":[2]}' | dashboard jq 'sort keys %$d' prints ["bar","foo"].

The same contract applies to yq, tomq, propq, iniq, csvq, and xmlq.

xmlq follows the same decoded-data model as the other query commands. XML elements decode into nested hashes and arrays, repeated sibling tags become arrays, attributes live under _attributes, and mixed text lives under _text. That means printf '<root<value>demo</value></root>' | dashboard xmlq root.value> prints demo, while d2 xmlq feed.xml '$d' prints the full decoded XML tree as canonical JSON.

A terminal session: a small CSV file of three products is shown, then d2 csvq returns its first row as JSON, and the price of the second row by its path, 4.25.

csvq reads a CSV file as data: a row comes back as JSON, and a single cell by its path.

SEE ALSO

Developer::Dashboard