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
package/lib/native-review-cli.ts
CHANGED
|
@@ -67,8 +67,6 @@ export const NATIVE_REVIEW_OPERATION = {
|
|
|
67
67
|
CAPTURE_PROVIDER_ROLE: "review/capture-provider-role",
|
|
68
68
|
CAPTURE_UNACHIEVABLE: "review/capture-unachievable",
|
|
69
69
|
ACKNOWLEDGE_APPROVED: "review/acknowledge-approved",
|
|
70
|
-
SDD_STATUS: "sdd-status",
|
|
71
|
-
SDD_CONTINUE: "sdd-continue",
|
|
72
70
|
} as const;
|
|
73
71
|
export type NativeReviewOperation = (typeof NATIVE_REVIEW_OPERATION)[keyof typeof NATIVE_REVIEW_OPERATION];
|
|
74
72
|
|
|
@@ -121,11 +119,6 @@ export interface NativeReviewCli {
|
|
|
121
119
|
// an older binary without the verb, or any other process/decode failure,
|
|
122
120
|
// rejects the returned promise -- callers fail closed to `high` risk.
|
|
123
121
|
assess?(request: NativeReviewAssessRequest): Promise<ReviewAssessmentV1>;
|
|
124
|
-
// Exact native SDD readiness authority for an explicitly selected phase.
|
|
125
|
-
// This is intentionally separate from review/RDD gates and carries no
|
|
126
|
-
// delivery or review-transaction authority.
|
|
127
|
-
sddStatus?(request: NativeSddStatusRequest): Promise<NativeSddStatusV2>;
|
|
128
|
-
sddContinue?(request: NativeSddStatusRequest): Promise<NativeSddStatusV2>;
|
|
129
122
|
}
|
|
130
123
|
|
|
131
124
|
export const NATIVE_REVIEW_MODE_OPERATION = {
|
|
@@ -162,35 +155,6 @@ export const NATIVE_REVIEW_MODE_SCOPE = {
|
|
|
162
155
|
} as const;
|
|
163
156
|
export type NativeReviewModeScope = (typeof NATIVE_REVIEW_MODE_SCOPE)[keyof typeof NATIVE_REVIEW_MODE_SCOPE];
|
|
164
157
|
|
|
165
|
-
export interface NativeSddStatusRequest {
|
|
166
|
-
changeName?: string;
|
|
167
|
-
workspaceRoot: string;
|
|
168
|
-
signal?: AbortSignal;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export type NativeSddPhase = "apply" | "verify" | "archive";
|
|
172
|
-
export type NativeSddDependencyState = "blocked" | "ready" | "all_done";
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* The native CLI owns this complete v2 record. The decoder validates the fields
|
|
176
|
-
* Pi relies on and returns the original object without adding, omitting, or
|
|
177
|
-
* reconciling local SDD state.
|
|
178
|
-
*/
|
|
179
|
-
export interface NativeSddStatusV2 extends Readonly<Record<string, unknown>> {
|
|
180
|
-
schemaName: "gentle-ai.sdd-status";
|
|
181
|
-
schemaVersion: 2;
|
|
182
|
-
changeName: string | null;
|
|
183
|
-
artifactStore: "openspec" | "engram" | "hybrid" | "none";
|
|
184
|
-
planningHome: Readonly<Record<string, unknown>> & { mode: "repo-local"; path: string };
|
|
185
|
-
changeRoot: string | null;
|
|
186
|
-
actionContext: Readonly<Record<string, unknown>> & { mode: "repo-local"; workspaceRoot: string; allowedEditRoots: readonly string[] };
|
|
187
|
-
dependencies: Readonly<Record<(typeof NATIVE_SDD_DEPENDENCIES)[number], NativeSddDependencyState>>;
|
|
188
|
-
phaseInstructions?: Readonly<Record<(typeof NATIVE_SDD_INSTRUCTION_PHASES)[number], readonly string[]> & { remediate?: readonly string[] }>;
|
|
189
|
-
blockedReasons: readonly string[];
|
|
190
|
-
nextRecommended: string;
|
|
191
|
-
remediationState?: { required: boolean; complete: boolean; failedEvidenceRevision: string };
|
|
192
|
-
}
|
|
193
|
-
|
|
194
158
|
export interface NativeReviewModeRequest {
|
|
195
159
|
cwd: string;
|
|
196
160
|
operation: NativeReviewModeOperation;
|
|
@@ -747,6 +711,21 @@ function nativeUntrackedSelectionArguments(selection: NativeUntrackedSelection):
|
|
|
747
711
|
];
|
|
748
712
|
}
|
|
749
713
|
|
|
714
|
+
// Fail closed on malformed or duplicate provider selectors before invoking STATUS.
|
|
715
|
+
function providerFlagValue(tokens: readonly string[], flag: string): string | undefined {
|
|
716
|
+
let found: string | undefined;
|
|
717
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
718
|
+
const token = tokens[index]!;
|
|
719
|
+
if (token !== `--${flag}` && !token.startsWith(`--${flag}=`)) continue;
|
|
720
|
+
if (found !== undefined) throw new TypeError(`Native intended-untracked selection repeats --${flag}`);
|
|
721
|
+
const value = token === `--${flag}` ? tokens[index + 1] : token.slice(`--${flag}=`.length);
|
|
722
|
+
if (value === undefined || value === "" || value.startsWith("--")) throw new TypeError(`Native intended-untracked selection has an invalid --${flag} value`);
|
|
723
|
+
found = value;
|
|
724
|
+
if (token === `--${flag}`) index++;
|
|
725
|
+
}
|
|
726
|
+
return found;
|
|
727
|
+
}
|
|
728
|
+
|
|
750
729
|
const NATIVE_RISK_LEVEL = ["low", "medium", "high"] as const;
|
|
751
730
|
|
|
752
731
|
// gentle-ai's negotiated `start/v2` envelope is a closed schema
|
|
@@ -1044,6 +1023,17 @@ export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
|
1044
1023
|
// changes no review-integration schema or capability source. riskEvidence and
|
|
1045
1024
|
// hint remain dark because neither is proven in Pi's negotiated START path.
|
|
1046
1025
|
"3.6.1": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
1026
|
+
// v3.7.0 repeats 3.6.1: the published provider-contract tar remains SHA-256
|
|
1027
|
+
// 547b68e172cc87aa297309d61624e5fc2c24d407a494b53eeb5a2b053904352c
|
|
1028
|
+
// at contract 1.2.0. No new negotiated capability is asserted.
|
|
1029
|
+
"3.7.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
1030
|
+
// v4.0.0 repeats 3.7.0: the published provider-contract tar remains SHA-256
|
|
1031
|
+
// 547b68e172cc87aa297309d61624e5fc2c24d407a494b53eeb5a2b053904352c
|
|
1032
|
+
// at contract 1.2.0, and the published binary still advertises
|
|
1033
|
+
// capabilities/v2.6 under review-integration/v2. The Go module path moved
|
|
1034
|
+
// to /v4 without a review-integration/v2 change. No new negotiated
|
|
1035
|
+
// capability is asserted.
|
|
1036
|
+
"4.0.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
1047
1037
|
});
|
|
1048
1038
|
|
|
1049
1039
|
export interface NativeReviewProcessDiagnostics {
|
|
@@ -1511,52 +1501,6 @@ interface NativeJsonExecution {
|
|
|
1511
1501
|
process: ExecFileResult;
|
|
1512
1502
|
}
|
|
1513
1503
|
|
|
1514
|
-
const NATIVE_SDD_DEPENDENCIES = ["proposal", "specs", "design", "tasks", "apply", "verify", "archive"] as const;
|
|
1515
|
-
const NATIVE_SDD_INSTRUCTION_PHASES = ["apply", "verify", "archive"] as const;
|
|
1516
|
-
const NATIVE_SDD_NEXT_RECOMMENDATIONS = ["apply", "verify", "remediate", "archive", "archived", "resolve-blockers", "sdd-new", "select-change", "propose", "spec", "design", "tasks"] as const;
|
|
1517
|
-
const NATIVE_SDD_DEPENDENCY_STATES = ["blocked", "ready", "all_done"] as const;
|
|
1518
|
-
|
|
1519
|
-
/** Strictly validates the native v2 contract while preserving its whole record. */
|
|
1520
|
-
export function decodeNativeSddStatusV2(value: unknown, request: Pick<NativeSddStatusRequest, "changeName" | "workspaceRoot">): NativeSddStatusV2 {
|
|
1521
|
-
const status = object(value);
|
|
1522
|
-
if (status.schemaName !== "gentle-ai.sdd-status" || status.schemaVersion !== 2) throw new Error("wrong native SDD status schema");
|
|
1523
|
-
if ((request.changeName !== undefined && status.changeName !== request.changeName) || (status.changeName !== null && !isCanonicalProcessString(status.changeName))) throw new Error("native SDD status change identity mismatch");
|
|
1524
|
-
const artifactStore = enumString(status.artifactStore, ["openspec", "engram", "hybrid", "none"]);
|
|
1525
|
-
const planningHome = object(status.planningHome);
|
|
1526
|
-
if (planningHome.mode !== "repo-local" || !isCanonicalProcessString(planningHome.path)) throw new Error("invalid native SDD planning home");
|
|
1527
|
-
const expectedOpenSpecHome = join(request.workspaceRoot, "openspec");
|
|
1528
|
-
if (planningHome.path !== expectedOpenSpecHome && !((artifactStore === "engram" || artifactStore === "hybrid") && planningHome.path === "engram:sdd")) throw new Error("native SDD planning home escaped its workspace");
|
|
1529
|
-
if (status.changeRoot !== null && !isCanonicalProcessString(status.changeRoot)) throw new Error("invalid native SDD change root");
|
|
1530
|
-
const actionContext = object(status.actionContext);
|
|
1531
|
-
if (actionContext.mode !== "repo-local" || actionContext.workspaceRoot !== request.workspaceRoot || !isCanonicalProcessString(actionContext.workspaceRoot)) throw new Error("native SDD status workspace root mismatch");
|
|
1532
|
-
const allowedEditRoots = stringArray(actionContext.allowedEditRoots);
|
|
1533
|
-
if (!allowedEditRoots.includes(request.workspaceRoot) || allowedEditRoots.some((root) => !isAbsolute(root) || root !== join(root))) throw new Error("invalid native SDD allowed edit roots");
|
|
1534
|
-
const dependencies = object(status.dependencies);
|
|
1535
|
-
for (const phase of NATIVE_SDD_DEPENDENCIES) {
|
|
1536
|
-
if (enumString(dependencies[phase], NATIVE_SDD_DEPENDENCY_STATES) !== dependencies[phase]) throw new Error("invalid native SDD dependency");
|
|
1537
|
-
}
|
|
1538
|
-
if (Object.keys(dependencies).length !== NATIVE_SDD_DEPENDENCIES.length) throw new Error("native SDD dependencies have an unsupported shape");
|
|
1539
|
-
if (status.instructions !== undefined) throw new Error("native SDD status uses phaseInstructions, not instructions");
|
|
1540
|
-
if (status.phaseInstructions !== undefined) {
|
|
1541
|
-
const instructions = object(status.phaseInstructions);
|
|
1542
|
-
for (const phase of NATIVE_SDD_INSTRUCTION_PHASES) stringArray(instructions[phase]);
|
|
1543
|
-
// Classical SDD no longer emits a remediation phase. Keep the published
|
|
1544
|
-
// producer's optional legacy instructions intact without inventing them
|
|
1545
|
-
// for a newer producer or accepting unknown phase keys.
|
|
1546
|
-
const hasRemediation = Object.hasOwn(instructions, "remediate");
|
|
1547
|
-
if (hasRemediation) stringArray(instructions.remediate);
|
|
1548
|
-
if (Object.keys(instructions).length !== NATIVE_SDD_INSTRUCTION_PHASES.length + Number(hasRemediation)) throw new Error("native SDD instructions have an unsupported shape");
|
|
1549
|
-
if (status.nextRecommended === "remediate" && !hasRemediation) throw new Error("native SDD remediation instructions are missing");
|
|
1550
|
-
}
|
|
1551
|
-
if (status.nextRecommended === "remediate" || status.remediationState !== undefined) {
|
|
1552
|
-
const remediation = object(status.remediationState);
|
|
1553
|
-
if (typeof remediation.required !== "boolean" || typeof remediation.complete !== "boolean" || typeof remediation.failedEvidenceRevision !== "string" || (remediation.failedEvidenceRevision !== "" && !/^sha256:[0-9a-f]{64}$/.test(remediation.failedEvidenceRevision)) || (status.nextRecommended === "remediate" && (!remediation.required || remediation.complete || !remediation.failedEvidenceRevision))) throw new Error("Invalid native remediation state");
|
|
1554
|
-
}
|
|
1555
|
-
stringArray(status.blockedReasons);
|
|
1556
|
-
enumString(status.nextRecommended, NATIVE_SDD_NEXT_RECOMMENDATIONS);
|
|
1557
|
-
return status as NativeSddStatusV2;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
1504
|
class NativeReviewPlainCli {
|
|
1561
1505
|
private readonly adapter: ExecFileAdapter;
|
|
1562
1506
|
private readonly executable: string | (() => string);
|
|
@@ -2195,30 +2139,6 @@ export class NativeReviewCliV216 implements NativeReviewCli {
|
|
|
2195
2139
|
return this.invoke(operation, cwd, arguments_, mutating, signal, this.executablePath(operation, mutating), toleratedStderr);
|
|
2196
2140
|
}
|
|
2197
2141
|
|
|
2198
|
-
async sddStatus(request: NativeSddStatusRequest): Promise<NativeSddStatusV2> {
|
|
2199
|
-
return this.sddProjection(request, false);
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
async sddContinue(request: NativeSddStatusRequest): Promise<NativeSddStatusV2> {
|
|
2203
|
-
if (!isCanonicalProcessString(request.changeName)) throw new TypeError("Native SDD continuation requires an exact selected change");
|
|
2204
|
-
return this.sddProjection(request, true);
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
private async sddProjection(request: NativeSddStatusRequest, mutating: boolean): Promise<NativeSddStatusV2> {
|
|
2208
|
-
if ((request.changeName !== undefined && !isCanonicalProcessString(request.changeName)) || !isCanonicalProcessString(request.workspaceRoot) || !isAbsolute(request.workspaceRoot)) {
|
|
2209
|
-
throw new TypeError("Native SDD status requires a canonical change and absolute workspace root");
|
|
2210
|
-
}
|
|
2211
|
-
const operation = mutating ? NATIVE_REVIEW_OPERATION.SDD_CONTINUE : NATIVE_REVIEW_OPERATION.SDD_STATUS;
|
|
2212
|
-
const execution = await this.negotiated(
|
|
2213
|
-
operation,
|
|
2214
|
-
request.workspaceRoot,
|
|
2215
|
-
[operation, ...(request.changeName === undefined ? [] : [request.changeName]), "--cwd", request.workspaceRoot, "--json", "--instructions"],
|
|
2216
|
-
mutating,
|
|
2217
|
-
request.signal,
|
|
2218
|
-
);
|
|
2219
|
-
return decode(operation, mutating, () => decodeNativeSddStatusV2(execution.body, request));
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
2142
|
async start(request: NativeStartRequest): Promise<NativeStartResult> {
|
|
2223
2143
|
if (request.baseRef !== undefined && !isCanonicalProcessString(request.baseRef)) throw new TypeError("Native START baseRef must be a non-empty, trimmed, NUL-free string");
|
|
2224
2144
|
if (request.baseRef !== undefined && request.committedOnly !== true) throw new TypeError("Native START baseRef requires explicit committedOnly acknowledgement");
|
|
@@ -2341,7 +2261,32 @@ export class NativeReviewCliV216 implements NativeReviewCli {
|
|
|
2341
2261
|
const selection = nativeUntrackedSelection(request);
|
|
2342
2262
|
const submitted = request.intendedUntrackedSelection;
|
|
2343
2263
|
if (submitted !== undefined && submitted.argumentTokens.reduce((count, token) => count + token.split("{{value}}").length - 1, 0) !== 1) throw new TypeError("Native intended-untracked selection requires exactly one provider-issued {{value}} token");
|
|
2344
|
-
const
|
|
2264
|
+
const submittedTokens = submitted === undefined ? undefined : submitted.argumentTokens.map((token) => token.replaceAll("{{value}}", submitted.value));
|
|
2265
|
+
// gentle-ai 3.7.1 submission argument_tokens never carry --base-ref /
|
|
2266
|
+
// --committed-only / --lineage, so a forwarded selector must be appended
|
|
2267
|
+
// after them; only bail if the provider already staked out a conflicting
|
|
2268
|
+
// value for the same flag. providerFlagValue also fails closed on a
|
|
2269
|
+
// dangling `--flag` (last token, no value) or an empty `--flag=`.
|
|
2270
|
+
const submittedBaseRefValue = submittedTokens === undefined ? undefined : providerFlagValue(submittedTokens, "base-ref");
|
|
2271
|
+
if (request.baseRef !== undefined && submittedBaseRefValue !== undefined && submittedBaseRefValue !== request.baseRef) throw new TypeError("Native intended-untracked selection already carries a conflicting base-ref");
|
|
2272
|
+
const submittedLineageValue = submittedTokens === undefined ? undefined : providerFlagValue(submittedTokens, "lineage");
|
|
2273
|
+
if (request.lineageId !== undefined && submittedLineageValue !== undefined && submittedLineageValue !== request.lineageId) throw new TypeError("Native intended-untracked selection already carries a conflicting lineage");
|
|
2274
|
+
let submittedHasCommittedOnly = false;
|
|
2275
|
+
for (const token of submittedTokens ?? []) {
|
|
2276
|
+
if (token !== "--committed-only" && !token.startsWith("--committed-only=")) continue;
|
|
2277
|
+
if (token !== "--committed-only" && token !== "--committed-only=true") throw new TypeError("Native intended-untracked selection has an invalid --committed-only value");
|
|
2278
|
+
if (submittedHasCommittedOnly) throw new TypeError("Native intended-untracked selection repeats --committed-only");
|
|
2279
|
+
submittedHasCommittedOnly = true;
|
|
2280
|
+
}
|
|
2281
|
+
// Append only the half of the base-ref/committed-only pair the provider
|
|
2282
|
+
// did not already carry (a present base-ref already equals
|
|
2283
|
+
// request.baseRef; the throw above ruled out the conflicting case).
|
|
2284
|
+
const forwardedBaseRef = request.baseRef === undefined ? [] : [
|
|
2285
|
+
...(submittedBaseRefValue === undefined ? ["--base-ref", request.baseRef] : []),
|
|
2286
|
+
...(submittedHasCommittedOnly ? [] : ["--committed-only"]),
|
|
2287
|
+
];
|
|
2288
|
+
const forwardedLineage = request.lineageId === undefined || submittedLineageValue !== undefined ? [] : ["--lineage", request.lineageId];
|
|
2289
|
+
const statusArguments = submittedTokens === undefined ? [
|
|
2345
2290
|
"review", "status", "--contract", REVIEW_INTEGRATION_CONTRACT, "--cwd", request.cwd,
|
|
2346
2291
|
"--projection", request.projection ?? "workspace",
|
|
2347
2292
|
...nativeUntrackedSelectionArguments(selection),
|
|
@@ -2349,7 +2294,7 @@ export class NativeReviewCliV216 implements NativeReviewCli {
|
|
|
2349
2294
|
...(request.lineageId === undefined ? [] : ["--lineage", request.lineageId]),
|
|
2350
2295
|
...(request.agent === undefined ? [] : ["--agent", request.agent]),
|
|
2351
2296
|
"--next-transition",
|
|
2352
|
-
] : ["review", "status", "--cwd", request.cwd, ...
|
|
2297
|
+
] : ["review", "status", "--cwd", request.cwd, ...submittedTokens, ...forwardedBaseRef, ...forwardedLineage];
|
|
2353
2298
|
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.STATUS, request.cwd, statusArguments, false, request.signal);
|
|
2354
2299
|
assertSupportedNextTransitionOperation(execution.body);
|
|
2355
2300
|
return decode(NATIVE_REVIEW_OPERATION.STATUS, false, () => decodeReviewStatusV3(execution.body));
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// Deterministic ODD phase inference from observed tool activity. The Gentle
|
|
2
|
+
// Shell working label used to depend only on the model calling
|
|
3
|
+
// gentle_odd_phase, which models routinely skip; the tools the primary
|
|
4
|
+
// session actually runs are a reliable, observable signal instead.
|
|
5
|
+
//
|
|
6
|
+
// The mapping is deliberately conservative: an unknown tool, unknown subagent
|
|
7
|
+
// role, or an ambiguous shell command returns undefined so the caller leaves
|
|
8
|
+
// the current label unchanged. This module is pure (no Pi or registry
|
|
9
|
+
// imports); precedence against explicit reports lives in OddPhaseRegistry.
|
|
10
|
+
|
|
11
|
+
import type { OddPhase } from "./odd-phase.ts";
|
|
12
|
+
|
|
13
|
+
const TOOL_PHASES: Readonly<Record<string, OddPhase>> = {
|
|
14
|
+
read: "exploring",
|
|
15
|
+
grep: "exploring",
|
|
16
|
+
find: "exploring",
|
|
17
|
+
ls: "exploring",
|
|
18
|
+
codegraph: "exploring",
|
|
19
|
+
ask_user_choice: "deciding",
|
|
20
|
+
ask_user_question: "deciding",
|
|
21
|
+
todo: "planning",
|
|
22
|
+
gentle_review: "checking",
|
|
23
|
+
gentle_review_scope: "checking",
|
|
24
|
+
gentle_review_capture: "checking",
|
|
25
|
+
gentle_review_capture_group: "checking",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const DELEGATED_PHASES: Readonly<Record<string, OddPhase>> = {
|
|
29
|
+
"gentle-ai-worker": "implementing",
|
|
30
|
+
"gentle-ai-verify": "checking",
|
|
31
|
+
"gentle-ai-explore": "exploring",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const WRITE_TOOLS = new Set(["edit", "write"]);
|
|
35
|
+
const SHELL_TOOLS = new Set(["bash", "powershell"]);
|
|
36
|
+
|
|
37
|
+
// Test, typecheck, lint, and build runners. Matched per shell segment.
|
|
38
|
+
const CHECKING_COMMANDS: readonly RegExp[] = [
|
|
39
|
+
/^(pnpm|npm|yarn|bun)\s+(run\s+)?(test|typecheck|lint|build|check)\b/,
|
|
40
|
+
/^node\b.*\s--test\b/,
|
|
41
|
+
/^node\s+\S*(test|check|lint|typecheck)[\w-]*\.m?[jt]s\b/,
|
|
42
|
+
/^((npx|pnpx|bunx)\s+|(pnpm|yarn)\s+exec\s+)?(vitest|jest|mocha|tsc|eslint|pytest)\b/,
|
|
43
|
+
/^python3?\s+-m\s+pytest\b/,
|
|
44
|
+
/^go\s+(test|build|vet)\b/,
|
|
45
|
+
/^cargo\s+(test|build|check|clippy)\b/,
|
|
46
|
+
/^make\b/,
|
|
47
|
+
// Waiting on or reading CI results verifies work; it is not exploration.
|
|
48
|
+
/^gh\s+pr\s+checks\b/,
|
|
49
|
+
/^gh\s+run\s+(view|watch|list)\b/,
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
// Git listing flags that may take one non-flag argument (`--contains <rev>`)
|
|
53
|
+
// without turning `git branch`/`git tag` into a create.
|
|
54
|
+
const GIT_LIST_FLAG = String.raw`(\s+(-a|-r|-l|-v|-vv|-n\d*|--all|--remotes|--list|--show-current|--contains|--merged|--no-merged|--points-at|--sort=\S+)(\s+[^-\s]\S*)?)*$`;
|
|
55
|
+
|
|
56
|
+
// Read-only inspection. Matched per shell segment.
|
|
57
|
+
const EXPLORING_COMMANDS: readonly RegExp[] = [
|
|
58
|
+
/^git\s+(status|log|diff|show|blame|rev-parse|rev-list|merge-base|ls-files|ls-remote|ls-tree|cat-file|describe|shortlog|reflog|grep|check-ignore|for-each-ref|name-rev|count-objects)\b/,
|
|
59
|
+
new RegExp(String.raw`^git\s+(branch|tag)${GIT_LIST_FLAG}`),
|
|
60
|
+
/^git\s+remote(\s+(-v|--verbose|show|get-url)\b.*)?$/,
|
|
61
|
+
/^git\s+(worktree|stash)\s+list\b/,
|
|
62
|
+
/^git\s+config\s+(--get|--get-all|--get-regexp|-l|--list)\b/,
|
|
63
|
+
/^gh\s+(pr|issue|repo|release)\s+(view|list|diff|status)\b/,
|
|
64
|
+
/^(ls|cat|head|tail|grep|egrep|rg|wc|pwd|tree|stat|file|which|type|readlink|realpath|dirname|basename|cut|uniq|tr|nl|column|strings|diff|cmp|od|xxd|hexdump|shasum|sha256sum|md5|md5sum|du|df|date|uname|whoami|ps|pgrep|lsof|jq|awk)\b/,
|
|
65
|
+
/^command\s+-v\b/,
|
|
66
|
+
/^(\[\[?|test)\s/,
|
|
67
|
+
/^sort\b(?!.*\s(-o|--output)\b)/,
|
|
68
|
+
/^sed\b(?!.*\s(-[a-zA-Z]*i|--in-place)\b)/,
|
|
69
|
+
/^find\b(?!.*\s-(delete|exec|execdir|ok|okdir|fprint\w*)\b)/,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
// Segments that neither inspect nor change anything worth labeling: shell
|
|
73
|
+
// control words, no-op builtins, and bare variable assignments (their
|
|
74
|
+
// command substitutions are classified as commands of their own).
|
|
75
|
+
const NEUTRAL_COMMANDS: readonly RegExp[] = [
|
|
76
|
+
/^(cd|pushd|popd|echo|printf|sleep|true|false|export|set)\b/,
|
|
77
|
+
/^(done|fi|esac|\}|\))$/,
|
|
78
|
+
/^for\s+\w+(\s+in\b.*)?$/,
|
|
79
|
+
// Each assignment must end at whitespace or the end: an optional separator
|
|
80
|
+
// would let `a=a=a=…` split anywhere and backtrack exponentially.
|
|
81
|
+
/^([A-Za-z_][A-Za-z0-9_]*=("[^"]*"|'[^']*'|[^\s"'])*(\s+|$))+$/,
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
// Shell keywords that prefix the command they introduce (`do grep x`).
|
|
85
|
+
const LEADING_KEYWORDS = /^(do|then|else|elif|if|while|until|time|!|\{|\()\s+/;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Infers the ODD phase implied by a tool call, or undefined when the call
|
|
89
|
+
* carries no reliable phase signal and the label must stay as it is.
|
|
90
|
+
*/
|
|
91
|
+
export function inferOddPhase(toolName: string, args: unknown): OddPhase | undefined {
|
|
92
|
+
const name = normalizeToolName(toolName);
|
|
93
|
+
if (name === "subagent_run") {
|
|
94
|
+
const agent = stringArg(args, "agent");
|
|
95
|
+
return agent && Object.hasOwn(DELEGATED_PHASES, agent) ? DELEGATED_PHASES[agent] : undefined;
|
|
96
|
+
}
|
|
97
|
+
if (WRITE_TOOLS.has(name)) return isOddTaskPath(stringArg(args, "path") ?? stringArg(args, "file_path")) ? "planning" : "implementing";
|
|
98
|
+
if (SHELL_TOOLS.has(name)) return inferShellPhase(stringArg(args, "command"));
|
|
99
|
+
return Object.hasOwn(TOOL_PHASES, name) ? TOOL_PHASES[name] : undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Some runtimes expose tools through an MCP proxy as `mcp__<server>__<tool>`.
|
|
103
|
+
function normalizeToolName(toolName: string): string {
|
|
104
|
+
return toolName.replace(/^mcp__.+?__/, "");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function stringArg(args: unknown, key: string): string | undefined {
|
|
108
|
+
if (typeof args !== "object" || args === null) return undefined;
|
|
109
|
+
const value = (args as Record<string, unknown>)[key];
|
|
110
|
+
return typeof value === "string" ? value : undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function isOddTaskPath(path: string | undefined): boolean {
|
|
114
|
+
return path !== undefined && /(^|\/)odd\/tasks\//.test(path.replaceAll("\\", "/"));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A command checks when any segment runs a checker; it explores only when
|
|
119
|
+
* every segment is read-only inspection (or neutral like `cd`). Anything
|
|
120
|
+
* else — a mutation, an install, an unknown program — is ambiguous.
|
|
121
|
+
*/
|
|
122
|
+
function inferShellPhase(command: string | undefined): OddPhase | undefined {
|
|
123
|
+
if (command === undefined) return undefined;
|
|
124
|
+
const segments = splitShellCommands(command)
|
|
125
|
+
.map(stripSegment)
|
|
126
|
+
.filter((segment) => segment.length > 0 && !isNeutral(segment));
|
|
127
|
+
if (segments.length === 0) return undefined;
|
|
128
|
+
if (segments.some((segment) => matchesAny(CHECKING_COMMANDS, segment))) return "checking";
|
|
129
|
+
return segments.every(isReadOnlyInspection) ? "exploring" : undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Splits a shell command into simple commands. Top-level `&&`, `||`, `;`,
|
|
134
|
+
* `|`, `&`, and newlines separate them; quoted text never does; and every
|
|
135
|
+
* `$(...)` substitution contributes its own commands, leaving a `$_`
|
|
136
|
+
* placeholder behind. Not a full shell parser: whatever it cannot follow
|
|
137
|
+
* lands in a segment that matches no pattern, so the label stays unchanged.
|
|
138
|
+
*/
|
|
139
|
+
function splitShellCommands(command: string): string[] {
|
|
140
|
+
const commands: string[] = [];
|
|
141
|
+
let current = "";
|
|
142
|
+
let quote: "'" | '"' | undefined;
|
|
143
|
+
for (let i = 0; i < command.length; i++) {
|
|
144
|
+
const char = command[i];
|
|
145
|
+
if (quote === "'") {
|
|
146
|
+
current += char;
|
|
147
|
+
if (char === "'") quote = undefined;
|
|
148
|
+
} else if (char === "\\") {
|
|
149
|
+
current += char + (command[i + 1] ?? "");
|
|
150
|
+
i++;
|
|
151
|
+
} else if (char === "$" && command[i + 1] === "(") {
|
|
152
|
+
const end = findSubstitutionEnd(command, i + 2);
|
|
153
|
+
if (end < 0) return [...commands, current + command.slice(i)];
|
|
154
|
+
commands.push(...splitShellCommands(command.slice(i + 2, end)));
|
|
155
|
+
current += "$_";
|
|
156
|
+
i = end;
|
|
157
|
+
} else if (quote === '"') {
|
|
158
|
+
current += char;
|
|
159
|
+
if (char === '"') quote = undefined;
|
|
160
|
+
} else if (char === "'" || char === '"') {
|
|
161
|
+
quote = char;
|
|
162
|
+
current += char;
|
|
163
|
+
} else if (isSeparator(command, i)) {
|
|
164
|
+
commands.push(current);
|
|
165
|
+
current = "";
|
|
166
|
+
if ((char === "|" || char === "&") && command[i + 1] === char) i++;
|
|
167
|
+
} else {
|
|
168
|
+
current += char;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
commands.push(current);
|
|
172
|
+
return commands;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// `&` inside a redirection (`2>&1`, `&>/dev/null`) is not a separator.
|
|
176
|
+
function isSeparator(command: string, i: number): boolean {
|
|
177
|
+
const char = command[i];
|
|
178
|
+
if (char === "&") return command[i - 1] !== ">" && command[i + 1] !== ">";
|
|
179
|
+
return char === ";" || char === "|" || char === "\n";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Index of the `)` closing a `$(` whose body starts at `start`, or -1.
|
|
183
|
+
function findSubstitutionEnd(command: string, start: number): number {
|
|
184
|
+
let depth = 1;
|
|
185
|
+
let quote: "'" | '"' | undefined;
|
|
186
|
+
for (let i = start; i < command.length; i++) {
|
|
187
|
+
const char = command[i];
|
|
188
|
+
if (quote) {
|
|
189
|
+
if (char === quote) quote = undefined;
|
|
190
|
+
else if (char === "\\" && quote === '"') i++;
|
|
191
|
+
} else if (char === "\\") i++;
|
|
192
|
+
else if (char === "'" || char === '"') quote = char;
|
|
193
|
+
else if (char === "(") depth++;
|
|
194
|
+
else if (char === ")" && --depth === 0) return i;
|
|
195
|
+
}
|
|
196
|
+
return -1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Drops harmless redirections (`2>&1`, `2>/dev/null`), leading shell
|
|
200
|
+
// keywords (`do grep x`), environment assignments (`CI=1 pnpm test`), git
|
|
201
|
+
// global options (`git -C dir status`), and whitespace. A bare assignment
|
|
202
|
+
// is left intact for NEUTRAL_COMMANDS.
|
|
203
|
+
function stripSegment(segment: string): string {
|
|
204
|
+
let stripped = segment.replace(HARMLESS_REDIRECTS, "").trim();
|
|
205
|
+
while (LEADING_KEYWORDS.test(stripped)) stripped = stripped.replace(LEADING_KEYWORDS, "");
|
|
206
|
+
return stripped
|
|
207
|
+
.replace(/^([A-Za-z_][A-Za-z0-9_]*=("[^"]*"|'[^']*'|[^\s"'])*\s+)+(?=\S)/, "")
|
|
208
|
+
.replace(/^git\s+((-C|-c)\s+\S+\s+|--no-pager\s+)+/, "git ");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// A segment that writes a file (`echo x > out`) is never a no-op.
|
|
212
|
+
function isNeutral(segment: string): boolean {
|
|
213
|
+
return !writesFile(segment) && matchesAny(NEUTRAL_COMMANDS, segment);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isReadOnlyInspection(segment: string): boolean {
|
|
217
|
+
return !writesFile(segment) && matchesAny(EXPLORING_COMMANDS, segment);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Stream merges and discarded output; neither writes a file.
|
|
221
|
+
const HARMLESS_REDIRECTS = /\s*(\d?>&\d|&?\d?>\s*\/dev\/null)/g;
|
|
222
|
+
|
|
223
|
+
// Output redirection to a file is a write. Deliberately naive: a `>` inside
|
|
224
|
+
// quoted text also counts, which only ever leaves the label unchanged.
|
|
225
|
+
function writesFile(segment: string): boolean {
|
|
226
|
+
return segment.replace(HARMLESS_REDIRECTS, "").includes(">");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function matchesAny(patterns: readonly RegExp[], segment: string): boolean {
|
|
230
|
+
return patterns.some((pattern) => pattern.test(segment));
|
|
231
|
+
}
|
package/lib/odd-phase.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Bounded ODD phase signal for the Gentle prompt's working label. There is
|
|
2
|
+
// no Pi runtime event for ODD phases, so the label comes from two sources:
|
|
3
|
+
// phases inferred deterministically from the primary session's tool activity
|
|
4
|
+
// (lib/odd-phase-inference.ts, wired in extensions/gentle-shell.ts) and
|
|
5
|
+
// explicit reports by the orchestrator through gentle_odd_phase, which
|
|
6
|
+
// refine it with phases tools cannot show (see
|
|
7
|
+
// assets/orchestrator-delegation.md). Never inferred from assistant prose;
|
|
8
|
+
// the prompt falls back to the generic "working…" label when nothing applies.
|
|
9
|
+
|
|
10
|
+
// Covers the ODD protocol steps in AGENTS.md (1 authorize .. 7 close); not a
|
|
11
|
+
// strict one-to-one mapping. "researching"/"deciding" both cover step 3
|
|
12
|
+
// (resolve uncertainty), and "deciding" also covers step 4's classify
|
|
13
|
+
// decision (no dedicated label: classifying is typically an instantaneous
|
|
14
|
+
// internal decision, not standalone visible work). "checking"/"closing"
|
|
15
|
+
// both cover step 7 (close).
|
|
16
|
+
export const ODD_PHASES = [
|
|
17
|
+
"authorizing",
|
|
18
|
+
"exploring",
|
|
19
|
+
"researching",
|
|
20
|
+
"deciding",
|
|
21
|
+
"planning",
|
|
22
|
+
"implementing",
|
|
23
|
+
"checking",
|
|
24
|
+
"closing",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export type OddPhase = (typeof ODD_PHASES)[number];
|
|
28
|
+
|
|
29
|
+
export function isOddPhase(value: unknown): value is OddPhase {
|
|
30
|
+
return typeof value === "string" && (ODD_PHASES as readonly string[]).includes(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function oddPhaseLabel(phase: OddPhase): string {
|
|
34
|
+
return `${phase}…`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Who set a session's phase: the orchestrator through gentle_odd_phase, or tool-activity inference. */
|
|
38
|
+
export type OddPhaseSource = "explicit" | "inferred";
|
|
39
|
+
|
|
40
|
+
interface ReportedOddPhase {
|
|
41
|
+
phase: OddPhase;
|
|
42
|
+
source: OddPhaseSource;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Session-scoped, best-effort ODD phase signal. Keyed by Pi session id so a
|
|
47
|
+
* background/child agent — which runs as its own OS process with its own
|
|
48
|
+
* module state (see lib/agents-runner.ts) — can never see or override the
|
|
49
|
+
* primary session's reported phase. The owning extension clears a session's
|
|
50
|
+
* entry at turn and session boundaries (agent_start, agent_settled,
|
|
51
|
+
* session_shutdown) so a stale phase from a finished turn never leaks into
|
|
52
|
+
* the next one.
|
|
53
|
+
*/
|
|
54
|
+
export class OddPhaseRegistry {
|
|
55
|
+
private readonly phases = new Map<string, ReportedOddPhase>();
|
|
56
|
+
// The WORKING-state pulse loop does not run at all under the "potato"
|
|
57
|
+
// animation policy (see GentlePromptEditor.startPulse), and workingLabel
|
|
58
|
+
// is otherwise only read on the next incidental render. Pi's own docs
|
|
59
|
+
// (docs/tui.md) instruct components to call requestRender() themselves
|
|
60
|
+
// after a state change; no host re-render is implicitly guaranteed. The
|
|
61
|
+
// owning prompt registers its own redraw callback here so a phase change
|
|
62
|
+
// is visible immediately regardless of animation policy.
|
|
63
|
+
private readonly renderRequests = new Map<string, () => void>();
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Sets the current ODD phase for a session. Only accepts an
|
|
67
|
+
* already-validated OddPhase; callers must validate untrusted input
|
|
68
|
+
* with isOddPhase() (or use clear() for the explicit "clear" token)
|
|
69
|
+
* before calling this. Returns undefined, without mutating any state or
|
|
70
|
+
* requesting a redraw, when there is no session id to scope the report
|
|
71
|
+
* to. The source defaults to "explicit"; tool-activity inference goes
|
|
72
|
+
* through infer() so its precedence rule applies.
|
|
73
|
+
*/
|
|
74
|
+
report(sessionId: string | undefined, phase: OddPhase, source: OddPhaseSource = "explicit"): OddPhase | undefined {
|
|
75
|
+
if (!sessionId) return undefined;
|
|
76
|
+
this.phases.set(sessionId, { phase, source });
|
|
77
|
+
this.renderRequests.get(sessionId)?.();
|
|
78
|
+
return phase;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Applies a phase inferred from tool activity and returns the session's
|
|
83
|
+
* resulting phase. An explicit report is not overridden by an inferred
|
|
84
|
+
* "exploring" (read-only tools are routine while researching or
|
|
85
|
+
* deciding). Incidental reads and planning bookkeeping also cannot
|
|
86
|
+
* displace active implementation/checking. A known delegated exploration
|
|
87
|
+
* is a deliberate transition, not an incidental read; later edits and
|
|
88
|
+
* checks can still move between active work phases. Inferring the phase
|
|
89
|
+
* already shown changes nothing,
|
|
90
|
+
* keeps an explicit source explicit, and never requests a redraw, so
|
|
91
|
+
* repeated tool calls do not repaint the prompt.
|
|
92
|
+
*/
|
|
93
|
+
infer(sessionId: string | undefined, phase: OddPhase, cause: "tool" | "delegation" = "tool"): OddPhase | undefined {
|
|
94
|
+
if (!sessionId) return undefined;
|
|
95
|
+
const current = this.phases.get(sessionId);
|
|
96
|
+
if (current?.phase === phase) return phase;
|
|
97
|
+
if (phase === "exploring" && cause !== "delegation" &&
|
|
98
|
+
(current?.source === "explicit" || current?.phase === "implementing" || current?.phase === "checking")) return current?.phase;
|
|
99
|
+
if (phase === "planning" && (current?.phase === "implementing" || current?.phase === "checking")) return current.phase;
|
|
100
|
+
return this.report(sessionId, phase, "inferred");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Clears a session's reported phase (turn/session boundary, or the
|
|
105
|
+
* explicit "clear" token). An invalid/unrecognized phase report is
|
|
106
|
+
* never a reason to clear: only this method resets the session, so a
|
|
107
|
+
* malformed report leaves the previously reported phase in place.
|
|
108
|
+
* Clearing also drops the report's source.
|
|
109
|
+
*/
|
|
110
|
+
clear(sessionId: string | undefined): void {
|
|
111
|
+
if (!sessionId) return;
|
|
112
|
+
if (this.phases.delete(sessionId)) this.renderRequests.get(sessionId)?.();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get(sessionId: string | undefined): OddPhase | undefined {
|
|
116
|
+
return sessionId ? this.phases.get(sessionId)?.phase : undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Working label for the reported phase, or undefined to fall back to the generic "working…" label. */
|
|
120
|
+
label(sessionId: string | undefined): string | undefined {
|
|
121
|
+
const phase = this.get(sessionId);
|
|
122
|
+
return phase ? oddPhaseLabel(phase) : undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Registers (replacing any previous registration) the callback used to request an immediate redraw when this session's phase changes. */
|
|
126
|
+
setRenderRequest(sessionId: string | undefined, requestRender: () => void): void {
|
|
127
|
+
if (sessionId) this.renderRequests.set(sessionId, requestRender);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
clearRenderRequest(sessionId: string | undefined): void {
|
|
131
|
+
if (sessionId) this.renderRequests.delete(sessionId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Pi loads extensions with separate jiti moduleCache:false loaders, so a
|
|
136
|
+
// module-local singleton is duplicated. The global symbol bridges only those
|
|
137
|
+
// loaders inside this process; subagents run in separate OS processes. Keep
|
|
138
|
+
// the session key inside the registry and clear it at turn/session boundaries.
|
|
139
|
+
const ODD_PHASE_REGISTRY = Symbol.for("gentle-pi.odd-phase-registry");
|
|
140
|
+
const processState = globalThis as typeof globalThis & { [ODD_PHASE_REGISTRY]?: OddPhaseRegistry };
|
|
141
|
+
export const oddPhaseRegistry = processState[ODD_PHASE_REGISTRY] ??= new OddPhaseRegistry();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TUI } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrap an overlay's `done` callback so closing the overlay forces the terminal
|
|
5
|
+
* to repaint the full cell buffer. Pi restores the editor behind a closed
|
|
6
|
+
* overlay with an incremental diff render; a fullscreen overlay's stale cell
|
|
7
|
+
* state can survive that pass — keys keep working while the screen stops
|
|
8
|
+
* updating (field-reported as "selection keys are dead" after /gentle:agents
|
|
9
|
+
* + Esc). `tui.requestRender(true)` resets the renderer's written-frame state
|
|
10
|
+
* so the next paint rewrites EVERY cell to the terminal, clearing the ghost —
|
|
11
|
+
* without rebuilding component rows, which on long sessions costs seconds of
|
|
12
|
+
* full-transcript re-render (the reason plain `invalidate()` is avoided
|
|
13
|
+
* here). `done(result)` runs first, so the overlay is fully torn down before
|
|
14
|
+
* the forced paint is scheduled. Failures are swallowed: a dead terminal must
|
|
15
|
+
* never break the close path.
|
|
16
|
+
*/
|
|
17
|
+
export function withOverlayRepaint<T>(tui: TUI, done: (result: T) => void): (result: T) => void {
|
|
18
|
+
return (result: T): void => {
|
|
19
|
+
done(result);
|
|
20
|
+
try {
|
|
21
|
+
tui.requestRender(true);
|
|
22
|
+
} catch {
|
|
23
|
+
/* best-effort repaint: never break the overlay close path */
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|