cognitive-core 0.2.0 → 0.2.2
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/.claude/settings.json +111 -2
- package/.sessionlog/settings.json +4 -0
- package/dist/atlas.d.ts +10 -0
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +65 -0
- package/dist/atlas.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/learning/index.d.ts +1 -1
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js.map +1 -1
- package/dist/learning/pipeline.d.ts +4 -31
- package/dist/learning/pipeline.d.ts.map +1 -1
- package/dist/learning/pipeline.js +12 -64
- package/dist/learning/pipeline.js.map +1 -1
- package/dist/learning/unified-pipeline.d.ts +30 -0
- package/dist/learning/unified-pipeline.d.ts.map +1 -1
- package/dist/learning/unified-pipeline.js +207 -0
- package/dist/learning/unified-pipeline.js.map +1 -1
- package/dist/memory/candidate-retrieval.d.ts.map +1 -1
- package/dist/memory/candidate-retrieval.js +3 -1
- package/dist/memory/candidate-retrieval.js.map +1 -1
- package/dist/memory/curated-loader.d.ts +21 -4
- package/dist/memory/curated-loader.d.ts.map +1 -1
- package/dist/memory/curated-loader.js +53 -16
- package/dist/memory/curated-loader.js.map +1 -1
- package/dist/memory/index.d.ts +2 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +3 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/playbook.d.ts +6 -0
- package/dist/memory/playbook.d.ts.map +1 -1
- package/dist/memory/playbook.js +15 -0
- package/dist/memory/playbook.js.map +1 -1
- package/dist/memory/source-resolver.d.ts +120 -0
- package/dist/memory/source-resolver.d.ts.map +1 -0
- package/dist/memory/source-resolver.js +300 -0
- package/dist/memory/source-resolver.js.map +1 -0
- package/dist/types/config.d.ts +141 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +40 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/error-classifier.js +8 -8
- package/dist/utils/error-classifier.js.map +1 -1
- package/dist/workspace/efficacy-toolkit.d.ts +164 -0
- package/dist/workspace/efficacy-toolkit.d.ts.map +1 -0
- package/dist/workspace/efficacy-toolkit.js +281 -0
- package/dist/workspace/efficacy-toolkit.js.map +1 -0
- package/dist/workspace/index.d.ts +2 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/templates/index.d.ts +3 -0
- package/dist/workspace/templates/index.d.ts.map +1 -1
- package/dist/workspace/templates/index.js +6 -0
- package/dist/workspace/templates/index.js.map +1 -1
- package/dist/workspace/templates/playbook-decay-detection.d.ts +46 -0
- package/dist/workspace/templates/playbook-decay-detection.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-decay-detection.js +197 -0
- package/dist/workspace/templates/playbook-decay-detection.js.map +1 -0
- package/dist/workspace/templates/playbook-efficacy-audit.d.ts +46 -0
- package/dist/workspace/templates/playbook-efficacy-audit.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-efficacy-audit.js +160 -0
- package/dist/workspace/templates/playbook-efficacy-audit.js.map +1 -0
- package/dist/workspace/templates/playbook-lifecycle-review.d.ts +51 -0
- package/dist/workspace/templates/playbook-lifecycle-review.d.ts.map +1 -0
- package/dist/workspace/templates/playbook-lifecycle-review.js +187 -0
- package/dist/workspace/templates/playbook-lifecycle-review.js.map +1 -0
- package/dist/workspace/types.d.ts +12 -54
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/types.js.map +1 -1
- package/package.json +8 -2
- package/playbooks/compound-engineering/adversarial-review.json +51 -0
- package/playbooks/compound-engineering/agent-native-architecture.json +59 -0
- package/playbooks/compound-engineering/agent-native-review.json +54 -0
- package/playbooks/compound-engineering/api-contract-review.json +52 -0
- package/playbooks/compound-engineering/brainstorm-requirements.json +55 -0
- package/playbooks/compound-engineering/bug-reproduction.json +62 -0
- package/playbooks/compound-engineering/confidence-calibration.json +49 -0
- package/playbooks/compound-engineering/correctness-review.json +49 -0
- package/playbooks/compound-engineering/data-migration-safety.json +59 -0
- package/playbooks/compound-engineering/deployment-verification.json +63 -0
- package/playbooks/compound-engineering/error-recovery-patterns.json +53 -0
- package/playbooks/compound-engineering/implementation-planning.json +64 -0
- package/playbooks/compound-engineering/issue-pattern-analysis.json +53 -0
- package/playbooks/compound-engineering/knowledge-compounding.json +63 -0
- package/playbooks/compound-engineering/learnings-research.json +54 -0
- package/playbooks/compound-engineering/maintainability-review.json +49 -0
- package/playbooks/compound-engineering/performance-review.json +54 -0
- package/playbooks/compound-engineering/plan-adversarial-review.json +56 -0
- package/playbooks/compound-engineering/plan-feasibility-review.json +56 -0
- package/playbooks/compound-engineering/project-standards-review.json +52 -0
- package/playbooks/compound-engineering/reliability-review.json +53 -0
- package/playbooks/compound-engineering/review-orchestration.json +64 -0
- package/playbooks/compound-engineering/security-review.json +54 -0
- package/playbooks/compound-engineering/systematic-execution.json +64 -0
- package/playbooks/compound-engineering/testing-review.json +50 -0
- package/src/atlas.ts +96 -0
- package/src/index.ts +27 -0
- package/src/learning/index.ts +1 -0
- package/src/learning/unified-pipeline.ts +271 -1
- package/src/memory/candidate-retrieval.ts +2 -1
- package/src/memory/curated-loader.ts +69 -16
- package/src/memory/index.ts +16 -0
- package/src/memory/playbook.ts +19 -0
- package/src/memory/source-resolver.ts +422 -0
- package/src/types/config.ts +46 -0
- package/src/types/index.ts +4 -0
- package/src/utils/error-classifier.ts +8 -8
- package/src/workspace/efficacy-toolkit.ts +496 -0
- package/src/workspace/index.ts +29 -0
- package/src/workspace/templates/index.ts +24 -0
- package/src/workspace/templates/playbook-decay-detection.ts +272 -0
- package/src/workspace/templates/playbook-efficacy-audit.ts +246 -0
- package/src/workspace/templates/playbook-lifecycle-review.ts +274 -0
- package/src/workspace/types.ts +22 -78
- package/tests/fixtures/behavioral-trajectories.ts +210 -0
- package/tests/integration/curated-sources-e2e.test.ts +502 -0
- package/tests/integration/pipeline-data-correctness.test.ts +794 -0
- package/tests/learning/meta-learner.test.ts +418 -0
- package/tests/learning/pipeline-memory-updates.test.ts +721 -0
- package/tests/learning/unified-pipeline-efficacy.test.ts +232 -0
- package/tests/memory/candidate-retrieval.test.ts +167 -0
- package/tests/memory/compound-engineering-seed.test.ts +338 -0
- package/tests/memory/curated-loader-extended.test.ts +225 -0
- package/tests/memory/meta.test.ts +399 -0
- package/tests/memory/playbook-quality-validation.test.ts +430 -0
- package/tests/memory/source-resolver.test.ts +700 -0
- package/tests/search/evaluator.test.ts +257 -0
- package/tests/search/verification-runner.test.ts +357 -0
- package/tests/utils/error-classifier.test.ts +149 -0
- package/tests/utils/trajectory-helpers.test.ts +163 -0
- package/tests/workspace/efficacy-toolkit.test.ts +404 -0
- package/tests/workspace/templates/playbook-efficacy.test.ts +377 -0
- package/.claude/settings.local.json +0 -11
- package/dist/learning/llm-extractor.d.ts +0 -88
- package/dist/learning/llm-extractor.d.ts.map +0 -1
- package/dist/learning/llm-extractor.js +0 -372
- package/dist/learning/llm-extractor.js.map +0 -1
- package/dist/learning/loop-coordinator.d.ts +0 -61
- package/dist/learning/loop-coordinator.d.ts.map +0 -1
- package/dist/learning/loop-coordinator.js +0 -96
- package/dist/learning/loop-coordinator.js.map +0 -1
- package/references/agent-workspace/CLAUDE.md +0 -74
- package/references/agent-workspace/README.md +0 -587
- package/references/agent-workspace/media/banner.png +0 -0
- package/references/agent-workspace/package-lock.json +0 -2061
- package/references/agent-workspace/package.json +0 -54
- package/references/agent-workspace/src/handle.ts +0 -122
- package/references/agent-workspace/src/index.ts +0 -32
- package/references/agent-workspace/src/manager.ts +0 -102
- package/references/agent-workspace/src/readers/json.ts +0 -71
- package/references/agent-workspace/src/readers/markdown.ts +0 -37
- package/references/agent-workspace/src/readers/raw.ts +0 -27
- package/references/agent-workspace/src/types.ts +0 -68
- package/references/agent-workspace/src/validation.ts +0 -93
- package/references/agent-workspace/src/writers/json.ts +0 -17
- package/references/agent-workspace/src/writers/markdown.ts +0 -27
- package/references/agent-workspace/src/writers/raw.ts +0 -22
- package/references/agent-workspace/tests/errors.test.ts +0 -652
- package/references/agent-workspace/tests/handle.test.ts +0 -144
- package/references/agent-workspace/tests/manager.test.ts +0 -124
- package/references/agent-workspace/tests/readers.test.ts +0 -205
- package/references/agent-workspace/tests/validation.test.ts +0 -196
- package/references/agent-workspace/tests/writers.test.ts +0 -108
- package/references/agent-workspace/tsconfig.json +0 -20
- package/references/agent-workspace/tsup.config.ts +0 -9
- package/references/minimem/.claude/settings.json +0 -7
- package/references/minimem/.sudocode/issues.jsonl +0 -18
- package/references/minimem/.sudocode/specs.jsonl +0 -1
- package/references/minimem/CLAUDE.md +0 -310
- package/references/minimem/README.md +0 -556
- package/references/minimem/claude-plugin/.claude-plugin/plugin.json +0 -10
- package/references/minimem/claude-plugin/.mcp.json +0 -7
- package/references/minimem/claude-plugin/README.md +0 -158
- package/references/minimem/claude-plugin/commands/recall.md +0 -47
- package/references/minimem/claude-plugin/commands/remember.md +0 -41
- package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +0 -272
- package/references/minimem/claude-plugin/hooks/hooks.json +0 -27
- package/references/minimem/claude-plugin/hooks/session-end.sh +0 -86
- package/references/minimem/claude-plugin/hooks/session-start.sh +0 -85
- package/references/minimem/claude-plugin/skills/memory/SKILL.md +0 -108
- package/references/minimem/package-lock.json +0 -5373
- package/references/minimem/package.json +0 -60
- package/references/minimem/scripts/postbuild.js +0 -35
- package/references/minimem/src/__tests__/edge-cases.test.ts +0 -371
- package/references/minimem/src/__tests__/errors.test.ts +0 -265
- package/references/minimem/src/__tests__/helpers.ts +0 -199
- package/references/minimem/src/__tests__/internal.test.ts +0 -407
- package/references/minimem/src/__tests__/knowledge.test.ts +0 -287
- package/references/minimem/src/__tests__/minimem.integration.test.ts +0 -1127
- package/references/minimem/src/__tests__/session.test.ts +0 -190
- package/references/minimem/src/cli/__tests__/commands.test.ts +0 -759
- package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +0 -141
- package/references/minimem/src/cli/commands/append.ts +0 -76
- package/references/minimem/src/cli/commands/config.ts +0 -262
- package/references/minimem/src/cli/commands/conflicts.ts +0 -413
- package/references/minimem/src/cli/commands/daemon.ts +0 -169
- package/references/minimem/src/cli/commands/index.ts +0 -12
- package/references/minimem/src/cli/commands/init.ts +0 -88
- package/references/minimem/src/cli/commands/mcp.ts +0 -177
- package/references/minimem/src/cli/commands/push-pull.ts +0 -213
- package/references/minimem/src/cli/commands/search.ts +0 -158
- package/references/minimem/src/cli/commands/status.ts +0 -84
- package/references/minimem/src/cli/commands/sync-init.ts +0 -290
- package/references/minimem/src/cli/commands/sync.ts +0 -70
- package/references/minimem/src/cli/commands/upsert.ts +0 -197
- package/references/minimem/src/cli/config.ts +0 -584
- package/references/minimem/src/cli/index.ts +0 -264
- package/references/minimem/src/cli/shared.ts +0 -161
- package/references/minimem/src/cli/sync/__tests__/central.test.ts +0 -152
- package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +0 -209
- package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +0 -118
- package/references/minimem/src/cli/sync/__tests__/detection.test.ts +0 -207
- package/references/minimem/src/cli/sync/__tests__/integration.test.ts +0 -476
- package/references/minimem/src/cli/sync/__tests__/registry.test.ts +0 -363
- package/references/minimem/src/cli/sync/__tests__/state.test.ts +0 -255
- package/references/minimem/src/cli/sync/__tests__/validation.test.ts +0 -193
- package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +0 -178
- package/references/minimem/src/cli/sync/central.ts +0 -292
- package/references/minimem/src/cli/sync/conflicts.ts +0 -204
- package/references/minimem/src/cli/sync/daemon.ts +0 -407
- package/references/minimem/src/cli/sync/detection.ts +0 -138
- package/references/minimem/src/cli/sync/index.ts +0 -107
- package/references/minimem/src/cli/sync/operations.ts +0 -373
- package/references/minimem/src/cli/sync/registry.ts +0 -279
- package/references/minimem/src/cli/sync/state.ts +0 -355
- package/references/minimem/src/cli/sync/validation.ts +0 -206
- package/references/minimem/src/cli/sync/watcher.ts +0 -234
- package/references/minimem/src/cli/version.ts +0 -34
- package/references/minimem/src/core/index.ts +0 -9
- package/references/minimem/src/core/indexer.ts +0 -628
- package/references/minimem/src/core/searcher.ts +0 -221
- package/references/minimem/src/db/schema.ts +0 -183
- package/references/minimem/src/db/sqlite-vec.ts +0 -24
- package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +0 -431
- package/references/minimem/src/embeddings/batch-gemini.ts +0 -392
- package/references/minimem/src/embeddings/batch-openai.ts +0 -409
- package/references/minimem/src/embeddings/embeddings.ts +0 -434
- package/references/minimem/src/index.ts +0 -109
- package/references/minimem/src/internal.ts +0 -299
- package/references/minimem/src/minimem.ts +0 -1276
- package/references/minimem/src/search/__tests__/hybrid.test.ts +0 -247
- package/references/minimem/src/search/graph.ts +0 -234
- package/references/minimem/src/search/hybrid.ts +0 -151
- package/references/minimem/src/search/search.ts +0 -256
- package/references/minimem/src/server/__tests__/mcp.test.ts +0 -341
- package/references/minimem/src/server/__tests__/tools.test.ts +0 -364
- package/references/minimem/src/server/mcp.ts +0 -326
- package/references/minimem/src/server/tools.ts +0 -720
- package/references/minimem/src/session.ts +0 -460
- package/references/minimem/tsconfig.json +0 -19
- package/references/minimem/tsup.config.ts +0 -26
- package/references/minimem/vitest.config.ts +0 -24
- package/references/sessionlog/.husky/pre-commit +0 -1
- package/references/sessionlog/.lintstagedrc.json +0 -4
- package/references/sessionlog/.prettierignore +0 -4
- package/references/sessionlog/.prettierrc.json +0 -11
- package/references/sessionlog/LICENSE +0 -21
- package/references/sessionlog/README.md +0 -453
- package/references/sessionlog/eslint.config.js +0 -58
- package/references/sessionlog/package-lock.json +0 -3672
- package/references/sessionlog/package.json +0 -65
- package/references/sessionlog/src/__tests__/agent-hooks.test.ts +0 -570
- package/references/sessionlog/src/__tests__/agent-registry.test.ts +0 -127
- package/references/sessionlog/src/__tests__/claude-code-hooks.test.ts +0 -225
- package/references/sessionlog/src/__tests__/claude-generator.test.ts +0 -46
- package/references/sessionlog/src/__tests__/commit-msg.test.ts +0 -86
- package/references/sessionlog/src/__tests__/cursor-agent.test.ts +0 -224
- package/references/sessionlog/src/__tests__/e2e-live.test.ts +0 -890
- package/references/sessionlog/src/__tests__/event-log.test.ts +0 -183
- package/references/sessionlog/src/__tests__/flush-sentinel.test.ts +0 -105
- package/references/sessionlog/src/__tests__/gemini-agent.test.ts +0 -375
- package/references/sessionlog/src/__tests__/git-hooks.test.ts +0 -78
- package/references/sessionlog/src/__tests__/hook-managers.test.ts +0 -121
- package/references/sessionlog/src/__tests__/lifecycle-tasks.test.ts +0 -759
- package/references/sessionlog/src/__tests__/opencode-agent.test.ts +0 -338
- package/references/sessionlog/src/__tests__/redaction.test.ts +0 -136
- package/references/sessionlog/src/__tests__/session-repo.test.ts +0 -353
- package/references/sessionlog/src/__tests__/session-store.test.ts +0 -166
- package/references/sessionlog/src/__tests__/setup-ccweb.test.ts +0 -466
- package/references/sessionlog/src/__tests__/skill-live.test.ts +0 -461
- package/references/sessionlog/src/__tests__/summarize.test.ts +0 -348
- package/references/sessionlog/src/__tests__/task-plan-e2e.test.ts +0 -610
- package/references/sessionlog/src/__tests__/task-plan-live.test.ts +0 -632
- package/references/sessionlog/src/__tests__/transcript-timestamp.test.ts +0 -121
- package/references/sessionlog/src/__tests__/types.test.ts +0 -166
- package/references/sessionlog/src/__tests__/utils.test.ts +0 -333
- package/references/sessionlog/src/__tests__/validation.test.ts +0 -103
- package/references/sessionlog/src/__tests__/worktree.test.ts +0 -57
- package/references/sessionlog/src/agent/agents/claude-code.ts +0 -1089
- package/references/sessionlog/src/agent/agents/cursor.ts +0 -361
- package/references/sessionlog/src/agent/agents/gemini-cli.ts +0 -632
- package/references/sessionlog/src/agent/agents/opencode.ts +0 -540
- package/references/sessionlog/src/agent/registry.ts +0 -143
- package/references/sessionlog/src/agent/session-types.ts +0 -113
- package/references/sessionlog/src/agent/types.ts +0 -220
- package/references/sessionlog/src/cli.ts +0 -597
- package/references/sessionlog/src/commands/clean.ts +0 -133
- package/references/sessionlog/src/commands/disable.ts +0 -84
- package/references/sessionlog/src/commands/doctor.ts +0 -145
- package/references/sessionlog/src/commands/enable.ts +0 -202
- package/references/sessionlog/src/commands/explain.ts +0 -261
- package/references/sessionlog/src/commands/reset.ts +0 -105
- package/references/sessionlog/src/commands/resume.ts +0 -180
- package/references/sessionlog/src/commands/rewind.ts +0 -195
- package/references/sessionlog/src/commands/setup-ccweb.ts +0 -275
- package/references/sessionlog/src/commands/status.ts +0 -172
- package/references/sessionlog/src/config.ts +0 -165
- package/references/sessionlog/src/events/event-log.ts +0 -126
- package/references/sessionlog/src/git-operations.ts +0 -558
- package/references/sessionlog/src/hooks/git-hooks.ts +0 -165
- package/references/sessionlog/src/hooks/lifecycle.ts +0 -391
- package/references/sessionlog/src/index.ts +0 -650
- package/references/sessionlog/src/security/redaction.ts +0 -283
- package/references/sessionlog/src/session/state-machine.ts +0 -452
- package/references/sessionlog/src/store/checkpoint-store.ts +0 -509
- package/references/sessionlog/src/store/native-store.ts +0 -173
- package/references/sessionlog/src/store/provider-types.ts +0 -99
- package/references/sessionlog/src/store/session-store.ts +0 -266
- package/references/sessionlog/src/strategy/attribution.ts +0 -296
- package/references/sessionlog/src/strategy/common.ts +0 -207
- package/references/sessionlog/src/strategy/content-overlap.ts +0 -228
- package/references/sessionlog/src/strategy/manual-commit.ts +0 -988
- package/references/sessionlog/src/strategy/types.ts +0 -279
- package/references/sessionlog/src/summarize/claude-generator.ts +0 -115
- package/references/sessionlog/src/summarize/summarize.ts +0 -432
- package/references/sessionlog/src/types.ts +0 -508
- package/references/sessionlog/src/utils/chunk-files.ts +0 -49
- package/references/sessionlog/src/utils/commit-message.ts +0 -65
- package/references/sessionlog/src/utils/detect-agent.ts +0 -36
- package/references/sessionlog/src/utils/hook-managers.ts +0 -125
- package/references/sessionlog/src/utils/ide-tags.ts +0 -32
- package/references/sessionlog/src/utils/paths.ts +0 -79
- package/references/sessionlog/src/utils/preview-rewind.ts +0 -80
- package/references/sessionlog/src/utils/rewind-conflict.ts +0 -121
- package/references/sessionlog/src/utils/shadow-branch.ts +0 -109
- package/references/sessionlog/src/utils/string-utils.ts +0 -46
- package/references/sessionlog/src/utils/todo-extract.ts +0 -188
- package/references/sessionlog/src/utils/trailers.ts +0 -187
- package/references/sessionlog/src/utils/transcript-parse.ts +0 -177
- package/references/sessionlog/src/utils/transcript-timestamp.ts +0 -59
- package/references/sessionlog/src/utils/tree-ops.ts +0 -219
- package/references/sessionlog/src/utils/tty.ts +0 -72
- package/references/sessionlog/src/utils/validation.ts +0 -65
- package/references/sessionlog/src/utils/worktree.ts +0 -58
- package/references/sessionlog/src/wire-types.ts +0 -59
- package/references/sessionlog/templates/setup-env.sh +0 -153
- package/references/sessionlog/tsconfig.json +0 -18
- package/references/sessionlog/vitest.config.ts +0 -12
- package/references/skill-tree/.claude/settings.json +0 -6
- package/references/skill-tree/.sudocode/issues.jsonl +0 -19
- package/references/skill-tree/.sudocode/specs.jsonl +0 -3
- package/references/skill-tree/CLAUDE.md +0 -126
- package/references/skill-tree/README.md +0 -372
- package/references/skill-tree/docs/GAPS_v1.md +0 -221
- package/references/skill-tree/docs/INTEGRATION_PLAN.md +0 -467
- package/references/skill-tree/docs/TODOS.md +0 -91
- package/references/skill-tree/docs/anthropic_skill_guide.md +0 -1364
- package/references/skill-tree/docs/design/federated-skill-trees.md +0 -524
- package/references/skill-tree/docs/design/multi-agent-sync.md +0 -759
- package/references/skill-tree/docs/scraper/BRAINSTORM.md +0 -583
- package/references/skill-tree/docs/scraper/POC_PLAN.md +0 -420
- package/references/skill-tree/docs/scraper/README.md +0 -170
- package/references/skill-tree/examples/basic-usage.ts +0 -164
- package/references/skill-tree/package-lock.json +0 -1852
- package/references/skill-tree/package.json +0 -66
- package/references/skill-tree/scraper/README.md +0 -123
- package/references/skill-tree/scraper/docs/DESIGN.md +0 -683
- package/references/skill-tree/scraper/docs/PLAN.md +0 -336
- package/references/skill-tree/scraper/drizzle.config.ts +0 -10
- package/references/skill-tree/scraper/package-lock.json +0 -6329
- package/references/skill-tree/scraper/package.json +0 -68
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +0 -27
- package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +0 -21
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +0 -54
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +0 -24
- package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +0 -93
- package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +0 -22
- package/references/skill-tree/scraper/tsup.config.ts +0 -14
- package/references/skill-tree/scraper/vitest.config.ts +0 -17
- package/references/skill-tree/scripts/convert-to-vitest.ts +0 -166
- package/references/skill-tree/skills/skill-writer/SKILL.md +0 -339
- package/references/skill-tree/skills/skill-writer/references/examples.md +0 -326
- package/references/skill-tree/skills/skill-writer/references/patterns.md +0 -210
- package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +0 -123
- package/references/skill-tree/test/run-all.ts +0 -106
- package/references/skill-tree/test/utils.ts +0 -128
- package/references/skill-tree/vitest.config.ts +0 -16
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sessionlog",
|
|
3
|
-
"version": "0.0.5",
|
|
4
|
-
"description": "Session tracking and checkpoint management for AI coding agents",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.js",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"bin": {
|
|
16
|
-
"sessionlog": "./dist/cli.js"
|
|
17
|
-
},
|
|
18
|
-
"files": [
|
|
19
|
-
"dist",
|
|
20
|
-
"templates"
|
|
21
|
-
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"prepublishOnly": "npm run build",
|
|
27
|
-
"version:patch": "npm version patch && git push && git push --tags",
|
|
28
|
-
"version:minor": "npm version minor && git push && git push --tags",
|
|
29
|
-
"version:major": "npm version major && git push && git push --tags",
|
|
30
|
-
"publish:npm": "npm run build && npm publish",
|
|
31
|
-
"lint": "eslint src/",
|
|
32
|
-
"lint:fix": "eslint src/ --fix",
|
|
33
|
-
"format": "prettier --write \"src/**/*.{ts,js,json}\"",
|
|
34
|
-
"format:check": "prettier --check \"src/**/*.{ts,js,json}\"",
|
|
35
|
-
"prepare": "husky"
|
|
36
|
-
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"sessionlog",
|
|
39
|
-
"git",
|
|
40
|
-
"session-tracking",
|
|
41
|
-
"checkpoints",
|
|
42
|
-
"ai-agents"
|
|
43
|
-
],
|
|
44
|
-
"author": "Alex Ngai",
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@eslint/js": "^9.39.2",
|
|
48
|
-
"@types/node": "^25.0.10",
|
|
49
|
-
"eslint": "^9.39.2",
|
|
50
|
-
"eslint-config-prettier": "^10.1.8",
|
|
51
|
-
"husky": "^9.1.7",
|
|
52
|
-
"lint-staged": "^15.5.2",
|
|
53
|
-
"prettier": "^3.8.1",
|
|
54
|
-
"typescript": "^5.3.0",
|
|
55
|
-
"typescript-eslint": "^8.55.0",
|
|
56
|
-
"vitest": "^4.0.18"
|
|
57
|
-
},
|
|
58
|
-
"engines": {
|
|
59
|
-
"node": ">=18"
|
|
60
|
-
},
|
|
61
|
-
"repository": {
|
|
62
|
-
"type": "git",
|
|
63
|
-
"url": "git+https://github.com/alexngai/sessionlog.git"
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Agent Hook Dispatch (CLI `sessionlog hooks <agent-name> <hook-name>`)
|
|
3
|
-
*
|
|
4
|
-
* Validates the missing functionality: agent lifecycle hooks were installed
|
|
5
|
-
* by each agent's installHooks() but the CLI had no handler for
|
|
6
|
-
* `sessionlog hooks <agent-name>` — only `sessionlog hooks git` was implemented.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
import * as fs from 'node:fs';
|
|
11
|
-
import * as path from 'node:path';
|
|
12
|
-
import * as os from 'node:os';
|
|
13
|
-
import { execSync } from 'node:child_process';
|
|
14
|
-
import { createLifecycleHandler } from '../hooks/lifecycle.js';
|
|
15
|
-
import { createSessionStore } from '../store/session-store.js';
|
|
16
|
-
import { createCheckpointStore } from '../store/checkpoint-store.js';
|
|
17
|
-
import { getAgent } from '../agent/registry.js';
|
|
18
|
-
import { hasHookSupport } from '../agent/types.js';
|
|
19
|
-
import { EventType } from '../types.js';
|
|
20
|
-
|
|
21
|
-
// Ensure agents are registered
|
|
22
|
-
import '../agent/agents/claude-code.js';
|
|
23
|
-
import '../agent/agents/cursor.js';
|
|
24
|
-
import '../agent/agents/gemini-cli.js';
|
|
25
|
-
import '../agent/agents/opencode.js';
|
|
26
|
-
|
|
27
|
-
// ============================================================================
|
|
28
|
-
// Helpers
|
|
29
|
-
// ============================================================================
|
|
30
|
-
|
|
31
|
-
function initRepo(dir: string): void {
|
|
32
|
-
execSync('git init', { cwd: dir, stdio: 'pipe' });
|
|
33
|
-
execSync('git config user.email "test@test.com"', { cwd: dir, stdio: 'pipe' });
|
|
34
|
-
execSync('git config user.name "Test"', { cwd: dir, stdio: 'pipe' });
|
|
35
|
-
// Need an initial commit for getHead() to work
|
|
36
|
-
fs.writeFileSync(path.join(dir, 'README.md'), '# test');
|
|
37
|
-
execSync('git add . && git commit -m "init"', { cwd: dir, stdio: 'pipe' });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function enableSessionlog(dir: string): void {
|
|
41
|
-
const slDir = path.join(dir, '.sessionlog');
|
|
42
|
-
fs.mkdirSync(slDir, { recursive: true });
|
|
43
|
-
fs.writeFileSync(path.join(slDir, 'settings.json'), JSON.stringify({ enabled: true }));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Run the CLI as a subprocess and return stdout/stderr/exit code */
|
|
47
|
-
function runCLI(
|
|
48
|
-
args: string[],
|
|
49
|
-
opts: { cwd: string; stdin?: string },
|
|
50
|
-
): { stdout: string; stderr: string; exitCode: number } {
|
|
51
|
-
const cliPath = path.resolve(__dirname, '../../dist/cli.js');
|
|
52
|
-
try {
|
|
53
|
-
const result = execSync(`node ${cliPath} ${args.join(' ')}`, {
|
|
54
|
-
cwd: opts.cwd,
|
|
55
|
-
input: opts.stdin,
|
|
56
|
-
encoding: 'utf-8',
|
|
57
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
58
|
-
});
|
|
59
|
-
return { stdout: result, stderr: '', exitCode: 0 };
|
|
60
|
-
} catch (err: unknown) {
|
|
61
|
-
const e = err as { stdout?: string; stderr?: string; status?: number };
|
|
62
|
-
return {
|
|
63
|
-
stdout: String(e.stdout ?? ''),
|
|
64
|
-
stderr: String(e.stderr ?? ''),
|
|
65
|
-
exitCode: e.status ?? 1,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ============================================================================
|
|
71
|
-
// Unit Tests: parseHookEvent
|
|
72
|
-
// ============================================================================
|
|
73
|
-
|
|
74
|
-
describe('Agent parseHookEvent', () => {
|
|
75
|
-
it('claude-code should parse session-start event', () => {
|
|
76
|
-
const agent = getAgent('claude-code');
|
|
77
|
-
expect(agent).not.toBeNull();
|
|
78
|
-
expect(hasHookSupport(agent!)).toBe(true);
|
|
79
|
-
if (!hasHookSupport(agent!)) return;
|
|
80
|
-
|
|
81
|
-
const event = agent.parseHookEvent(
|
|
82
|
-
'session-start',
|
|
83
|
-
JSON.stringify({ session_id: 'abc-123', transcript_path: '/tmp/transcript.jsonl' }),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
expect(event).not.toBeNull();
|
|
87
|
-
expect(event!.type).toBe(EventType.SessionStart);
|
|
88
|
-
expect(event!.sessionID).toBe('abc-123');
|
|
89
|
-
expect(event!.sessionRef).toBe('/tmp/transcript.jsonl');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('claude-code should parse user-prompt-submit event', () => {
|
|
93
|
-
const agent = getAgent('claude-code');
|
|
94
|
-
if (!hasHookSupport(agent!)) return;
|
|
95
|
-
|
|
96
|
-
const event = agent!.parseHookEvent(
|
|
97
|
-
'user-prompt-submit',
|
|
98
|
-
JSON.stringify({
|
|
99
|
-
session_id: 'abc-123',
|
|
100
|
-
transcript_path: '/tmp/transcript.jsonl',
|
|
101
|
-
prompt: 'fix the login bug',
|
|
102
|
-
}),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(event).not.toBeNull();
|
|
106
|
-
expect(event!.type).toBe(EventType.TurnStart);
|
|
107
|
-
expect((event as { prompt?: string }).prompt).toBe('fix the login bug');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('claude-code should parse stop event', () => {
|
|
111
|
-
const agent = getAgent('claude-code');
|
|
112
|
-
if (!hasHookSupport(agent!)) return;
|
|
113
|
-
|
|
114
|
-
const event = agent!.parseHookEvent(
|
|
115
|
-
'stop',
|
|
116
|
-
JSON.stringify({ session_id: 'abc-123', transcript_path: '/tmp/transcript.jsonl' }),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
expect(event).not.toBeNull();
|
|
120
|
-
expect(event!.type).toBe(EventType.TurnEnd);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('claude-code should parse session-end event', () => {
|
|
124
|
-
const agent = getAgent('claude-code');
|
|
125
|
-
if (!hasHookSupport(agent!)) return;
|
|
126
|
-
|
|
127
|
-
const event = agent!.parseHookEvent(
|
|
128
|
-
'session-end',
|
|
129
|
-
JSON.stringify({ session_id: 'abc-123', transcript_path: '/tmp/transcript.jsonl' }),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expect(event).not.toBeNull();
|
|
133
|
-
expect(event!.type).toBe(EventType.SessionEnd);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('claude-code should parse pre-task (subagent start) event', () => {
|
|
137
|
-
const agent = getAgent('claude-code');
|
|
138
|
-
if (!hasHookSupport(agent!)) return;
|
|
139
|
-
|
|
140
|
-
const event = agent!.parseHookEvent(
|
|
141
|
-
'pre-task',
|
|
142
|
-
JSON.stringify({
|
|
143
|
-
session_id: 'abc-123',
|
|
144
|
-
transcript_path: '/tmp/transcript.jsonl',
|
|
145
|
-
tool_use_id: 'tool-xyz',
|
|
146
|
-
tool_input: { prompt: 'research something' },
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
expect(event).not.toBeNull();
|
|
151
|
-
expect(event!.type).toBe(EventType.SubagentStart);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('claude-code should parse post-task (subagent end) event', () => {
|
|
155
|
-
const agent = getAgent('claude-code');
|
|
156
|
-
if (!hasHookSupport(agent!)) return;
|
|
157
|
-
|
|
158
|
-
const event = agent!.parseHookEvent(
|
|
159
|
-
'post-task',
|
|
160
|
-
JSON.stringify({
|
|
161
|
-
session_id: 'abc-123',
|
|
162
|
-
transcript_path: '/tmp/transcript.jsonl',
|
|
163
|
-
tool_use_id: 'tool-xyz',
|
|
164
|
-
tool_response: { agentId: 'sub-agent-1' },
|
|
165
|
-
}),
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
expect(event).not.toBeNull();
|
|
169
|
-
expect(event!.type).toBe(EventType.SubagentEnd);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('claude-code should return null for unknown hook name', () => {
|
|
173
|
-
const agent = getAgent('claude-code');
|
|
174
|
-
if (!hasHookSupport(agent!)) return;
|
|
175
|
-
|
|
176
|
-
const event = agent!.parseHookEvent('bogus-hook', JSON.stringify({ session_id: 'abc' }));
|
|
177
|
-
expect(event).toBeNull();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('claude-code should return null for invalid JSON', () => {
|
|
181
|
-
const agent = getAgent('claude-code');
|
|
182
|
-
if (!hasHookSupport(agent!)) return;
|
|
183
|
-
|
|
184
|
-
const event = agent!.parseHookEvent('session-start', 'not json');
|
|
185
|
-
expect(event).toBeNull();
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// ============================================================================
|
|
190
|
-
// Unit Tests: Lifecycle Handler Dispatch
|
|
191
|
-
// ============================================================================
|
|
192
|
-
|
|
193
|
-
describe('Lifecycle Handler with Agent Events', () => {
|
|
194
|
-
let tmpDir: string;
|
|
195
|
-
|
|
196
|
-
beforeEach(() => {
|
|
197
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-hooks-'));
|
|
198
|
-
initRepo(tmpDir);
|
|
199
|
-
enableSessionlog(tmpDir);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
afterEach(() => {
|
|
203
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should create a session on SessionStart dispatch', async () => {
|
|
207
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
208
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
209
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
210
|
-
|
|
211
|
-
const agent = getAgent('claude-code')!;
|
|
212
|
-
await handler.dispatch(agent, {
|
|
213
|
-
type: EventType.SessionStart,
|
|
214
|
-
sessionID: 'test-session-1',
|
|
215
|
-
sessionRef: '/tmp/test-transcript.jsonl',
|
|
216
|
-
timestamp: new Date(),
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const session = await sessionStore.load('test-session-1');
|
|
220
|
-
expect(session).not.toBeNull();
|
|
221
|
-
expect(session!.sessionID).toBe('test-session-1');
|
|
222
|
-
expect(session!.phase).toBe('idle');
|
|
223
|
-
expect(session!.agentType).toBe('Claude Code');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('should transition to active on TurnStart dispatch', async () => {
|
|
227
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
228
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
229
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
230
|
-
const agent = getAgent('claude-code')!;
|
|
231
|
-
|
|
232
|
-
// Start session
|
|
233
|
-
await handler.dispatch(agent, {
|
|
234
|
-
type: EventType.SessionStart,
|
|
235
|
-
sessionID: 'test-session-2',
|
|
236
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
237
|
-
timestamp: new Date(),
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// Start turn
|
|
241
|
-
await handler.dispatch(agent, {
|
|
242
|
-
type: EventType.TurnStart,
|
|
243
|
-
sessionID: 'test-session-2',
|
|
244
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
245
|
-
prompt: 'hello world',
|
|
246
|
-
timestamp: new Date(),
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
const session = await sessionStore.load('test-session-2');
|
|
250
|
-
expect(session!.phase).toBe('active');
|
|
251
|
-
expect(session!.firstPrompt).toBe('hello world');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should transition to idle on TurnEnd dispatch', async () => {
|
|
255
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
256
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
257
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
258
|
-
const agent = getAgent('claude-code')!;
|
|
259
|
-
|
|
260
|
-
// Start session + turn
|
|
261
|
-
await handler.dispatch(agent, {
|
|
262
|
-
type: EventType.SessionStart,
|
|
263
|
-
sessionID: 'test-session-3',
|
|
264
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
265
|
-
timestamp: new Date(),
|
|
266
|
-
});
|
|
267
|
-
await handler.dispatch(agent, {
|
|
268
|
-
type: EventType.TurnStart,
|
|
269
|
-
sessionID: 'test-session-3',
|
|
270
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
271
|
-
prompt: 'do something',
|
|
272
|
-
timestamp: new Date(),
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
// End turn
|
|
276
|
-
await handler.dispatch(agent, {
|
|
277
|
-
type: EventType.TurnEnd,
|
|
278
|
-
sessionID: 'test-session-3',
|
|
279
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
280
|
-
timestamp: new Date(),
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
const session = await sessionStore.load('test-session-3');
|
|
284
|
-
expect(session!.phase).toBe('idle');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should transition to ended on SessionEnd dispatch', async () => {
|
|
288
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
289
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
290
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
291
|
-
const agent = getAgent('claude-code')!;
|
|
292
|
-
|
|
293
|
-
await handler.dispatch(agent, {
|
|
294
|
-
type: EventType.SessionStart,
|
|
295
|
-
sessionID: 'test-session-4',
|
|
296
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
297
|
-
timestamp: new Date(),
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
await handler.dispatch(agent, {
|
|
301
|
-
type: EventType.SessionEnd,
|
|
302
|
-
sessionID: 'test-session-4',
|
|
303
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
304
|
-
timestamp: new Date(),
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const session = await sessionStore.load('test-session-4');
|
|
308
|
-
expect(session!.phase).toBe('ended');
|
|
309
|
-
expect(session!.endedAt).toBeDefined();
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
it('should create shadow branch on TurnEnd when files were modified', async () => {
|
|
313
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
314
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
315
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
316
|
-
const agent = getAgent('claude-code')!;
|
|
317
|
-
|
|
318
|
-
// Create an empty transcript file (TurnStart records the current position)
|
|
319
|
-
const transcriptPath = path.join(tmpDir, 'transcript.jsonl');
|
|
320
|
-
fs.writeFileSync(transcriptPath, '');
|
|
321
|
-
|
|
322
|
-
// Dispatch SessionStart → TurnStart
|
|
323
|
-
await handler.dispatch(agent, {
|
|
324
|
-
type: EventType.SessionStart,
|
|
325
|
-
sessionID: 'shadow-test',
|
|
326
|
-
sessionRef: transcriptPath,
|
|
327
|
-
timestamp: new Date(),
|
|
328
|
-
});
|
|
329
|
-
await handler.dispatch(agent, {
|
|
330
|
-
type: EventType.TurnStart,
|
|
331
|
-
sessionID: 'shadow-test',
|
|
332
|
-
sessionRef: transcriptPath,
|
|
333
|
-
prompt: 'create hello',
|
|
334
|
-
timestamp: new Date(),
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// Simulate agent writing a file (transcript updated DURING the turn)
|
|
338
|
-
const transcriptLine = JSON.stringify({
|
|
339
|
-
type: 'assistant',
|
|
340
|
-
message: {
|
|
341
|
-
content: [
|
|
342
|
-
{
|
|
343
|
-
type: 'tool_use',
|
|
344
|
-
name: 'Write',
|
|
345
|
-
input: { file_path: 'src/hello.ts' },
|
|
346
|
-
},
|
|
347
|
-
],
|
|
348
|
-
},
|
|
349
|
-
});
|
|
350
|
-
fs.writeFileSync(transcriptPath, transcriptLine + '\n');
|
|
351
|
-
|
|
352
|
-
// TurnEnd extracts files from transcript and creates shadow branch
|
|
353
|
-
await handler.dispatch(agent, {
|
|
354
|
-
type: EventType.TurnEnd,
|
|
355
|
-
sessionID: 'shadow-test',
|
|
356
|
-
sessionRef: transcriptPath,
|
|
357
|
-
timestamp: new Date(),
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
const session = await sessionStore.load('shadow-test');
|
|
361
|
-
expect(session).not.toBeNull();
|
|
362
|
-
expect(session!.filesTouched).toContain('src/hello.ts');
|
|
363
|
-
expect(session!.stepCount).toBe(1);
|
|
364
|
-
|
|
365
|
-
// Verify shadow branch was created
|
|
366
|
-
const shadowBranch = checkpointStore.getShadowBranchName(
|
|
367
|
-
session!.baseCommit,
|
|
368
|
-
session!.worktreeID,
|
|
369
|
-
);
|
|
370
|
-
const branchList = execSync(`git branch --list "${shadowBranch}"`, {
|
|
371
|
-
cwd: tmpDir,
|
|
372
|
-
encoding: 'utf-8',
|
|
373
|
-
});
|
|
374
|
-
expect(branchList.trim()).toContain(shadowBranch);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
it('should auto-create session on TurnStart if session does not exist', async () => {
|
|
378
|
-
const sessionStore = createSessionStore(tmpDir);
|
|
379
|
-
const checkpointStore = createCheckpointStore(tmpDir);
|
|
380
|
-
const handler = createLifecycleHandler({ sessionStore, checkpointStore, cwd: tmpDir });
|
|
381
|
-
const agent = getAgent('claude-code')!;
|
|
382
|
-
|
|
383
|
-
// Dispatch TurnStart without prior SessionStart
|
|
384
|
-
await handler.dispatch(agent, {
|
|
385
|
-
type: EventType.TurnStart,
|
|
386
|
-
sessionID: 'auto-created-session',
|
|
387
|
-
sessionRef: '/tmp/transcript.jsonl',
|
|
388
|
-
prompt: 'first prompt',
|
|
389
|
-
timestamp: new Date(),
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
const session = await sessionStore.load('auto-created-session');
|
|
393
|
-
expect(session).not.toBeNull();
|
|
394
|
-
expect(session!.phase).toBe('active');
|
|
395
|
-
expect(session!.firstPrompt).toBe('first prompt');
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
// ============================================================================
|
|
400
|
-
// CLI Integration Tests
|
|
401
|
-
// ============================================================================
|
|
402
|
-
|
|
403
|
-
describe('CLI hooks agent dispatch', () => {
|
|
404
|
-
let tmpDir: string;
|
|
405
|
-
|
|
406
|
-
beforeEach(() => {
|
|
407
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cli-agent-hooks-'));
|
|
408
|
-
initRepo(tmpDir);
|
|
409
|
-
enableSessionlog(tmpDir);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
afterEach(() => {
|
|
413
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it('should handle `hooks claude-code session-start` via CLI', () => {
|
|
417
|
-
const result = runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
418
|
-
cwd: tmpDir,
|
|
419
|
-
stdin: JSON.stringify({ session_id: 'cli-test-1', transcript_path: '/tmp/t.jsonl' }),
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
expect(result.exitCode).toBe(0);
|
|
423
|
-
|
|
424
|
-
// Verify session was created
|
|
425
|
-
const sessionFile = path.join(tmpDir, '.git', 'sessionlog-sessions', 'cli-test-1.json');
|
|
426
|
-
expect(fs.existsSync(sessionFile)).toBe(true);
|
|
427
|
-
|
|
428
|
-
const session = JSON.parse(fs.readFileSync(sessionFile, 'utf-8'));
|
|
429
|
-
expect(session.sessionID).toBe('cli-test-1');
|
|
430
|
-
expect(session.phase).toBe('idle');
|
|
431
|
-
expect(session.agentType).toBe('Claude Code');
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
it('should handle `hooks claude-code user-prompt-submit` via CLI', () => {
|
|
435
|
-
// First create the session
|
|
436
|
-
runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
437
|
-
cwd: tmpDir,
|
|
438
|
-
stdin: JSON.stringify({ session_id: 'cli-test-2', transcript_path: '/tmp/t.jsonl' }),
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
// Then send a prompt
|
|
442
|
-
const result = runCLI(['hooks', 'claude-code', 'user-prompt-submit'], {
|
|
443
|
-
cwd: tmpDir,
|
|
444
|
-
stdin: JSON.stringify({
|
|
445
|
-
session_id: 'cli-test-2',
|
|
446
|
-
transcript_path: '/tmp/t.jsonl',
|
|
447
|
-
prompt: 'implement feature X',
|
|
448
|
-
}),
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
expect(result.exitCode).toBe(0);
|
|
452
|
-
|
|
453
|
-
const sessionFile = path.join(tmpDir, '.git', 'sessionlog-sessions', 'cli-test-2.json');
|
|
454
|
-
const session = JSON.parse(fs.readFileSync(sessionFile, 'utf-8'));
|
|
455
|
-
expect(session.phase).toBe('active');
|
|
456
|
-
expect(session.firstPrompt).toBe('implement feature X');
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it('should handle `hooks claude-code session-end` via CLI', () => {
|
|
460
|
-
// Create and end session
|
|
461
|
-
runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
462
|
-
cwd: tmpDir,
|
|
463
|
-
stdin: JSON.stringify({ session_id: 'cli-test-3', transcript_path: '/tmp/t.jsonl' }),
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
const result = runCLI(['hooks', 'claude-code', 'session-end'], {
|
|
467
|
-
cwd: tmpDir,
|
|
468
|
-
stdin: JSON.stringify({ session_id: 'cli-test-3', transcript_path: '/tmp/t.jsonl' }),
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
expect(result.exitCode).toBe(0);
|
|
472
|
-
|
|
473
|
-
const sessionFile = path.join(tmpDir, '.git', 'sessionlog-sessions', 'cli-test-3.json');
|
|
474
|
-
const session = JSON.parse(fs.readFileSync(sessionFile, 'utf-8'));
|
|
475
|
-
expect(session.phase).toBe('ended');
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
it('should exit 0 silently with no stdin', () => {
|
|
479
|
-
const result = runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
480
|
-
cwd: tmpDir,
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
expect(result.exitCode).toBe(0);
|
|
484
|
-
expect(result.stderr).toBe('');
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it('should exit 0 silently with empty stdin', () => {
|
|
488
|
-
const result = runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
489
|
-
cwd: tmpDir,
|
|
490
|
-
stdin: '',
|
|
491
|
-
});
|
|
492
|
-
|
|
493
|
-
expect(result.exitCode).toBe(0);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it('should exit 0 silently with invalid JSON stdin', () => {
|
|
497
|
-
const result = runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
498
|
-
cwd: tmpDir,
|
|
499
|
-
stdin: 'not json at all',
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
expect(result.exitCode).toBe(0);
|
|
503
|
-
expect(result.stderr).toBe('');
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
it('should exit 1 for unknown agent name', () => {
|
|
507
|
-
const result = runCLI(['hooks', 'nonexistent-agent', 'session-start'], {
|
|
508
|
-
cwd: tmpDir,
|
|
509
|
-
stdin: JSON.stringify({ session_id: 'test' }),
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
expect(result.exitCode).toBe(1);
|
|
513
|
-
expect(result.stderr).toContain('Unknown hooks subcommand');
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
it('should exit 0 silently when sessionlog is disabled', () => {
|
|
517
|
-
// Overwrite settings to disable
|
|
518
|
-
const settingsPath = path.join(tmpDir, '.sessionlog', 'settings.json');
|
|
519
|
-
fs.writeFileSync(settingsPath, JSON.stringify({ enabled: false }));
|
|
520
|
-
|
|
521
|
-
const result = runCLI(['hooks', 'claude-code', 'session-start'], {
|
|
522
|
-
cwd: tmpDir,
|
|
523
|
-
stdin: JSON.stringify({ session_id: 'disabled-test', transcript_path: '/tmp/t.jsonl' }),
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
expect(result.exitCode).toBe(0);
|
|
527
|
-
|
|
528
|
-
// Session should NOT be created
|
|
529
|
-
const sessionFile = path.join(tmpDir, '.git', 'sessionlog-sessions', 'disabled-test.json');
|
|
530
|
-
expect(fs.existsSync(sessionFile)).toBe(false);
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
it('should handle full session lifecycle via CLI', () => {
|
|
534
|
-
const sid = 'lifecycle-test';
|
|
535
|
-
const stdin = (extra: Record<string, unknown> = {}) =>
|
|
536
|
-
JSON.stringify({ session_id: sid, transcript_path: '/tmp/t.jsonl', ...extra });
|
|
537
|
-
|
|
538
|
-
// 1. Session start
|
|
539
|
-
runCLI(['hooks', 'claude-code', 'session-start'], { cwd: tmpDir, stdin: stdin() });
|
|
540
|
-
|
|
541
|
-
// 2. User prompt
|
|
542
|
-
runCLI(['hooks', 'claude-code', 'user-prompt-submit'], {
|
|
543
|
-
cwd: tmpDir,
|
|
544
|
-
stdin: stdin({ prompt: 'build a REST API' }),
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
// 3. Agent stop (turn end)
|
|
548
|
-
runCLI(['hooks', 'claude-code', 'stop'], { cwd: tmpDir, stdin: stdin() });
|
|
549
|
-
|
|
550
|
-
// 4. Another prompt
|
|
551
|
-
runCLI(['hooks', 'claude-code', 'user-prompt-submit'], {
|
|
552
|
-
cwd: tmpDir,
|
|
553
|
-
stdin: stdin({ prompt: 'add tests' }),
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
// 5. Agent stop again
|
|
557
|
-
runCLI(['hooks', 'claude-code', 'stop'], { cwd: tmpDir, stdin: stdin() });
|
|
558
|
-
|
|
559
|
-
// 6. Session end
|
|
560
|
-
runCLI(['hooks', 'claude-code', 'session-end'], { cwd: tmpDir, stdin: stdin() });
|
|
561
|
-
|
|
562
|
-
const sessionFile = path.join(tmpDir, '.git', 'sessionlog-sessions', `${sid}.json`);
|
|
563
|
-
const session = JSON.parse(fs.readFileSync(sessionFile, 'utf-8'));
|
|
564
|
-
|
|
565
|
-
expect(session.phase).toBe('ended');
|
|
566
|
-
expect(session.endedAt).toBeDefined();
|
|
567
|
-
// First prompt should be preserved (not overwritten by second)
|
|
568
|
-
expect(session.firstPrompt).toBe('build a REST API');
|
|
569
|
-
});
|
|
570
|
-
});
|