gentle-pi 3.6.0 → 4.0.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/README.md +37 -6
- package/assets/agents/gentle-ai-explore.md +4 -4
- package/assets/agents/gentle-ai-verify.md +6 -4
- package/assets/agents/gentle-ai-worker.md +7 -9
- package/assets/orchestrator-delegation.md +40 -41
- package/assets/orchestrator-memory.md +1 -22
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator.md +12 -24
- package/assets/support/strict-tdd-verify.md +4 -266
- package/assets/support/strict-tdd.md +8 -360
- package/bin/gentle-shell.mjs +254 -29
- package/docs/delegated-verification.md +26 -1
- package/docs/gentle-agents-activity.md +24 -0
- package/docs/gentle-shell.md +95 -30
- package/docs/native-authority-architecture.md +2 -2
- package/docs/prompt-history.md +280 -0
- package/docs/readme-reference.md +117 -235
- package/docs/telemetry.md +1 -1
- package/docs/yolo-mode.md +86 -0
- package/extensions/child-context.ts +26 -0
- package/extensions/child-safety.ts +23 -0
- package/extensions/gentle-agents.ts +509 -275
- package/extensions/gentle-ai.ts +781 -683
- package/extensions/gentle-shell.ts +1375 -88
- package/extensions/gentle-stats.ts +101 -0
- package/extensions/gentle-todo.ts +18 -7
- package/extensions/history/atomic-write.ts +38 -0
- package/extensions/history/hide-prompts.ts +183 -0
- package/extensions/history/index.ts +1419 -0
- package/extensions/history/load-shared-history.ts +39 -0
- package/extensions/history/selector-helpers.ts +538 -0
- package/extensions/history/session-scan.ts +233 -0
- package/extensions/history/store.ts +1119 -0
- package/extensions/nan-provider.ts +6 -0
- package/extensions/quiet-tools.ts +179 -87
- package/extensions/resume-hint.ts +60 -0
- package/extensions/skill-registry.ts +16 -12
- package/extensions/startup-banner.ts +60 -31
- package/lib/agent-assets.ts +604 -0
- package/lib/agent-profile-pin.ts +12 -0
- package/lib/agents-message-delivery.ts +181 -0
- package/lib/agents-protocol.ts +60 -0
- package/lib/agents-runner.ts +105 -98
- package/lib/agents-view.ts +26 -3
- package/lib/agents-widget.ts +16 -9
- package/lib/append-system-prompt.ts +21 -0
- package/lib/bounded-writer-admission.ts +147 -0
- package/lib/card-style-policy.ts +60 -0
- package/lib/child-context-files.ts +166 -0
- package/lib/codemode-renderer.ts +185 -0
- package/lib/command-palette-catalog.ts +3 -9
- package/lib/command-palette.ts +25 -14
- package/lib/destructive-command-guard.ts +144 -0
- package/lib/foreign-target-grants.ts +32 -0
- package/lib/gentle-ai-elapsed-store.ts +87 -0
- package/lib/gentle-ai-renderer.ts +196 -39
- package/lib/gentle-shell-launcher.ts +24 -13
- package/lib/gentle-shell-resume-hint.ts +176 -0
- package/lib/history-capture-policy.ts +95 -0
- package/lib/model-routing-authority.ts +5 -1
- package/lib/nan-provider.ts +227 -0
- package/lib/native-review-cli.ts +53 -108
- package/lib/odd-phase-inference.ts +231 -0
- package/lib/odd-phase.ts +141 -0
- package/lib/overlay-repaint.ts +26 -0
- package/lib/pi-tui-keys.ts +53 -0
- package/lib/review-candidate-view-owner.ts +67 -17
- package/lib/review-candidate-view.ts +112 -25
- package/lib/review-reminder-receipt.ts +48 -8
- package/lib/review-risk-assessment.ts +156 -11
- package/lib/review-sidebar-state.ts +223 -0
- package/lib/selection-engine.ts +515 -0
- package/lib/session-change-capture.ts +10 -1
- package/lib/session-messaging-grants.ts +135 -0
- package/lib/session-worktree-registry.ts +14 -2
- package/lib/shell-bar.ts +179 -24
- package/lib/shell-card.ts +287 -18
- package/lib/shell-changes-view.ts +2 -1
- package/lib/shell-prompt.ts +102 -6
- package/lib/shell-sidebar-layout.ts +78 -14
- package/lib/shell-sidebar.ts +15 -1
- package/lib/shell-todo.ts +23 -13
- package/lib/shell-usage-view.ts +9 -4
- package/lib/shell-usage.ts +66 -10
- package/lib/stats-collector.ts +381 -0
- package/lib/stats-view.ts +431 -0
- package/lib/theme-customization.ts +52 -0
- package/lib/vim-editor-adapter.ts +379 -0
- package/lib/vim-normal-engine.ts +154 -0
- package/lib/vim-operator-engine.ts +416 -0
- package/lib/vim-policy.ts +49 -0
- package/lib/vim-visual-engine.ts +107 -0
- package/lib/visual-customization-policy.ts +108 -0
- package/lib/visual-customize-view.ts +330 -0
- package/lib/visual-profiles.ts +228 -0
- package/lib/yolo-session-policy.ts +240 -0
- package/package.json +20 -8
- package/runtime/gentle-shell-launcher.mjs +23 -12
- package/runtime/gentle-shell-resume-hint.mjs +177 -0
- package/runtime/native-review-cli.mjs +53 -108
- package/runtime/review-risk-assessment.mjs +154 -9
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +14 -13
- package/scripts/mirror-odd-routing.mjs +2 -2
- package/scripts/run-test-suite.mjs +76 -0
- package/scripts/test-packed-runner.mjs +31 -14
- package/scripts/verify-package-files.mjs +11 -22
- package/skills/branch-pr/SKILL.md +24 -52
- package/skills/chained-pr/SKILL.md +31 -15
- package/skills/chained-pr/references/chaining-details.md +31 -20
- package/skills/gentle-ai/SKILL.md +9 -15
- package/skills/issue-creation/SKILL.md +8 -2
- package/skills/issue-creation/references/delegated-workflow-actions.md +19 -0
- package/skills/work-unit-commits/SKILL.md +4 -3
- package/tests/agent-profiles.test.ts +18 -0
- package/tests/agents-fake-child.ts +2 -2
- package/tests/agents-message-delivery.test.ts +106 -0
- package/tests/agents-protocol.test.ts +40 -0
- package/tests/agents-runner.test.ts +400 -89
- package/tests/agents-view-thread-identity.test.ts +169 -0
- package/tests/agents-view.test.ts +8 -2
- package/tests/agents-widget.test.ts +154 -15
- package/tests/append-system-prompt-route.test.ts +160 -0
- package/tests/append-system-prompt.test.ts +46 -0
- package/tests/artifact-language.test.ts +19 -213
- package/tests/ask-user-question.test.ts +44 -1
- package/tests/asset-installation-runtime.test.ts +5 -16
- package/tests/autonomous-guard.test.ts +69 -1
- package/tests/bounded-writer-admission.test.ts +95 -0
- package/tests/branch-pr-skill.test.ts +43 -0
- package/tests/card-style-policy.test.ts +55 -0
- package/tests/chained-pr-skill.test.ts +124 -0
- package/tests/child-context-files.test.ts +255 -0
- package/tests/child-safety.test.ts +82 -0
- package/tests/codemode-rendering.test.ts +491 -0
- package/tests/command-palette.test.ts +39 -3
- package/tests/delegated-key-learnings-contract.test.ts +0 -76
- package/tests/destructive-command-guard.test.ts +84 -0
- package/tests/devbinary/native-review-parity.devtest.ts +170 -2
- package/tests/devbinary/non-git-subagent-bootstrap.devtest.ts +193 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +7 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +3 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T08-00-00-000Z_ddd.jsonl +2 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T09-00-00-000Z_eee.jsonl +3 -0
- package/tests/fixtures/stats/sessions/--work-alpha--/run-1/session.jsonl +2 -0
- package/tests/fixtures/stats/sessions/--work-beta--/2026-09-01T12-00-00-000Z_ccc.jsonl +2 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +2 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +4 -0
- package/tests/fixtures/stats/user-pi/sessions/--work-gamma--/2026-09-20T09-00-00-000Z_fff.jsonl +3 -0
- package/tests/foreign-target-grants.test.ts +58 -0
- package/tests/generic-agent-tools.test.ts +54 -0
- package/tests/gentle-agents.test.ts +1411 -256
- package/tests/gentle-ai-binary.test.ts +3 -3
- package/tests/gentle-ai-elapsed-store.test.ts +68 -0
- package/tests/gentle-ai-installer.test.ts +68 -54
- package/tests/gentle-ai-renderer.test.ts +487 -8
- package/tests/gentle-ai.test.ts +288 -65
- package/tests/gentle-card-text.ts +2 -1
- package/tests/gentle-shell-bin.test.ts +651 -114
- package/tests/gentle-shell-launcher.test.ts +99 -52
- package/tests/gentle-shell-resume-hint.test.ts +270 -0
- package/tests/gentle-shell.test.ts +3839 -187
- package/tests/gentle-stats.test.ts +152 -0
- package/tests/gentle-theme.test.ts +4 -1
- package/tests/gentle-todo.test.ts +80 -8
- package/tests/history-atomic-write.test.ts +57 -0
- package/tests/history-capture-policy.test.ts +102 -0
- package/tests/history-command-registration.test.ts +164 -0
- package/tests/history-dedupe-entries.test.ts +123 -0
- package/tests/history-delete-backfill.test.ts +190 -0
- package/tests/history-delete-confirm.test.ts +460 -0
- package/tests/history-dispatch.test.ts +180 -0
- package/tests/history-drain-hidden.test.ts +110 -0
- package/tests/history-drain-order.test.ts +98 -0
- package/tests/history-expanded-globals.test.ts +62 -0
- package/tests/history-gc.test.ts +832 -0
- package/tests/history-header-layout.test.ts +265 -0
- package/tests/history-hide-prompts.test.ts +275 -0
- package/tests/history-lazy-windowing.test.ts +508 -0
- package/tests/history-legacy-migrate-v2.test.ts +297 -0
- package/tests/history-load-shared-history.test.ts +53 -0
- package/tests/history-max-results-cap.test.ts +76 -0
- package/tests/history-multi-reader.test.ts +203 -0
- package/tests/history-off-path.test.ts +170 -0
- package/tests/history-openflow-integration.test.ts +173 -0
- package/tests/history-overlay-margin.test.ts +326 -0
- package/tests/history-preview-layout.test.ts +93 -0
- package/tests/history-registry.test.ts +143 -0
- package/tests/history-scope-delete.test.ts +411 -0
- package/tests/history-search-caret-keys.test.ts +142 -0
- package/tests/history-seed-bootstrap.test.ts +170 -0
- package/tests/history-seed-regen.test.ts +129 -0
- package/tests/history-selector-windowing.test.ts +94 -0
- package/tests/history-session-scan-directory.test.ts +87 -0
- package/tests/history-session-scan-extract.test.ts +583 -0
- package/tests/history-session-writer.test.ts +351 -0
- package/tests/history-store-paths.test.ts +79 -0
- package/tests/history-tombstone-exact.test.ts +139 -0
- package/tests/history-wheel-mouse.test.ts +242 -0
- package/tests/inprocess-reviewer.test.ts +29 -19
- package/tests/issue-creation-skill.test.ts +61 -0
- package/tests/model-routing-authority.test.ts +16 -0
- package/tests/nan-provider.test.ts +471 -0
- package/tests/native-review-capability-contract.test.ts +13 -1
- package/tests/native-review-cli.test.ts +6 -120
- package/tests/native-review-parity-runtime.test.ts +100 -3
- package/tests/odd-integration.test.ts +67 -0
- package/tests/odd-phase-inference.test.ts +213 -0
- package/tests/odd-phase-loader.test.ts +253 -0
- package/tests/odd-phase.test.ts +307 -0
- package/tests/odd-routing-canonical-ratchet.test.ts +11 -6
- package/tests/odd-routing-contract.test.ts +86 -35
- package/tests/orchestrator-budget.test.ts +14 -39
- package/tests/orchestrator-rdd-ownership.test.ts +3 -3
- package/tests/overlay-repaint.test.ts +74 -0
- package/tests/package-manifest.test.ts +252 -115
- package/tests/packed-runner-owned-path.test.ts +46 -0
- package/tests/persona-single-channel.test.ts +6 -6
- package/tests/provider-defect-handoff.test.ts +3 -11
- package/tests/quiet-bash-runtime.test.ts +76 -0
- package/tests/quiet-tool-rendering.test.ts +409 -184
- package/tests/rdd-aware-verification-contract.test.ts +76 -1
- package/tests/rdd-status-line.test.ts +9 -4
- package/tests/resume-hint-extension.test.ts +122 -0
- package/tests/review-agent-end-preflight.test.ts +176 -12
- package/tests/review-candidate-owner-retry.test.ts +22 -1
- package/tests/review-candidate-view.test.ts +298 -0
- package/tests/review-contract-prompt.test.ts +108 -43
- package/tests/review-controller-lock-status.test.ts +0 -1
- package/tests/review-controller-native-routing.test.ts +611 -5
- package/tests/review-controller-workspace-root.test.ts +163 -4
- package/tests/review-host-relay-routing.test.ts +338 -2
- package/tests/review-integration-v2-forward.test.ts +200 -0
- package/tests/review-ledger-contract.test.ts +10 -34
- package/tests/review-reminder-receipt.test.ts +47 -1
- package/tests/review-risk-assessment.test.ts +498 -6
- package/tests/review-sidebar-state.test.ts +402 -0
- package/tests/run-test-suite.test.ts +124 -0
- package/tests/runtime-harness.mjs +145 -786
- package/tests/runtime-metrics-children.test.ts +16 -23
- package/tests/selection-engine.test.ts +421 -0
- package/tests/session-change-capture.test.ts +12 -1
- package/tests/session-messaging-grants.test.ts +255 -0
- package/tests/session-worktree-registry.test.ts +77 -0
- package/tests/shell-bar.test.ts +382 -1
- package/tests/shell-card.test.ts +353 -1
- package/tests/shell-changes-view.test.ts +52 -0
- package/tests/shell-prompt.test.ts +94 -2
- package/tests/shell-sidebar-layout.test.ts +325 -21
- package/tests/shell-sidebar-scroll-benchmark.test.ts +255 -0
- package/tests/shell-todo.test.ts +87 -1
- package/tests/shell-usage-view.test.ts +27 -0
- package/tests/shell-usage.test.ts +73 -0
- package/tests/skill-registry.test.ts +50 -1
- package/tests/startup-banner.test.ts +130 -2
- package/tests/stats-collector.test.ts +195 -0
- package/tests/stats-view.test.ts +202 -0
- package/tests/telemetry-trigger.test.ts +81 -20
- package/tests/theme-customization.test.ts +72 -0
- package/tests/vim-editor-adapter-host-resolution.test.ts +37 -0
- package/tests/vim-editor-adapter.test.ts +804 -0
- package/tests/vim-normal-engine.test.ts +101 -0
- package/tests/vim-operator-engine.test.ts +215 -0
- package/tests/vim-policy.test.ts +19 -0
- package/tests/vim-visual-engine.test.ts +52 -0
- package/tests/visual-customization-policy.test.ts +110 -0
- package/tests/visual-customize-view.test.ts +418 -0
- package/tests/visual-profiles.test.ts +87 -0
- package/tests/yolo-customize.test.ts +256 -0
- package/tests/yolo-mode-runtime.test.ts +161 -0
- package/tests/yolo-mode.test.ts +261 -0
- package/tests/yolo-session-policy.test.ts +59 -0
- package/themes/Gentle.json +2 -1
- package/themes/Gentleman-Cute.json +2 -1
- package/themes/Gentleman-Sexy.json +2 -1
- package/assets/agents/sdd-apply.md +0 -159
- package/assets/agents/sdd-archive.md +0 -228
- package/assets/agents/sdd-design.md +0 -49
- package/assets/agents/sdd-explore.md +0 -48
- package/assets/agents/sdd-init.md +0 -56
- package/assets/agents/sdd-onboard.md +0 -52
- package/assets/agents/sdd-proposal.md +0 -64
- package/assets/agents/sdd-remediate.md +0 -37
- package/assets/agents/sdd-research.md +0 -49
- package/assets/agents/sdd-spec.md +0 -192
- package/assets/agents/sdd-status.md +0 -54
- package/assets/agents/sdd-tasks.md +0 -108
- package/assets/agents/sdd-verify.md +0 -124
- package/assets/chains/sdd-full.chain.md +0 -83
- package/assets/chains/sdd-plan.chain.md +0 -56
- package/assets/chains/sdd-verify.chain.md +0 -43
- package/assets/sdd-orchestrator-workflow.md +0 -319
- package/assets/support/sdd-status-contract.md +0 -77
- package/docs/assets/diagrams/sdd-cycle.svg +0 -14
- package/extensions/sdd-init.ts +0 -816
- package/lib/openspec-deltas.ts +0 -156
- package/lib/sdd-preflight.ts +0 -1066
- package/lib/sdd-research-capabilities.ts +0 -94
- package/lib/sdd-status.ts +0 -26
- package/tests/fixtures/legacy/sdd-research-v2.5.0.md +0 -54
- package/tests/fixtures/native-review-cli/v2.1.3/bind-sdd.json +0 -25
- package/tests/fixtures/v0.10.7/assets/agents/sdd-apply.md +0 -132
- package/tests/openspec-deltas.test.ts +0 -209
- package/tests/sdd-agent-tools.test.ts +0 -156
- package/tests/sdd-archive-replay.test.ts +0 -82
- package/tests/sdd-classical-continuation.test.ts +0 -74
- package/tests/sdd-execution-routing-contract.test.ts +0 -44
- package/tests/sdd-managed-runtime-settlement.test.ts +0 -155
- package/tests/sdd-native-managed-uptake.test.ts +0 -243
- package/tests/sdd-no-attempts-contract.test.ts +0 -15
- package/tests/sdd-odd-integration.test.ts +0 -33
- package/tests/sdd-optional-research.test.ts +0 -124
- package/tests/sdd-planning-routing-contract.test.ts +0 -45
- package/tests/sdd-preflight-rpc-input.test.ts +0 -125
- package/tests/sdd-preflight.test.ts +0 -541
- package/tests/sdd-research-capabilities.test.ts +0 -114
- package/tests/sdd-research-live.test.ts +0 -241
- package/tests/sdd-selection-transport.test.ts +0 -653
- package/tests/sdd-status.test.ts +0 -9
- package/tests/sdd-task-truth.test.ts +0 -43
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { execFileSync, spawn } from "node:child_process";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { appendFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { dirname, join, resolve } from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import test from "node:test";
|
|
9
|
-
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
10
|
-
import { AgentRunner, type ChildLike, type TaskRequest } from "../lib/agents-runner.ts";
|
|
11
|
-
import { TaskStore } from "../lib/agents-protocol.ts";
|
|
12
|
-
import { parseAgentDefinition } from "../lib/agents-config.ts";
|
|
13
|
-
import { Type } from "typebox";
|
|
14
|
-
import { RESEARCH_CHILD_TOOLS_ENV } from "../lib/sdd-research-capabilities.ts";
|
|
15
|
-
import { admitManagedRemediation } from "../extensions/gentle-agents.ts";
|
|
16
|
-
|
|
17
|
-
import { NativeReviewCliV216, createNodeExecFileAdapter } from "../lib/native-review-cli.ts";
|
|
18
|
-
|
|
19
|
-
const self = fileURLToPath(import.meta.url);
|
|
20
|
-
const source = dirname(dirname(self));
|
|
21
|
-
const binary = process.env.SDD_TEST_PRODUCER;
|
|
22
|
-
const childRole = process.env.UPTAKE_CHILD === "1";
|
|
23
|
-
const digest = (value: string | Buffer) => createHash("sha256").update(value).digest("hex");
|
|
24
|
-
const json = (path: string) => JSON.parse(readFileSync(path, "utf8"));
|
|
25
|
-
const cost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 };
|
|
26
|
-
|
|
27
|
-
// The model is a finite local script, not a provider call or an actor verdict.
|
|
28
|
-
// SDK/extension hooks, tools, session persistence, RPC and AgentRunner are real.
|
|
29
|
-
export async function launch(): Promise<void> {
|
|
30
|
-
const sdk = await import("@earendil-works/pi-coding-agent");
|
|
31
|
-
const ai = await import("@earendil-works/pi-ai");
|
|
32
|
-
const args = process.argv.slice(1), value = (flag: string) => args[args.indexOf(flag) + 1];
|
|
33
|
-
const paths = args.flatMap((arg, i) => arg === "--extension" ? [args[i + 1]] : []);
|
|
34
|
-
const home = process.env.GENTLE_PI_AGENT_HOME!;
|
|
35
|
-
const runtimeModels = await sdk.ModelRuntime.create({ credentials: new ai.InMemoryCredentialStore(), modelsPath: join(home, "models.json"), modelsStorePath: join(home, "models-store.json"), allowModelNetwork: false });
|
|
36
|
-
const settings = sdk.SettingsManager.inMemory({ retry: { enabled: false }, compaction: { enabled: false } });
|
|
37
|
-
let turn = 0;
|
|
38
|
-
const script = json(process.env.UPTAKE_SCRIPT!);
|
|
39
|
-
const runtime = await sdk.createAgentSessionRuntime(async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
40
|
-
const services = await sdk.createAgentSessionServices({ cwd, agentDir: home, modelRuntime: runtimeModels, settingsManager: settings, resourceLoaderOptions: {
|
|
41
|
-
noExtensions: true, noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true,
|
|
42
|
-
additionalExtensionPaths: paths, appendSystemPrompt: [value("--append-system-prompt")],
|
|
43
|
-
extensionFactories: [pi => {
|
|
44
|
-
pi.registerProvider("uptake-control", { baseUrl: "http://127.0.0.1:1", apiKey: "offline-control", api: "openai-completions", models: [{ id: "control", name: "control", reasoning: false, input: ["text"], cost, contextWindow: 200000, maxTokens: 1000 }],
|
|
45
|
-
streamSimple: (model, context) => {
|
|
46
|
-
writeFileSync(join(process.env.UPTAKE_RUN!, `input-${turn}.json`), JSON.stringify(context));
|
|
47
|
-
const calls = script[turn++] ?? [];
|
|
48
|
-
const stopReason = calls.length ? "toolUse" as const : "stop" as const;
|
|
49
|
-
const message: AssistantMessage = { role: "assistant", content: calls.length ? calls.map(([name, arguments_], i) => ({ type: "toolCall", id: `${turn}-${i}`, name, arguments: arguments_ })) : [{ type: "text", text: "Controlled script exhausted; not acceptance." }], api: model.api, provider: model.provider, model: model.id, usage: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0, totalTokens: 2, cost }, stopReason, timestamp: Date.now() };
|
|
50
|
-
const stream = ai.createAssistantMessageEventStream();
|
|
51
|
-
queueMicrotask(() => { stream.push({ type: "start", partial: message }); stream.push({ type: "done", reason: stopReason, message }); stream.end(message); });
|
|
52
|
-
return stream;
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}],
|
|
56
|
-
} });
|
|
57
|
-
assert.deepEqual(services.resourceLoader.getExtensions().errors, []);
|
|
58
|
-
if (args.includes("--gentle-sdd-change")) services.resourceLoader.getExtensions().runtime.flagValues.set("gentle-sdd-change", value("--gentle-sdd-change"));
|
|
59
|
-
return { ...(await sdk.createAgentSessionFromServices({ services, sessionManager, sessionStartEvent, model: runtimeModels.getModel("uptake-control", "control"), tools: value("--tools").split(",") })), services, diagnostics: services.diagnostics };
|
|
60
|
-
}, { cwd: process.cwd(), agentDir: home, sessionManager: sdk.SessionManager.create(process.cwd(), value("--session-dir")) });
|
|
61
|
-
await sdk.runRpcMode(runtime);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// A local documentation capability with real extension provenance and an observable effect.
|
|
65
|
-
export default function controlledDocumentation(pi) {
|
|
66
|
-
pi.registerTool({ name: "fetch_content", label: "Controlled documentation", description: "Read the isolated documentation fixture only", parameters: Type.Object({}), execute: async () => {
|
|
67
|
-
appendFileSync(join(process.env.UPTAKE_RUN!, "fetch-calls"), "called\n");
|
|
68
|
-
return { content: [{ type: "text", text: "Independent controlled documentation bytes" }], details: {} };
|
|
69
|
-
} });
|
|
70
|
-
pi.on("session_start", (_event, ctx) => {
|
|
71
|
-
writeFileSync(join(process.env.UPTAKE_RUN!, "inventory.json"), JSON.stringify(pi.getAllTools()));
|
|
72
|
-
writeFileSync(join(process.env.UPTAKE_RUN!, "startup.json"), JSON.stringify({ cwd: ctx.cwd, flag: pi.getFlag("gentle-sdd-change"), grant: process.env.GENTLE_PI_SDD_REMEDIATION_PLAN }));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!childRole) test("installed AI producer → fixed Pi extensions → managed child input and tools", { skip: !binary, timeout: 90000 }, async t => {
|
|
77
|
-
assert.ok(binary && resolve(binary) === binary && existsSync(binary), "Explicit independently built AI binary required");
|
|
78
|
-
const producerIdentity = json(`${binary}.identity.json`);
|
|
79
|
-
assert.equal(producerIdentity.sourceRevision, "01e6fac15df169e8993e02549b9edcbd01abc0ee");
|
|
80
|
-
assert.equal(producerIdentity.sha256, digest(readFileSync(binary)), "Producer bytes must match the independent build record");
|
|
81
|
-
const root = mkdtempSync(join(tmpdir(), "pi-native-uptake-"));
|
|
82
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
83
|
-
const cwd = join(root, "workspace"), home = join(root, "profile"), pkg = join(root, "pi");
|
|
84
|
-
const change = join(cwd, "openspec", "changes", "uptake");
|
|
85
|
-
mkdirSync(join(change, "specs", "sample"), { recursive: true });
|
|
86
|
-
mkdirSync(home); mkdirSync(pkg);
|
|
87
|
-
execFileSync("git", ["init", "--quiet", cwd]);
|
|
88
|
-
for (const name of ["assets", "extensions", "lib", "runtime", "contracts", "scripts", "package.json", "tests"]) cpSync(join(source, name), join(pkg, name), { recursive: true });
|
|
89
|
-
symlinkSync(join(source, "node_modules"), join(pkg, "node_modules"), "dir");
|
|
90
|
-
execFileSync(process.execPath, ["scripts/build-runtime-modules.mjs", "--write"], { cwd: pkg });
|
|
91
|
-
const previousHome = process.env.GENTLE_PI_AGENT_HOME;
|
|
92
|
-
process.env.GENTLE_PI_AGENT_HOME = home;
|
|
93
|
-
try {
|
|
94
|
-
const { installPackageAssets } = await import(join(pkg, "lib", "sdd-preflight.ts"));
|
|
95
|
-
installPackageAssets(cwd, false, ["sdd"]);
|
|
96
|
-
} finally {
|
|
97
|
-
if (previousHome === undefined) delete process.env.GENTLE_PI_AGENT_HOME; else process.env.GENTLE_PI_AGENT_HOME = previousHome;
|
|
98
|
-
}
|
|
99
|
-
const manifest = json(join(home, "gentle-ai", "managed-assets.json"));
|
|
100
|
-
const actor = (phase: string) => {
|
|
101
|
-
const path = join(home, "agents", `sdd-${phase}.md`);
|
|
102
|
-
const bytes = readFileSync(path, "utf8");
|
|
103
|
-
assert.equal(digest(bytes), manifest.assets[`agents/sdd-${phase}.md`]);
|
|
104
|
-
assert.equal(bytes, readFileSync(join(pkg, "assets", "agents", `sdd-${phase}.md`), "utf8"));
|
|
105
|
-
const definition = parseAgentDefinition(bytes, path, "global");
|
|
106
|
-
if (!("instructions" in definition)) throw new Error(`Invalid fixture agent: ${phase}`);
|
|
107
|
-
return definition;
|
|
108
|
-
};
|
|
109
|
-
for (const phase of ["apply", "research", "remediate"]) assert.equal(actor(phase).name, `sdd-${phase}`);
|
|
110
|
-
writeFileSync(join(change, "proposal.md"), "Native uptake controlled fixture\n");
|
|
111
|
-
writeFileSync(join(change, "design.md"), "Read-only controlled fixture\n");
|
|
112
|
-
writeFileSync(join(change, "specs", "sample", "spec.md"), "### Requirement: Controlled boundary\n#### Scenario: Read\n");
|
|
113
|
-
writeFileSync(join(change, "tasks.md"), "- [ ] Read controlled fixture\n");
|
|
114
|
-
const native = new NativeReviewCliV216(createNodeExecFileAdapter(), binary);
|
|
115
|
-
const status = await native.sddStatus({ changeName: "uptake", workspaceRoot: cwd });
|
|
116
|
-
assert.equal(status.schemaName, "gentle-ai.sdd-status"); assert.equal(status.schemaVersion, 2);
|
|
117
|
-
assert.equal(status.nextRecommended, "apply");
|
|
118
|
-
await t.test("installed host suppresses continuation for read-only and excluded-marker answers", async () => {
|
|
119
|
-
const { createGentleAiExtension } = await import(join(pkg, "extensions", "gentle-ai.ts"));
|
|
120
|
-
for (const answer of [false, undefined]) {
|
|
121
|
-
const verbs: string[] = [], confirmations: string[] = [], notices: string[] = [];
|
|
122
|
-
const commands = new Map();
|
|
123
|
-
const adapter = createNodeExecFileAdapter();
|
|
124
|
-
const client = new NativeReviewCliV216(request => { verbs.push(request.arguments[0]); return adapter(request); }, binary);
|
|
125
|
-
createGentleAiExtension({ nativeReviewCli: client, processEnv: {} })({ on() {}, events: { emit() {} }, registerTool() {}, registerCommand: (name, command) => commands.set(name, command.handler), sendUserMessage: () => assert.fail("Unexpected launch"), sendMessage: () => assert.fail("Unexpected launch") });
|
|
126
|
-
const context = { cwd, hasUI: true, ui: { notify: text => notices.push(text), confirm: async (_title, text) => { confirmations.push(text); return answer; } } };
|
|
127
|
-
await commands.get("gentle-sdd-status")("uptake --json", context);
|
|
128
|
-
assert.deepEqual(JSON.parse(notices[0]), status);
|
|
129
|
-
assert.equal(confirmations.length, 0);
|
|
130
|
-
await commands.get("gentle-sdd-continue")("uptake --json", context);
|
|
131
|
-
assert.deepEqual(verbs, ["sdd-status", "sdd-status"]);
|
|
132
|
-
assert.equal(confirmations.length, 1);
|
|
133
|
-
assert.ok(confirmations[0].includes(join(change, ".gentle-ai-instance")));
|
|
134
|
-
assert.equal(existsSync(join(change, ".gentle-ai-instance")), false);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
const fixed = [join(pkg, "extensions", "gentle-ai.ts"), join(pkg, "extensions", "gentle-agents.ts")];
|
|
138
|
-
const docExtension = join(pkg, "tests", "sdd-native-managed-uptake.test.ts");
|
|
139
|
-
const selection = { documentation: { tools: ["fetch_content"], extensions: { fetch_content: docExtension } } };
|
|
140
|
-
async function run(id: string, phase: "apply" | "research" | "remediate", script: unknown[], options: Record<string, any> = {}) {
|
|
141
|
-
const directory = join(root, id); mkdirSync(directory);
|
|
142
|
-
const scriptPath = join(directory, "script.json"); writeFileSync(scriptPath, JSON.stringify(script));
|
|
143
|
-
const events: any[] = [], launches: any[] = [];
|
|
144
|
-
const runner = new AgentRunner(new TaskStore(), { maxConcurrency: 1, stallTimeoutMs: 15000 }, {
|
|
145
|
-
pi: { command: process.execPath, args: ["--experimental-strip-types", "--input-type=module", "--eval", `import(${JSON.stringify(docExtension)}).then(m=>m.launch())`, "--"] },
|
|
146
|
-
now: Date.now, schedule: (fn, ms) => { const timer = setTimeout(fn, ms); return () => clearTimeout(timer); },
|
|
147
|
-
spawn: (command, args, spawnOptions): ChildLike => {
|
|
148
|
-
launches.push({ args, cwd: spawnOptions.cwd });
|
|
149
|
-
const child = spawn(command, args, { ...spawnOptions, stdio: ["pipe", "pipe", "pipe"] });
|
|
150
|
-
let buffer = "";
|
|
151
|
-
child.stdout.on("data", data => { buffer += data; const lines = buffer.split("\n"); buffer = lines.pop()!; for (const line of lines) { try { events.push(JSON.parse(line)); } catch { /* Diagnostics are not RPC evidence. */ } } });
|
|
152
|
-
child.stderr.on("data", data => appendFileSync(join(directory, "stderr.log"), data));
|
|
153
|
-
return child as unknown as ChildLike;
|
|
154
|
-
},
|
|
155
|
-
}, { askUser: async () => ({ cancelled: true }) });
|
|
156
|
-
try {
|
|
157
|
-
const task = runner.run({ agent: { ...actor(phase), ...(phase === "research" ? { tools: ["read", "write", "fetch_content"] } : {}) }, prompt: "Controlled boundary probe only; no implementation or acceptance.", label: undefined, context: phase === "research" ? JSON.stringify(status) : undefined, mode: "task", cwd, parentSessionId: "uptake", model: undefined, thinking: undefined, sessionDir: join(directory, "sessions"), resumeSessionPath: undefined, env: { PATH: process.env.PATH, HOME: home, PI_CODING_AGENT_DIR: home, GENTLE_PI_AGENT_HOME: home, PI_OFFLINE: "1", UPTAKE_CHILD: "1", UPTAKE_RUN: directory, UPTAKE_SCRIPT: scriptPath, GENTLE_PI_GENTLE_AI_DEV_BINARY: binary, ...(phase === "research" ? { [RESEARCH_CHILD_TOOLS_ENV]: JSON.stringify(["read", "write", "fetch_content"]) } : {}), ...options.env }, extensionPaths: [...fixed, ...(options.absentTool ? [] : [docExtension])], researchSelection: selection, sddRemediation: options.remediation, ...(phase === "research" ? {} : { sddChange: { phase, changeName: "uptake", workspaceRoot: cwd, ...options.selection } }) });
|
|
158
|
-
const result = await runner.waitFor(task.id);
|
|
159
|
-
assert.equal(launches.length, 1);
|
|
160
|
-
assert.deepEqual(launches[0].args.flatMap((arg, i, args) => arg === "--extension" ? [args[i + 1]] : []), [...fixed, ...(options.absentTool ? [] : [docExtension])]);
|
|
161
|
-
writeFileSync(join(directory, "events.json"), JSON.stringify(events));
|
|
162
|
-
writeFileSync(join(directory, "launch.json"), JSON.stringify(launches));
|
|
163
|
-
if (process.env.UPTAKE_EVIDENCE_DIR) cpSync(directory, join(process.env.UPTAKE_EVIDENCE_DIR, id), { recursive: true });
|
|
164
|
-
return { result, events, directory, input: existsSync(join(directory, "input-0.json")) ? json(join(directory, "input-0.json")) : undefined };
|
|
165
|
-
} finally { runner.cancelAll(); }
|
|
166
|
-
}
|
|
167
|
-
const ended = (run, name: string) => run.events.filter(event => event.type === "tool_execution_end" && event.toolName === name);
|
|
168
|
-
await t.test("native apply context and installed actor reach actual model/tool input", async () => {
|
|
169
|
-
const observed = await run("apply", "apply", [[["read", { path: join(change, "proposal.md") }]]]);
|
|
170
|
-
assert.equal(observed.result.status, "completed", JSON.stringify(observed.result));
|
|
171
|
-
assert.ok(observed.input.systemPrompt.includes(JSON.stringify(status, null, 2)));
|
|
172
|
-
assert.ok(observed.input.systemPrompt.includes(actor("apply").instructions));
|
|
173
|
-
assert.equal(ended(observed, "read").length, 1); assert.equal(ended(observed, "read")[0].isError, false);
|
|
174
|
-
assert.match(JSON.stringify(ended(observed, "read")[0].result), /Native uptake controlled fixture/);
|
|
175
|
-
});
|
|
176
|
-
const path = join(change, "research.md");
|
|
177
|
-
for (const absentTool of [true, false]) await t.test(`output-only research provisioning absent=${absentTool} preserves parent ownership`, async () => {
|
|
178
|
-
const content = "# Partial research\nExternal questions remain open.\n";
|
|
179
|
-
const before = existsSync(path) ? readFileSync(path, "utf8") : undefined;
|
|
180
|
-
const observed = await run(`research-${absentTool}`, "research", [[["fetch_content", {}]], [["read", { path }]], [["write", { path, content }]]], { absentTool });
|
|
181
|
-
assert.equal(observed.result.status, "completed", JSON.stringify(observed.result));
|
|
182
|
-
assert.equal(ended(observed, "fetch_content")[0].isError, absentTool);
|
|
183
|
-
assert.equal(existsSync(join(observed.directory, "fetch-calls")), !absentTool);
|
|
184
|
-
for (const tool of ["read", "write"]) assert.equal(ended(observed, tool)[0].isError, true);
|
|
185
|
-
assert.equal(existsSync(path) ? readFileSync(path, "utf8") : undefined, before);
|
|
186
|
-
// Scripted parent persistence/readback, not autonomous model proof.
|
|
187
|
-
writeFileSync(path, content);
|
|
188
|
-
assert.equal(readFileSync(path, "utf8"), content);
|
|
189
|
-
if (!absentTool) assert.equal(json(join(observed.directory, "inventory.json")).find(tool => tool.name === "fetch_content").sourceInfo.path, docExtension);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
await t.test("wrong native worktree refuses actual child tool work", async () => {
|
|
193
|
-
const observed = await run("wrong-worktree", "apply", [[["read", { path: join(change, "proposal.md") }]]], { selection: { workspaceRoot: root } });
|
|
194
|
-
assert.match(observed.input.systemPrompt, /SDD selection blocked/);
|
|
195
|
-
assert.equal(ended(observed, "read").length, 1);
|
|
196
|
-
assert.equal(ended(observed, "read")[0].isError, true);
|
|
197
|
-
});
|
|
198
|
-
await t.test("missing installed typed remediation asset refuses before native acquire", async () => {
|
|
199
|
-
const definition = actor("remediate");
|
|
200
|
-
const bytes = readFileSync(definition.filePath);
|
|
201
|
-
rmSync(definition.filePath);
|
|
202
|
-
let acquires = 0;
|
|
203
|
-
try {
|
|
204
|
-
await assert.rejects(admitManagedRemediation({ agent: definition, cwd, sddChange: { phase: "remediate", changeName: "uptake", workspaceRoot: cwd, failedEvidenceRevision: `sha256:${"a".repeat(64)}` } } as unknown as TaskRequest, {}, { ...native, sddAttemptAcquire: async () => { acquires++; throw new Error("Must not acquire"); } } as unknown as import("../lib/native-review-cli.ts").NativeReviewCli), /unsupported/i);
|
|
205
|
-
assert.equal(acquires, 0);
|
|
206
|
-
} finally { writeFileSync(definition.filePath, bytes); }
|
|
207
|
-
});
|
|
208
|
-
await t.test("native failed-evidence identity reaches the installed distinct remediation child; stale binding refuses", async () => {
|
|
209
|
-
writeFileSync(join(change, "tasks.md"), "- [x] Controlled fixture complete\n");
|
|
210
|
-
// A declared failing verification fixture, never a passing evidence claim.
|
|
211
|
-
const failed = `sha256:${"a".repeat(64)}`;
|
|
212
|
-
writeFileSync(join(change, "verify-report.md"), ["```yaml", "schema: gentle-ai.verify-result/v1", `evidence_revision: ${failed}`, "verdict: fail", "blockers: 1", "critical_findings: 0", "requirements: 1/1", "scenarios: 1/1", "test_command: false", "test_exit_code: 1", `test_output_hash: sha256:${digest("")}`, "build_command: true", "build_exit_code: 0", `build_output_hash: sha256:${digest("")}`, "```"].join("\n"));
|
|
213
|
-
const remediationStatus = await native.sddStatus({ changeName: "uptake", workspaceRoot: cwd });
|
|
214
|
-
assert.equal(remediationStatus.nextRecommended, "remediate");
|
|
215
|
-
assert.equal(remediationStatus.remediationState.failedEvidenceRevision, failed);
|
|
216
|
-
const plan = { cwd, editPaths: [join(change, "proposal.md")], commands: ["true"], runtimeHarness: { naReason: "No correction harness because this controlled boundary performs no source correction or acceptance." }, rollback: { boundary: "Remove the isolated controlled fixture only", command: "true" } };
|
|
217
|
-
const remediation = { failedEvidenceRevision: failed, plan, scope: { cwd, commands: ["true", "true"], editPaths: [join(change, "proposal.md")], allowedEditRoots: [cwd] }, observations: [], pending: {}, invalid: false };
|
|
218
|
-
const observed = await run("remediate", "remediate", [[["read", { path: join(change, "proposal.md") }]]], { selection: { failedEvidenceRevision: failed }, remediation });
|
|
219
|
-
assert.ok(observed.input.systemPrompt.includes(JSON.stringify(remediationStatus, null, 2)), observed.input.systemPrompt.slice(-9000));
|
|
220
|
-
assert.ok(observed.input.systemPrompt.includes(actor("remediate").instructions));
|
|
221
|
-
assert.equal(ended(observed, "read")[0].isError, false, JSON.stringify({ ended: ended(observed, "read"), startup: json(join(observed.directory, "startup.json")) }));
|
|
222
|
-
const stale = await run("stale-remediation", "remediate", [[["read", { path: join(change, "proposal.md") }]]], { selection: { failedEvidenceRevision: `sha256:${"b".repeat(64)}` }, remediation });
|
|
223
|
-
assert.match(stale.input.systemPrompt, /Stale remediation selection/);
|
|
224
|
-
assert.equal(ended(stale, "read")[0].isError, true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
const buildFiles: Record<string, string> = {};
|
|
228
|
-
const inventory = (directory: string) => {
|
|
229
|
-
for (const entry of readdirSync(join(pkg, directory), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
230
|
-
const name = join(directory, entry.name);
|
|
231
|
-
if (entry.isDirectory()) inventory(name); else if (entry.isFile()) buildFiles[name] = digest(readFileSync(join(pkg, name)));
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
for (const directory of ["assets", "extensions", "lib", "runtime", "contracts", "scripts"]) inventory(directory);
|
|
235
|
-
buildFiles["package.json"] = digest(readFileSync(join(pkg, "package.json")));
|
|
236
|
-
const tuple = { aiSource: producerIdentity.sourceRevision, aiBinary: producerIdentity.sha256, piHead: execFileSync("git", ["rev-parse", "HEAD"], { cwd: source, encoding: "utf8" }).trim(), piBuild: digest(JSON.stringify(buildFiles)), buildFiles, manifest, contract: "gentle-ai.sdd-status/v2" };
|
|
237
|
-
if (process.env.UPTAKE_EVIDENCE_DIR) {
|
|
238
|
-
writeFileSync(join(process.env.UPTAKE_EVIDENCE_DIR, "tuple.json"), JSON.stringify(tuple, null, 2));
|
|
239
|
-
cpSync(join(home, "agents"), join(process.env.UPTAKE_EVIDENCE_DIR, "installed-agents"), { recursive: true });
|
|
240
|
-
}
|
|
241
|
-
t.diagnostic(JSON.stringify({ aiSource: tuple.aiSource, aiBinary: tuple.aiBinary, piHead: tuple.piHead, piBuild: tuple.piBuild, contract: tuple.contract }));
|
|
242
|
-
|
|
243
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import test from "node:test";
|
|
4
|
-
|
|
5
|
-
test("ordinary SDD instructions keep native selection and TDD without attempt launch governance", () => {
|
|
6
|
-
const read = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8");
|
|
7
|
-
const workflow = read("assets/sdd-orchestrator-workflow.md");
|
|
8
|
-
const status = read("assets/support/sdd-status-contract.md");
|
|
9
|
-
for (const text of [workflow, status, read("assets/agents/sdd-remediate.md")]) {
|
|
10
|
-
assert.doesNotMatch(text, /sdd-attempt (acquire|settle)|Native Runtime Attempt Authority|compact acquire\/settle/);
|
|
11
|
-
}
|
|
12
|
-
assert.match(workflow, /Strict TDD/);
|
|
13
|
-
assert.match(status, /native.*authoritative|authoritative.*native/i);
|
|
14
|
-
assert.match(status, /edit.*grant|grant.*edit/i);
|
|
15
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import test from "node:test";
|
|
4
|
-
|
|
5
|
-
const read = (path: string) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8");
|
|
6
|
-
|
|
7
|
-
test("integrated organic continuity and selected SDD keep separate persistence ownership", () => {
|
|
8
|
-
const memory = read("assets/orchestrator-memory.md");
|
|
9
|
-
assert.match(memory, /one feature document, not a separate plan file or topic/);
|
|
10
|
-
assert.match(memory, /odd\/tasks\/<feature-name>\.md/);
|
|
11
|
-
assert.match(memory, /odd\/<feature-name>\/tasks/);
|
|
12
|
-
assert.match(memory, /Research is output-only/);
|
|
13
|
-
assert.match(memory, /Except for output-only `sdd-research`/);
|
|
14
|
-
assert.match(memory, /do not switch the selected store/);
|
|
15
|
-
const delegation = read("assets/orchestrator-delegation.md");
|
|
16
|
-
assert.match(delegation, /organic work, not explicitly selected SDD/);
|
|
17
|
-
assert.match(delegation, /do not create a specialized agent or invoke `sdd-research`/);
|
|
18
|
-
assert.match(read("assets/agents/sdd-research.md"), /Do not read local artifacts/);
|
|
19
|
-
assert.match(read("assets/sdd-orchestrator-workflow.md"), /Optional research takes precedence/);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("integrated TDD guidance preserves native SDD completion without retired consumers", () => {
|
|
23
|
-
const wrapper = read("extensions/gentle-ai.ts"), tasks = read("assets/agents/sdd-tasks.md");
|
|
24
|
-
assert.match(wrapper, /Use configured TDD mode, source, and exact runner/);
|
|
25
|
-
assert.doesNotMatch(wrapper + tasks, /If tests exist(?:, use strict TDD| or strict TDD)/);
|
|
26
|
-
assert.match(tasks, /Only when configured strict TDD is active/);
|
|
27
|
-
assert.match(read("assets/agents/sdd-apply.md"), /native task progress and authorized scope/);
|
|
28
|
-
assert.match(read("assets/agents/sdd-verify.md"), /Archive admission follows fresh native status and real permissions/);
|
|
29
|
-
assert.match(read("assets/chains/sdd-full.chain.md"), /apply -> archive/);
|
|
30
|
-
for (const path of ["assets/agents/sdd-sync.md", "lib/openspec-guardrails.ts"]) {
|
|
31
|
-
assert.equal(existsSync(new URL(`../${path}`, import.meta.url)), false, path);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
|
-
import assert from "node:assert/strict";
|
|
4
|
-
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import test from "node:test";
|
|
8
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
9
|
-
import gentleAgents from "../extensions/gentle-agents.ts";
|
|
10
|
-
|
|
11
|
-
interface HookEvent {
|
|
12
|
-
systemPrompt?: string;
|
|
13
|
-
toolName?: string;
|
|
14
|
-
toolCallId?: string;
|
|
15
|
-
input?: Record<string, unknown>;
|
|
16
|
-
content?: Array<{ type: "text"; text: string }>;
|
|
17
|
-
isError?: boolean;
|
|
18
|
-
}
|
|
19
|
-
interface HookResult { block?: boolean; reason?: string; isError?: boolean; systemPrompt?: string }
|
|
20
|
-
type Hook = (event: HookEvent, ctx: { cwd: string }) => HookResult | undefined;
|
|
21
|
-
|
|
22
|
-
function child(cwd: string, artifact?: unknown, selection?: unknown) {
|
|
23
|
-
const hooks = new Map<string, Hook>();
|
|
24
|
-
let active = ["read", "grep", "find", "write", "edit", "mem_save", "mem_search", "mem_get_observation", "web_search", "subagent_parent_message"];
|
|
25
|
-
let source = "/installed/search.ts";
|
|
26
|
-
const pi = { on: (name: string, hook: Hook) => hooks.set(name, hook),
|
|
27
|
-
getActiveTools: () => active,
|
|
28
|
-
getAllTools: () => active.map(name => ({ name, sourceInfo: { source: "extension", path: source } })),
|
|
29
|
-
appendEntry: () => assert.fail("research must not create a second persistence checkpoint"),
|
|
30
|
-
};
|
|
31
|
-
gentleAgents(pi as unknown as ExtensionAPI, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_RESEARCH_TOOLS: JSON.stringify(active),
|
|
32
|
-
GENTLE_PI_RESEARCH_SELECTION: JSON.stringify(selection ?? null), GENTLE_PI_RESEARCH_ARTIFACT: JSON.stringify(artifact ?? null) });
|
|
33
|
-
// No physical session file or pre-existing artifact is necessary.
|
|
34
|
-
const ctx = { cwd };
|
|
35
|
-
hooks.get("before_agent_start")!({ systemPrompt: "Research a question" }, ctx);
|
|
36
|
-
return {
|
|
37
|
-
call: (toolName: string, input: Record<string, unknown> = {}) => hooks.get("tool_call")!({ toolName, input, toolCallId: "call" }, ctx),
|
|
38
|
-
result: (toolName: string, input: Record<string, unknown>, content: string, isError = false) => {
|
|
39
|
-
const event = { toolName, input, toolCallId: "call", content: [{ type: "text" as const, text: content }], isError };
|
|
40
|
-
return { ...event, ...hooks.get("tool_result")?.(event, ctx) };
|
|
41
|
-
},
|
|
42
|
-
deactivate: (name: string) => { active = active.filter(tool => tool !== name); },
|
|
43
|
-
replaceSource: () => { source = "/different/search.ts"; },
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function workspace(t: test.TestContext) {
|
|
48
|
-
const cwd = realpathSync(mkdtempSync(join(tmpdir(), "pi-optional-research-")));
|
|
49
|
-
t.after(() => rmSync(cwd, { recursive: true, force: true }));
|
|
50
|
-
return cwd;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
test("optional research is output-only even with historical artifact identity", t => {
|
|
54
|
-
const cwd = workspace(t);
|
|
55
|
-
const path = join(cwd, "openspec/changes/demo/research.md"), content = '{"revision":1,"outcome":"partial"}';
|
|
56
|
-
mkdirSync(join(cwd, "openspec/changes/demo"), { recursive: true });
|
|
57
|
-
writeFileSync(path, content);
|
|
58
|
-
const h = child(cwd, { store: "openspec", worktree: cwd, changeName: "demo", retainedIntent: "Research question", locators: [{ artifact: "research", path, revision: 1, digest: createHash("sha256").update(content).digest("hex") }] });
|
|
59
|
-
for (const tool of ["read", "grep", "find", "write", "edit", "mem_save", "mem_search", "mem_get_observation", "bash"]) {
|
|
60
|
-
assert.equal(h.call(tool, { path, content: "overwrite", id: 1 })?.block, true, tool);
|
|
61
|
-
}
|
|
62
|
-
assert.equal(readFileSync(path, "utf8"), content);
|
|
63
|
-
assert.equal(h.call("subagent_parent_message", { message: "Partial findings; external sources unavailable." }), undefined);
|
|
64
|
-
assert.equal(h.result("web_search", {}, "Partial search results").isError, false);
|
|
65
|
-
assert.equal(h.result("web_search", {}, "Permission denied", true).isError, true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test("optional research uses individually authorized external tools but never invents grants", t => {
|
|
69
|
-
const cwd = workspace(t);
|
|
70
|
-
const selection = { "open-web": { tools: ["web_search"], extensions: { web_search: "/installed/search.ts" } } };
|
|
71
|
-
const h = child(cwd, undefined, selection);
|
|
72
|
-
assert.equal(h.call("web_search", { query: "official reference" }), undefined);
|
|
73
|
-
assert.equal(h.call("fetch_content", { url: "https://example.com" })?.block, true);
|
|
74
|
-
assert.equal(h.call("mcp", {})?.block, true);
|
|
75
|
-
h.replaceSource();
|
|
76
|
-
assert.equal(h.call("web_search", {})?.block, true, "changed extension provenance revokes the route");
|
|
77
|
-
const inactive = child(cwd, undefined, selection); inactive.deactivate("web_search");
|
|
78
|
-
assert.equal(inactive.call("web_search", {})?.block, true);
|
|
79
|
-
assert.equal(child(cwd).call("web_search", {})?.block, true, "availability alone is not authorization");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (process.env.SDD_TEST_ENGRAM) test("research parent can persist first partial artifact through actual isolated Engram", t => {
|
|
83
|
-
const cwd = workspace(t), project = "research-fixture", binary = process.env.SDD_TEST_ENGRAM!;
|
|
84
|
-
const env = { ...process.env, ENGRAM_DATA_DIR: join(cwd, "memory"), ENGRAM_PROJECT: project };
|
|
85
|
-
// Establish a known test project, not a research artifact or session checkpoint.
|
|
86
|
-
execFileSync(binary, ["save", "Fixture context", "Isolated project context", "--project", project], { cwd, env, stdio: "pipe" });
|
|
87
|
-
const invoke = (name: string, args: Record<string, unknown>) => {
|
|
88
|
-
const messages = [
|
|
89
|
-
{ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "research-integration", version: "1" } } },
|
|
90
|
-
{ jsonrpc: "2.0", method: "notifications/initialized" },
|
|
91
|
-
{ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name, arguments: args } },
|
|
92
|
-
];
|
|
93
|
-
const raw = execFileSync(binary, ["mcp", "--project", project], { cwd, env, encoding: "utf8", input: messages.map(value => JSON.stringify(value)).join("\n") + "\n", timeout: 15_000 });
|
|
94
|
-
const response = raw.trim().split("\n").map(line => JSON.parse(line)).find(value => value.id === 2);
|
|
95
|
-
assert.ok(response?.result && !response.error);
|
|
96
|
-
assert.notEqual(response.result.isError, true);
|
|
97
|
-
return response.result.content.map((part: { text: string }) => part.text).join("");
|
|
98
|
-
};
|
|
99
|
-
const engram = { project, topic_key: "sdd/demo/research" };
|
|
100
|
-
// The parent owns persistence; research child hooks never perform or approve it.
|
|
101
|
-
const input = { ...engram, title: "Partial documentation research", content: "External sources unavailable; product question remains unanswered.", capture_prompt: false };
|
|
102
|
-
const saved = invoke("mem_save", input);
|
|
103
|
-
const id = JSON.parse(saved).id; assert.ok(Number.isSafeInteger(id));
|
|
104
|
-
const readback = invoke("mem_get_observation", { id });
|
|
105
|
-
assert.ok(JSON.parse(readback).result.includes(input.content));
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
test("optional research handoff keeps first file persistence and readback parent-owned", t => {
|
|
111
|
-
const cwd = workspace(t), path = join(cwd, "openspec/changes/demo/research.md");
|
|
112
|
-
const findings = "# Research\nPartial findings; external sources unavailable.\n";
|
|
113
|
-
assert.equal(child(cwd).call("write", { path, content: findings })?.block, true);
|
|
114
|
-
// This models the parent using its existing file tools, not a child persistence adapter.
|
|
115
|
-
mkdirSync(join(cwd, "openspec/changes/demo"), { recursive: true });
|
|
116
|
-
writeFileSync(path, findings);
|
|
117
|
-
assert.equal(readFileSync(path, "utf8"), findings);
|
|
118
|
-
const workflow = readFileSync(new URL("../assets/sdd-orchestrator-workflow.md", import.meta.url), "utf8");
|
|
119
|
-
const gate = workflow.slice(workflow.indexOf("## Automatic Mode Gatekeeper"));
|
|
120
|
-
assert.ok(gate.indexOf("Optional research takes precedence") < gate.indexOf("**Contract conformance:**"));
|
|
121
|
-
assert.match(gate, /accept honest partial, unavailable, or inline findings without requiring an artifact or retry/);
|
|
122
|
-
assert.match(workflow, /parent owns local reads, product choices, and any authorized persistence\/readback/);
|
|
123
|
-
assert.match(workflow, /First artifacts and in-memory sessions require no prior identity or checkpoint/);
|
|
124
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import test from "node:test";
|
|
4
|
-
|
|
5
|
-
const paths = [
|
|
6
|
-
"assets/sdd-orchestrator-workflow.md",
|
|
7
|
-
"assets/support/sdd-status-contract.md",
|
|
8
|
-
];
|
|
9
|
-
const documents = paths.map((path) => readFileSync(new URL(`../${path}`, import.meta.url), "utf8"));
|
|
10
|
-
|
|
11
|
-
function routingContract(document: string): string {
|
|
12
|
-
const section = document.match(/## Bounded Planning Routing\n([\s\S]*?)(?=\n## |$)/);
|
|
13
|
-
assert.ok(section, "explicit bounded planning routing contract is required");
|
|
14
|
-
return section[1].trim();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const [index, path] of paths.entries()) {
|
|
18
|
-
test(`${path}: native planning tokens are the only automatic routes`, () => {
|
|
19
|
-
const contract = routingContract(documents[index]);
|
|
20
|
-
for (const [token, phase] of [["propose", "sdd-proposal"], ["spec", "sdd-spec"], ["design", "sdd-design"], ["tasks", "sdd-tasks"]]) {
|
|
21
|
-
assert.ok(contract.includes(`| \`${token}\` | \`${phase}\` |`));
|
|
22
|
-
}
|
|
23
|
-
assert.match(contract, /only automatic planning routes/i);
|
|
24
|
-
assert.doesNotMatch(contract, /^\| `sdd-(?:propose|spec|design|tasks)`/m);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test(`${path}: planning preserves native blocker and edit-root guards`, () => {
|
|
28
|
-
const contract = routingContract(documents[index]);
|
|
29
|
-
for (const guard of [
|
|
30
|
-
"stop for ambiguous change selection, unresolved session preflight, or unsafe action context",
|
|
31
|
-
"prove planned writes are within the authoritative workspace or allowed edit roots",
|
|
32
|
-
"workspace-planning without allowed edit roots remains read-only",
|
|
33
|
-
"Planning does not bypass the init guard, optional research guidance, or phase approval requirements",
|
|
34
|
-
"never infer a route from prose",
|
|
35
|
-
"Keep genuine blockers in `blockedReasons` and non-blocking diagnostics in `notes`, never in `nextRecommended`",
|
|
36
|
-
"report them without discarding them to enable a route",
|
|
37
|
-
]) {
|
|
38
|
-
assert.ok(contract.includes(guard), `missing guard: ${guard}`);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
test("workflow and support contract agree on bounded planning routing", () => {
|
|
44
|
-
assert.equal(routingContract(documents[0]), routingContract(documents[1]));
|
|
45
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
9
|
-
import { isSddPreflightTrigger, sddPreflightDiskPath } from "../lib/sdd-preflight.ts";
|
|
10
|
-
|
|
11
|
-
// The `input` hook is syntax-only: slash SDD commands may originate preflight
|
|
12
|
-
// in an interactive parent, while ordinary natural-language text always reaches
|
|
13
|
-
// the model. Natural-language SDD selection belongs to the parent/orchestrator;
|
|
14
|
-
// dispatch and before_agent_start gates enforce preflight at the action boundary.
|
|
15
|
-
// RPC children consume the parent-rendered preflight block transported in task
|
|
16
|
-
// context and never originate preflight.
|
|
17
|
-
|
|
18
|
-
type InputResult = { action: "continue" | "handled" };
|
|
19
|
-
type InputHandler = (event: { text?: unknown }, ctx: ExtensionContext) => Promise<InputResult>;
|
|
20
|
-
|
|
21
|
-
const DELEGATED_SDD_TASK = "Implement the accepted SDD change.";
|
|
22
|
-
|
|
23
|
-
function inputHook(): InputHandler {
|
|
24
|
-
const handlers = new Map<string, InputHandler>();
|
|
25
|
-
const pi = {
|
|
26
|
-
on(name: string, handler: InputHandler) {
|
|
27
|
-
handlers.set(name, handler);
|
|
28
|
-
},
|
|
29
|
-
events: { emit() {} },
|
|
30
|
-
registerCommand() {},
|
|
31
|
-
registerTool() {},
|
|
32
|
-
getActiveTools: () => [],
|
|
33
|
-
} as unknown as ExtensionAPI;
|
|
34
|
-
createGentleAiExtension({ nativeReviewCli: null })(pi);
|
|
35
|
-
const input = handlers.get("input");
|
|
36
|
-
assert.equal(typeof input, "function", "the extension must register an input hook");
|
|
37
|
-
return input as InputHandler;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function ctx(overrides: Record<string, unknown>): ExtensionContext {
|
|
41
|
-
return {
|
|
42
|
-
cwd: process.cwd(),
|
|
43
|
-
hasUI: true,
|
|
44
|
-
ui: { notify() {} },
|
|
45
|
-
sessionManager: { getSessionId: () => "sdd-preflight-rpc-input" },
|
|
46
|
-
...overrides,
|
|
47
|
-
} as unknown as ExtensionContext;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
test("natural-language SDD task text bypasses the input preflight interceptor", () => {
|
|
51
|
-
assert.equal(isSddPreflightTrigger(DELEGATED_SDD_TASK), false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("an RPC child's natural-language SDD prompt is not consumed by the input hook", async () => {
|
|
55
|
-
const input = inputHook();
|
|
56
|
-
const cwd = await mkdtemp(join(tmpdir(), "gentle-pi-rpc-input-"));
|
|
57
|
-
const notifications: string[] = [];
|
|
58
|
-
try {
|
|
59
|
-
const result = await input(
|
|
60
|
-
{ text: DELEGATED_SDD_TASK },
|
|
61
|
-
ctx({
|
|
62
|
-
cwd,
|
|
63
|
-
mode: "rpc",
|
|
64
|
-
sessionManager: { getSessionId: () => "sdd-preflight-rpc-child" },
|
|
65
|
-
ui: { notify: (message: string) => notifications.push(message) },
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
assert.deepEqual(result, { action: "continue" }, "a delegated prompt must reach the agent");
|
|
69
|
-
assert.deepEqual(notifications, [], "an RPC child must not originate preflight at all");
|
|
70
|
-
assert.equal(existsSync(sddPreflightDiskPath(cwd)), false, "an RPC child must not persist defaults");
|
|
71
|
-
} finally {
|
|
72
|
-
await rm(cwd, { recursive: true, force: true });
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("an RPC child's ordinary prompt still continues", async () => {
|
|
77
|
-
const input = inputHook();
|
|
78
|
-
const cwd = await mkdtemp(join(tmpdir(), "gentle-pi-rpc-input-control-"));
|
|
79
|
-
try {
|
|
80
|
-
const result = await input(
|
|
81
|
-
{ text: "Implement a small Rust selection type." },
|
|
82
|
-
ctx({ cwd, mode: "rpc", sessionManager: { getSessionId: () => "sdd-preflight-rpc-control" } }),
|
|
83
|
-
);
|
|
84
|
-
assert.deepEqual(result, { action: "continue" });
|
|
85
|
-
assert.equal(existsSync(sddPreflightDiskPath(cwd)), false);
|
|
86
|
-
} finally {
|
|
87
|
-
await rm(cwd, { recursive: true, force: true });
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("an interactive parent's natural-language SDD request has no input-hook side effect", async () => {
|
|
92
|
-
const input = inputHook();
|
|
93
|
-
const cwd = await mkdtemp(join(tmpdir(), "gentle-pi-parent-natural-input-"));
|
|
94
|
-
try {
|
|
95
|
-
const result = await input(
|
|
96
|
-
{ text: DELEGATED_SDD_TASK },
|
|
97
|
-
ctx({ cwd, hasUI: false, sessionManager: { getSessionId: () => "sdd-preflight-natural-parent" } }),
|
|
98
|
-
);
|
|
99
|
-
assert.deepEqual(result, { action: "continue" });
|
|
100
|
-
assert.equal(existsSync(sddPreflightDiskPath(cwd)), false, "text alone must not persist preflight");
|
|
101
|
-
} finally {
|
|
102
|
-
await rm(cwd, { recursive: true, force: true });
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test("an interactive parent still resolves preflight for an explicit slash SDD command", async () => {
|
|
107
|
-
const input = inputHook();
|
|
108
|
-
const cwd = await mkdtemp(join(tmpdir(), "gentle-pi-parent-slash-input-"));
|
|
109
|
-
const agentHome = await mkdtemp(join(tmpdir(), "gentle-pi-parent-agent-home-"));
|
|
110
|
-
const previousAgentHome = process.env.GENTLE_PI_AGENT_HOME;
|
|
111
|
-
process.env.GENTLE_PI_AGENT_HOME = agentHome;
|
|
112
|
-
try {
|
|
113
|
-
const result = await input(
|
|
114
|
-
{ text: "/sdd-new feature" },
|
|
115
|
-
ctx({ cwd, hasUI: false, sessionManager: { getSessionId: () => "sdd-preflight-slash-parent" } }),
|
|
116
|
-
);
|
|
117
|
-
assert.deepEqual(result, { action: "continue" });
|
|
118
|
-
assert.equal(existsSync(sddPreflightDiskPath(cwd)), true, "slash SDD commands still resolve preflight");
|
|
119
|
-
} finally {
|
|
120
|
-
if (previousAgentHome === undefined) delete process.env.GENTLE_PI_AGENT_HOME;
|
|
121
|
-
else process.env.GENTLE_PI_AGENT_HOME = previousAgentHome;
|
|
122
|
-
await rm(cwd, { recursive: true, force: true });
|
|
123
|
-
await rm(agentHome, { recursive: true, force: true });
|
|
124
|
-
}
|
|
125
|
-
});
|