@blackbelt-technology/pi-dashboard-extension 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pi/skills/browser/LICENSE +201 -0
- package/.pi/skills/browser/SKILL.md +105 -0
- package/.pi/skills/browser/UPSTREAM.md +46 -0
- package/.pi/skills/browser/references/electron.md +351 -0
- package/.pi/skills/browser/references/web.md +2789 -0
- package/.pi/skills/browser/scripts/detect-dashboard.sh +55 -0
- package/.pi/skills/doctor/AGENTS.md +27 -0
- package/.pi/skills/doctor/SKILL.md +89 -0
- package/.pi/skills/doctor/_lib/checks.ts +177 -0
- package/.pi/skills/doctor/_lib/derive-tokens.ts +43 -0
- package/.pi/skills/doctor/_lib/front-matter.ts +122 -0
- package/.pi/skills/doctor/_lib/index.ts +14 -0
- package/.pi/skills/doctor/_lib/knowledge-hash.ts +74 -0
- package/.pi/skills/doctor/_lib/provenance.ts +50 -0
- package/.pi/skills/doctor/_lib/regenerate.ts +100 -0
- package/.pi/skills/doctor/_lib/router.ts +155 -0
- package/.pi/skills/doctor/_lib/server-tier.ts +62 -0
- package/.pi/skills/doctor/modules/build-reload.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/build-reload.md +51 -0
- package/.pi/skills/doctor/modules/env-node.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/env-node.md +49 -0
- package/.pi/skills/doctor/modules/install-topology.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/install-topology.md +53 -0
- package/.pi/skills/doctor/modules/model-resolution.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/model-resolution.md +53 -0
- package/.pi/skills/doctor/modules/peers.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/peers.md +57 -0
- package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/pi-resolution.md +60 -0
- package/.pi/skills/doctor/modules/plugins-bridges.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/plugins-bridges.md +56 -0
- package/.pi/skills/pi-dashboard/SKILL.md +68 -0
- package/.pi/skills/pi-dashboard/commands/README.md +45 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-flow-abort.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-flow-auto.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-branches.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-init.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-stash-pop.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-list-models.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-peer-list.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-peer-scan.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-pin-list.md +5 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-archive.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-attach.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-detach.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-config.md +5 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-health.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-off.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-on.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-status.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-abort-all.md +14 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-abort.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-diff.md +11 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-fork.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-hide.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-info.md +11 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-kill.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list-active.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list-here.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-model.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-rename.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-resume.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-spawn.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-tell.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-thinking.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-unhide.md +10 -0
- package/.pi/skills/pi-dashboard/references/api-reference.md +30 -0
- package/.pi/skills/pi-dashboard/references/recipes.md +38 -0
- package/.pi/skills/pi-dashboard/references/slash-commands.md +71 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-api.sh +6 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +217 -0
- package/.pi/skills/project-init/SKILL.md +279 -0
- package/.pi/skills/project-init/dox-doctrine.md +104 -0
- package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +111 -0
- package/.pi/skills/project-init/profiles/coding/profile.json +5 -0
- package/.pi/skills/project-init/profiles/coding/prompts/plan-change.md +5 -0
- package/.pi/skills/project-init/profiles/coding/prompts/tdd-loop.md +6 -0
- package/.pi/skills/project-init/profiles/coding/settings.json.tmpl +9 -0
- package/.pi/skills/project-init/profiles/docs/AGENTS.md.tmpl +37 -0
- package/.pi/skills/project-init/profiles/docs/profile.json +4 -0
- package/.pi/skills/project-init/profiles/docs/prompts/draft-page.md +5 -0
- package/.pi/skills/project-init/profiles/docs/settings.json.tmpl +9 -0
- package/package.json +12 -4
- package/src/AGENTS.md +56 -0
- package/src/__tests__/abort-latch.test.ts +97 -0
- package/src/__tests__/agent-settled.test.ts +82 -0
- package/src/__tests__/artifact-roots.test.ts +83 -0
- package/src/__tests__/ask-user-attachments.test.ts +106 -0
- package/src/__tests__/ask-user-tool.test.ts +90 -27
- package/src/__tests__/auto-session-namer.test.ts +339 -0
- package/src/__tests__/bridge-default-model-apply.test.ts +242 -0
- package/src/__tests__/bridge-default-model-gate.test.ts +50 -0
- package/src/__tests__/bridge-followup-chat-order.test.ts +215 -0
- package/src/__tests__/bridge-followup-multi-entry.test.ts +202 -0
- package/src/__tests__/bridge-followup-mutation.test.ts +217 -0
- package/src/__tests__/bridge-followup-queue-drain.test.ts +266 -0
- package/src/__tests__/bridge-hasui-flip.test.ts +109 -0
- package/src/__tests__/bridge-no-queue-mutation.test.ts +112 -0
- package/src/__tests__/bridge-plugin-emit-event.test.ts +44 -0
- package/src/__tests__/bridge-queue-update-forward.test.ts +77 -0
- package/src/__tests__/bridge-shadow-queue-gate.test.ts +299 -0
- package/src/__tests__/bridge-shutdown-reset.test.ts +159 -0
- package/src/__tests__/bridge-slash-command-routing.test.ts +127 -31
- package/src/__tests__/bridge-stop-after-turn.test.ts +72 -0
- package/src/__tests__/bridge-system-followup.test.ts +163 -0
- package/src/__tests__/bridge-thinking-level-select.test.ts +68 -0
- package/src/__tests__/browser-skill-registered.test.ts +84 -0
- package/src/__tests__/build-provider-catalogue.test.ts +35 -1
- package/src/__tests__/command-handler.test.ts +427 -29
- package/src/__tests__/commit-draft.test.ts +100 -0
- package/src/__tests__/connection-dropped-frames.test.ts +78 -0
- package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +128 -0
- package/src/__tests__/cwd-missing-probe.test.ts +82 -0
- package/src/__tests__/dashboard-commands-shipped.test.ts +53 -0
- package/src/__tests__/dashboard-context-injector.test.ts +190 -0
- package/src/__tests__/doctor/checks.test.ts +121 -0
- package/src/__tests__/doctor/modules.test.ts +64 -0
- package/src/__tests__/doctor/provenance-hash.test.ts +94 -0
- package/src/__tests__/doctor/router.test.ts +143 -0
- package/src/__tests__/empty-actionable-guard-config.test.ts +32 -0
- package/src/__tests__/empty-actionable-guard.test.ts +73 -0
- package/src/__tests__/enrich-model-metadata.test.ts +21 -0
- package/src/__tests__/extension-slash-command-detection.test.ts +37 -1
- package/src/__tests__/filter-enabled-models.test.ts +151 -0
- package/src/__tests__/fixtures/turn-actionability-fixtures.ts +69 -0
- package/src/__tests__/git-info-status.test.ts +73 -0
- package/src/__tests__/git-poll.test.ts +69 -0
- package/src/__tests__/markdown-image-inliner.test.ts +37 -0
- package/src/__tests__/model-resolve.test.ts +379 -0
- package/src/__tests__/pi-version-tracker.test.ts +109 -0
- package/src/__tests__/process-scanner.test.ts +112 -22
- package/src/__tests__/project-init-detect-stack.test.ts +61 -0
- package/src/__tests__/project-init-dox-kb-config.test.ts +53 -0
- package/src/__tests__/project-init-profiles.test.ts +84 -0
- package/src/__tests__/project-init-scaffold.test.ts +139 -0
- package/src/__tests__/project-init-seed-doctrine.test.ts +100 -0
- package/src/__tests__/project-trust.test.ts +92 -0
- package/src/__tests__/prompt-expander.test.ts +191 -1
- package/src/__tests__/provider-register-reload.test.ts +36 -6
- package/src/__tests__/provider-register-thinking-levels.test.ts +51 -0
- package/src/__tests__/retry-tracker.test.ts +75 -70
- package/src/__tests__/role-manager.test.ts +585 -0
- package/src/__tests__/role-model-tools-registry-readiness.test.ts +114 -0
- package/src/__tests__/role-model-tools.test.ts +229 -0
- package/src/__tests__/search-files-completeness.test.ts +111 -0
- package/src/__tests__/search-files-ranking.test.ts +168 -0
- package/src/__tests__/server-auto-start.test.ts +121 -4
- package/src/__tests__/server-launcher-launch.test.ts +24 -6
- package/src/__tests__/server-launcher.test.ts +19 -2
- package/src/__tests__/session-sync.test.ts +36 -0
- package/src/__tests__/source-detector.test.ts +15 -0
- package/src/__tests__/subagent-frame-buffer.test.ts +239 -0
- package/src/__tests__/tool-result-image-inliner.test.ts +206 -0
- package/src/__tests__/tui-prompt-adapter.test.ts +70 -64
- package/src/__tests__/turn-actionability.test.ts +86 -0
- package/src/__tests__/vcs-info.test.ts +145 -4
- package/src/__tests__/visibility-intent.test.ts +43 -0
- package/src/abort-latch.ts +55 -0
- package/src/abort-latch.ts.AGENTS.md +3 -0
- package/src/agent-settled.ts +72 -0
- package/src/agent-settled.ts.AGENTS.md +3 -0
- package/src/artifact-roots.ts +73 -0
- package/src/artifact-roots.ts.AGENTS.md +3 -0
- package/src/ask-user-attachments.ts +121 -0
- package/src/ask-user-attachments.ts.AGENTS.md +3 -0
- package/src/ask-user-tool.ts +56 -58
- package/src/ask-user-tool.ts.AGENTS.md +3 -0
- package/src/auto-session-namer.ts +334 -0
- package/src/auto-session-namer.ts.AGENTS.md +3 -0
- package/src/bridge-context.ts +86 -8
- package/src/bridge-context.ts.AGENTS.md +3 -0
- package/src/bridge-default-model-gate.ts +48 -0
- package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
- package/src/bridge.ts +1373 -213
- package/src/bridge.ts.AGENTS.md +3 -0
- package/src/canvas-tool.ts +107 -0
- package/src/command-handler.ts +527 -42
- package/src/command-handler.ts.AGENTS.md +3 -0
- package/src/commit-draft-agent.ts +114 -0
- package/src/commit-draft-agent.ts.AGENTS.md +3 -0
- package/src/commit-draft.ts +136 -0
- package/src/commit-draft.ts.AGENTS.md +3 -0
- package/src/connection.ts +32 -1
- package/src/connection.ts.AGENTS.md +3 -0
- package/src/dashboard-context-injector.ts +124 -0
- package/src/dashboard-context-injector.ts.AGENTS.md +3 -0
- package/src/dashboard-default-adapter.ts +5 -0
- package/src/dashboard-default-adapter.ts.AGENTS.md +3 -0
- package/src/dev-build.ts.AGENTS.md +3 -0
- package/src/empty-actionable-guard-config.ts +32 -0
- package/src/empty-actionable-guard-config.ts.AGENTS.md +3 -0
- package/src/empty-actionable-guard.ts +90 -0
- package/src/empty-actionable-guard.ts.AGENTS.md +3 -0
- package/src/event-forwarder.ts.AGENTS.md +3 -0
- package/src/flow-event-wiring.ts +4 -14
- package/src/flow-event-wiring.ts.AGENTS.md +3 -0
- package/src/git-link-builder.ts.AGENTS.md +3 -0
- package/src/git-poll.ts +38 -0
- package/src/git-poll.ts.AGENTS.md +3 -0
- package/src/hasui-flip.ts +56 -0
- package/src/hasui-flip.ts.AGENTS.md +3 -0
- package/src/markdown-image-inliner.ts +45 -2
- package/src/markdown-image-inliner.ts.AGENTS.md +3 -0
- package/src/model-tracker.ts +145 -19
- package/src/model-tracker.ts.AGENTS.md +3 -0
- package/src/multiselect-decode.ts.AGENTS.md +3 -0
- package/src/multiselect-list.ts.AGENTS.md +3 -0
- package/src/multiselect-polyfill.ts.AGENTS.md +3 -0
- package/src/process-metrics.ts.AGENTS.md +3 -0
- package/src/process-scanner.ts +114 -103
- package/src/process-scanner.ts.AGENTS.md +3 -0
- package/src/project-init/AGENTS.md +12 -0
- package/src/project-init/detect-stack.ts +146 -0
- package/src/project-init/dox-kb-config.ts +47 -0
- package/src/project-init/profiles.ts +135 -0
- package/src/project-init/scaffold.ts +192 -0
- package/src/project-init/seed-doctrine.ts +95 -0
- package/src/project-trust.ts +63 -0
- package/src/project-trust.ts.AGENTS.md +3 -0
- package/src/prompt-bus.ts +25 -1
- package/src/prompt-bus.ts.AGENTS.md +3 -0
- package/src/prompt-expander.ts +238 -37
- package/src/prompt-expander.ts.AGENTS.md +3 -0
- package/src/provider-register.ts +323 -54
- package/src/provider-register.ts.AGENTS.md +3 -0
- package/src/retry-tracker.ts +64 -39
- package/src/retry-tracker.ts.AGENTS.md +3 -0
- package/src/role-manager.ts +436 -0
- package/src/role-manager.ts.AGENTS.md +3 -0
- package/src/role-model-tools.ts +301 -0
- package/src/role-model-tools.ts.AGENTS.md +3 -0
- package/src/server-auto-start.ts +59 -23
- package/src/server-auto-start.ts.AGENTS.md +3 -0
- package/src/server-launcher.ts +56 -16
- package/src/server-launcher.ts.AGENTS.md +3 -0
- package/src/session-sync.ts +111 -15
- package/src/session-sync.ts.AGENTS.md +3 -0
- package/src/slash-dispatch.ts +32 -15
- package/src/slash-dispatch.ts.AGENTS.md +3 -0
- package/src/source-detector.ts +13 -5
- package/src/source-detector.ts.AGENTS.md +3 -0
- package/src/subagent-frame-buffer.ts +220 -0
- package/src/subagent-frame-buffer.ts.AGENTS.md +3 -0
- package/src/tool-result-image-inliner.ts +204 -0
- package/src/tool-result-image-inliner.ts.AGENTS.md +3 -0
- package/src/tui-prompt-adapter.ts +123 -0
- package/src/tui-prompt-adapter.ts.AGENTS.md +3 -0
- package/src/turn-actionability.ts +117 -0
- package/src/turn-actionability.ts.AGENTS.md +3 -0
- package/src/ui-modules.ts.AGENTS.md +3 -0
- package/src/vcs-info.ts +91 -129
- package/src/vcs-info.ts.AGENTS.md +3 -0
- package/src/visibility-intent.ts +34 -0
- package/src/visibility-intent.ts.AGENTS.md +3 -0
- package/src/__tests__/usage-limit-orderer.test.ts +0 -105
- package/src/__tests__/vcs-info-jj.test.ts +0 -145
- package/src/usage-limit-orderer.ts +0 -76
package/src/prompt-expander.ts
CHANGED
|
@@ -10,7 +10,22 @@ import { dirname, join } from "node:path";
|
|
|
10
10
|
import { readdirSync, statSync } from "node:fs";
|
|
11
11
|
import { buildSkillBlock } from "@blackbelt-technology/pi-dashboard-shared/skill-block-parser.js";
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Scan directories for .md prompt template files.
|
|
15
|
+
*
|
|
16
|
+
* Resolution path (in precedence order, consumed by resolveTemplate):
|
|
17
|
+
* 1. `<cwd>/.pi/prompts/*.md` — flat prompt templates, keyed by basename.
|
|
18
|
+
* 2. `<cwd>/.pi/skills/<skill>/SKILL.md` — keyed `skill:<skill>`.
|
|
19
|
+
* 3. `<cwd>/.pi/skills/<skill>/commands/*.md` — skill-bundled slash commands,
|
|
20
|
+
* keyed by basename (e.g. `dashboard-server-health`). Scanned directly
|
|
21
|
+
* because pi.getCommands() does not reliably surface nested skill command
|
|
22
|
+
* files across pi versions. See change: add-dashboard-slash-commands.
|
|
23
|
+
* 4. pi.getCommands() registry (skills + global/project/package prompt
|
|
24
|
+
* templates) — consulted as a fallback in resolveTemplate via sourceInfo.path.
|
|
25
|
+
* `loadPromptTemplate` additionally harvests each registry skill's
|
|
26
|
+
* `commands/*.md` (via `addSkillCommandsFromRegistry`) so bundled commands
|
|
27
|
+
* resolve when cwd is not the extension install dir.
|
|
28
|
+
*/
|
|
14
29
|
function findPromptTemplates(cwd: string): Map<string, string> {
|
|
15
30
|
const templates = new Map<string, string>();
|
|
16
31
|
const dirs = [
|
|
@@ -38,6 +53,13 @@ function scanDir(dir: string, templates: Map<string, string>): void {
|
|
|
38
53
|
if (existsSync(skillFile)) {
|
|
39
54
|
templates.set(`skill:${entry}`, skillFile);
|
|
40
55
|
}
|
|
56
|
+
// Skill-bundled slash commands live in `<skill>/commands/*.md`.
|
|
57
|
+
// pi.getCommands() does not reliably surface these nested files
|
|
58
|
+
// across pi versions, so scan them directly (exactly one level
|
|
59
|
+
// into `commands/`). Each file is keyed by its basename so
|
|
60
|
+
// `/dashboard:server-health` resolves `dashboard-server-health.md`.
|
|
61
|
+
// See change: add-dashboard-slash-commands.
|
|
62
|
+
scanCommandsSubdir(join(fullPath, "commands"), templates);
|
|
41
63
|
} else if (entry.endsWith(".md")) {
|
|
42
64
|
const name = entry.replace(/\.md$/, "");
|
|
43
65
|
templates.set(name, fullPath);
|
|
@@ -46,12 +68,117 @@ function scanDir(dir: string, templates: Map<string, string>): void {
|
|
|
46
68
|
}
|
|
47
69
|
}
|
|
48
70
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Harvest skill-bundled `commands/*.md` from `pi.getCommands()` so they resolve
|
|
73
|
+
* regardless of the session's cwd. End-user / Docker sessions run with cwd set
|
|
74
|
+
* to the user's project (NOT the extension install dir), so the cwd scan never
|
|
75
|
+
* sees the bundled skill. `pi.getCommands()` surfaces each skill dir via
|
|
76
|
+
* `sourceInfo.path` (its SKILL.md); we scan that dir's sibling `commands/`.
|
|
77
|
+
* Keyed by basename; does not clobber a cwd-local template of the same name.
|
|
78
|
+
* See change: add-dashboard-slash-commands.
|
|
79
|
+
*/
|
|
80
|
+
function addSkillCommandsFromRegistry(pi: any | undefined, templates: Map<string, string>): void {
|
|
81
|
+
if (!pi?.getCommands) return;
|
|
82
|
+
try {
|
|
83
|
+
const cmds = pi.getCommands();
|
|
84
|
+
if (!Array.isArray(cmds)) return;
|
|
85
|
+
for (const c of cmds) {
|
|
86
|
+
if (c?.source !== "skill") continue;
|
|
87
|
+
const p = c?.sourceInfo?.path ?? c?.path;
|
|
88
|
+
if (typeof p !== "string" || p.length === 0) continue;
|
|
89
|
+
// `p` points at the skill's SKILL.md (or its dir). Derive the dir.
|
|
90
|
+
const skillDir = p.endsWith(".md") ? dirname(p) : p;
|
|
91
|
+
scanCommandsSubdir(join(skillDir, "commands"), templates);
|
|
92
|
+
}
|
|
93
|
+
} catch { /* ignore */ }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Scan a skill's `commands/` subdir (one level) for `.md` templates. */
|
|
97
|
+
function scanCommandsSubdir(commandsDir: string, templates: Map<string, string>): void {
|
|
98
|
+
if (!existsSync(commandsDir)) return;
|
|
99
|
+
try {
|
|
100
|
+
for (const entry of readdirSync(commandsDir)) {
|
|
101
|
+
if (!entry.endsWith(".md")) continue;
|
|
102
|
+
const fullPath = join(commandsDir, entry);
|
|
103
|
+
try {
|
|
104
|
+
if (!statSync(fullPath).isFile()) continue;
|
|
105
|
+
} catch { continue; }
|
|
106
|
+
const name = entry.replace(/\.md$/, "");
|
|
107
|
+
// Do not clobber a top-level prompt/skill of the same name.
|
|
108
|
+
if (!templates.has(name)) templates.set(name, fullPath);
|
|
109
|
+
}
|
|
110
|
+
} catch { /* ignore */ }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Typed frontmatter recognised on prompt templates. Only these three keys are
|
|
115
|
+
* interpreted; every other key is ignored for forward compatibility so future
|
|
116
|
+
* fields (e.g. `format:`, `priority:`) never break older bridges.
|
|
117
|
+
* See change: add-dashboard-slash-commands.
|
|
118
|
+
*/
|
|
119
|
+
export interface PromptFrontmatter {
|
|
120
|
+
/** Opt-in executable mode. v1 supports only the literal "bash". */
|
|
121
|
+
executable?: "bash";
|
|
122
|
+
/** When true, output is NOT appended to LLM context (mirrors `!!`). */
|
|
123
|
+
excludeFromContext?: boolean;
|
|
124
|
+
/** Cosmetic description (autocomplete tooltip — not used in v1). */
|
|
125
|
+
description?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Parse a YAML-lite frontmatter block (line-oriented `key: value`, no nesting,
|
|
130
|
+
* no lists). Unknown keys are ignored. Malformed lines (no colon) are skipped
|
|
131
|
+
* rather than throwing. `executable` accepts only the literal "bash"; any other
|
|
132
|
+
* value is dropped (template degrades to LLM mode).
|
|
133
|
+
* See change: add-dashboard-slash-commands.
|
|
134
|
+
*/
|
|
135
|
+
function parseFrontmatterBlock(block: string): PromptFrontmatter {
|
|
136
|
+
const fm: PromptFrontmatter = {};
|
|
137
|
+
for (const rawLine of block.split("\n")) {
|
|
138
|
+
const line = rawLine.trim();
|
|
139
|
+
if (!line || line.startsWith("#")) continue;
|
|
140
|
+
const idx = line.indexOf(":");
|
|
141
|
+
if (idx === -1) continue; // key without colon → ignore (forward-compat)
|
|
142
|
+
const key = line.slice(0, idx).trim();
|
|
143
|
+
let value = line.slice(idx + 1).trim();
|
|
144
|
+
if (
|
|
145
|
+
value.length >= 2 &&
|
|
146
|
+
((value.startsWith('"') && value.endsWith('"')) ||
|
|
147
|
+
(value.startsWith("'") && value.endsWith("'")))
|
|
148
|
+
) {
|
|
149
|
+
value = value.slice(1, -1);
|
|
150
|
+
}
|
|
151
|
+
switch (key) {
|
|
152
|
+
case "executable":
|
|
153
|
+
if (value === "bash") fm.executable = "bash";
|
|
154
|
+
// Unsupported values (node, python, …) intentionally ignored → LLM mode.
|
|
155
|
+
break;
|
|
156
|
+
case "excludeFromContext":
|
|
157
|
+
if (value === "true") fm.excludeFromContext = true;
|
|
158
|
+
else if (value === "false") fm.excludeFromContext = false;
|
|
159
|
+
break;
|
|
160
|
+
case "description":
|
|
161
|
+
fm.description = value;
|
|
162
|
+
break;
|
|
163
|
+
// Unknown keys ignored (forward compat).
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return fm;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Read template content, parsing YAML frontmatter into a typed object and
|
|
171
|
+
* returning the body separately. An unclosed / absent frontmatter block yields
|
|
172
|
+
* empty frontmatter and the whole content as body (graceful fall-back to LLM).
|
|
173
|
+
*/
|
|
174
|
+
function readTemplate(filePath: string): { frontmatter: PromptFrontmatter; body: string } {
|
|
51
175
|
const content = readFileSync(filePath, "utf-8");
|
|
52
|
-
//
|
|
53
|
-
const match = content.match(/^---\n[\s\S]
|
|
54
|
-
|
|
176
|
+
// Capture both the frontmatter block (group 1) and the body (group 2).
|
|
177
|
+
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
178
|
+
if (match) {
|
|
179
|
+
return { frontmatter: parseFrontmatterBlock(match[1]), body: match[2].trim() };
|
|
180
|
+
}
|
|
181
|
+
return { frontmatter: {}, body: content.trim() };
|
|
55
182
|
}
|
|
56
183
|
|
|
57
184
|
/**
|
|
@@ -101,15 +228,38 @@ function resolveTemplate(
|
|
|
101
228
|
if (localSkill) {
|
|
102
229
|
return { filePath: localSkill, source: "skill", resolvedName: cand };
|
|
103
230
|
}
|
|
104
|
-
// Step 3: pi.getCommands() registry skill.
|
|
231
|
+
// Step 3: pi.getCommands() registry skill / prompt template.
|
|
105
232
|
if (pi?.getCommands) {
|
|
106
233
|
try {
|
|
107
|
-
const
|
|
234
|
+
const commandsRaw = pi.getCommands();
|
|
235
|
+
const commands = Array.isArray(commandsRaw) ? commandsRaw : [];
|
|
236
|
+
// pi's getCommands() carries the on-disk path under `sourceInfo.path`
|
|
237
|
+
// (synthetic SourceInfo: { path, source, scope, origin, baseDir }).
|
|
238
|
+
// Older builds / unit stubs use a top-level `path`. Accept both.
|
|
239
|
+
// Guard the type: a malformed entry with a non-string path must not
|
|
240
|
+
// throw in existsSync (which would abort the loop and shadow an
|
|
241
|
+
// otherwise-resolvable entry). See change:
|
|
242
|
+
// resolve-global-prompt-templates-from-dashboard.
|
|
243
|
+
const cmdPath = (c: any): string | undefined => {
|
|
244
|
+
const p = c?.sourceInfo?.path ?? c?.path;
|
|
245
|
+
return typeof p === "string" && p.length > 0 ? p : undefined;
|
|
246
|
+
};
|
|
108
247
|
const skill = commands.find(
|
|
109
|
-
(c: any) => c.name === cand && c.source === "skill" && c
|
|
248
|
+
(c: any) => c.name === cand && c.source === "skill" && cmdPath(c),
|
|
110
249
|
);
|
|
111
|
-
|
|
112
|
-
|
|
250
|
+
const skillPath = skill && cmdPath(skill);
|
|
251
|
+
if (skillPath && existsSync(skillPath)) {
|
|
252
|
+
return { filePath: skillPath, source: "skill", resolvedName: cand };
|
|
253
|
+
}
|
|
254
|
+
// Global/project/package prompt templates register as source: "prompt".
|
|
255
|
+
// pi.getCommands() already carries their absolute path — no fs scan added.
|
|
256
|
+
// Probed inside the same candidate loop so original-form-first precedence holds.
|
|
257
|
+
const prompt = commands.find(
|
|
258
|
+
(c: any) => c.name === cand && c.source === "prompt" && cmdPath(c),
|
|
259
|
+
);
|
|
260
|
+
const promptPath = prompt && cmdPath(prompt);
|
|
261
|
+
if (promptPath && existsSync(promptPath)) {
|
|
262
|
+
return { filePath: promptPath, source: "prompt", resolvedName: cand };
|
|
113
263
|
}
|
|
114
264
|
} catch { /* ignore */ }
|
|
115
265
|
}
|
|
@@ -118,14 +268,54 @@ function resolveTemplate(
|
|
|
118
268
|
}
|
|
119
269
|
|
|
120
270
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
271
|
+
* Assemble the LLM-bound text for a resolved template: skill templates get the
|
|
272
|
+
* skill-block wrapper, plain prompt templates append args after a blank line.
|
|
273
|
+
*/
|
|
274
|
+
function assembleLlmText(resolution: Resolution, body: string, argsString: string): string {
|
|
275
|
+
if (resolution.source === "skill") {
|
|
276
|
+
// Strip leading `skill:` prefix (only present for local-scan step-1 hits
|
|
277
|
+
// whose key was `skill:<dir>`); registry hits and step-2 hits already
|
|
278
|
+
// hold the bare name.
|
|
279
|
+
const bareName = resolution.resolvedName.replace(/^skill:/, "");
|
|
280
|
+
return buildSkillBlock({
|
|
281
|
+
name: bareName,
|
|
282
|
+
filePath: resolution.filePath,
|
|
283
|
+
baseDir: dirname(resolution.filePath),
|
|
284
|
+
body,
|
|
285
|
+
userArgs: argsString || undefined,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
// Plain prompt templates: append args after a blank line, no wrapper.
|
|
289
|
+
if (argsString) return `${body}\n\n${argsString}`;
|
|
290
|
+
return body;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Discriminated result of resolving a slash command to a prompt template.
|
|
295
|
+
* - `llm`: expand to user-message text and route through the LLM (default).
|
|
296
|
+
* - `exec`: run the body as bash and skip the LLM entirely (`executable: bash`).
|
|
297
|
+
* `null` when no template matched the typed slash command.
|
|
298
|
+
* See change: add-dashboard-slash-commands.
|
|
299
|
+
*/
|
|
300
|
+
export type LoadedPromptTemplate =
|
|
301
|
+
| { kind: "llm"; text: string }
|
|
302
|
+
| { kind: "exec"; body: string; excludeFromContext: boolean; argsString: string };
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Resolve a slash command to its template and classify it as LLM-bound or
|
|
306
|
+
* executable. Templates carrying `executable: bash` frontmatter resolve to
|
|
307
|
+
* `kind: "exec"`; everything else (including unsupported `executable:` values)
|
|
308
|
+
* resolves to `kind: "llm"`. Returns `null` when no template matched.
|
|
309
|
+
*
|
|
310
|
+
* Resolution path: local `.pi/prompts` + `.pi/skills` scan first, then
|
|
311
|
+
* `pi.getCommands()` (which already carries skill/prompt template paths under
|
|
312
|
+
* `sourceInfo.path`). See change: add-dashboard-slash-commands.
|
|
123
313
|
*
|
|
124
314
|
* @param pi Optional pi extension API — used to find globally installed skills
|
|
125
315
|
* and package skills via pi.getCommands() when local scan misses them.
|
|
126
316
|
*/
|
|
127
|
-
export function
|
|
128
|
-
if (!text.startsWith("/")) return
|
|
317
|
+
export function loadPromptTemplate(text: string, cwd: string, pi?: any): LoadedPromptTemplate | null {
|
|
318
|
+
if (!text.startsWith("/")) return null;
|
|
129
319
|
|
|
130
320
|
// Split template name from args on first whitespace (space OR newline).
|
|
131
321
|
// Using indexOf(" ") alone breaks multi-line payloads like "/skill:foo\nargs"
|
|
@@ -136,32 +326,43 @@ export function expandPromptTemplateFromDisk(text: string, cwd: string, pi?: any
|
|
|
136
326
|
const argsString = m?.[2] ?? "";
|
|
137
327
|
|
|
138
328
|
const templates = findPromptTemplates(cwd);
|
|
329
|
+
// Also harvest skill-bundled commands/*.md from the registry so /dashboard:*
|
|
330
|
+
// resolves when cwd is not the extension install dir (real / Docker sessions).
|
|
331
|
+
addSkillCommandsFromRegistry(pi, templates);
|
|
139
332
|
const resolution = resolveTemplate(templateName, templates, pi);
|
|
140
|
-
if (!resolution) return
|
|
333
|
+
if (!resolution) return null;
|
|
141
334
|
|
|
142
335
|
try {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const bareName = resolution.resolvedName.replace(/^skill:/, "");
|
|
150
|
-
return buildSkillBlock({
|
|
151
|
-
name: bareName,
|
|
152
|
-
filePath: resolution.filePath,
|
|
153
|
-
baseDir: dirname(resolution.filePath),
|
|
154
|
-
body: content,
|
|
155
|
-
userArgs: argsString || undefined,
|
|
156
|
-
});
|
|
336
|
+
const { frontmatter, body } = readTemplate(resolution.filePath);
|
|
337
|
+
if (frontmatter.executable === "bash") {
|
|
338
|
+
// Default to !!-style context exclusion; authors opt back in with
|
|
339
|
+
// `excludeFromContext: false` to capture output for follow-up reasoning.
|
|
340
|
+
const excludeFromContext = frontmatter.excludeFromContext ?? true;
|
|
341
|
+
return { kind: "exec", body, excludeFromContext, argsString };
|
|
157
342
|
}
|
|
158
|
-
|
|
159
|
-
// Plain prompt templates: append args after a blank line, no wrapper.
|
|
160
|
-
if (argsString) {
|
|
161
|
-
return `${content}\n\n${argsString}`;
|
|
162
|
-
}
|
|
163
|
-
return content;
|
|
343
|
+
return { kind: "llm", text: assembleLlmText(resolution, body, argsString) };
|
|
164
344
|
} catch {
|
|
165
|
-
return
|
|
345
|
+
return null;
|
|
166
346
|
}
|
|
167
347
|
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Expand a slash command by finding and reading the prompt template from disk.
|
|
351
|
+
* Returns the expanded text, or the original text if no template found.
|
|
352
|
+
*
|
|
353
|
+
* Backward-compat wrapper around `loadPromptTemplate`: always returns an
|
|
354
|
+
* LLM-text string. Exec-mode templates (`executable: bash`) should be routed
|
|
355
|
+
* via `loadPromptTemplate` by the dispatcher BEFORE reaching this function.
|
|
356
|
+
* If one slips through here (e.g. the multi-line / image-bearing passthrough
|
|
357
|
+
* path that calls this then `sendUserMessage`), the ORIGINAL `text` is returned
|
|
358
|
+
* — never the raw bash body, which must not reach the LLM. See change:
|
|
359
|
+
* add-dashboard-slash-commands (CodeRabbit: do not send exec bodies to the LLM).
|
|
360
|
+
*
|
|
361
|
+
* @param pi Optional pi extension API — used to find globally installed skills
|
|
362
|
+
* and package skills via pi.getCommands() when local scan misses them.
|
|
363
|
+
*/
|
|
364
|
+
export function expandPromptTemplateFromDisk(text: string, cwd: string, pi?: any): string {
|
|
365
|
+
const loaded = loadPromptTemplate(text, cwd, pi);
|
|
366
|
+
if (!loaded) return text;
|
|
367
|
+
return loaded.kind === "exec" ? text : loaded.text;
|
|
368
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# prompt-expander.ts — index
|
|
2
|
+
|
|
3
|
+
Expand prompt templates from disk for dashboard slash commands (`pi.sendUserMessage` skips expansion). Exports `loadPromptTemplate`, `expandPromptTemplateFromDisk`, `LoadedPromptTemplate`, `PromptFrontmatter`. Resolves from `.pi/prompts/`, `.pi/skills/<skill>/SKILL.md`, `<skill>/commands/*.md`, pi.getCommands registry; `:` ↔ `-` alias resolution.
|