@blackbelt-technology/pi-dashboard-extension 0.5.4 → 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 +6 -3
- 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-shutdown-reset.test.ts +57 -136
- package/src/__tests__/bridge-slash-command-routing.test.ts +7 -7
- 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 +331 -35
- 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__/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 +22 -6
- package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
- package/src/bridge.ts +1241 -360
- package/src/bridge.ts.AGENTS.md +3 -0
- package/src/canvas-tool.ts +107 -0
- package/src/command-handler.ts +490 -51
- 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.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 +10 -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 +13 -11
- package/src/slash-dispatch.ts.AGENTS.md +3 -0
- 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__/bridge-retry-ordering.test.ts +0 -148
- package/src/__tests__/bridge-shadow-queue-drain.test.ts +0 -221
- package/src/__tests__/fixtures/usage-limit-error-strings.ts +0 -127
- package/src/__tests__/usage-limit-orderer.test.ts +0 -117
- package/src/__tests__/vcs-info-jj.test.ts +0 -145
- package/src/usage-limit-orderer.ts +0 -93
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scaffold a chosen profile into a target directory.
|
|
3
|
+
*
|
|
4
|
+
* Writes, from the profile bundle:
|
|
5
|
+
* <dir>/AGENTS.md ← AGENTS.md.tmpl ({{PROJECT_NAME}} substituted)
|
|
6
|
+
* <dir>/.pi/settings.json ← settings.json.tmpl (worktreeInit hook + toolset)
|
|
7
|
+
* <dir>/.pi/prompts/*.md ← prompts/*.md
|
|
8
|
+
* and, when the profile opts into DOX:
|
|
9
|
+
* appends the doctrine block to <dir>/AGENTS.md (marker-gated, idempotent)
|
|
10
|
+
* writes <dir>/.pi/dashboard/knowledge_base.json (directory-level AGENTS.md toolset)
|
|
11
|
+
*
|
|
12
|
+
* Writing `worktreeInit` flips the directory to "configured": the next
|
|
13
|
+
* Initialize click hits change-A's `hasHook: true` path.
|
|
14
|
+
*
|
|
15
|
+
* Idempotency: `planScaffold` reports which target files already exist so the
|
|
16
|
+
* interactive skill can ask before overwriting; `scaffoldProfile` overwrites
|
|
17
|
+
* only when `overwrite: true`.
|
|
18
|
+
*
|
|
19
|
+
* See change: project-init-skill-and-profiles.
|
|
20
|
+
*/
|
|
21
|
+
import * as fs from "node:fs";
|
|
22
|
+
import * as path from "node:path";
|
|
23
|
+
import { writeDoxKbConfig } from "./dox-kb-config.js";
|
|
24
|
+
import type { Profile } from "./profiles.js";
|
|
25
|
+
import { seedDoctrine } from "./seed-doctrine.js";
|
|
26
|
+
|
|
27
|
+
export interface ScaffoldOptions {
|
|
28
|
+
profile: Profile;
|
|
29
|
+
targetDir: string;
|
|
30
|
+
/** Substituted for `{{PROJECT_NAME}}` in AGENTS.md.tmpl. Defaults to the dir basename. */
|
|
31
|
+
projectName?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Extra `{{KEY}}` → value substitutions applied to every rendered template
|
|
34
|
+
* (e.g. the stack fills `INSTALL_CMD` / `INIT_GATE` from `detect-stack.ts`).
|
|
35
|
+
* `PROJECT_NAME` is always merged in. See change: project-init-skill-and-profiles.
|
|
36
|
+
*/
|
|
37
|
+
substitutions?: Record<string, string>;
|
|
38
|
+
/** Whether the kb toolset is wired (selects the doctrine READ variant). Defaults to profile.dox. */
|
|
39
|
+
kbWired?: boolean;
|
|
40
|
+
/** Overwrite existing files. Default false (throws on conflict). */
|
|
41
|
+
overwrite?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ScaffoldPlan {
|
|
45
|
+
/** Absolute paths the scaffold will write. */
|
|
46
|
+
writes: string[];
|
|
47
|
+
/** Subset of `writes` that already exist on disk (would be overwritten). */
|
|
48
|
+
conflicts: string[];
|
|
49
|
+
/** True when the profile opts into DOX (doctrine seed + kb toolset). */
|
|
50
|
+
dox: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Substitute every `{{KEY}}` for which a value is supplied. Unknown keys are
|
|
55
|
+
* left as-is. `escape` transforms each substituted value — used to JSON-escape
|
|
56
|
+
* values rendered into a JSON template so a command/name containing `"` or `\`
|
|
57
|
+
* cannot corrupt the output.
|
|
58
|
+
*/
|
|
59
|
+
function render(
|
|
60
|
+
tmpl: string,
|
|
61
|
+
subs: Record<string, string>,
|
|
62
|
+
escape: (v: string) => string = (v) => v,
|
|
63
|
+
): string {
|
|
64
|
+
return tmpl.replace(/\{\{([A-Z_]+)\}\}/g, (whole, key: string) =>
|
|
65
|
+
Object.hasOwn(subs, key) ? escape(subs[key]!) : whole,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Escape a value for safe interpolation inside a JSON string literal. */
|
|
70
|
+
const jsonEscape = (v: string): string => JSON.stringify(v).slice(1, -1);
|
|
71
|
+
|
|
72
|
+
/** Unresolved `{{KEY}}` placeholders remaining in rendered text. */
|
|
73
|
+
function leftoverPlaceholders(text: string): string[] {
|
|
74
|
+
return [...text.matchAll(/\{\{([A-Z_]+)\}\}/g)].map((m) => m[1]!);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Structural validity check for a `worktreeInit` hook, mirroring change-A's
|
|
79
|
+
* `normalizeHook` (packages/server/src/worktree-init.ts). Returns true when the
|
|
80
|
+
* hook would be accepted (non-empty gate + a valid script|agent run); false
|
|
81
|
+
* when change-A would fail-open to `null`.
|
|
82
|
+
*/
|
|
83
|
+
export function isValidWorktreeInit(hook: unknown): boolean {
|
|
84
|
+
if (!hook || typeof hook !== "object" || Array.isArray(hook)) return false;
|
|
85
|
+
const h = hook as { gate?: unknown; run?: unknown };
|
|
86
|
+
if (typeof h.gate !== "string" || h.gate.length === 0) return false;
|
|
87
|
+
if (!h.run || typeof h.run !== "object" || Array.isArray(h.run)) return false;
|
|
88
|
+
const run = h.run as { type?: unknown; command?: unknown; prompt?: unknown };
|
|
89
|
+
if (run.type === "script") return typeof run.command === "string" && run.command.length > 0;
|
|
90
|
+
if (run.type === "agent") return typeof run.prompt === "string" && run.prompt.length > 0;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function listPrompts(profileDir: string): string[] {
|
|
95
|
+
const dir = path.join(profileDir, "prompts");
|
|
96
|
+
try {
|
|
97
|
+
return fs.readdirSync(dir).filter((f) => f.endsWith(".md")).sort();
|
|
98
|
+
} catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Enumerate the files a scaffold would write + which already exist. */
|
|
104
|
+
export function planScaffold(opts: ScaffoldOptions): ScaffoldPlan {
|
|
105
|
+
const { profile, targetDir } = opts;
|
|
106
|
+
const writes = [
|
|
107
|
+
path.join(targetDir, "AGENTS.md"),
|
|
108
|
+
path.join(targetDir, ".pi", "settings.json"),
|
|
109
|
+
...listPrompts(profile.dir).map((f) => path.join(targetDir, ".pi", "prompts", f)),
|
|
110
|
+
];
|
|
111
|
+
if (profile.dox) {
|
|
112
|
+
writes.push(path.join(targetDir, ".pi", "dashboard", "knowledge_base.json"));
|
|
113
|
+
}
|
|
114
|
+
const conflicts = writes.filter((p) => fs.existsSync(p));
|
|
115
|
+
return { writes, conflicts, dox: profile.dox };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ScaffoldResult extends ScaffoldPlan {
|
|
119
|
+
/** True when the DOX doctrine was appended (false = already present or not dox). */
|
|
120
|
+
doctrineSeeded: boolean;
|
|
121
|
+
/** True when the worktreeInit hook rendered is structurally valid. */
|
|
122
|
+
hookValid: boolean;
|
|
123
|
+
/** `{{KEY}}` placeholders left unfilled across the written templates (should be empty). */
|
|
124
|
+
leftover: string[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Perform the scaffold. Throws when a target file exists and `overwrite` is
|
|
129
|
+
* false (the interactive skill previews `planScaffold().conflicts` first).
|
|
130
|
+
*/
|
|
131
|
+
export function scaffoldProfile(opts: ScaffoldOptions): ScaffoldResult {
|
|
132
|
+
const { profile, targetDir } = opts;
|
|
133
|
+
const projectName = opts.projectName ?? path.basename(targetDir);
|
|
134
|
+
const overwrite = opts.overwrite ?? false;
|
|
135
|
+
const kbWired = opts.kbWired ?? profile.dox;
|
|
136
|
+
const subs = { PROJECT_NAME: projectName, ...(opts.substitutions ?? {}) };
|
|
137
|
+
const leftover: string[] = [];
|
|
138
|
+
|
|
139
|
+
const plan = planScaffold(opts);
|
|
140
|
+
if (!overwrite && plan.conflicts.length > 0) {
|
|
141
|
+
throw new Error(`refusing to overwrite existing files: ${plan.conflicts.join(", ")}`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// AGENTS.md
|
|
145
|
+
const agentsMd = path.join(targetDir, "AGENTS.md");
|
|
146
|
+
const agentsTmpl = fs.readFileSync(path.join(profile.dir, "AGENTS.md.tmpl"), "utf8");
|
|
147
|
+
const agentsText = render(agentsTmpl, subs);
|
|
148
|
+
leftover.push(...leftoverPlaceholders(agentsText));
|
|
149
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
150
|
+
fs.writeFileSync(agentsMd, agentsText, "utf8");
|
|
151
|
+
|
|
152
|
+
// .pi/settings.json. Substitutions are JSON-escaped so a stack command or
|
|
153
|
+
// project name containing `"`/`\` cannot corrupt the file; the rendered text
|
|
154
|
+
// is validated as JSON BEFORE writing so corruption surfaces as a thrown
|
|
155
|
+
// error rather than a silently-broken settings file.
|
|
156
|
+
const settingsRaw = fs.readFileSync(path.join(profile.dir, "settings.json.tmpl"), "utf8");
|
|
157
|
+
const settingsText = render(settingsRaw, subs, jsonEscape);
|
|
158
|
+
leftover.push(...leftoverPlaceholders(settingsText));
|
|
159
|
+
let parsedSettings: { worktreeInit?: unknown };
|
|
160
|
+
try {
|
|
161
|
+
parsedSettings = JSON.parse(settingsText) as { worktreeInit?: unknown };
|
|
162
|
+
} catch (err) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`rendered .pi/settings.json is not valid JSON (check the profile template + substitutions): ${(err as Error).message}`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const settingsDir = path.join(targetDir, ".pi");
|
|
168
|
+
fs.mkdirSync(settingsDir, { recursive: true });
|
|
169
|
+
fs.writeFileSync(path.join(settingsDir, "settings.json"), settingsText, "utf8");
|
|
170
|
+
const hookValid = isValidWorktreeInit(parsedSettings.worktreeInit);
|
|
171
|
+
|
|
172
|
+
// prompts/*.md
|
|
173
|
+
const prompts = listPrompts(profile.dir);
|
|
174
|
+
if (prompts.length > 0) {
|
|
175
|
+
const promptsDir = path.join(targetDir, ".pi", "prompts");
|
|
176
|
+
fs.mkdirSync(promptsDir, { recursive: true });
|
|
177
|
+
for (const f of prompts) {
|
|
178
|
+
fs.copyFileSync(path.join(profile.dir, "prompts", f), path.join(promptsDir, f));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// DOX: seed doctrine + kb toolset.
|
|
183
|
+
let doctrineSeeded = false;
|
|
184
|
+
if (profile.dox) {
|
|
185
|
+
doctrineSeeded = seedDoctrine(agentsMd, { kbWired }).seeded;
|
|
186
|
+
// Honor overwrite for the kb config too, so the plan/conflict UX (which
|
|
187
|
+
// lists knowledge_base.json as a conflict) matches actual write behavior.
|
|
188
|
+
writeDoxKbConfig(targetDir, { overwrite });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return { ...plan, doctrineSeeded, hookValid, leftover };
|
|
192
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOX-doctrine seeding for the `project-init` skill.
|
|
3
|
+
*
|
|
4
|
+
* The canonical doctrine ships ONCE as `<skill>/dox-doctrine.md` (kb-indexed,
|
|
5
|
+
* so `kb_search "dox doctrine"` retrieves it). It carries three delimited
|
|
6
|
+
* sections:
|
|
7
|
+
* WRITE — maintaining the per-directory AGENTS.md tree (incl. the
|
|
8
|
+
* large-AGENTS.md split rule).
|
|
9
|
+
* READ (kb) — retrieval via `kb agents` / `kb_search` before grep.
|
|
10
|
+
* READ (manual) — upstream manual chain-walk wording; NO kb references.
|
|
11
|
+
*
|
|
12
|
+
* The seeded block = WRITE + one READ variant, chosen by whether the profile
|
|
13
|
+
* wires the kb toolset. Marker-gated + idempotent: a target `AGENTS.md` that
|
|
14
|
+
* already carries the `<!-- dox-doctrine -->` marker is left untouched.
|
|
15
|
+
*
|
|
16
|
+
* See change: project-init-skill-and-profiles.
|
|
17
|
+
*/
|
|
18
|
+
import * as fs from "node:fs";
|
|
19
|
+
import * as path from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
|
|
22
|
+
/** Stable sentinel that marks an AGENTS.md as already carrying the doctrine. */
|
|
23
|
+
export const DOX_MARKER = "<!-- dox-doctrine -->";
|
|
24
|
+
|
|
25
|
+
const WRITE_START = "<!-- dox:write:start -->";
|
|
26
|
+
const WRITE_END = "<!-- dox:write:end -->";
|
|
27
|
+
const READ_KB_START = "<!-- dox:read:kb:start -->";
|
|
28
|
+
const READ_KB_END = "<!-- dox:read:kb:end -->";
|
|
29
|
+
const READ_MANUAL_START = "<!-- dox:read:manual:start -->";
|
|
30
|
+
const READ_MANUAL_END = "<!-- dox:read:manual:end -->";
|
|
31
|
+
|
|
32
|
+
/** Absolute path to the shipped canonical doctrine file. */
|
|
33
|
+
export function doctrinePath(): string {
|
|
34
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
35
|
+
const pkgRoot = path.resolve(here, "..", "..");
|
|
36
|
+
return path.join(pkgRoot, ".pi", "skills", "project-init", "dox-doctrine.md");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Extract the text between two delimiter lines (exclusive), trimmed. */
|
|
40
|
+
function section(source: string, start: string, end: string): string {
|
|
41
|
+
const s = source.indexOf(start);
|
|
42
|
+
const e = source.indexOf(end);
|
|
43
|
+
if (s === -1 || e === -1 || e < s) return "";
|
|
44
|
+
return source.slice(s + start.length, e).trim();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface BuildDoctrineOptions {
|
|
48
|
+
/** True when the profile wires the kb toolset (indexAgentsFiles etc.). */
|
|
49
|
+
kbWired: boolean;
|
|
50
|
+
/** Override the doctrine source text (tests). Defaults to the shipped file. */
|
|
51
|
+
source?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Compose the seeded doctrine block for an AGENTS.md: the marker followed by
|
|
56
|
+
* the WRITE discipline and the kb-appropriate READ discipline.
|
|
57
|
+
*/
|
|
58
|
+
export function buildDoctrineBlock(opts: BuildDoctrineOptions): string {
|
|
59
|
+
const raw = opts.source ?? fs.readFileSync(doctrinePath(), "utf8");
|
|
60
|
+
const write = section(raw, WRITE_START, WRITE_END);
|
|
61
|
+
const read = opts.kbWired
|
|
62
|
+
? section(raw, READ_KB_START, READ_KB_END)
|
|
63
|
+
: section(raw, READ_MANUAL_START, READ_MANUAL_END);
|
|
64
|
+
return `${DOX_MARKER}\n\n${write}\n\n${read}\n`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface SeedResult {
|
|
68
|
+
/** True when the doctrine was appended; false when it was already present. */
|
|
69
|
+
seeded: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Append the doctrine block to `agentsMdPath` only when the file does not
|
|
74
|
+
* already carry the marker. Idempotent: a present marker is a no-op.
|
|
75
|
+
* Creates the file when absent.
|
|
76
|
+
*/
|
|
77
|
+
export function seedDoctrine(
|
|
78
|
+
agentsMdPath: string,
|
|
79
|
+
opts: BuildDoctrineOptions,
|
|
80
|
+
): SeedResult {
|
|
81
|
+
let existing = "";
|
|
82
|
+
try {
|
|
83
|
+
existing = fs.readFileSync(agentsMdPath, "utf8");
|
|
84
|
+
} catch {
|
|
85
|
+
existing = "";
|
|
86
|
+
}
|
|
87
|
+
if (existing.includes(DOX_MARKER)) return { seeded: false };
|
|
88
|
+
|
|
89
|
+
const block = buildDoctrineBlock(opts);
|
|
90
|
+
const sep = existing.length === 0 || existing.endsWith("\n") ? "" : "\n";
|
|
91
|
+
const joiner = existing.length === 0 ? "" : "\n";
|
|
92
|
+
fs.mkdirSync(path.dirname(agentsMdPath), { recursive: true });
|
|
93
|
+
fs.writeFileSync(agentsMdPath, `${existing}${sep}${joiner}${block}`, "utf8");
|
|
94
|
+
return { seeded: true };
|
|
95
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `project_trust` auto-decision — pure gate + defensive cwd read.
|
|
3
|
+
*
|
|
4
|
+
* A dashboard-spawned headless RPC session has no human at pi's TUI to answer
|
|
5
|
+
* `project_trust`, so pi leaves the no-UI decision un-trusted and the session
|
|
6
|
+
* can stall. The bridge auto-decides "trust" ONLY for the exact dir the
|
|
7
|
+
* dashboard spawned into — never an arbitrary tree.
|
|
8
|
+
*
|
|
9
|
+
* pi emits `project_trust` during resource-loader reload, BEFORE `session_start`
|
|
10
|
+
* reaches extension handlers, so the gate compares the event cwd to the
|
|
11
|
+
* ACTIVATION cwd (captured at bridge module scope, not session_start — a cwd
|
|
12
|
+
* captured at session_start is still undefined when this fires: the cycle-2
|
|
13
|
+
* dead-on-arrival bug).
|
|
14
|
+
*
|
|
15
|
+
* pi's handler contract: return `{ trusted: "yes" }` to trust (with
|
|
16
|
+
* `remember:false` = this run only), `{ trusted: "undecided" }` to defer to
|
|
17
|
+
* pi's default. Pure decision logic lives here so it is unit-testable without
|
|
18
|
+
* the bridge. See change: adopt-pi-074-080-features (A.3).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export interface ProjectTrustDecisionInput {
|
|
22
|
+
/** True when this pi was spawned by the dashboard (PI_DASHBOARD_SPAWN_TOKEN). */
|
|
23
|
+
dashboardSpawned: boolean;
|
|
24
|
+
/** True for a headless RPC session (no TTY, bridge over WebSocket). */
|
|
25
|
+
isHeadless: boolean;
|
|
26
|
+
/** cwd carried by the project_trust event (undefined when unreadable). */
|
|
27
|
+
eventCwd: string | undefined;
|
|
28
|
+
/** cwd captured at bridge activation (the dashboard-provided spawn cwd). */
|
|
29
|
+
activationCwd: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type ProjectTrustDecision = "trust" | "defer";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Deny-by-default gate. Trust ONLY when ALL hold: dashboard-spawned AND
|
|
36
|
+
* headless AND the event cwd still equals the activation cwd. Any other case
|
|
37
|
+
* — interactive/TUI, non-dashboard-spawn, a differing/unknown cwd — defers to
|
|
38
|
+
* pi's default.
|
|
39
|
+
*/
|
|
40
|
+
export function decideProjectTrust(input: ProjectTrustDecisionInput): ProjectTrustDecision {
|
|
41
|
+
if (!input.dashboardSpawned) return "defer";
|
|
42
|
+
if (!input.isHeadless) return "defer";
|
|
43
|
+
if (input.eventCwd === undefined || input.eventCwd !== input.activationCwd) return "defer";
|
|
44
|
+
return "trust";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read the trust-decision cwd from the `project_trust` event (authoritative)
|
|
49
|
+
* or, failing that, its per-event context — defensively. The read is wrapped
|
|
50
|
+
* in try/catch so a stale/replaced ctx whose `cwd` getter throws yields
|
|
51
|
+
* `undefined` (→ the gate defers, no crash). NEVER reads a cached ctx.
|
|
52
|
+
*/
|
|
53
|
+
export function readEventCwd(event: unknown, ctx: unknown): string | undefined {
|
|
54
|
+
try {
|
|
55
|
+
const fromEvent = (event as { cwd?: unknown } | null | undefined)?.cwd;
|
|
56
|
+
if (typeof fromEvent === "string") return fromEvent;
|
|
57
|
+
const fromCtx = (ctx as { cwd?: unknown } | null | undefined)?.cwd;
|
|
58
|
+
if (typeof fromCtx === "string") return fromCtx;
|
|
59
|
+
return undefined;
|
|
60
|
+
} catch {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# project-trust.ts — index
|
|
2
|
+
|
|
3
|
+
`project_trust` auto-decision (pure gate + defensive cwd read). `decideProjectTrust({dashboardSpawned,isHeadless,eventCwd,activationCwd})` → `"trust"` ONLY when all hold (dashboard-spawned AND headless AND `eventCwd===activationCwd`); every other case (incl. `eventCwd` undefined) → `"defer"` (deny-by-default). `readEventCwd(event,ctx)` reads `event.cwd` then `ctx.cwd` inside try/catch (stale/replaced ctx throw → undefined → defer); never a cached ctx. Bridge registers a `project_trust` handler at activation returning `{trusted:"yes",remember:false}` (per-run) / `{trusted:"undecided"}`; captures `activationCwd` at module scope (event fires pre-`session_start`, during resource-loader reload). See change: adopt-pi-074-080-features.
|
package/src/prompt-bus.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* Replaces the ui-proxy race pattern and emitPromptAndAwait event system.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import type { ImageContent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
10
|
+
|
|
9
11
|
// ── Interfaces ──────────────────────────────────────────────────────
|
|
10
12
|
|
|
11
13
|
export interface PromptComponent {
|
|
@@ -25,7 +27,7 @@ export interface PromptClaim {
|
|
|
25
27
|
export interface PromptRequest {
|
|
26
28
|
id: string;
|
|
27
29
|
pipeline: string;
|
|
28
|
-
type: "select" | "input" | "confirm" | "editor" | "multiselect";
|
|
30
|
+
type: "select" | "input" | "confirm" | "editor" | "multiselect" | "batch";
|
|
29
31
|
question: string;
|
|
30
32
|
options?: string[];
|
|
31
33
|
defaultValue?: string;
|
|
@@ -37,6 +39,13 @@ export interface PromptResponse {
|
|
|
37
39
|
answer?: string;
|
|
38
40
|
cancelled?: boolean;
|
|
39
41
|
source: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optional pasted images riding alongside a `type:"input"` answer.
|
|
44
|
+
* Standalone `ask_user{method:"input"}` transport only. Additive;
|
|
45
|
+
* adapters that ignore it keep working. See change:
|
|
46
|
+
* add-ask-user-input-multiline-paste.
|
|
47
|
+
*/
|
|
48
|
+
images?: ImageContent[];
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
export interface PromptAdapter {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# prompt-bus.ts — index
|
|
2
|
+
|
|
3
|
+
Prompt dispatch bus — first-response-wins adapter routing + cross-adapter dismissal. Exports `PromptBus`, `PromptComponent`, `PromptClaim`, `PromptRequest`, `PromptResponse`, `PromptAdapter`, `PromptBusOptions`. Replaces ui-proxy race pattern / `emitPromptAndAwait`. Routes by priority; default 5min timeout.
|