@cmetech/otto 1.1.1 → 1.2.5
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/dist/coworker/persona-commands.d.ts +1 -0
- package/dist/coworker/persona-commands.js +5 -0
- package/dist/coworker/persona-commands.test.d.ts +1 -0
- package/dist/coworker/persona-commands.test.js +45 -0
- package/dist/resources/.managed-resources-content-hash +1 -1
- package/dist/resources/extensions/coworker-artifacts/artifacts-command.js +31 -0
- package/dist/resources/extensions/coworker-artifacts/artifacts-singleton.js +17 -0
- package/dist/resources/extensions/coworker-artifacts/extension-manifest.json +13 -0
- package/dist/resources/extensions/coworker-artifacts/index.js +125 -0
- package/dist/resources/extensions/coworker-artifacts/list-tool.js +27 -0
- package/dist/resources/extensions/coworker-artifacts/open-tool.js +25 -0
- package/dist/resources/extensions/coworker-memory/extension-manifest.json +13 -0
- package/dist/resources/extensions/coworker-memory/index.js +219 -0
- package/dist/resources/extensions/coworker-memory/memorize-tool.js +10 -0
- package/dist/resources/extensions/coworker-memory/memory-command.js +157 -0
- package/dist/resources/extensions/coworker-memory/memory-singleton.js +55 -0
- package/dist/resources/extensions/coworker-memory/recall-tool.js +18 -0
- package/dist/resources/extensions/coworker-memory/session-hooks.js +45 -0
- package/dist/resources/extensions/coworker-scratchpad/attach-banners.js +53 -0
- package/dist/resources/extensions/coworker-scratchpad/extension-manifest.json +13 -0
- package/dist/resources/extensions/coworker-scratchpad/format-age.js +9 -0
- package/dist/resources/extensions/coworker-scratchpad/helpers.js +38 -0
- package/dist/resources/extensions/coworker-scratchpad/index.js +199 -0
- package/dist/resources/extensions/coworker-scratchpad/mime-bundle.js +20 -0
- package/dist/resources/extensions/coworker-scratchpad/scratchpad-tool.js +118 -0
- package/dist/resources/extensions/coworker-scratchpad/session-sidecar.js +60 -0
- package/dist/resources/extensions/coworker-scratchpad/sp-command.js +597 -0
- package/dist/resources/extensions/coworker-scratchpad/workspace-pointer.js +41 -0
- package/dist/resources/extensions/coworker-scratchpad/workspace-root.js +17 -0
- package/dist/resources/extensions/coworker-vault/audit-command.js +35 -0
- package/dist/resources/extensions/coworker-vault/connect-command.js +42 -0
- package/dist/resources/extensions/coworker-vault/datasource-command.js +50 -0
- package/dist/resources/extensions/coworker-vault/extension-manifest.json +12 -0
- package/dist/resources/extensions/coworker-vault/index.js +171 -0
- package/dist/resources/extensions/coworker-vault/test-helpers.js +86 -0
- package/dist/resources/extensions/coworker-vault/vault-singleton.js +24 -0
- package/dist/resources/extensions/otto/commands/release-notes/_data.js +83 -0
- package/dist/resources/extensions/otto/commands/release-notes/command.js +15 -4
- package/dist/resources/extensions/otto/index.js +31 -6
- package/dist/resources/extensions/shared/coworker-paths.js +8 -0
- package/dist/resources/extensions/slash-commands/{audit.js → audit-codebase.js} +4 -4
- package/dist/resources/extensions/slash-commands/extension-manifest.json +1 -1
- package/dist/resources/extensions/slash-commands/index.js +2 -2
- package/dist/resources/extensions/subagent/index.js +8 -1
- package/dist/resources/extensions/subagent/launch.js +37 -5
- package/dist/resources/extensions/subagent/run-store.js +1 -0
- package/dist/resources/extensions/workflow/bootstrap/register-extension.js +2 -0
- package/dist/resources/extensions/workflow/bootstrap/register-hooks.js +10 -0
- package/dist/resources/extensions/workflow/health-widget-core.js +1 -1
- package/dist/resources/extensions/workflow/persona-status.js +87 -0
- package/package.json +26 -10
- package/packages/contracts/package.json +1 -1
- package/packages/coworker-artifacts/dist/artifact-store.d.ts +25 -0
- package/packages/coworker-artifacts/dist/artifact-store.js +187 -0
- package/packages/coworker-artifacts/dist/dir-snapshot.d.ts +7 -0
- package/packages/coworker-artifacts/dist/dir-snapshot.js +54 -0
- package/packages/coworker-artifacts/dist/errors.d.ts +18 -0
- package/packages/coworker-artifacts/dist/errors.js +37 -0
- package/packages/coworker-artifacts/dist/index.d.ts +7 -0
- package/packages/coworker-artifacts/dist/index.js +7 -0
- package/packages/coworker-artifacts/dist/readme-renderer.d.ts +5 -0
- package/packages/coworker-artifacts/dist/readme-renderer.js +47 -0
- package/packages/coworker-artifacts/dist/resolve-uri.d.ts +3 -0
- package/packages/coworker-artifacts/dist/resolve-uri.js +29 -0
- package/packages/coworker-artifacts/dist/slug.d.ts +4 -0
- package/packages/coworker-artifacts/dist/slug.js +32 -0
- package/packages/coworker-artifacts/dist/types.d.ts +52 -0
- package/packages/coworker-artifacts/dist/types.js +1 -0
- package/packages/coworker-artifacts/package.json +20 -0
- package/packages/coworker-artifacts/src/artifact-store.test.ts +188 -0
- package/packages/coworker-artifacts/src/artifact-store.ts +206 -0
- package/packages/coworker-artifacts/src/artifacts-integration.test.ts +109 -0
- package/packages/coworker-artifacts/src/dir-snapshot.test.ts +71 -0
- package/packages/coworker-artifacts/src/dir-snapshot.ts +52 -0
- package/packages/coworker-artifacts/src/errors.test.ts +37 -0
- package/packages/coworker-artifacts/src/errors.ts +28 -0
- package/packages/coworker-artifacts/src/index.test.ts +22 -0
- package/packages/coworker-artifacts/src/index.ts +7 -0
- package/packages/coworker-artifacts/src/readme-renderer.test.ts +72 -0
- package/packages/coworker-artifacts/src/readme-renderer.ts +56 -0
- package/packages/coworker-artifacts/src/resolve-uri.test.ts +46 -0
- package/packages/coworker-artifacts/src/resolve-uri.ts +29 -0
- package/packages/coworker-artifacts/src/slug.test.ts +47 -0
- package/packages/coworker-artifacts/src/slug.ts +31 -0
- package/packages/coworker-artifacts/src/types.ts +61 -0
- package/packages/coworker-artifacts/tsconfig.json +15 -0
- package/packages/coworker-artifacts/tsconfig.publish.json +4 -0
- package/packages/coworker-memory/dist/context-injection.d.ts +9 -0
- package/packages/coworker-memory/dist/context-injection.js +41 -0
- package/packages/coworker-memory/dist/errors.d.ts +25 -0
- package/packages/coworker-memory/dist/errors.js +51 -0
- package/packages/coworker-memory/dist/index.d.ts +12 -0
- package/packages/coworker-memory/dist/index.js +12 -0
- package/packages/coworker-memory/dist/layer-a-store.d.ts +16 -0
- package/packages/coworker-memory/dist/layer-a-store.js +78 -0
- package/packages/coworker-memory/dist/local-sqlite-backend.d.ts +28 -0
- package/packages/coworker-memory/dist/local-sqlite-backend.js +167 -0
- package/packages/coworker-memory/dist/memory-backend.d.ts +14 -0
- package/packages/coworker-memory/dist/memory-backend.js +1 -0
- package/packages/coworker-memory/dist/memory-recorder.d.ts +50 -0
- package/packages/coworker-memory/dist/memory-recorder.js +69 -0
- package/packages/coworker-memory/dist/migrations/001-init.sql +38 -0
- package/packages/coworker-memory/dist/migrations/002-artifact-kind.sql +50 -0
- package/packages/coworker-memory/dist/paste-detector.d.ts +5 -0
- package/packages/coworker-memory/dist/paste-detector.js +14 -0
- package/packages/coworker-memory/dist/persona-seed.d.ts +10 -0
- package/packages/coworker-memory/dist/persona-seed.js +38 -0
- package/packages/coworker-memory/dist/recall-formatter.d.ts +2 -0
- package/packages/coworker-memory/dist/recall-formatter.js +14 -0
- package/packages/coworker-memory/dist/scope-resolver.d.ts +9 -0
- package/packages/coworker-memory/dist/scope-resolver.js +10 -0
- package/packages/coworker-memory/dist/types.d.ts +51 -0
- package/packages/coworker-memory/dist/types.js +2 -0
- package/packages/coworker-memory/dist/workspace-id.d.ts +3 -0
- package/packages/coworker-memory/dist/workspace-id.js +54 -0
- package/packages/coworker-memory/package.json +35 -0
- package/packages/coworker-memory/src/activator-integration.test.ts +141 -0
- package/packages/coworker-memory/src/context-injection.test.ts +72 -0
- package/packages/coworker-memory/src/context-injection.ts +57 -0
- package/packages/coworker-memory/src/errors.test.ts +45 -0
- package/packages/coworker-memory/src/errors.ts +42 -0
- package/packages/coworker-memory/src/index.test.ts +21 -0
- package/packages/coworker-memory/src/index.ts +12 -0
- package/packages/coworker-memory/src/layer-a-store.test.ts +85 -0
- package/packages/coworker-memory/src/layer-a-store.ts +88 -0
- package/packages/coworker-memory/src/local-sqlite-backend.test.ts +110 -0
- package/packages/coworker-memory/src/local-sqlite-backend.ts +185 -0
- package/packages/coworker-memory/src/memory-backend.ts +10 -0
- package/packages/coworker-memory/src/memory-integration.test.ts +89 -0
- package/packages/coworker-memory/src/memory-recorder.test.ts +101 -0
- package/packages/coworker-memory/src/memory-recorder.ts +95 -0
- package/packages/coworker-memory/src/migrations/001-init.sql +38 -0
- package/packages/coworker-memory/src/migrations/002-artifact-kind.sql +50 -0
- package/packages/coworker-memory/src/paste-detector.test.ts +23 -0
- package/packages/coworker-memory/src/paste-detector.ts +18 -0
- package/packages/coworker-memory/src/persona-seed.test.ts +57 -0
- package/packages/coworker-memory/src/persona-seed.ts +46 -0
- package/packages/coworker-memory/src/recall-formatter.test.ts +34 -0
- package/packages/coworker-memory/src/recall-formatter.ts +15 -0
- package/packages/coworker-memory/src/scope-resolver.test.ts +23 -0
- package/packages/coworker-memory/src/scope-resolver.ts +18 -0
- package/packages/coworker-memory/src/types.ts +61 -0
- package/packages/coworker-memory/src/workspace-id.test.ts +48 -0
- package/packages/coworker-memory/src/workspace-id.ts +56 -0
- package/packages/coworker-memory/tsconfig.json +15 -0
- package/packages/coworker-memory/tsconfig.publish.json +4 -0
- package/packages/coworker-persona/dist/commands.d.ts +7 -0
- package/packages/coworker-persona/dist/commands.js +35 -0
- package/packages/coworker-persona/dist/defaults/manifest.yaml +12 -0
- package/packages/coworker-persona/dist/defaults/steering/identity.md +3 -0
- package/packages/coworker-persona/dist/index.d.ts +3 -0
- package/packages/coworker-persona/dist/index.js +3 -0
- package/packages/coworker-persona/dist/manifest.d.ts +24 -0
- package/packages/coworker-persona/dist/manifest.js +21 -0
- package/packages/coworker-persona/dist/registry.d.ts +22 -0
- package/packages/coworker-persona/dist/registry.js +142 -0
- package/packages/coworker-persona/package.json +28 -0
- package/packages/coworker-persona/scripts/copy-defaults.cjs +17 -0
- package/packages/coworker-persona/src/commands.ts +47 -0
- package/packages/coworker-persona/src/defaults/manifest.yaml +12 -0
- package/packages/coworker-persona/src/defaults/steering/identity.md +3 -0
- package/packages/coworker-persona/src/index.ts +3 -0
- package/packages/coworker-persona/src/manifest.test.ts +67 -0
- package/packages/coworker-persona/src/manifest.ts +49 -0
- package/packages/coworker-persona/src/registry.test.ts +89 -0
- package/packages/coworker-persona/src/registry.ts +147 -0
- package/packages/coworker-persona/tsconfig.json +15 -0
- package/packages/coworker-persona/tsconfig.publish.json +4 -0
- package/packages/coworker-scratchpad/dist/cell-archive.d.ts +39 -0
- package/packages/coworker-scratchpad/dist/cell-archive.js +77 -0
- package/packages/coworker-scratchpad/dist/cell-tree.d.ts +14 -0
- package/packages/coworker-scratchpad/dist/cell-tree.js +72 -0
- package/packages/coworker-scratchpad/dist/child-process-runtime.d.ts +129 -0
- package/packages/coworker-scratchpad/dist/child-process-runtime.js +427 -0
- package/packages/coworker-scratchpad/dist/collector-registry.d.ts +12 -0
- package/packages/coworker-scratchpad/dist/collector-registry.js +29 -0
- package/packages/coworker-scratchpad/dist/detect-kind.d.ts +3 -0
- package/packages/coworker-scratchpad/dist/detect-kind.js +19 -0
- package/packages/coworker-scratchpad/dist/file-collector.d.ts +15 -0
- package/packages/coworker-scratchpad/dist/file-collector.js +99 -0
- package/packages/coworker-scratchpad/dist/index.d.ts +13 -0
- package/packages/coworker-scratchpad/dist/index.js +13 -0
- package/packages/coworker-scratchpad/dist/kernel-bindings.d.ts +49 -0
- package/packages/coworker-scratchpad/dist/kernel-bindings.js +220 -0
- package/packages/coworker-scratchpad/dist/kernel-entry.d.ts +1 -0
- package/packages/coworker-scratchpad/dist/kernel-entry.js +355 -0
- package/packages/coworker-scratchpad/dist/kernel-protocol.d.ts +171 -0
- package/packages/coworker-scratchpad/dist/kernel-protocol.js +48 -0
- package/packages/coworker-scratchpad/dist/kernel-spawn.d.ts +3 -0
- package/packages/coworker-scratchpad/dist/kernel-spawn.js +54 -0
- package/packages/coworker-scratchpad/dist/namespace-codec.d.ts +22 -0
- package/packages/coworker-scratchpad/dist/namespace-codec.js +61 -0
- package/packages/coworker-scratchpad/dist/scratchpad-lock.d.ts +24 -0
- package/packages/coworker-scratchpad/dist/scratchpad-lock.js +86 -0
- package/packages/coworker-scratchpad/dist/scratchpad-manager.d.ts +193 -0
- package/packages/coworker-scratchpad/dist/scratchpad-manager.js +866 -0
- package/packages/coworker-scratchpad/dist/staleness-banner.d.ts +12 -0
- package/packages/coworker-scratchpad/dist/staleness-banner.js +27 -0
- package/packages/coworker-scratchpad/package.json +31 -0
- package/packages/coworker-scratchpad/src/cell-archive.test.ts +150 -0
- package/packages/coworker-scratchpad/src/cell-archive.ts +97 -0
- package/packages/coworker-scratchpad/src/cell-tree.test.ts +105 -0
- package/packages/coworker-scratchpad/src/cell-tree.ts +90 -0
- package/packages/coworker-scratchpad/src/child-process-runtime.test.ts +413 -0
- package/packages/coworker-scratchpad/src/child-process-runtime.ts +493 -0
- package/packages/coworker-scratchpad/src/collector-registry.test.ts +69 -0
- package/packages/coworker-scratchpad/src/collector-registry.ts +33 -0
- package/packages/coworker-scratchpad/src/detect-kind.test.ts +33 -0
- package/packages/coworker-scratchpad/src/detect-kind.ts +22 -0
- package/packages/coworker-scratchpad/src/file-collector.test.ts +109 -0
- package/packages/coworker-scratchpad/src/file-collector.ts +114 -0
- package/packages/coworker-scratchpad/src/index.ts +74 -0
- package/packages/coworker-scratchpad/src/kernel-bindings.test.ts +188 -0
- package/packages/coworker-scratchpad/src/kernel-bindings.ts +279 -0
- package/packages/coworker-scratchpad/src/kernel-entry.test.ts +123 -0
- package/packages/coworker-scratchpad/src/kernel-entry.ts +390 -0
- package/packages/coworker-scratchpad/src/kernel-protocol.test.ts +105 -0
- package/packages/coworker-scratchpad/src/kernel-protocol.ts +230 -0
- package/packages/coworker-scratchpad/src/kernel-spawn.test.ts +60 -0
- package/packages/coworker-scratchpad/src/kernel-spawn.ts +54 -0
- package/packages/coworker-scratchpad/src/namespace-codec.test.ts +102 -0
- package/packages/coworker-scratchpad/src/namespace-codec.ts +90 -0
- package/packages/coworker-scratchpad/src/scratchpad-lock.test.ts +98 -0
- package/packages/coworker-scratchpad/src/scratchpad-lock.ts +102 -0
- package/packages/coworker-scratchpad/src/scratchpad-manager.test.ts +1343 -0
- package/packages/coworker-scratchpad/src/scratchpad-manager.ts +891 -0
- package/packages/coworker-scratchpad/src/staleness-banner.test.ts +53 -0
- package/packages/coworker-scratchpad/src/staleness-banner.ts +33 -0
- package/packages/coworker-scratchpad/src/vault-integration.test.ts +221 -0
- package/packages/coworker-scratchpad/tsconfig.json +15 -0
- package/packages/coworker-scratchpad/tsconfig.publish.json +4 -0
- package/packages/coworker-types/dist/artifacts.d.ts +31 -0
- package/packages/coworker-types/dist/artifacts.js +2 -0
- package/packages/coworker-types/dist/contracts.d.ts +32 -0
- package/packages/coworker-types/dist/contracts.js +1 -0
- package/packages/coworker-types/dist/index.d.ts +5 -0
- package/packages/coworker-types/dist/index.js +5 -0
- package/packages/coworker-types/dist/memory.d.ts +61 -0
- package/packages/coworker-types/dist/memory.js +3 -0
- package/packages/coworker-types/dist/scratchpad.d.ts +43 -0
- package/packages/coworker-types/dist/scratchpad.js +2 -0
- package/packages/coworker-types/dist/vault.d.ts +34 -0
- package/packages/coworker-types/dist/vault.js +2 -0
- package/packages/coworker-types/package.json +24 -0
- package/packages/coworker-types/src/artifacts.test.ts +52 -0
- package/packages/coworker-types/src/artifacts.ts +35 -0
- package/packages/coworker-types/src/contracts.test.ts +43 -0
- package/packages/coworker-types/src/contracts.ts +36 -0
- package/packages/coworker-types/src/index.ts +5 -0
- package/packages/coworker-types/src/memory.test.ts +50 -0
- package/packages/coworker-types/src/memory.ts +79 -0
- package/packages/coworker-types/src/scratchpad.test.ts +46 -0
- package/packages/coworker-types/src/scratchpad.ts +51 -0
- package/packages/coworker-types/src/smoke.test.ts +34 -0
- package/packages/coworker-types/src/vault.test.ts +49 -0
- package/packages/coworker-types/src/vault.ts +40 -0
- package/packages/coworker-types/tsconfig.json +15 -0
- package/packages/coworker-types/tsconfig.publish.json +4 -0
- package/packages/coworker-utils/dist/audit-log.d.ts +34 -0
- package/packages/coworker-utils/dist/audit-log.js +88 -0
- package/packages/coworker-utils/dist/index.d.ts +6 -0
- package/packages/coworker-utils/dist/index.js +6 -0
- package/packages/coworker-utils/dist/lease.d.ts +7 -0
- package/packages/coworker-utils/dist/lease.js +67 -0
- package/packages/coworker-utils/dist/logger.d.ts +13 -0
- package/packages/coworker-utils/dist/logger.js +26 -0
- package/packages/coworker-utils/dist/migration-runner.d.ts +7 -0
- package/packages/coworker-utils/dist/migration-runner.js +36 -0
- package/packages/coworker-utils/dist/ndjson-channel.d.ts +3 -0
- package/packages/coworker-utils/dist/ndjson-channel.js +38 -0
- package/packages/coworker-utils/dist/secret-scanner.d.ts +10 -0
- package/packages/coworker-utils/dist/secret-scanner.js +42 -0
- package/packages/coworker-utils/package.json +24 -0
- package/packages/coworker-utils/src/audit-log.test.ts +140 -0
- package/packages/coworker-utils/src/audit-log.ts +107 -0
- package/packages/coworker-utils/src/index.ts +6 -0
- package/packages/coworker-utils/src/lease.test.ts +64 -0
- package/packages/coworker-utils/src/lease.ts +76 -0
- package/packages/coworker-utils/src/logger.test.ts +50 -0
- package/packages/coworker-utils/src/logger.ts +45 -0
- package/packages/coworker-utils/src/migration-runner.test.ts +65 -0
- package/packages/coworker-utils/src/migration-runner.ts +50 -0
- package/packages/coworker-utils/src/ndjson-channel.test.ts +76 -0
- package/packages/coworker-utils/src/ndjson-channel.ts +41 -0
- package/packages/coworker-utils/src/secret-scanner.test.ts +61 -0
- package/packages/coworker-utils/src/secret-scanner.ts +56 -0
- package/packages/coworker-utils/tsconfig.json +15 -0
- package/packages/coworker-utils/tsconfig.publish.json +4 -0
- package/packages/coworker-vault/dist/data-vault.d.ts +41 -0
- package/packages/coworker-vault/dist/data-vault.js +223 -0
- package/packages/coworker-vault/dist/engine-registry.d.ts +34 -0
- package/packages/coworker-vault/dist/engine-registry.js +90 -0
- package/packages/coworker-vault/dist/engines/jira.yaml +17 -0
- package/packages/coworker-vault/dist/errors.d.ts +28 -0
- package/packages/coworker-vault/dist/errors.js +57 -0
- package/packages/coworker-vault/dist/index.d.ts +6 -0
- package/packages/coworker-vault/dist/index.js +6 -0
- package/packages/coworker-vault/dist/injector.d.ts +19 -0
- package/packages/coworker-vault/dist/injector.js +77 -0
- package/packages/coworker-vault/dist/types.d.ts +28 -0
- package/packages/coworker-vault/dist/types.js +1 -0
- package/packages/coworker-vault/dist/vault-keep.d.ts +4 -0
- package/packages/coworker-vault/dist/vault-keep.js +21 -0
- package/packages/coworker-vault/package.json +29 -0
- package/packages/coworker-vault/src/data-vault.test.ts +199 -0
- package/packages/coworker-vault/src/data-vault.ts +257 -0
- package/packages/coworker-vault/src/engine-registry.test.ts +120 -0
- package/packages/coworker-vault/src/engine-registry.ts +107 -0
- package/packages/coworker-vault/src/engines/jira.yaml +17 -0
- package/packages/coworker-vault/src/errors.test.ts +58 -0
- package/packages/coworker-vault/src/errors.ts +50 -0
- package/packages/coworker-vault/src/index.test.ts +24 -0
- package/packages/coworker-vault/src/index.ts +6 -0
- package/packages/coworker-vault/src/injector.test.ts +109 -0
- package/packages/coworker-vault/src/injector.ts +98 -0
- package/packages/coworker-vault/src/types.ts +33 -0
- package/packages/coworker-vault/src/vault-keep.test.ts +49 -0
- package/packages/coworker-vault/src/vault-keep.ts +31 -0
- package/packages/coworker-vault/tsconfig.json +15 -0
- package/packages/coworker-vault/tsconfig.publish.json +4 -0
- package/packages/daemon/package.json +3 -3
- package/packages/mcp-server/package.json +3 -3
- package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
- package/packages/native/package.json +1 -1
- package/packages/native/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-agent-core/package.json +1 -1
- package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-ai/package.json +1 -1
- package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +6 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +22 -3
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js +11 -0
- package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.d.ts +47 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.js +107 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.regression.test.d.ts +19 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.regression.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.regression.test.js +121 -0
- package/packages/pi-coding-agent/dist/modes/rpc/raw-stdout.regression.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +17 -1
- package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/packages/pi-coding-agent/package.json +2 -2
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +22 -3
- package/packages/pi-coding-agent/src/core/resolve-config-value.test.ts +11 -0
- package/packages/pi-coding-agent/src/modes/rpc/raw-stdout.regression.test.ts +129 -0
- package/packages/pi-coding-agent/src/modes/rpc/raw-stdout.ts +117 -0
- package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +18 -1
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-tui/package.json +1 -1
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
- package/packages/rpc-client/package.json +2 -2
- package/packages/rpc-client/tsconfig.tsbuildinfo +1 -1
- package/pkg/package.json +1 -1
- package/scripts/install.js +6 -5
- package/src/resources/extensions/coworker-artifacts/artifacts-command.test.ts +54 -0
- package/src/resources/extensions/coworker-artifacts/artifacts-command.ts +43 -0
- package/src/resources/extensions/coworker-artifacts/artifacts-singleton.test.ts +25 -0
- package/src/resources/extensions/coworker-artifacts/artifacts-singleton.ts +29 -0
- package/src/resources/extensions/coworker-artifacts/extension-manifest.json +13 -0
- package/src/resources/extensions/coworker-artifacts/index.test.ts +46 -0
- package/src/resources/extensions/coworker-artifacts/index.ts +154 -0
- package/src/resources/extensions/coworker-artifacts/list-tool.test.ts +29 -0
- package/src/resources/extensions/coworker-artifacts/list-tool.ts +53 -0
- package/src/resources/extensions/coworker-artifacts/open-tool.test.ts +30 -0
- package/src/resources/extensions/coworker-artifacts/open-tool.ts +43 -0
- package/src/resources/extensions/coworker-memory/extension-manifest.json +13 -0
- package/src/resources/extensions/coworker-memory/index.test.ts +137 -0
- package/src/resources/extensions/coworker-memory/index.ts +257 -0
- package/src/resources/extensions/coworker-memory/memorize-tool.test.ts +41 -0
- package/src/resources/extensions/coworker-memory/memorize-tool.ts +20 -0
- package/src/resources/extensions/coworker-memory/memory-command.test.ts +134 -0
- package/src/resources/extensions/coworker-memory/memory-command.ts +131 -0
- package/src/resources/extensions/coworker-memory/memory-singleton.test.ts +41 -0
- package/src/resources/extensions/coworker-memory/memory-singleton.ts +89 -0
- package/src/resources/extensions/coworker-memory/recall-tool.test.ts +50 -0
- package/src/resources/extensions/coworker-memory/recall-tool.ts +35 -0
- package/src/resources/extensions/coworker-memory/session-hooks.test.ts +77 -0
- package/src/resources/extensions/coworker-memory/session-hooks.ts +61 -0
- package/src/resources/extensions/coworker-scratchpad/attach-banners.test.ts +124 -0
- package/src/resources/extensions/coworker-scratchpad/attach-banners.ts +67 -0
- package/src/resources/extensions/coworker-scratchpad/extension-manifest.json +13 -0
- package/src/resources/extensions/coworker-scratchpad/format-age.test.ts +30 -0
- package/src/resources/extensions/coworker-scratchpad/format-age.ts +6 -0
- package/src/resources/extensions/coworker-scratchpad/helpers.test.ts +93 -0
- package/src/resources/extensions/coworker-scratchpad/helpers.ts +42 -0
- package/src/resources/extensions/coworker-scratchpad/index.test.ts +514 -0
- package/src/resources/extensions/coworker-scratchpad/index.ts +207 -0
- package/src/resources/extensions/coworker-scratchpad/mime-bundle.test.ts +61 -0
- package/src/resources/extensions/coworker-scratchpad/mime-bundle.ts +23 -0
- package/src/resources/extensions/coworker-scratchpad/scratchpad-tool.test.ts +137 -0
- package/src/resources/extensions/coworker-scratchpad/scratchpad-tool.ts +165 -0
- package/src/resources/extensions/coworker-scratchpad/session-sidecar.test.ts +133 -0
- package/src/resources/extensions/coworker-scratchpad/session-sidecar.ts +68 -0
- package/src/resources/extensions/coworker-scratchpad/sp-command.test.ts +836 -0
- package/src/resources/extensions/coworker-scratchpad/sp-command.ts +602 -0
- package/src/resources/extensions/coworker-scratchpad/workspace-pointer.test.ts +74 -0
- package/src/resources/extensions/coworker-scratchpad/workspace-pointer.ts +55 -0
- package/src/resources/extensions/coworker-scratchpad/workspace-root.test.ts +51 -0
- package/src/resources/extensions/coworker-scratchpad/workspace-root.ts +16 -0
- package/src/resources/extensions/coworker-vault/audit-command.test.ts +109 -0
- package/src/resources/extensions/coworker-vault/audit-command.ts +56 -0
- package/src/resources/extensions/coworker-vault/connect-command.test.ts +103 -0
- package/src/resources/extensions/coworker-vault/connect-command.ts +69 -0
- package/src/resources/extensions/coworker-vault/datasource-command.test.ts +80 -0
- package/src/resources/extensions/coworker-vault/datasource-command.ts +81 -0
- package/src/resources/extensions/coworker-vault/extension-manifest.json +12 -0
- package/src/resources/extensions/coworker-vault/index.test.ts +82 -0
- package/src/resources/extensions/coworker-vault/index.ts +181 -0
- package/src/resources/extensions/coworker-vault/test-helpers.ts +120 -0
- package/src/resources/extensions/coworker-vault/vault-singleton.test.ts +27 -0
- package/src/resources/extensions/coworker-vault/vault-singleton.ts +40 -0
- package/src/resources/extensions/otto/commands/release-notes/_data.ts +97 -0
- package/src/resources/extensions/otto/commands/release-notes/command.ts +16 -3
- package/src/resources/extensions/otto/index.ts +29 -6
- package/src/resources/extensions/shared/coworker-paths.test.ts +40 -0
- package/src/resources/extensions/shared/coworker-paths.ts +10 -0
- package/src/resources/extensions/slash-commands/{audit.ts → audit-codebase.ts} +4 -4
- package/src/resources/extensions/slash-commands/extension-manifest.json +1 -1
- package/src/resources/extensions/slash-commands/index.ts +2 -2
- package/src/resources/extensions/subagent/index.ts +9 -0
- package/src/resources/extensions/subagent/launch.test.ts +97 -0
- package/src/resources/extensions/subagent/launch.ts +42 -5
- package/src/resources/extensions/subagent/run-store.ts +3 -1
- package/src/resources/extensions/workflow/bootstrap/register-extension.ts +2 -0
- package/src/resources/extensions/workflow/bootstrap/register-hooks.ts +10 -0
- package/src/resources/extensions/workflow/health-widget-core.ts +1 -1
- package/src/resources/extensions/workflow/persona-status.ts +109 -0
- package/src/resources/extensions/workflow/tests/auto-recovery.test.ts +34 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface StalenessCheck {
|
|
2
|
+
scratchpadName: string;
|
|
3
|
+
sessionId: string;
|
|
4
|
+
bindings: string[];
|
|
5
|
+
spawnTime: Date;
|
|
6
|
+
lookupLastModified: (ref: string) => Promise<string | null>;
|
|
7
|
+
}
|
|
8
|
+
export declare class StalenessBanner {
|
|
9
|
+
private readonly shown;
|
|
10
|
+
check(args: StalenessCheck): Promise<string | null>;
|
|
11
|
+
resetForRespawn(scratchpadName: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export class StalenessBanner {
|
|
2
|
+
shown = new Map(); // scratchpadName → set of "session|ref"
|
|
3
|
+
async check(args) {
|
|
4
|
+
const stale = [];
|
|
5
|
+
for (const ref of args.bindings) {
|
|
6
|
+
const lm = await args.lookupLastModified(ref);
|
|
7
|
+
if (!lm)
|
|
8
|
+
continue;
|
|
9
|
+
if (new Date(lm).getTime() <= args.spawnTime.getTime())
|
|
10
|
+
continue;
|
|
11
|
+
const key = `${args.sessionId}|${ref}`;
|
|
12
|
+
const set = this.shown.get(args.scratchpadName) ?? new Set();
|
|
13
|
+
if (set.has(key))
|
|
14
|
+
continue;
|
|
15
|
+
set.add(key);
|
|
16
|
+
this.shown.set(args.scratchpadName, set);
|
|
17
|
+
stale.push(ref);
|
|
18
|
+
}
|
|
19
|
+
if (stale.length === 0)
|
|
20
|
+
return null;
|
|
21
|
+
const list = stale.join(', ');
|
|
22
|
+
return `${list} was modified after this kernel was spawned; env vars are stale. Run /sp reset to respawn with current values.`;
|
|
23
|
+
}
|
|
24
|
+
resetForRespawn(scratchpadName) {
|
|
25
|
+
this.shown.delete(scratchpadName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@otto/coworker-scratchpad",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Otto co-worker package: coworker-scratchpad",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"otto": {
|
|
7
|
+
"linkable": true,
|
|
8
|
+
"scope": "@otto",
|
|
9
|
+
"name": "coworker-scratchpad"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@otto/coworker-artifacts": "*",
|
|
13
|
+
"@otto/coworker-types": "*",
|
|
14
|
+
"@otto/coworker-utils": "*",
|
|
15
|
+
"@otto/coworker-vault": "*",
|
|
16
|
+
"chokidar": "^5.0.0"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.json",
|
|
28
|
+
"build:publish": "tsc -p tsconfig.publish.json"
|
|
29
|
+
},
|
|
30
|
+
"files": ["dist"]
|
|
31
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { CellArchive, CELLS_SCHEMA_VERSION } from './cell-archive.js';
|
|
8
|
+
|
|
9
|
+
let dir: string;
|
|
10
|
+
const lines = (p: string): string[] => readFileSync(p, 'utf8').split('\n').filter((l) => l.trim());
|
|
11
|
+
const cellsPath = (): string => join(dir, 'cells.jsonl');
|
|
12
|
+
|
|
13
|
+
describe('CellArchive', () => {
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
dir = await mkdtemp(join(tmpdir(), 'cells-'));
|
|
16
|
+
});
|
|
17
|
+
afterEach(async () => {
|
|
18
|
+
await rm(dir, { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('writes a schema header once, then a first entry with id 1 / parentId null', () => {
|
|
22
|
+
const a = new CellArchive(dir, () => 1000);
|
|
23
|
+
const e = a.append({ code: 'return 1;', ok: true, value: 1, stdout: '' });
|
|
24
|
+
assert.equal(e.id, 1);
|
|
25
|
+
assert.equal(e.parentId, null);
|
|
26
|
+
const ls = lines(cellsPath());
|
|
27
|
+
assert.deepEqual(JSON.parse(ls[0]), { type: 'header', version: CELLS_SCHEMA_VERSION });
|
|
28
|
+
const rec = JSON.parse(ls[1]);
|
|
29
|
+
assert.equal(rec.id, 1);
|
|
30
|
+
assert.equal(rec.ok, true);
|
|
31
|
+
assert.equal(rec.value, 1);
|
|
32
|
+
assert.equal(rec.ts, new Date(1000).toISOString());
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('chains parentId to the previous entry', () => {
|
|
36
|
+
const a = new CellArchive(dir, () => 0);
|
|
37
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' });
|
|
38
|
+
const second = a.append({ code: 'b', ok: true, value: null, stdout: '' });
|
|
39
|
+
assert.equal(second.id, 2);
|
|
40
|
+
assert.equal(second.parentId, 1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('records a failed cell with ok:false and an error (no value)', () => {
|
|
44
|
+
const a = new CellArchive(dir, () => 0);
|
|
45
|
+
const e = a.append({ code: 'throw 1', ok: false, error: { name: 'Error', message: 'boom' }, stdout: '' });
|
|
46
|
+
assert.equal(e.ok, false);
|
|
47
|
+
assert.equal(e.error!.message, 'boom');
|
|
48
|
+
assert.equal('value' in e, false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('continues ids across a fresh archive over the same file (re-attach durability)', () => {
|
|
52
|
+
const a1 = new CellArchive(dir, () => 0);
|
|
53
|
+
a1.append({ code: 'a', ok: true, value: null, stdout: '' }); // id 1
|
|
54
|
+
a1.append({ code: 'b', ok: true, value: null, stdout: '' }); // id 2
|
|
55
|
+
const a2 = new CellArchive(dir, () => 0); // re-attach: scans existing file
|
|
56
|
+
const next = a2.append({ code: 'c', ok: true, value: null, stdout: '' });
|
|
57
|
+
assert.equal(next.id, 3);
|
|
58
|
+
assert.equal(next.parentId, 2);
|
|
59
|
+
assert.equal(lines(cellsPath()).filter((l) => l.includes('"id"')).length, 3);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('exposes lastId — null before any append, the most recent id after', () => {
|
|
63
|
+
const a = new CellArchive(dir, () => 0);
|
|
64
|
+
assert.equal(a.lastId, null);
|
|
65
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' });
|
|
66
|
+
assert.equal(a.lastId, 1);
|
|
67
|
+
a.append({ code: 'b', ok: true, value: null, stdout: '' });
|
|
68
|
+
assert.equal(a.lastId, 2);
|
|
69
|
+
// re-attach preserves it
|
|
70
|
+
const a2 = new CellArchive(dir, () => 0);
|
|
71
|
+
assert.equal(a2.lastId, 2);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('leafId equals lastId after construct on a linear chain (backward-compat)', () => {
|
|
75
|
+
const a = new CellArchive(dir, () => 0);
|
|
76
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' });
|
|
77
|
+
a.append({ code: 'b', ok: true, value: null, stdout: '' });
|
|
78
|
+
assert.equal(a.lastId, 2);
|
|
79
|
+
assert.equal(a.leafId, 2);
|
|
80
|
+
// Re-construct over the same file: both seed to file-max.
|
|
81
|
+
const a2 = new CellArchive(dir, () => 0);
|
|
82
|
+
assert.equal(a2.lastId, 2);
|
|
83
|
+
assert.equal(a2.leafId, 2);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('setLeaf moves leafId without affecting lastId', () => {
|
|
87
|
+
const a = new CellArchive(dir, () => 0);
|
|
88
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' }); // id 1
|
|
89
|
+
a.append({ code: 'b', ok: true, value: null, stdout: '' }); // id 2
|
|
90
|
+
a.append({ code: 'c', ok: true, value: null, stdout: '' }); // id 3
|
|
91
|
+
a.setLeaf(1);
|
|
92
|
+
assert.equal(a.lastId, 3);
|
|
93
|
+
assert.equal(a.leafId, 1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('append after setLeaf chains parentId from leaf, not from lastId', () => {
|
|
97
|
+
const a = new CellArchive(dir, () => 0);
|
|
98
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' }); // id 1, parent null
|
|
99
|
+
a.append({ code: 'b', ok: true, value: null, stdout: '' }); // id 2, parent 1
|
|
100
|
+
a.append({ code: 'c', ok: true, value: null, stdout: '' }); // id 3, parent 2
|
|
101
|
+
a.setLeaf(1);
|
|
102
|
+
const branched = a.append({ code: 'd', ok: true, value: null, stdout: '' }); // id 4, parent 1
|
|
103
|
+
assert.equal(branched.id, 4);
|
|
104
|
+
assert.equal(branched.parentId, 1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('append after setLeaf updates BOTH lastId and leafId to the new id', () => {
|
|
108
|
+
const a = new CellArchive(dir, () => 0);
|
|
109
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' }); // id 1
|
|
110
|
+
a.append({ code: 'b', ok: true, value: null, stdout: '' }); // id 2
|
|
111
|
+
a.setLeaf(1);
|
|
112
|
+
a.append({ code: 'c', ok: true, value: null, stdout: '' }); // id 3, parent 1
|
|
113
|
+
assert.equal(a.lastId, 3);
|
|
114
|
+
assert.equal(a.leafId, 3);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('setLeaf(null) makes the next append a root cell (parentId null)', () => {
|
|
118
|
+
const a = new CellArchive(dir, () => 0);
|
|
119
|
+
a.append({ code: 'a', ok: true, value: null, stdout: '' });
|
|
120
|
+
a.setLeaf(null);
|
|
121
|
+
const next = a.append({ code: 'b', ok: true, value: null, stdout: '' });
|
|
122
|
+
assert.equal(next.parentId, null);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('reset truncates the file back to the schema header and clears lastId + leafId', () => {
|
|
126
|
+
const a = new CellArchive(dir, () => 1000);
|
|
127
|
+
a.append({ code: 'a', ok: true, value: 1, stdout: '' });
|
|
128
|
+
a.append({ code: 'b', ok: true, value: 2, stdout: '' });
|
|
129
|
+
assert.equal(a.lastId, 2);
|
|
130
|
+
assert.equal(a.leafId, 2);
|
|
131
|
+
a.reset();
|
|
132
|
+
assert.equal(a.lastId, null);
|
|
133
|
+
assert.equal(a.leafId, null);
|
|
134
|
+
const ls = lines(cellsPath());
|
|
135
|
+
assert.equal(ls.length, 1);
|
|
136
|
+
assert.deepEqual(JSON.parse(ls[0]), { type: 'header', version: CELLS_SCHEMA_VERSION });
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('append after reset starts a fresh chain at id 1, parentId null', () => {
|
|
140
|
+
const a = new CellArchive(dir, () => 1000);
|
|
141
|
+
a.append({ code: 'a', ok: true, value: 1, stdout: '' });
|
|
142
|
+
a.append({ code: 'b', ok: true, value: 2, stdout: '' });
|
|
143
|
+
a.reset();
|
|
144
|
+
const next = a.append({ code: 'c', ok: true, value: 3, stdout: '' });
|
|
145
|
+
assert.equal(next.id, 1);
|
|
146
|
+
assert.equal(next.parentId, null);
|
|
147
|
+
assert.equal(a.lastId, 1);
|
|
148
|
+
assert.equal(a.leafId, 1);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const CELLS_SCHEMA_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
export interface CellEntry {
|
|
7
|
+
id: number;
|
|
8
|
+
parentId: number | null;
|
|
9
|
+
code: string;
|
|
10
|
+
ok: boolean;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
error?: { name: string; message: string };
|
|
13
|
+
stdout: string;
|
|
14
|
+
ts: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AppendInput {
|
|
18
|
+
code: string;
|
|
19
|
+
ok: boolean;
|
|
20
|
+
value?: unknown;
|
|
21
|
+
error?: { name: string; message: string };
|
|
22
|
+
stdout: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class CellArchive {
|
|
26
|
+
private readonly path: string;
|
|
27
|
+
private nextId: number;
|
|
28
|
+
#lastId: number | null;
|
|
29
|
+
#leafId: number | null;
|
|
30
|
+
|
|
31
|
+
constructor(private readonly dir: string, private readonly now: () => number = Date.now) {
|
|
32
|
+
this.path = join(dir, 'cells.jsonl');
|
|
33
|
+
const { nextId, lastId } = this.scan();
|
|
34
|
+
this.nextId = nextId;
|
|
35
|
+
this.#lastId = lastId;
|
|
36
|
+
this.#leafId = lastId;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private scan(): { nextId: number; lastId: number | null } {
|
|
40
|
+
if (!existsSync(this.path)) return { nextId: 1, lastId: null };
|
|
41
|
+
let lastId: number | null = null;
|
|
42
|
+
for (const line of readFileSync(this.path, 'utf8').split('\n')) {
|
|
43
|
+
if (!line.trim()) continue;
|
|
44
|
+
try {
|
|
45
|
+
const obj = JSON.parse(line) as { id?: unknown };
|
|
46
|
+
if (typeof obj.id === 'number') lastId = obj.id;
|
|
47
|
+
} catch {
|
|
48
|
+
// header or corrupt line -> ignore
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { nextId: (lastId ?? 0) + 1, lastId };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private ensureHeader(): void {
|
|
55
|
+
if (existsSync(this.path)) return;
|
|
56
|
+
mkdirSync(this.dir, { recursive: true });
|
|
57
|
+
appendFileSync(this.path, JSON.stringify({ type: 'header', version: CELLS_SCHEMA_VERSION }) + '\n');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
append(input: AppendInput): CellEntry {
|
|
61
|
+
this.ensureHeader();
|
|
62
|
+
const id = this.nextId++;
|
|
63
|
+
const entry: CellEntry = {
|
|
64
|
+
id,
|
|
65
|
+
parentId: this.#leafId,
|
|
66
|
+
code: input.code,
|
|
67
|
+
ok: input.ok,
|
|
68
|
+
...(input.ok ? { value: input.value } : { error: input.error }),
|
|
69
|
+
stdout: input.stdout,
|
|
70
|
+
ts: new Date(this.now()).toISOString(),
|
|
71
|
+
};
|
|
72
|
+
appendFileSync(this.path, JSON.stringify(entry) + '\n');
|
|
73
|
+
this.#lastId = id;
|
|
74
|
+
this.#leafId = id;
|
|
75
|
+
return entry;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get lastId(): number | null {
|
|
79
|
+
return this.#lastId;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get leafId(): number | null {
|
|
83
|
+
return this.#leafId;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setLeaf(id: number | null): void {
|
|
87
|
+
this.#leafId = id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
reset(): void {
|
|
91
|
+
mkdirSync(this.dir, { recursive: true });
|
|
92
|
+
writeFileSync(this.path, JSON.stringify({ type: 'header', version: CELLS_SCHEMA_VERSION }) + '\n');
|
|
93
|
+
this.nextId = 1;
|
|
94
|
+
this.#lastId = null;
|
|
95
|
+
this.#leafId = null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import type { CellEntry } from './cell-archive.js';
|
|
4
|
+
import { projectTree, findLeaves, validateLeafId, formatTreeText } from './cell-tree.js';
|
|
5
|
+
|
|
6
|
+
function mkCell(id: number, parentId: number | null, ok = true, value: unknown = id, code = `return ${id};`): CellEntry {
|
|
7
|
+
return ok
|
|
8
|
+
? { id, parentId, code, ok: true, value, stdout: '', ts: `t${id}` }
|
|
9
|
+
: { id, parentId, code, ok: false, error: { name: 'Error', message: String(value) }, stdout: '', ts: `t${id}` };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('projectTree', () => {
|
|
13
|
+
it('returns null root and empty maps for an empty cell list', () => {
|
|
14
|
+
const t = projectTree([]);
|
|
15
|
+
assert.equal(t.root, null);
|
|
16
|
+
assert.equal(t.byId.size, 0);
|
|
17
|
+
assert.deepEqual(t.orphans, []);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('builds a linear chain into a single-spine tree', () => {
|
|
21
|
+
const cells = [mkCell(1, null), mkCell(2, 1), mkCell(3, 2)];
|
|
22
|
+
const t = projectTree(cells);
|
|
23
|
+
assert.equal(t.root?.cell.id, 1);
|
|
24
|
+
assert.equal(t.root?.children.length, 1);
|
|
25
|
+
assert.equal(t.root?.children[0].cell.id, 2);
|
|
26
|
+
assert.equal(t.root?.children[0].children[0].cell.id, 3);
|
|
27
|
+
assert.equal(t.byId.size, 3);
|
|
28
|
+
assert.deepEqual(t.orphans, []);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('builds a branching tree when a parent has two children', () => {
|
|
32
|
+
// 1 → 2 → 3
|
|
33
|
+
// └→ 4
|
|
34
|
+
const cells = [mkCell(1, null), mkCell(2, 1), mkCell(3, 2), mkCell(4, 2)];
|
|
35
|
+
const t = projectTree(cells);
|
|
36
|
+
assert.equal(t.byId.get(2)!.children.length, 2);
|
|
37
|
+
const ids = t.byId.get(2)!.children.map((c) => c.cell.id).sort();
|
|
38
|
+
assert.deepEqual(ids, [3, 4]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('collects orphans when parentId points to a missing id', () => {
|
|
42
|
+
const cells = [mkCell(1, null), mkCell(5, 99)]; // 99 doesn't exist
|
|
43
|
+
const t = projectTree(cells);
|
|
44
|
+
assert.equal(t.root?.cell.id, 1);
|
|
45
|
+
assert.equal(t.orphans.length, 1);
|
|
46
|
+
assert.equal(t.orphans[0].cell.id, 5);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('findLeaves', () => {
|
|
51
|
+
it('returns all childless nodes', () => {
|
|
52
|
+
// 1 → 2 → 3
|
|
53
|
+
// └→ 4
|
|
54
|
+
const cells = [mkCell(1, null), mkCell(2, 1), mkCell(3, 2), mkCell(4, 2)];
|
|
55
|
+
const leaves = findLeaves(projectTree(cells));
|
|
56
|
+
const ids = leaves.map((n) => n.cell.id).sort();
|
|
57
|
+
assert.deepEqual(ids, [3, 4]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('validateLeafId', () => {
|
|
62
|
+
it('returns without throwing when id is present', () => {
|
|
63
|
+
const t = projectTree([mkCell(1, null), mkCell(2, 1)]);
|
|
64
|
+
assert.doesNotThrow(() => validateLeafId(t, 2));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('throws when id is missing', () => {
|
|
68
|
+
const t = projectTree([mkCell(1, null)]);
|
|
69
|
+
assert.throws(() => validateLeafId(t, 99), /cell id 99 not found/);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('formatTreeText', () => {
|
|
74
|
+
it('renders ok cells with #id, ok flag, value, and code preview', () => {
|
|
75
|
+
const text = formatTreeText(projectTree([mkCell(1, null, true, 42, 'return 42;')]));
|
|
76
|
+
assert.match(text, /#1/);
|
|
77
|
+
assert.match(text, /\bok\b/);
|
|
78
|
+
assert.match(text, /value=42/);
|
|
79
|
+
assert.match(text, /return 42;/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renders err cells with error message instead of value', () => {
|
|
83
|
+
const text = formatTreeText(projectTree([mkCell(1, null, false, 'boom', 'throw 1;')]));
|
|
84
|
+
assert.match(text, /\berr\b/);
|
|
85
|
+
assert.match(text, /error=boom/);
|
|
86
|
+
assert.doesNotMatch(text, /value=/);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('marks the current leaf with a trailing *', () => {
|
|
90
|
+
const cells = [mkCell(1, null), mkCell(2, 1)];
|
|
91
|
+
const text = formatTreeText(projectTree(cells), 2);
|
|
92
|
+
const lineWith2 = text.split('\n').find((l) => l.includes('#2'))!;
|
|
93
|
+
assert.match(lineWith2, /\*\s*$/);
|
|
94
|
+
const lineWith1 = text.split('\n').find((l) => l.includes('#1'))!;
|
|
95
|
+
assert.doesNotMatch(lineWith1, /\*\s*$/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('truncates code preview to 60 chars', () => {
|
|
99
|
+
const longCode = 'const x = '.padEnd(200, 'A');
|
|
100
|
+
const text = formatTreeText(projectTree([mkCell(1, null, true, null, longCode)]));
|
|
101
|
+
const line = text.split('\n').find((l) => l.includes('#1'))!;
|
|
102
|
+
// The 60-char preview plus ellipsis OR cut at 60; either way the full 200-char source must not appear.
|
|
103
|
+
assert.doesNotMatch(line, /A{100}/);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CellEntry } from './cell-archive.js';
|
|
2
|
+
|
|
3
|
+
export interface TreeNode {
|
|
4
|
+
cell: CellEntry;
|
|
5
|
+
children: TreeNode[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CellTree {
|
|
9
|
+
root: TreeNode | null;
|
|
10
|
+
byId: Map<number, TreeNode>;
|
|
11
|
+
orphans: TreeNode[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function projectTree(cells: CellEntry[]): CellTree {
|
|
15
|
+
const byId = new Map<number, TreeNode>();
|
|
16
|
+
for (const cell of cells) byId.set(cell.id, { cell, children: [] });
|
|
17
|
+
const orphans: TreeNode[] = [];
|
|
18
|
+
const rootCandidates: TreeNode[] = [];
|
|
19
|
+
for (const cell of cells) {
|
|
20
|
+
const node = byId.get(cell.id)!;
|
|
21
|
+
if (cell.parentId === null) {
|
|
22
|
+
rootCandidates.push(node);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const parent = byId.get(cell.parentId);
|
|
26
|
+
if (parent) parent.children.push(node);
|
|
27
|
+
else orphans.push(node);
|
|
28
|
+
}
|
|
29
|
+
let root: TreeNode | null = null;
|
|
30
|
+
if (rootCandidates.length >= 1) {
|
|
31
|
+
root = rootCandidates[0];
|
|
32
|
+
// 1d/1d2 invariant: exactly one root. Defensive: extra roots become orphans.
|
|
33
|
+
for (let i = 1; i < rootCandidates.length; i++) orphans.push(rootCandidates[i]);
|
|
34
|
+
}
|
|
35
|
+
return { root, byId, orphans };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function findLeaves(tree: CellTree): TreeNode[] {
|
|
39
|
+
const out: TreeNode[] = [];
|
|
40
|
+
for (const node of tree.byId.values()) {
|
|
41
|
+
if (node.children.length === 0) out.push(node);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function validateLeafId(tree: CellTree, id: number): void {
|
|
47
|
+
if (!tree.byId.has(id)) {
|
|
48
|
+
throw new Error(`cell id ${id} not found`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function truncate(s: string, max: number): string {
|
|
53
|
+
if (s.length <= max) return s;
|
|
54
|
+
return s.slice(0, max - 1) + '…';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function summarizeCell(cell: CellEntry): string {
|
|
58
|
+
const okFlag = cell.ok ? 'ok ' : 'err';
|
|
59
|
+
const detail = cell.ok
|
|
60
|
+
? `value=${truncate(JSON.stringify(cell.value ?? null), 40)}`
|
|
61
|
+
: `error=${truncate(cell.error?.message ?? '', 40)}`;
|
|
62
|
+
const codePreview = truncate(cell.code.split('\n')[0], 60);
|
|
63
|
+
return `#${cell.id} ${okFlag} ${detail.padEnd(45)} ${codePreview}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function renderNode(
|
|
67
|
+
node: TreeNode,
|
|
68
|
+
depth: number,
|
|
69
|
+
lastSibling: boolean,
|
|
70
|
+
currentLeaf: number | null | undefined,
|
|
71
|
+
out: string[],
|
|
72
|
+
): void {
|
|
73
|
+
const indent = ' '.repeat(depth);
|
|
74
|
+
const connector = lastSibling ? '└─' : '├─';
|
|
75
|
+
const marker = currentLeaf === node.cell.id ? ' *' : '';
|
|
76
|
+
out.push(`${indent}${connector} ${summarizeCell(node.cell)}${marker}`);
|
|
77
|
+
const last = node.children.length - 1;
|
|
78
|
+
node.children.forEach((child, i) => renderNode(child, depth + 1, i === last, currentLeaf, out));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function formatTreeText(tree: CellTree, currentLeaf?: number | null): string {
|
|
82
|
+
const lines: string[] = [];
|
|
83
|
+
if (tree.root) renderNode(tree.root, 0, true, currentLeaf ?? null, lines);
|
|
84
|
+
if (tree.orphans.length > 0) {
|
|
85
|
+
lines.push('# orphans:');
|
|
86
|
+
const last = tree.orphans.length - 1;
|
|
87
|
+
tree.orphans.forEach((o, i) => renderNode(o, 0, i === last, currentLeaf ?? null, lines));
|
|
88
|
+
}
|
|
89
|
+
return lines.join('\n');
|
|
90
|
+
}
|