gsd-pi 2.80.0-dev.c5c38454b → 2.80.0-dev.cf9433f56
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 +4 -2
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/GSD-WORKFLOW.md +2 -2
- package/dist/resources/extensions/gsd/auto/loop.js +32 -1
- package/dist/resources/extensions/gsd/auto/phases.js +66 -45
- package/dist/resources/extensions/gsd/auto/resolve.js +17 -0
- package/dist/resources/extensions/gsd/auto/run-unit.js +13 -1
- package/dist/resources/extensions/gsd/auto-post-unit.js +10 -10
- package/dist/resources/extensions/gsd/auto-prompts.js +124 -2
- package/dist/resources/extensions/gsd/auto-recovery.js +43 -1
- package/dist/resources/extensions/gsd/auto-supervisor.js +8 -1
- package/dist/resources/extensions/gsd/auto-timeout-recovery.js +2 -2
- package/dist/resources/extensions/gsd/auto.js +77 -5
- package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +21 -2
- package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +27 -20
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +21 -0
- package/dist/resources/extensions/gsd/clean-root-preflight.js +42 -4
- package/dist/resources/extensions/gsd/commands/dispatcher.js +5 -0
- package/dist/resources/extensions/gsd/context-budget.js +37 -2
- package/dist/resources/extensions/gsd/crash-recovery.js +56 -10
- package/dist/resources/extensions/gsd/db/unit-dispatches.js +39 -0
- package/dist/resources/extensions/gsd/db-base-schema.js +4 -2
- package/dist/resources/extensions/gsd/db-migration-steps.js +6 -0
- package/dist/resources/extensions/gsd/detection.js +106 -0
- package/dist/resources/extensions/gsd/git-service.js +36 -4
- package/dist/resources/extensions/gsd/gsd-db.js +46 -13
- package/dist/resources/extensions/gsd/guided-flow.js +80 -14
- package/dist/resources/extensions/gsd/memory-store.js +69 -12
- package/dist/resources/extensions/gsd/migrate/command.js +40 -1
- package/dist/resources/extensions/gsd/migration-auto-check.js +87 -0
- package/dist/resources/extensions/gsd/planning-path-scope.js +26 -0
- package/dist/resources/extensions/gsd/pre-execution-checks.js +7 -0
- package/dist/resources/extensions/gsd/prompt-loader.js +28 -2
- package/dist/resources/extensions/gsd/prompts/complete-milestone.md +19 -19
- package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
- package/dist/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
- package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/dist/resources/extensions/gsd/prompts/quick-task.md +1 -5
- package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
- package/dist/resources/extensions/gsd/quick.js +34 -2
- package/dist/resources/extensions/gsd/safety/evidence-collector.js +10 -2
- package/dist/resources/extensions/gsd/tools/context-mode-tool-result.js +15 -0
- package/dist/resources/extensions/gsd/tools/exec-search-tool.js +5 -0
- package/dist/resources/extensions/gsd/tools/exec-tool.js +3 -15
- package/dist/resources/extensions/gsd/tools/memory-tools.js +1 -0
- package/dist/resources/extensions/gsd/tools/plan-slice.js +9 -0
- package/dist/resources/extensions/gsd/tools/plan-task.js +9 -0
- package/dist/resources/extensions/gsd/tools/resume-tool.js +5 -0
- package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +1 -1
- package/dist/resources/extensions/gsd/unit-context-composer.js +12 -3
- package/dist/resources/extensions/gsd/unit-runtime.js +22 -0
- package/dist/resources/extensions/gsd/worktree-manager.js +16 -14
- package/dist/resources/extensions/gsd/worktree-resolver.js +33 -17
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +7 -7
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +7 -7
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/package.json +3 -3
- package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
- package/packages/mcp-server/dist/workflow-tools.js +22 -17
- package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
- package/packages/mcp-server/src/workflow-tools.test.ts +75 -2
- package/packages/mcp-server/src/workflow-tools.ts +30 -16
- package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
- package/packages/native/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js +32 -0
- package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +8 -0
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +32 -0
- package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +11 -0
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js +9 -0
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js +103 -0
- package/packages/pi-coding-agent/dist/core/compaction-threshold.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts +15 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.js +66 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.js +24 -0
- package/packages/pi-coding-agent/dist/core/db-snapshot.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +3 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js +2 -0
- package/packages/pi-coding-agent/dist/core/extensions/runner.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +7 -0
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +20 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +25 -0
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +3 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +15 -5
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js +53 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +3 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js +10 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage-safety-guard.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js +3 -2
- package/packages/pi-coding-agent/dist/resources/extensions/memory/storage.js.map +1 -1
- package/packages/pi-coding-agent/src/core/agent-session-abort-order.test.ts +36 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +8 -0
- package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +38 -0
- package/packages/pi-coding-agent/src/core/compaction/compaction.ts +18 -0
- package/packages/pi-coding-agent/src/core/compaction-threshold.test.ts +121 -0
- package/packages/pi-coding-agent/src/core/db-snapshot.test.ts +32 -0
- package/packages/pi-coding-agent/src/core/db-snapshot.ts +66 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.test.ts +2 -0
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +3 -0
- package/packages/pi-coding-agent/src/core/extensions/types.ts +7 -0
- package/packages/pi-coding-agent/src/core/settings-manager.ts +39 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +4 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.test.ts +56 -0
- package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +24 -7
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +3 -0
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage-safety-guard.test.ts +14 -0
- package/packages/pi-coding-agent/src/resources/extensions/memory/storage.ts +3 -2
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +18 -8
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/src/tui.ts +20 -8
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
- package/src/resources/GSD-WORKFLOW.md +2 -2
- package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
- package/src/resources/extensions/gsd/auto/loop.ts +50 -8
- package/src/resources/extensions/gsd/auto/phases.ts +77 -48
- package/src/resources/extensions/gsd/auto/resolve.ts +23 -1
- package/src/resources/extensions/gsd/auto/run-unit.ts +18 -1
- package/src/resources/extensions/gsd/auto-post-unit.ts +10 -10
- package/src/resources/extensions/gsd/auto-prompts.ts +133 -2
- package/src/resources/extensions/gsd/auto-recovery.ts +54 -0
- package/src/resources/extensions/gsd/auto-supervisor.ts +7 -0
- package/src/resources/extensions/gsd/auto-timeout-recovery.ts +2 -2
- package/src/resources/extensions/gsd/auto.ts +92 -4
- package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +21 -1
- package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +27 -19
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +22 -0
- package/src/resources/extensions/gsd/clean-root-preflight.ts +41 -3
- package/src/resources/extensions/gsd/commands/dispatcher.ts +6 -0
- package/src/resources/extensions/gsd/context-budget.ts +44 -2
- package/src/resources/extensions/gsd/crash-recovery.ts +67 -10
- package/src/resources/extensions/gsd/db/unit-dispatches.ts +41 -0
- package/src/resources/extensions/gsd/db-base-schema.ts +4 -2
- package/src/resources/extensions/gsd/db-migration-steps.ts +8 -0
- package/src/resources/extensions/gsd/detection.ts +128 -0
- package/src/resources/extensions/gsd/git-service.ts +46 -8
- package/src/resources/extensions/gsd/gsd-db.ts +50 -13
- package/src/resources/extensions/gsd/guided-flow.ts +96 -14
- package/src/resources/extensions/gsd/memory-store.ts +77 -12
- package/src/resources/extensions/gsd/migrate/command.ts +47 -1
- package/src/resources/extensions/gsd/migration-auto-check.ts +129 -0
- package/src/resources/extensions/gsd/planning-path-scope.ts +35 -0
- package/src/resources/extensions/gsd/pre-execution-checks.ts +7 -0
- package/src/resources/extensions/gsd/preferences-types.ts +1 -1
- package/src/resources/extensions/gsd/prompt-loader.ts +27 -2
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +19 -19
- package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +1 -1
- package/src/resources/extensions/gsd/prompts/plan-milestone.md +3 -1
- package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
- package/src/resources/extensions/gsd/prompts/quick-task.md +1 -5
- package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -2
- package/src/resources/extensions/gsd/quick.ts +37 -2
- package/src/resources/extensions/gsd/safety/evidence-collector.ts +11 -2
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +72 -1
- package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +56 -13
- package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +14 -1
- package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +88 -2
- package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +14 -1
- package/src/resources/extensions/gsd/tests/context-budget.test.ts +10 -1
- package/src/resources/extensions/gsd/tests/crash-handler-secondary.test.ts +55 -0
- package/src/resources/extensions/gsd/tests/crash-recovery-via-db.test.ts +22 -0
- package/src/resources/extensions/gsd/tests/detection.test.ts +140 -0
- package/src/resources/extensions/gsd/tests/dispatch-rule-coverage.test.ts +313 -0
- package/src/resources/extensions/gsd/tests/exec-history.test.ts +15 -0
- package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +65 -0
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +54 -0
- package/src/resources/extensions/gsd/tests/journal-integration.test.ts +234 -0
- package/src/resources/extensions/gsd/tests/memory-decay-factor.test.ts +90 -0
- package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +48 -0
- package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +127 -0
- package/src/resources/extensions/gsd/tests/plan-slice.test.ts +50 -0
- package/src/resources/extensions/gsd/tests/plan-task.test.ts +21 -0
- package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/prompt-path-audit.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/prompt-step-ordering.test.ts +19 -0
- package/src/resources/extensions/gsd/tests/quick-external-gsd.test.ts +40 -0
- package/src/resources/extensions/gsd/tests/right-sized-workflow-prompts.test.ts +192 -0
- package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +29 -0
- package/src/resources/extensions/gsd/tests/schema-v27-v28-sequence.test.ts +156 -0
- package/src/resources/extensions/gsd/tests/signal-handlers.test.ts +27 -0
- package/src/resources/extensions/gsd/tests/smart-entry-complete.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/stalled-tool-recovery.test.ts +49 -1
- package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +101 -2
- package/src/resources/extensions/gsd/tests/status-db-open.test.ts +9 -0
- package/src/resources/extensions/gsd/tests/unit-context-composer.test.ts +136 -4
- package/src/resources/extensions/gsd/tests/unit-dispatches.test.ts +30 -0
- package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +37 -0
- package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +3 -0
- package/src/resources/extensions/gsd/tests/worktree-health-dispatch.test.ts +37 -6
- package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +7 -0
- package/src/resources/extensions/gsd/tests/worktree-nested-git-safety.test.ts +9 -2
- package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +63 -1
- package/src/resources/extensions/gsd/tools/context-mode-tool-result.ts +25 -0
- package/src/resources/extensions/gsd/tools/exec-search-tool.ts +7 -7
- package/src/resources/extensions/gsd/tools/exec-tool.ts +4 -23
- package/src/resources/extensions/gsd/tools/memory-tools.ts +1 -0
- package/src/resources/extensions/gsd/tools/plan-slice.ts +13 -0
- package/src/resources/extensions/gsd/tools/plan-task.ts +10 -0
- package/src/resources/extensions/gsd/tools/resume-tool.ts +7 -7
- package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +1 -1
- package/src/resources/extensions/gsd/unit-context-composer.ts +19 -4
- package/src/resources/extensions/gsd/unit-runtime.ts +25 -0
- package/src/resources/extensions/gsd/worktree-manager.ts +15 -4
- package/src/resources/extensions/gsd/worktree-resolver.ts +36 -15
- /package/dist/web/standalone/.next/static/{TCSim36ZpcPu2WgeoC45g → -5nHJWzSdG-WkPMul_khA}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{TCSim36ZpcPu2WgeoC45g → -5nHJWzSdG-WkPMul_khA}/_ssgManifest.js +0 -0
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// intentionally independent store for cross-worktree claim races and is
|
|
23
23
|
// excluded from this invariant.
|
|
24
24
|
import { createRequire } from "node:module";
|
|
25
|
+
import { createHash } from "node:crypto";
|
|
25
26
|
import { existsSync, copyFileSync, mkdirSync, realpathSync } from "node:fs";
|
|
26
27
|
import { dirname } from "node:path";
|
|
27
28
|
import { GSDError, GSD_STALE_STATE } from "./errors.js";
|
|
@@ -36,7 +37,7 @@ import { rowToActiveDecision, rowToActiveRequirement, rowToDecision, rowToRequir
|
|
|
36
37
|
import { rowToGate } from "./db-gate-rows.js";
|
|
37
38
|
import { rowToArtifact, rowToMilestone } from "./db-milestone-artifact-rows.js";
|
|
38
39
|
import { backupDatabaseBeforeMigration } from "./db-migration-backup.js";
|
|
39
|
-
import { applyMigrationV2Artifacts, applyMigrationV3Memories, applyMigrationV4DecisionMadeBy, applyMigrationV5HierarchyTables, applyMigrationV6SliceSummaries, applyMigrationV7Dependencies, applyMigrationV8PlanningFields, applyMigrationV9Ordering, applyMigrationV10ReplanTrigger, applyMigrationV11TaskPlanning, applyMigrationV12QualityGates, applyMigrationV13HotPathIndexes, applyMigrationV14SliceDependencies, applyMigrationV15AuditTables, applyMigrationV16EscalationSource, applyMigrationV17TaskEscalation, applyMigrationV18MemorySources, applyMigrationV19MemoryFts, applyMigrationV20MemoryRelations, applyMigrationV21StructuredMemories, applyMigrationV22QualityGateRepair, applyMigrationV23MilestoneQueue, applyMigrationV26MilestoneCommitAttributions, } from "./db-migration-steps.js";
|
|
40
|
+
import { applyMigrationV2Artifacts, applyMigrationV3Memories, applyMigrationV4DecisionMadeBy, applyMigrationV5HierarchyTables, applyMigrationV6SliceSummaries, applyMigrationV7Dependencies, applyMigrationV8PlanningFields, applyMigrationV9Ordering, applyMigrationV10ReplanTrigger, applyMigrationV11TaskPlanning, applyMigrationV12QualityGates, applyMigrationV13HotPathIndexes, applyMigrationV14SliceDependencies, applyMigrationV15AuditTables, applyMigrationV16EscalationSource, applyMigrationV17TaskEscalation, applyMigrationV18MemorySources, applyMigrationV19MemoryFts, applyMigrationV20MemoryRelations, applyMigrationV21StructuredMemories, applyMigrationV22QualityGateRepair, applyMigrationV23MilestoneQueue, applyMigrationV26MilestoneCommitAttributions, applyMigrationV27ArtifactHash, applyMigrationV28MemoryLastHitAt, } from "./db-migration-steps.js";
|
|
40
41
|
import { isMemoriesFtsAvailableSchema, tryCreateMemoriesFtsSchema } from "./db-memory-fts-schema.js";
|
|
41
42
|
import { createDbOpenState } from "./db-open-state.js";
|
|
42
43
|
import { createRuntimeKvTableV25 } from "./db-runtime-kv-schema.js";
|
|
@@ -52,7 +53,7 @@ const providerLoader = createSqliteProviderLoader({
|
|
|
52
53
|
nodeVersion: process.versions.node,
|
|
53
54
|
writeStderr: (message) => process.stderr.write(message),
|
|
54
55
|
});
|
|
55
|
-
export const SCHEMA_VERSION =
|
|
56
|
+
export const SCHEMA_VERSION = 28;
|
|
56
57
|
function initSchema(db, fileBacked) {
|
|
57
58
|
if (fileBacked)
|
|
58
59
|
db.exec("PRAGMA journal_mode=WAL");
|
|
@@ -250,6 +251,14 @@ function migrateSchema(db) {
|
|
|
250
251
|
applyMigrationV26MilestoneCommitAttributions(db);
|
|
251
252
|
recordSchemaVersion(db, 26);
|
|
252
253
|
}
|
|
254
|
+
if (currentVersion < 27) {
|
|
255
|
+
applyMigrationV27ArtifactHash(db);
|
|
256
|
+
recordSchemaVersion(db, 27);
|
|
257
|
+
}
|
|
258
|
+
if (currentVersion < 28) {
|
|
259
|
+
applyMigrationV28MemoryLastHitAt(db);
|
|
260
|
+
recordSchemaVersion(db, 28);
|
|
261
|
+
}
|
|
253
262
|
db.exec("COMMIT");
|
|
254
263
|
}
|
|
255
264
|
catch (err) {
|
|
@@ -821,8 +830,9 @@ export function clearArtifacts() {
|
|
|
821
830
|
export function insertArtifact(a) {
|
|
822
831
|
if (!currentDb)
|
|
823
832
|
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
824
|
-
|
|
825
|
-
|
|
833
|
+
const contentHash = createHash("sha256").update(a.full_content).digest("hex");
|
|
834
|
+
currentDb.prepare(`INSERT OR REPLACE INTO artifacts (path, artifact_type, milestone_id, slice_id, task_id, full_content, imported_at, content_hash)
|
|
835
|
+
VALUES (:path, :artifact_type, :milestone_id, :slice_id, :task_id, :full_content, :imported_at, :content_hash)`).run({
|
|
826
836
|
":path": a.path,
|
|
827
837
|
":artifact_type": a.artifact_type,
|
|
828
838
|
":milestone_id": a.milestone_id,
|
|
@@ -830,6 +840,7 @@ export function insertArtifact(a) {
|
|
|
830
840
|
":task_id": a.task_id,
|
|
831
841
|
":full_content": a.full_content,
|
|
832
842
|
":imported_at": new Date().toISOString(),
|
|
843
|
+
":content_hash": contentHash,
|
|
833
844
|
});
|
|
834
845
|
}
|
|
835
846
|
export function insertMilestone(m) {
|
|
@@ -1521,6 +1532,13 @@ export function reconcileWorktreeDb(mainDbPath, worktreeDbPath) {
|
|
|
1521
1532
|
const hasEscalationAwaiting = wtTaskInfo.some((col) => col["name"] === "escalation_awaiting_review");
|
|
1522
1533
|
const hasEscalationArtifact = wtTaskInfo.some((col) => col["name"] === "escalation_artifact_path");
|
|
1523
1534
|
const hasEscalationOverride = wtTaskInfo.some((col) => col["name"] === "escalation_override_applied_at");
|
|
1535
|
+
const wtArtifactInfo = adapter.prepare("PRAGMA wt.table_info('artifacts')").all();
|
|
1536
|
+
const hasArtifactContentHash = wtArtifactInfo.some((col) => col["name"] === "content_hash");
|
|
1537
|
+
const wtMemoryInfo = adapter.prepare("PRAGMA wt.table_info('memories')").all();
|
|
1538
|
+
const hasMemoryScope = wtMemoryInfo.some((col) => col["name"] === "scope");
|
|
1539
|
+
const hasMemoryTags = wtMemoryInfo.some((col) => col["name"] === "tags");
|
|
1540
|
+
const hasMemoryStructuredFields = wtMemoryInfo.some((col) => col["name"] === "structured_fields");
|
|
1541
|
+
const hasMemoryLastHitAt = wtMemoryInfo.some((col) => col["name"] === "last_hit_at");
|
|
1524
1542
|
const decConf = adapter.prepare(`SELECT m.id FROM decisions m INNER JOIN wt.decisions w ON m.id = w.id WHERE m.decision != w.decision OR m.choice != w.choice OR m.rationale != w.rationale OR ${hasMadeBy ? "m.made_by != w.made_by" : "'agent' != 'agent'"} OR m.superseded_by IS NOT w.superseded_by`).all();
|
|
1525
1543
|
for (const row of decConf)
|
|
1526
1544
|
conflicts.push(`decision ${row["id"]}: modified in both`);
|
|
@@ -1553,12 +1571,17 @@ export function reconcileWorktreeDb(mainDbPath, worktreeDbPath) {
|
|
|
1553
1571
|
supporting_slices, validation, notes, full_content, superseded_by
|
|
1554
1572
|
FROM wt.requirements
|
|
1555
1573
|
`).run());
|
|
1574
|
+
// V27: preserve content_hash. If the worktree predates V27 (no column),
|
|
1575
|
+
// fall back to the main DB's existing hash so reconcile doesn't null
|
|
1576
|
+
// out integrity fingerprints on artifacts that were unchanged in wt.
|
|
1556
1577
|
merged.artifacts = countChanges(adapter.prepare(`
|
|
1557
1578
|
INSERT OR REPLACE INTO artifacts (
|
|
1558
|
-
path, artifact_type, milestone_id, slice_id, task_id, full_content, imported_at
|
|
1579
|
+
path, artifact_type, milestone_id, slice_id, task_id, full_content, imported_at, content_hash
|
|
1559
1580
|
)
|
|
1560
|
-
SELECT path, artifact_type, milestone_id, slice_id, task_id, full_content, imported_at
|
|
1561
|
-
|
|
1581
|
+
SELECT w.path, w.artifact_type, w.milestone_id, w.slice_id, w.task_id, w.full_content, w.imported_at,
|
|
1582
|
+
${hasArtifactContentHash ? "w.content_hash" : "m.content_hash"}
|
|
1583
|
+
FROM wt.artifacts w
|
|
1584
|
+
LEFT JOIN artifacts m ON m.path = w.path
|
|
1562
1585
|
`).run());
|
|
1563
1586
|
// Merge milestones — worktree may have updated status/planning fields.
|
|
1564
1587
|
// Never downgrade status: complete > active > pre-planning (#4372).
|
|
@@ -1656,15 +1679,25 @@ export function reconcileWorktreeDb(mainDbPath, worktreeDbPath) {
|
|
|
1656
1679
|
FROM wt.tasks w
|
|
1657
1680
|
LEFT JOIN tasks m ON m.milestone_id = w.milestone_id AND m.slice_id = w.slice_id AND m.id = w.id
|
|
1658
1681
|
`).run());
|
|
1659
|
-
// Merge memories — keep worktree-learned insights
|
|
1682
|
+
// Merge memories — keep worktree-learned insights.
|
|
1683
|
+
// V18 (scope, tags), V21 (structured_fields), V28 (last_hit_at): for each
|
|
1684
|
+
// column the wt may not yet have (older worktree DB), fall back to the
|
|
1685
|
+
// main DB's existing value via LEFT JOIN so reconcile never silently
|
|
1686
|
+
// resets these fields to defaults on rows that already had them.
|
|
1660
1687
|
merged.memories = countChanges(adapter.prepare(`
|
|
1661
1688
|
INSERT OR REPLACE INTO memories (
|
|
1662
1689
|
seq, id, category, content, confidence, source_unit_type, source_unit_id,
|
|
1663
|
-
created_at, updated_at, superseded_by, hit_count
|
|
1690
|
+
created_at, updated_at, superseded_by, hit_count,
|
|
1691
|
+
scope, tags, structured_fields, last_hit_at
|
|
1664
1692
|
)
|
|
1665
|
-
SELECT seq, id, category, content, confidence, source_unit_type, source_unit_id,
|
|
1666
|
-
created_at, updated_at, superseded_by, hit_count
|
|
1667
|
-
|
|
1693
|
+
SELECT w.seq, w.id, w.category, w.content, w.confidence, w.source_unit_type, w.source_unit_id,
|
|
1694
|
+
w.created_at, w.updated_at, w.superseded_by, w.hit_count,
|
|
1695
|
+
${hasMemoryScope ? "w.scope" : "COALESCE(m.scope, 'project')"},
|
|
1696
|
+
${hasMemoryTags ? "w.tags" : "COALESCE(m.tags, '[]')"},
|
|
1697
|
+
${hasMemoryStructuredFields ? "w.structured_fields" : "m.structured_fields"},
|
|
1698
|
+
${hasMemoryLastHitAt ? "w.last_hit_at" : "m.last_hit_at"}
|
|
1699
|
+
FROM wt.memories w
|
|
1700
|
+
LEFT JOIN memories m ON m.id = w.id
|
|
1668
1701
|
`).run());
|
|
1669
1702
|
// Merge verification evidence — append-only, use INSERT OR IGNORE to avoid duplicates
|
|
1670
1703
|
merged.verification_evidence = countChanges(adapter.prepare(`
|
|
@@ -2423,7 +2456,7 @@ export function updateMemoryContentRow(id, content, confidence, updatedAt) {
|
|
|
2423
2456
|
export function incrementMemoryHitCount(id, updatedAt) {
|
|
2424
2457
|
if (!currentDb)
|
|
2425
2458
|
throw new GSDError(GSD_STALE_STATE, "gsd-db: No database open");
|
|
2426
|
-
currentDb.prepare("UPDATE memories SET hit_count = hit_count + 1, updated_at = :updated_at WHERE id = :id").run({ ":updated_at": updatedAt, ":id": id });
|
|
2459
|
+
currentDb.prepare("UPDATE memories SET hit_count = hit_count + 1, updated_at = :updated_at, last_hit_at = :last_hit_at WHERE id = :id").run({ ":updated_at": updatedAt, ":last_hit_at": updatedAt, ":id": id });
|
|
2427
2460
|
}
|
|
2428
2461
|
export function supersedeMemoryRow(oldId, newId, updatedAt) {
|
|
2429
2462
|
if (!currentDb)
|
|
@@ -16,7 +16,7 @@ import { invalidateAllCaches } from "./cache.js";
|
|
|
16
16
|
import { startAutoDetached } from "./auto.js";
|
|
17
17
|
import { clearLock } from "./crash-recovery.js";
|
|
18
18
|
import { assessInterruptedSession, formatInterruptedSessionRunningMessage, formatInterruptedSessionSummary, } from "./interrupted-session.js";
|
|
19
|
-
import { listUnitRuntimeRecords, clearUnitRuntimeRecord } from "./unit-runtime.js";
|
|
19
|
+
import { listUnitRuntimeRecords, clearUnitRuntimeRecord, isInFlightRuntimePhase } from "./unit-runtime.js";
|
|
20
20
|
import { resolveExpectedArtifactPath } from "./auto.js";
|
|
21
21
|
import { gsdHome } from "./gsd-home.js";
|
|
22
22
|
import { gsdRoot, milestonesDir, resolveMilestoneFile, resolveMilestonePath, resolveSliceFile, resolveSlicePath, resolveGsdRootFile, relGsdRootFile, relMilestoneFile, relSliceFile, clearPathCache, } from "./paths.js";
|
|
@@ -51,6 +51,21 @@ export { showQueue, handleQueueReorder, showQueueAdd, buildExistingMilestonesCon
|
|
|
51
51
|
import { logWarning } from "./workflow-logger.js";
|
|
52
52
|
import { deleteRuntimeKv } from "./db/runtime-kv.js";
|
|
53
53
|
import { PAUSED_SESSION_KV_KEY } from "./interrupted-session.js";
|
|
54
|
+
function scheduleAutoStartAfterIdle(ctx, pi, basePath, verboseMode, options, launch = startAutoDetached) {
|
|
55
|
+
const waitForIdle = typeof ctx.waitForIdle === "function"
|
|
56
|
+
? ctx.waitForIdle.bind(ctx)
|
|
57
|
+
: async () => { };
|
|
58
|
+
void waitForIdle()
|
|
59
|
+
.then(() => {
|
|
60
|
+
setTimeout(() => launch(ctx, pi, basePath, verboseMode, options), 0);
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
64
|
+
ctx.ui.notify(`Auto-start failed while waiting for the prior turn to settle: ${message}`, "error");
|
|
65
|
+
logWarning("guided", `auto-start idle wait failed: ${message}`);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export const _scheduleAutoStartAfterIdleForTest = scheduleAutoStartAfterIdle;
|
|
54
69
|
// ─── Scope-based validator wrappers ──────────────────────────────────────────
|
|
55
70
|
// These thin wrappers accept a MilestoneScope so callers that already hold a
|
|
56
71
|
// pinned scope never have to re-derive (basePath, milestoneId) separately.
|
|
@@ -71,6 +86,19 @@ export function verifyExpectedArtifactForScope(scope, unitType, unitId) {
|
|
|
71
86
|
export function resolveExpectedArtifactPathForScope(scope, unitType, unitId) {
|
|
72
87
|
return resolveExpectedArtifactPath(unitType, unitId, scope.workspace.projectRoot);
|
|
73
88
|
}
|
|
89
|
+
async function runQuickTaskChoice(ctx, pi) {
|
|
90
|
+
if (!ctx.hasUI) {
|
|
91
|
+
ctx.ui.notify("Run /gsd quick <task> for small bounded work, or /gsd do <task> for natural-language routing.", "info");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const task = (await ctx.ui.input("Quick task", "Describe the small task to run with /gsd quick"))?.trim();
|
|
95
|
+
if (!task) {
|
|
96
|
+
ctx.ui.notify("Quick task cancelled.", "info");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const { handleQuick } = await import("./quick.js");
|
|
100
|
+
await handleQuick(task, ctx, pi);
|
|
101
|
+
}
|
|
74
102
|
/**
|
|
75
103
|
* Scope-based overload of isGhostMilestone.
|
|
76
104
|
* Binds basePath and milestoneId from the scope, ensuring path resolution
|
|
@@ -312,7 +340,7 @@ async function dispatchNextDeepProjectSetupStage(entry) {
|
|
|
312
340
|
const { DISPATCH_RULES, hasPendingDeepStage } = await import("./auto-dispatch.js");
|
|
313
341
|
if (!hasPendingDeepStage(prefs, entry.basePath)) {
|
|
314
342
|
pendingDeepProjectSetupMap.delete(entry.basePath);
|
|
315
|
-
|
|
343
|
+
scheduleAutoStartAfterIdle(entry.ctx, entry.pi, entry.basePath, false, { step: entry.step });
|
|
316
344
|
return true;
|
|
317
345
|
}
|
|
318
346
|
const state = await deriveState(entry.basePath);
|
|
@@ -346,14 +374,14 @@ async function dispatchNextDeepProjectSetupStage(entry) {
|
|
|
346
374
|
}
|
|
347
375
|
else if (hasPendingDeepStage(prefs, entry.basePath)) {
|
|
348
376
|
pendingDeepProjectSetupMap.delete(entry.basePath);
|
|
349
|
-
|
|
377
|
+
scheduleAutoStartAfterIdle(entry.ctx, entry.pi, entry.basePath, false, { step: entry.step });
|
|
350
378
|
return true;
|
|
351
379
|
}
|
|
352
380
|
return false;
|
|
353
381
|
}
|
|
354
382
|
if (!USER_DRIVEN_DEEP_SETUP_UNITS.has(result.unitType)) {
|
|
355
383
|
pendingDeepProjectSetupMap.delete(entry.basePath);
|
|
356
|
-
|
|
384
|
+
scheduleAutoStartAfterIdle(entry.ctx, entry.pi, entry.basePath, false, { step: entry.step });
|
|
357
385
|
return true;
|
|
358
386
|
}
|
|
359
387
|
entry.currentUnitType = result.unitType;
|
|
@@ -531,7 +559,7 @@ export function checkAutoStartAfterDiscuss() {
|
|
|
531
559
|
}
|
|
532
560
|
pendingAutoStartMap.delete(basePath);
|
|
533
561
|
ctx.ui.notify(`Milestone ${milestoneId} ready.`, "success");
|
|
534
|
-
|
|
562
|
+
scheduleAutoStartAfterIdle(ctx, pi, basePath, false, { step });
|
|
535
563
|
return true;
|
|
536
564
|
}
|
|
537
565
|
/**
|
|
@@ -1469,8 +1497,8 @@ function selfHealRuntimeRecords(basePath, ctx) {
|
|
|
1469
1497
|
cleared++;
|
|
1470
1498
|
continue;
|
|
1471
1499
|
}
|
|
1472
|
-
// Clear records stuck in
|
|
1473
|
-
if (phase
|
|
1500
|
+
// Clear records stuck in an in-flight phase (process died mid-unit).
|
|
1501
|
+
if (isInFlightRuntimePhase(phase)) {
|
|
1474
1502
|
clearUnitRuntimeRecord(basePath, unitType, unitId);
|
|
1475
1503
|
cleared++;
|
|
1476
1504
|
}
|
|
@@ -1695,6 +1723,20 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1695
1723
|
return;
|
|
1696
1724
|
}
|
|
1697
1725
|
}
|
|
1726
|
+
if (interrupted.classification !== "recoverable") {
|
|
1727
|
+
try {
|
|
1728
|
+
const { autoImportMarkdownHierarchyIfDbMismatch } = await import("./migration-auto-check.js");
|
|
1729
|
+
const result = await autoImportMarkdownHierarchyIfDbMismatch(basePath);
|
|
1730
|
+
if (result.action === "imported") {
|
|
1731
|
+
ctx.ui.notify(`Recovered migrated planning state into gsd.db (${result.reason}): ${result.afterDb.milestones} milestone(s), ${result.afterDb.slices} slice(s), ${result.afterDb.tasks} task(s).`, "info");
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
catch (err) {
|
|
1735
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1736
|
+
ctx.ui.notify(`GSD could not auto-import existing planning state into gsd.db: ${message}`, "warning");
|
|
1737
|
+
logWarning("guided", `planning state auto-import failed: ${message}`, { file: "guided-flow.ts" });
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1698
1740
|
// Always derive from the project root — the assessment may have derived
|
|
1699
1741
|
// state from a worktree path that was cleaned up in the stale branch above.
|
|
1700
1742
|
const state = await deriveState(basePath);
|
|
@@ -1780,16 +1822,24 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1780
1822
|
title: "GSD — Get Shit Done",
|
|
1781
1823
|
summary: ["No active milestone."],
|
|
1782
1824
|
actions: [
|
|
1825
|
+
{
|
|
1826
|
+
id: "quick_task",
|
|
1827
|
+
label: "Quick task",
|
|
1828
|
+
description: "For small bounded work, run /gsd quick <task> or /gsd do <task>.",
|
|
1829
|
+
recommended: true,
|
|
1830
|
+
},
|
|
1783
1831
|
{
|
|
1784
1832
|
id: "new_milestone",
|
|
1785
1833
|
label: "Create next milestone",
|
|
1786
|
-
description: "Define
|
|
1787
|
-
recommended: true,
|
|
1834
|
+
description: "Define a larger body of work with planning artifacts.",
|
|
1788
1835
|
},
|
|
1789
1836
|
],
|
|
1790
1837
|
notYetMessage: "Run /gsd when ready.",
|
|
1791
1838
|
});
|
|
1792
|
-
if (choice === "
|
|
1839
|
+
if (choice === "quick_task") {
|
|
1840
|
+
await runQuickTaskChoice(ctx, pi);
|
|
1841
|
+
}
|
|
1842
|
+
else if (choice === "new_milestone") {
|
|
1793
1843
|
setPendingAutoStart(basePath, { ctx, pi, basePath, milestoneId: nextId, step: stepMode });
|
|
1794
1844
|
await dispatchWorkflow(pi, await prepareAndBuildDiscussPrompt(ctx, pi, nextId, `New milestone ${nextId}.`, basePath), "gsd-run", ctx, "discuss-milestone");
|
|
1795
1845
|
}
|
|
@@ -1809,11 +1859,16 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1809
1859
|
title: `GSD — ${milestoneId}: ${milestoneTitle}`,
|
|
1810
1860
|
summary: ["All milestones complete."],
|
|
1811
1861
|
actions: [
|
|
1862
|
+
{
|
|
1863
|
+
id: "quick_task",
|
|
1864
|
+
label: "Quick task",
|
|
1865
|
+
description: "Do a small bounded task without opening a milestone.",
|
|
1866
|
+
recommended: true,
|
|
1867
|
+
},
|
|
1812
1868
|
{
|
|
1813
1869
|
id: "new_milestone",
|
|
1814
1870
|
label: "Start new milestone",
|
|
1815
1871
|
description: "Define and plan the next milestone.",
|
|
1816
|
-
recommended: true,
|
|
1817
1872
|
},
|
|
1818
1873
|
{
|
|
1819
1874
|
id: "status",
|
|
@@ -1823,7 +1878,10 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1823
1878
|
],
|
|
1824
1879
|
notYetMessage: "Run /gsd when ready.",
|
|
1825
1880
|
});
|
|
1826
|
-
if (choice === "
|
|
1881
|
+
if (choice === "quick_task") {
|
|
1882
|
+
await runQuickTaskChoice(ctx, pi);
|
|
1883
|
+
}
|
|
1884
|
+
else if (choice === "new_milestone") {
|
|
1827
1885
|
const milestoneIds = findMilestoneIds(basePath);
|
|
1828
1886
|
const uniqueMilestoneIds = !!loadEffectiveGSDPreferences()?.preferences?.unique_milestone_ids;
|
|
1829
1887
|
const nextId = nextMilestoneIdReserved(milestoneIds, uniqueMilestoneIds, basePath);
|
|
@@ -1916,13 +1974,18 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1916
1974
|
const contextFile = resolveMilestoneFile(basePath, milestoneId, "CONTEXT");
|
|
1917
1975
|
const hasContext = !!(contextFile && await loadFile(contextFile));
|
|
1918
1976
|
const actions = [
|
|
1977
|
+
{
|
|
1978
|
+
id: "quick_task",
|
|
1979
|
+
label: "Quick task instead",
|
|
1980
|
+
description: "Use this when the work is small and should not become a milestone.",
|
|
1981
|
+
recommended: true,
|
|
1982
|
+
},
|
|
1919
1983
|
{
|
|
1920
1984
|
id: "plan",
|
|
1921
1985
|
label: "Create roadmap",
|
|
1922
1986
|
description: hasContext
|
|
1923
1987
|
? "Context captured. Decompose into slices with a boundary map."
|
|
1924
1988
|
: "Decompose the milestone into slices with a boundary map.",
|
|
1925
|
-
recommended: true,
|
|
1926
1989
|
},
|
|
1927
1990
|
...(!hasContext ? [{
|
|
1928
1991
|
id: "discuss",
|
|
@@ -1946,7 +2009,10 @@ export async function showSmartEntry(ctx, pi, basePath, options) {
|
|
|
1946
2009
|
actions,
|
|
1947
2010
|
notYetMessage: "Run /gsd when ready.",
|
|
1948
2011
|
});
|
|
1949
|
-
if (choice === "
|
|
2012
|
+
if (choice === "quick_task") {
|
|
2013
|
+
await runQuickTaskChoice(ctx, pi);
|
|
2014
|
+
}
|
|
2015
|
+
else if (choice === "plan") {
|
|
1950
2016
|
setPendingAutoStart(basePath, { ctx, pi, basePath, milestoneId, step: stepMode });
|
|
1951
2017
|
await dispatchWorkflow(pi, await buildPlanMilestonePrompt(milestoneId, milestoneTitle, basePath), "gsd-run", ctx, "plan-milestone");
|
|
1952
2018
|
}
|
|
@@ -14,6 +14,27 @@ const CATEGORY_PRIORITY = {
|
|
|
14
14
|
environment: 4,
|
|
15
15
|
preference: 5,
|
|
16
16
|
};
|
|
17
|
+
// ─── Scoring Helpers ─────────────────────────────────────────────────────────
|
|
18
|
+
/**
|
|
19
|
+
* Time-decay factor for memory relevance scoring.
|
|
20
|
+
* Returns 1.0 for never-hit or recently-hit memories, decaying linearly to
|
|
21
|
+
* 0.7 for memories not accessed in 90+ days. Floor at 0.7 keeps old-but-valid
|
|
22
|
+
* knowledge from being fully suppressed.
|
|
23
|
+
*
|
|
24
|
+
* Defensive parsing: invalid timestamp strings (NaN from Date.parse) are
|
|
25
|
+
* treated as "no decay" rather than propagating NaN into score arithmetic.
|
|
26
|
+
* Future timestamps (clock skew, manual DB edits) clamp to daysAgo=0 so the
|
|
27
|
+
* factor stays in the documented [0.7, 1.0] contract.
|
|
28
|
+
*/
|
|
29
|
+
export function memoryDecayFactor(lastHitAt) {
|
|
30
|
+
if (!lastHitAt)
|
|
31
|
+
return 1.0;
|
|
32
|
+
const ts = Date.parse(lastHitAt);
|
|
33
|
+
if (!Number.isFinite(ts))
|
|
34
|
+
return 1.0;
|
|
35
|
+
const daysAgo = Math.max(0, (Date.now() - ts) / 86_400_000);
|
|
36
|
+
return Math.max(0.7, 1.0 - 0.3 * Math.min(1.0, daysAgo / 90));
|
|
37
|
+
}
|
|
17
38
|
// ─── Row Mapping ────────────────────────────────────────────────────────────
|
|
18
39
|
function rowToMemory(row) {
|
|
19
40
|
return {
|
|
@@ -31,6 +52,7 @@ function rowToMemory(row) {
|
|
|
31
52
|
scope: row['scope'] ?? 'project',
|
|
32
53
|
tags: parseTags(row['tags']),
|
|
33
54
|
structured_fields: parseStructuredFields(row['structured_fields']),
|
|
55
|
+
last_hit_at: row['last_hit_at'] ?? null,
|
|
34
56
|
};
|
|
35
57
|
}
|
|
36
58
|
function parseStructuredFields(raw) {
|
|
@@ -114,15 +136,37 @@ export function queryMemoriesRanked(opts) {
|
|
|
114
136
|
? semanticSearch(adapter, opts.queryVector, activeClause, 50)
|
|
115
137
|
: [];
|
|
116
138
|
if (keywordHits.length === 0 && semanticHits.length === 0 && !trimmedQuery) {
|
|
117
|
-
// No query at all —
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
// No query at all — return top-k by decay-aware ranked score.
|
|
140
|
+
//
|
|
141
|
+
// Build the candidate pool from a direct SQL query that honors the
|
|
142
|
+
// request's activeClause (i.e. include_superseded). Using
|
|
143
|
+
// getActiveMemoriesRanked here would silently drop superseded rows even
|
|
144
|
+
// when the caller explicitly opted in, and would slice by raw score
|
|
145
|
+
// before decay/filters had a chance to reorder.
|
|
146
|
+
const candidatePool = Math.min(Math.max(k * 5, 50), 500);
|
|
147
|
+
const rows = adapter
|
|
148
|
+
.prepare(`SELECT * FROM memories ${activeClause}
|
|
149
|
+
ORDER BY (confidence * (1.0 + hit_count * 0.1)) DESC
|
|
150
|
+
LIMIT :limit`)
|
|
151
|
+
.all({ ':limit': candidatePool });
|
|
152
|
+
const ranked = [];
|
|
153
|
+
for (const row of rows) {
|
|
154
|
+
const memory = rowToMemory(row);
|
|
155
|
+
if (!passesFilters(memory, opts))
|
|
156
|
+
continue;
|
|
157
|
+
const decay = memoryDecayFactor(memory.last_hit_at);
|
|
158
|
+
const score = memory.confidence * (1 + memory.hit_count * 0.1) * decay;
|
|
159
|
+
ranked.push({
|
|
160
|
+
memory,
|
|
161
|
+
score,
|
|
162
|
+
keywordRank: null,
|
|
163
|
+
semanticRank: null,
|
|
164
|
+
confidenceBoost: score,
|
|
165
|
+
reason: 'ranked',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
ranked.sort((a, b) => b.score - a.score);
|
|
169
|
+
return ranked.slice(0, k);
|
|
126
170
|
}
|
|
127
171
|
// 3) Reciprocal rank fusion — each hit contributes 1/(rrfK + rank).
|
|
128
172
|
const fused = new Map();
|
|
@@ -155,7 +199,7 @@ export function queryMemoriesRanked(opts) {
|
|
|
155
199
|
for (const entry of fused.values()) {
|
|
156
200
|
if (!passesFilters(entry.memory, opts))
|
|
157
201
|
continue;
|
|
158
|
-
const boost = entry.memory.confidence * (1 + entry.memory.hit_count * 0.1);
|
|
202
|
+
const boost = entry.memory.confidence * (1 + entry.memory.hit_count * 0.1) * memoryDecayFactor(entry.memory.last_hit_at);
|
|
159
203
|
const reason = entry.kwRank != null && entry.semRank != null
|
|
160
204
|
? 'both'
|
|
161
205
|
: entry.kwRank != null
|
|
@@ -194,6 +238,7 @@ function passesFilters(memory, filters) {
|
|
|
194
238
|
}
|
|
195
239
|
return true;
|
|
196
240
|
}
|
|
241
|
+
let ftsWarningEmitted = false;
|
|
197
242
|
function keywordSearch(adapter, rawQuery, activeClause, limit) {
|
|
198
243
|
const ftsAvailable = isFtsAvailable(adapter);
|
|
199
244
|
if (ftsAvailable) {
|
|
@@ -215,14 +260,26 @@ function keywordSearch(adapter, rawQuery, activeClause, limit) {
|
|
|
215
260
|
// fall through to LIKE
|
|
216
261
|
}
|
|
217
262
|
}
|
|
218
|
-
// LIKE fallback — scans
|
|
263
|
+
// LIKE fallback — scans a capped candidate pool.
|
|
264
|
+
if (!ftsWarningEmitted) {
|
|
265
|
+
ftsWarningEmitted = true;
|
|
266
|
+
logWarning('memory-store', 'FTS5 unavailable — using LIKE fallback scan (consider enabling FTS5)');
|
|
267
|
+
}
|
|
219
268
|
const terms = rawQuery
|
|
220
269
|
.toLowerCase()
|
|
221
270
|
.split(/[^a-z0-9_]+/)
|
|
222
271
|
.filter((t) => t.length >= 2);
|
|
223
272
|
if (terms.length === 0)
|
|
224
273
|
return [];
|
|
225
|
-
const
|
|
274
|
+
const preScanCap = Math.min(limit * 20, 2000);
|
|
275
|
+
// ORDER BY confidence-weighted hit_count DESC so the cap keeps the most
|
|
276
|
+
// valuable candidates instead of the oldest-by-rowid (which would silently
|
|
277
|
+
// exclude recently-stored memories on tables larger than preScanCap).
|
|
278
|
+
const rows = adapter
|
|
279
|
+
.prepare(`SELECT * FROM memories ${activeClause}
|
|
280
|
+
ORDER BY (confidence * (1.0 + hit_count * 0.1)) DESC
|
|
281
|
+
LIMIT :preScanCap`)
|
|
282
|
+
.all({ ':preScanCap': preScanCap });
|
|
226
283
|
const scored = [];
|
|
227
284
|
for (const row of rows) {
|
|
228
285
|
const memory = rowToMemory(row);
|
|
@@ -15,6 +15,43 @@ import { fileURLToPath } from "node:url";
|
|
|
15
15
|
import { showNextAction } from "../../shared/tui.js";
|
|
16
16
|
import { validatePlanningDirectory, parsePlanningDirectory, transformToGSD, generatePreview, writeGSDDirectory, } from "./index.js";
|
|
17
17
|
import { homedir } from "node:os";
|
|
18
|
+
import { ensureDbOpen } from "../bootstrap/dynamic-tools.js";
|
|
19
|
+
import { clearEngineHierarchy, transaction } from "../gsd-db.js";
|
|
20
|
+
import { migrateFromMarkdown } from "../md-importer.js";
|
|
21
|
+
import { invalidateStateCache } from "../state.js";
|
|
22
|
+
function assertMigrationImportMatchesPreview(imported, preview) {
|
|
23
|
+
const mismatches = [];
|
|
24
|
+
if (imported.hierarchy.milestones !== preview.milestoneCount) {
|
|
25
|
+
mismatches.push(`milestones ${imported.hierarchy.milestones}/${preview.milestoneCount}`);
|
|
26
|
+
}
|
|
27
|
+
if (imported.hierarchy.slices !== preview.totalSlices) {
|
|
28
|
+
mismatches.push(`slices ${imported.hierarchy.slices}/${preview.totalSlices}`);
|
|
29
|
+
}
|
|
30
|
+
if (imported.hierarchy.tasks !== preview.totalTasks) {
|
|
31
|
+
mismatches.push(`tasks ${imported.hierarchy.tasks}/${preview.totalTasks}`);
|
|
32
|
+
}
|
|
33
|
+
if (imported.requirements !== preview.requirements.total) {
|
|
34
|
+
mismatches.push(`requirements ${imported.requirements}/${preview.requirements.total}`);
|
|
35
|
+
}
|
|
36
|
+
if (mismatches.length > 0) {
|
|
37
|
+
throw new Error(`migration DB import verification failed: ${mismatches.join(", ")}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function importWrittenMigrationToDb(basePath, preview) {
|
|
41
|
+
const opened = await ensureDbOpen(basePath);
|
|
42
|
+
if (!opened) {
|
|
43
|
+
throw new Error(`failed to open or create the GSD database at ${basePath}`);
|
|
44
|
+
}
|
|
45
|
+
const counts = transaction(() => {
|
|
46
|
+
clearEngineHierarchy();
|
|
47
|
+
const imported = migrateFromMarkdown(basePath);
|
|
48
|
+
if (preview)
|
|
49
|
+
assertMigrationImportMatchesPreview(imported, preview);
|
|
50
|
+
return imported;
|
|
51
|
+
});
|
|
52
|
+
invalidateStateCache();
|
|
53
|
+
return counts;
|
|
54
|
+
}
|
|
18
55
|
/** Format preview stats for embedding in the review prompt. */
|
|
19
56
|
function formatPreviewStats(preview) {
|
|
20
57
|
const lines = [
|
|
@@ -126,12 +163,14 @@ export async function handleMigrate(args, ctx, pi) {
|
|
|
126
163
|
ctx.ui.notify("Writing .gsd directory…", "info");
|
|
127
164
|
const result = await writeGSDDirectory(project, process.cwd());
|
|
128
165
|
const gsdPath = gsdRoot(process.cwd());
|
|
129
|
-
|
|
166
|
+
const imported = await importWrittenMigrationToDb(process.cwd(), preview);
|
|
167
|
+
ctx.ui.notify(`✓ Migration complete — ${result.paths.length} file(s) written to .gsd/ and ${imported.hierarchy.milestones}M/${imported.hierarchy.slices}S/${imported.hierarchy.tasks}T imported to the database`, "info");
|
|
130
168
|
// ── Post-write review offer ────────────────────────────────────────────────
|
|
131
169
|
const reviewChoice = await showNextAction(ctx, {
|
|
132
170
|
title: "Migration written",
|
|
133
171
|
summary: [
|
|
134
172
|
`${result.paths.length} files written to .gsd/`,
|
|
173
|
+
`${imported.hierarchy.milestones} milestone(s), ${imported.hierarchy.slices} slice(s), and ${imported.hierarchy.tasks} task(s) imported to gsd.db`,
|
|
135
174
|
"",
|
|
136
175
|
"The agent can now review the migrated output against GSD-2 standards —",
|
|
137
176
|
"checking structure, content quality, deriveState() round-trip, and",
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { ensureDbOpen } from "./bootstrap/dynamic-tools.js";
|
|
3
|
+
import { clearEngineHierarchy, getAllMilestones, getMilestoneSlices, getSliceTasks, isDbAvailable, transaction, } from "./gsd-db.js";
|
|
4
|
+
import { migrateHierarchyToDb } from "./md-importer.js";
|
|
5
|
+
import { parsePlan, parseRoadmap } from "./parsers-legacy.js";
|
|
6
|
+
import { milestonesDir, resolveMilestoneFile, resolveSliceFile, } from "./paths.js";
|
|
7
|
+
import { invalidateStateCache } from "./state.js";
|
|
8
|
+
function zeroCounts() {
|
|
9
|
+
return { milestones: 0, slices: 0, tasks: 0 };
|
|
10
|
+
}
|
|
11
|
+
function sameCounts(a, b) {
|
|
12
|
+
return a.milestones === b.milestones && a.slices === b.slices && a.tasks === b.tasks;
|
|
13
|
+
}
|
|
14
|
+
export function countMarkdownHierarchy(basePath) {
|
|
15
|
+
const root = milestonesDir(basePath);
|
|
16
|
+
if (!existsSync(root))
|
|
17
|
+
return zeroCounts();
|
|
18
|
+
const counts = zeroCounts();
|
|
19
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
20
|
+
if (!entry.isDirectory() || !/^M\d+/.test(entry.name))
|
|
21
|
+
continue;
|
|
22
|
+
counts.milestones++;
|
|
23
|
+
const roadmapPath = resolveMilestoneFile(basePath, entry.name, "ROADMAP");
|
|
24
|
+
if (!roadmapPath || !existsSync(roadmapPath))
|
|
25
|
+
continue;
|
|
26
|
+
const roadmap = parseRoadmap(readFileSync(roadmapPath, "utf-8"));
|
|
27
|
+
counts.slices += roadmap.slices.length;
|
|
28
|
+
for (const slice of roadmap.slices) {
|
|
29
|
+
const planPath = resolveSliceFile(basePath, entry.name, slice.id, "PLAN");
|
|
30
|
+
if (!planPath || !existsSync(planPath))
|
|
31
|
+
continue;
|
|
32
|
+
const plan = parsePlan(readFileSync(planPath, "utf-8"));
|
|
33
|
+
counts.tasks += plan.tasks.length;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return counts;
|
|
37
|
+
}
|
|
38
|
+
export function countDbHierarchy() {
|
|
39
|
+
if (!isDbAvailable())
|
|
40
|
+
return zeroCounts();
|
|
41
|
+
const counts = zeroCounts();
|
|
42
|
+
const milestones = getAllMilestones();
|
|
43
|
+
counts.milestones = milestones.length;
|
|
44
|
+
for (const milestone of milestones) {
|
|
45
|
+
const slices = getMilestoneSlices(milestone.id);
|
|
46
|
+
counts.slices += slices.length;
|
|
47
|
+
for (const slice of slices) {
|
|
48
|
+
counts.tasks += getSliceTasks(milestone.id, slice.id).length;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return counts;
|
|
52
|
+
}
|
|
53
|
+
export async function autoImportMarkdownHierarchyIfDbMismatch(basePath) {
|
|
54
|
+
const markdown = countMarkdownHierarchy(basePath);
|
|
55
|
+
if (sameCounts(markdown, zeroCounts())) {
|
|
56
|
+
return {
|
|
57
|
+
action: "none",
|
|
58
|
+
reason: "no-markdown",
|
|
59
|
+
markdown,
|
|
60
|
+
beforeDb: zeroCounts(),
|
|
61
|
+
afterDb: zeroCounts(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const opened = await ensureDbOpen(basePath);
|
|
65
|
+
if (!opened || !isDbAvailable()) {
|
|
66
|
+
throw new Error(`failed to open or create the GSD database at ${basePath}`);
|
|
67
|
+
}
|
|
68
|
+
const beforeDb = countDbHierarchy();
|
|
69
|
+
if (sameCounts(markdown, beforeDb)) {
|
|
70
|
+
return { action: "none", reason: "in-sync", markdown, beforeDb, afterDb: beforeDb };
|
|
71
|
+
}
|
|
72
|
+
const reason = sameCounts(beforeDb, zeroCounts()) ? "db-empty" : "count-mismatch";
|
|
73
|
+
const imported = transaction(() => {
|
|
74
|
+
clearEngineHierarchy();
|
|
75
|
+
return migrateHierarchyToDb(basePath);
|
|
76
|
+
});
|
|
77
|
+
invalidateStateCache();
|
|
78
|
+
const afterDb = {
|
|
79
|
+
milestones: imported.milestones,
|
|
80
|
+
slices: imported.slices,
|
|
81
|
+
tasks: imported.tasks,
|
|
82
|
+
};
|
|
83
|
+
if (!sameCounts(markdown, afterDb)) {
|
|
84
|
+
throw new Error(`migration auto-import verification failed: markdown ${markdown.milestones}M/${markdown.slices}S/${markdown.tasks}T, db ${afterDb.milestones}M/${afterDb.slices}S/${afterDb.tasks}T`);
|
|
85
|
+
}
|
|
86
|
+
return { action: "imported", reason, markdown, beforeDb, afterDb };
|
|
87
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
2
|
+
import { normalizePlannedFileReference } from "./files.js";
|
|
3
|
+
function isInsideBase(basePath, candidate) {
|
|
4
|
+
const base = resolve(basePath);
|
|
5
|
+
const abs = resolve(candidate);
|
|
6
|
+
const rel = relative(base, abs);
|
|
7
|
+
return rel === "" || (!!rel && !rel.startsWith("..") && !isAbsolute(rel));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Planning IO fields are execution contracts. Absolute paths are only safe when
|
|
11
|
+
* they stay inside the active working directory; in worktree mode, an absolute
|
|
12
|
+
* path to the original checkout makes executors edit the wrong tree.
|
|
13
|
+
*/
|
|
14
|
+
export function validatePlanningPathScope(basePath, fields) {
|
|
15
|
+
for (const { field, values } of fields) {
|
|
16
|
+
for (const raw of values) {
|
|
17
|
+
const candidate = normalizePlannedFileReference(raw);
|
|
18
|
+
if (!isAbsolute(candidate))
|
|
19
|
+
continue;
|
|
20
|
+
if (isInsideBase(basePath, candidate))
|
|
21
|
+
continue;
|
|
22
|
+
return `${field} contains absolute path outside working directory: ${candidate}. Use a path relative to ${basePath}.`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|