@cleocode/core 2026.3.76 → 2026.4.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/dist/agents/agent-schema.d.ts.map +1 -1
- package/dist/audit.d.ts +1 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +2 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/caamp/adapter.d.ts +6 -49
- package/dist/caamp/adapter.d.ts.map +1 -1
- package/dist/caamp/index.d.ts +2 -2
- package/dist/caamp/index.d.ts.map +1 -1
- package/dist/code/index.d.ts +10 -0
- package/dist/code/index.d.ts.map +1 -0
- package/dist/code/outline.d.ts +51 -0
- package/dist/code/outline.d.ts.map +1 -0
- package/dist/code/parser.d.ts +32 -0
- package/dist/code/parser.d.ts.map +1 -0
- package/dist/code/search.d.ts +42 -0
- package/dist/code/search.d.ts.map +1 -0
- package/dist/code/unfold.d.ts +44 -0
- package/dist/code/unfold.d.ts.map +1 -0
- package/dist/compliance/protocol-enforcement.d.ts +1 -1
- package/dist/compliance/protocol-rules.d.ts +1 -1
- package/dist/compliance/protocol-types.d.ts +2 -3
- package/dist/compliance/protocol-types.d.ts.map +1 -1
- package/dist/conduit/conduit-client.d.ts +14 -0
- package/dist/conduit/conduit-client.d.ts.map +1 -1
- package/dist/conduit/factory.d.ts +11 -1
- package/dist/conduit/factory.d.ts.map +1 -1
- package/dist/conduit/http-transport.d.ts +17 -5
- package/dist/conduit/http-transport.d.ts.map +1 -1
- package/dist/conduit/index.d.ts +5 -2
- package/dist/conduit/index.d.ts.map +1 -1
- package/dist/conduit/local-transport.d.ts +91 -0
- package/dist/conduit/local-transport.d.ts.map +1 -0
- package/dist/conduit/sse-transport.d.ts +68 -0
- package/dist/conduit/sse-transport.d.ts.map +1 -0
- package/dist/crypto/credentials.d.ts.map +1 -1
- package/dist/error-catalog.d.ts +3 -3
- package/dist/error-catalog.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/hooks/handlers/index.d.ts +2 -2
- package/dist/hooks/handlers/index.d.ts.map +1 -1
- package/dist/hooks/handlers/notification-hooks.d.ts +31 -0
- package/dist/hooks/handlers/notification-hooks.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4646 -3476
- package/dist/index.js.map +4 -4
- package/dist/init.d.ts +6 -6
- package/dist/init.d.ts.map +1 -1
- package/dist/injection.d.ts.map +1 -1
- package/dist/internal.d.ts +7 -5
- package/dist/internal.d.ts.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/tree-sitter-languages.d.ts +29 -0
- package/dist/lib/tree-sitter-languages.d.ts.map +1 -0
- package/dist/logger.d.ts +3 -3
- package/dist/memory/brain-links.d.ts.map +1 -1
- package/dist/memory/brain-maintenance.d.ts +13 -0
- package/dist/memory/brain-maintenance.d.ts.map +1 -1
- package/dist/memory/brain-retrieval.d.ts +1 -1
- package/dist/memory/brain-retrieval.d.ts.map +1 -1
- package/dist/memory/decisions.d.ts.map +1 -1
- package/dist/memory/engine-compat.d.ts +392 -25
- package/dist/memory/engine-compat.d.ts.map +1 -1
- package/dist/memory/index.d.ts +416 -3
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/metrics/token-service.d.ts +3 -3
- package/dist/metrics/token-service.d.ts.map +1 -1
- package/dist/orchestration/hierarchy.d.ts +32 -0
- package/dist/orchestration/hierarchy.d.ts.map +1 -0
- package/dist/orchestration/index.d.ts +1 -0
- package/dist/orchestration/index.d.ts.map +1 -1
- package/dist/paths.d.ts +335 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/routing/capability-matrix.d.ts +3 -3
- package/dist/routing/capability-matrix.d.ts.map +1 -1
- package/dist/scaffold.d.ts +422 -11
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/security/input-sanitization.d.ts +2 -2
- package/dist/skills/dynamic-skill-generator.d.ts +3 -2
- package/dist/skills/dynamic-skill-generator.d.ts.map +1 -1
- package/dist/skills/routing-table.d.ts +4 -4
- package/dist/skills/routing-table.d.ts.map +1 -1
- package/dist/store/agent-registry-accessor.d.ts +10 -433
- package/dist/store/agent-registry-accessor.d.ts.map +1 -1
- package/dist/store/cross-db-cleanup.d.ts +34 -0
- package/dist/store/cross-db-cleanup.d.ts.map +1 -1
- package/dist/store/provider.d.ts +1 -1
- package/dist/store/signaldock-sqlite.d.ts.map +1 -1
- package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
- package/dist/store/sqlite.d.ts +1 -1
- package/dist/store/task-store.d.ts.map +1 -1
- package/dist/store/tasks-schema.d.ts +4 -228
- package/dist/store/tasks-schema.d.ts.map +1 -1
- package/dist/store/validation-schemas.d.ts +4 -5
- package/dist/store/validation-schemas.d.ts.map +1 -1
- package/dist/system/archive-analytics.d.ts +1 -1
- package/dist/system/health.d.ts +2 -2
- package/dist/system/health.d.ts.map +1 -1
- package/dist/system/runtime.d.ts +2 -1
- package/dist/system/runtime.d.ts.map +1 -1
- package/dist/tasks/list.d.ts +1 -1
- package/dist/tasks/list.d.ts.map +1 -1
- package/dist/tasks/task-ops.d.ts +415 -3
- package/dist/tasks/task-ops.d.ts.map +1 -1
- package/dist/templates/parser.d.ts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/upgrade.d.ts +1 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/validation/operation-gate-validators.d.ts +1 -1
- package/dist/validation/operation-verification-gates.d.ts +3 -3
- package/dist/validation/param-utils.d.ts +6 -5
- package/dist/validation/param-utils.d.ts.map +1 -1
- package/dist/validation/validate-ops.d.ts +1 -1
- package/dist/validation/validate-ops.d.ts.map +1 -1
- package/package.json +19 -7
- package/src/__tests__/caamp-skill-install.test.js +0 -15
- package/src/__tests__/caamp-skill-install.test.js.map +1 -1
- package/src/__tests__/caamp-skill-install.test.ts +0 -16
- package/src/__tests__/injection-mvi-tiers.test.js +7 -7
- package/src/__tests__/injection-mvi-tiers.test.js.map +1 -1
- package/src/__tests__/injection-mvi-tiers.test.ts +55 -103
- package/src/agents/agent-schema.ts +2 -5
- package/src/audit.ts +2 -2
- package/src/bootstrap.ts +5 -39
- package/src/caamp/adapter.ts +3 -219
- package/src/caamp/index.ts +1 -13
- package/src/cant/__tests__/cant-agent-parse.test.d.ts.map +1 -0
- package/src/cant/__tests__/cant-agent-parse.test.js +77 -0
- package/src/cant/__tests__/cant-agent-parse.test.js.map +1 -0
- package/src/code/index.ts +10 -0
- package/src/code/outline.ts +214 -0
- package/src/code/parser.ts +331 -0
- package/src/code/search.ts +173 -0
- package/src/code/unfold.ts +204 -0
- package/src/codebase-map/analyzers/architecture.ts +2 -2
- package/src/compliance/protocol-enforcement.ts +1 -1
- package/src/compliance/protocol-rules.ts +1 -1
- package/src/compliance/protocol-types.ts +2 -3
- package/src/conduit/__tests__/dual-api-e2e.test.d.ts.map +1 -0
- package/src/conduit/__tests__/dual-api-e2e.test.js +178 -0
- package/src/conduit/__tests__/dual-api-e2e.test.js.map +1 -0
- package/src/conduit/__tests__/dual-api-e2e.test.ts +212 -0
- package/src/conduit/__tests__/local-credential-flow.test.d.ts.map +1 -0
- package/src/conduit/__tests__/local-credential-flow.test.js +185 -0
- package/src/conduit/__tests__/local-credential-flow.test.js.map +1 -0
- package/src/conduit/__tests__/local-credential-flow.test.ts +230 -0
- package/src/conduit/__tests__/local-transport.test.d.ts.map +1 -0
- package/src/conduit/__tests__/local-transport.test.js +404 -0
- package/src/conduit/__tests__/local-transport.test.js.map +1 -0
- package/src/conduit/__tests__/local-transport.test.ts +509 -0
- package/src/conduit/__tests__/sse-transport.test.d.ts.map +1 -0
- package/src/conduit/__tests__/sse-transport.test.js +291 -0
- package/src/conduit/__tests__/sse-transport.test.js.map +1 -0
- package/src/conduit/__tests__/sse-transport.test.ts +344 -0
- package/src/conduit/conduit-client.ts +14 -0
- package/src/conduit/factory.ts +29 -8
- package/src/conduit/http-transport.ts +78 -16
- package/src/conduit/index.ts +5 -2
- package/src/conduit/local-transport.ts +309 -0
- package/src/conduit/sse-transport.ts +382 -0
- package/src/crypto/credentials.ts +59 -13
- package/src/error-catalog.ts +3 -3
- package/src/errors.ts +1 -1
- package/src/hooks/__tests__/provider-hooks.test.js +4 -4
- package/src/hooks/__tests__/provider-hooks.test.js.map +1 -1
- package/src/hooks/__tests__/provider-hooks.test.ts +4 -4
- package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js +2 -2
- package/src/hooks/handlers/__tests__/hook-automation-e2e.test.js.map +1 -1
- package/src/hooks/handlers/__tests__/hook-automation-e2e.test.ts +6 -4
- package/src/hooks/handlers/index.ts +2 -6
- package/src/hooks/handlers/notification-hooks.ts +65 -0
- package/src/index.ts +2 -1
- package/src/init.ts +14 -54
- package/src/injection.ts +4 -3
- package/src/internal.ts +7 -5
- package/src/lib/index.ts +8 -0
- package/src/lib/tree-sitter-languages.ts +88 -0
- package/src/logger.ts +5 -5
- package/src/memory/__tests__/brain-links.test.js +13 -0
- package/src/memory/__tests__/brain-links.test.js.map +1 -1
- package/src/memory/__tests__/brain-links.test.ts +14 -0
- package/src/memory/__tests__/brain-retrieval.test.js +9 -0
- package/src/memory/__tests__/brain-retrieval.test.js.map +1 -1
- package/src/memory/__tests__/brain-retrieval.test.ts +10 -0
- package/src/memory/__tests__/session-memory.test.js +16 -0
- package/src/memory/__tests__/session-memory.test.js.map +1 -1
- package/src/memory/__tests__/session-memory.test.ts +17 -0
- package/src/memory/brain-links.ts +17 -0
- package/src/memory/brain-maintenance.ts +33 -1
- package/src/memory/brain-retrieval.ts +19 -3
- package/src/memory/decisions.ts +18 -2
- package/src/memory/engine-compat.ts +392 -25
- package/src/memory/index.ts +417 -4
- package/src/metrics/token-service.ts +4 -4
- package/src/migration/index.ts +1 -1
- package/src/orchestration/hierarchy.ts +202 -0
- package/src/orchestration/index.ts +1 -0
- package/src/paths.ts +340 -5
- package/src/routing/capability-matrix.ts +49 -49
- package/src/scaffold.ts +428 -70
- package/src/security/input-sanitization.ts +4 -4
- package/src/sessions/__tests__/session-grade.integration.test.js +9 -9
- package/src/sessions/__tests__/session-grade.integration.test.ts +9 -9
- package/src/sessions/__tests__/session-grade.test.js +10 -10
- package/src/sessions/__tests__/session-grade.test.js.map +1 -1
- package/src/sessions/__tests__/session-grade.test.ts +10 -10
- package/src/sessions/session-grade.ts +4 -4
- package/src/skills/__tests__/dynamic-skill-generator.test.js +24 -26
- package/src/skills/__tests__/dynamic-skill-generator.test.js.map +1 -1
- package/src/skills/__tests__/dynamic-skill-generator.test.ts +24 -26
- package/src/skills/__tests__/routing-table.test.js +22 -22
- package/src/skills/__tests__/routing-table.test.js.map +1 -1
- package/src/skills/__tests__/routing-table.test.ts +23 -23
- package/src/skills/dynamic-skill-generator.ts +13 -24
- package/src/skills/routing-table.ts +4 -4
- package/src/store/__tests__/data-safety-central.test.js +8 -0
- package/src/store/__tests__/data-safety-central.test.js.map +1 -1
- package/src/store/__tests__/data-safety-central.test.ts +8 -0
- package/src/store/__tests__/safety-accessor.test.js +8 -0
- package/src/store/__tests__/safety-accessor.test.js.map +1 -1
- package/src/store/__tests__/safety-accessor.test.ts +8 -0
- package/src/store/agent-registry-accessor.ts +284 -108
- package/src/store/cross-db-cleanup.ts +175 -1
- package/src/store/provider.ts +2 -2
- package/src/store/signaldock-sqlite.ts +262 -60
- package/src/store/sqlite-data-accessor.ts +3 -0
- package/src/store/sqlite.ts +2 -2
- package/src/store/task-store.ts +8 -1
- package/src/store/tasks-schema.ts +5 -40
- package/src/system/__tests__/health.test.js +2 -2
- package/src/system/__tests__/health.test.js.map +1 -1
- package/src/system/__tests__/health.test.ts +2 -2
- package/src/system/archive-analytics.ts +1 -1
- package/src/system/health.ts +43 -19
- package/src/system/inject-generate.ts +20 -20
- package/src/system/runtime.ts +5 -4
- package/src/tasks/atomicity.ts +1 -1
- package/src/tasks/list.ts +1 -1
- package/src/tasks/task-ops.ts +415 -3
- package/src/templates/parser.ts +1 -1
- package/src/ui/index.ts +4 -4
- package/src/upgrade.ts +3 -14
- package/src/validation/operation-gate-validators.ts +1 -1
- package/src/validation/operation-verification-gates.ts +3 -3
- package/src/validation/param-utils.ts +11 -10
- package/src/validation/validate-ops.ts +6 -6
- package/templates/CLEO-INJECTION.md +38 -110
- package/dist/hooks/handlers/mcp-hooks.d.ts +0 -48
- package/dist/hooks/handlers/mcp-hooks.d.ts.map +0 -1
- package/dist/mcp/index.d.ts +0 -42
- package/dist/mcp/index.d.ts.map +0 -1
- package/src/__tests__/audit-prune.test.d.ts +0 -2
- package/src/__tests__/caamp-skill-install.test.d.ts +0 -14
- package/src/__tests__/cli-mcp-parity.integration.test.d.ts +0 -34
- package/src/__tests__/cli-mcp-parity.integration.test.d.ts.map +0 -1
- package/src/__tests__/cli-mcp-parity.integration.test.js +0 -898
- package/src/__tests__/cli-mcp-parity.integration.test.js.map +0 -1
- package/src/__tests__/cli-parity.test.d.ts +0 -9
- package/src/__tests__/config.test.d.ts +0 -7
- package/src/__tests__/core-parity.test.d.ts +0 -17
- package/src/__tests__/error-catalog.test.d.ts +0 -2
- package/src/__tests__/golden-parity.test.d.ts +0 -12
- package/src/__tests__/hooks.test.d.ts +0 -5
- package/src/__tests__/human-output.test.d.ts +0 -12
- package/src/__tests__/index-api-compat.test.d.ts +0 -2
- package/src/__tests__/init-e2e.test.d.ts +0 -12
- package/src/__tests__/injection-chain.test.d.ts +0 -18
- package/src/__tests__/injection-mvi-tiers.test.d.ts +0 -14
- package/src/__tests__/injection-shared.test.d.ts +0 -10
- package/src/__tests__/lafs-conformance.test.d.ts +0 -18
- package/src/__tests__/logger.test.d.ts +0 -2
- package/src/__tests__/mcp-install-verify.test.d.ts +0 -13
- package/src/__tests__/mcp-install-verify.test.d.ts.map +0 -1
- package/src/__tests__/mcp-install-verify.test.js +0 -177
- package/src/__tests__/mcp-install-verify.test.js.map +0 -1
- package/src/__tests__/mcp-install-verify.test.ts +0 -217
- package/src/__tests__/paths.test.d.ts +0 -7
- package/src/__tests__/project-info.test.d.ts +0 -2
- package/src/__tests__/rcsd-pipeline-e2e.test.d.ts +0 -14
- package/src/__tests__/remote.test.d.ts +0 -6
- package/src/__tests__/scaffold.test.d.ts +0 -6
- package/src/__tests__/schema-management.test.d.ts +0 -5
- package/src/__tests__/schema.test.d.ts +0 -2
- package/src/__tests__/sharing.test.d.ts +0 -6
- package/src/__tests__/snapshot.test.d.ts +0 -6
- package/src/__tests__/upgrade.test.d.ts +0 -7
- package/src/adapters/__tests__/discovery.test.d.ts +0 -6
- package/src/adapters/__tests__/manager.test.d.ts +0 -6
- package/src/agents/__tests__/agent-registry.test.d.ts +0 -12
- package/src/agents/__tests__/capacity.test.d.ts +0 -7
- package/src/agents/__tests__/execution-learning.test.d.ts +0 -14
- package/src/agents/__tests__/health-monitor.test.d.ts +0 -10
- package/src/agents/__tests__/registry.test.d.ts +0 -8
- package/src/agents/__tests__/retry.test.d.ts +0 -7
- package/src/compliance/__tests__/sync.test.d.ts +0 -5
- package/src/hooks/__tests__/provider-hooks.test.d.ts +0 -2
- package/src/hooks/__tests__/registry.test.d.ts +0 -2
- package/src/hooks/handlers/__tests__/error-hooks.test.d.ts +0 -2
- package/src/hooks/handlers/__tests__/file-hooks.test.d.ts +0 -2
- package/src/hooks/handlers/__tests__/hook-automation-e2e.test.d.ts +0 -13
- package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts +0 -2
- package/src/hooks/handlers/__tests__/mcp-hooks.test.d.ts.map +0 -1
- package/src/hooks/handlers/__tests__/mcp-hooks.test.js +0 -119
- package/src/hooks/handlers/__tests__/mcp-hooks.test.js.map +0 -1
- package/src/hooks/handlers/__tests__/mcp-hooks.test.ts +0 -150
- package/src/hooks/handlers/__tests__/session-hooks.test.d.ts +0 -2
- package/src/hooks/handlers/__tests__/task-hooks.test.d.ts +0 -2
- package/src/hooks/handlers/mcp-hooks.ts +0 -162
- package/src/intelligence/__tests__/adaptive-validation.test.d.ts +0 -11
- package/src/intelligence/__tests__/impact.test.d.ts +0 -16
- package/src/intelligence/__tests__/patterns.test.d.ts +0 -8
- package/src/intelligence/__tests__/prediction.test.d.ts +0 -8
- package/src/lib/__tests__/retry.test.d.ts +0 -7
- package/src/lifecycle/__tests__/chain-store.test.d.ts +0 -10
- package/src/lifecycle/__tests__/consolidate-rcasd.test.d.ts +0 -7
- package/src/lifecycle/__tests__/default-chain.test.d.ts +0 -7
- package/src/lifecycle/__tests__/frontmatter.test.d.ts +0 -7
- package/src/lifecycle/__tests__/lifecycle.test.d.ts +0 -7
- package/src/lifecycle/__tests__/pipeline.integration.test.d.ts +0 -19
- package/src/lifecycle/__tests__/rcasd-paths.test.d.ts +0 -7
- package/src/lifecycle/__tests__/resume-schema-contract.test.d.ts +0 -16
- package/src/lifecycle/__tests__/stage-record-provenance.integration.test.d.ts +0 -7
- package/src/lifecycle/__tests__/tessera-engine.test.d.ts +0 -10
- package/src/mcp/index.ts +0 -163
- package/src/memory/__tests__/auto-extract.test.d.ts +0 -7
- package/src/memory/__tests__/brain-automation.test.d.ts +0 -11
- package/src/memory/__tests__/brain-embedding.test.d.ts +0 -2
- package/src/memory/__tests__/brain-links.test.d.ts +0 -8
- package/src/memory/__tests__/brain-migration.test.d.ts +0 -8
- package/src/memory/__tests__/brain-retrieval.test.d.ts +0 -10
- package/src/memory/__tests__/brain-search.test.d.ts +0 -8
- package/src/memory/__tests__/claude-mem-migration.test.d.ts +0 -12
- package/src/memory/__tests__/decisions.test.d.ts +0 -8
- package/src/memory/__tests__/engine-compat.test.d.ts +0 -12
- package/src/memory/__tests__/memory-bridge.test.d.ts +0 -10
- package/src/memory/__tests__/pipeline-manifest-sqlite.test.d.ts +0 -13
- package/src/memory/__tests__/session-memory.test.d.ts +0 -9
- package/src/metrics/__tests__/model-provider-registry.test.d.ts +0 -2
- package/src/metrics/__tests__/provider-detection.test.d.ts +0 -2
- package/src/migration/__tests__/checksum.test.d.ts +0 -8
- package/src/migration/__tests__/logger.test.d.ts +0 -5
- package/src/migration/__tests__/migration-failure.integration.test.d.ts +0 -15
- package/src/migration/__tests__/migration.test.d.ts +0 -13
- package/src/migration/__tests__/state.test.d.ts +0 -8
- package/src/migration/__tests__/validate.test.d.ts +0 -8
- package/src/nexus/__tests__/deps.test.d.ts +0 -7
- package/src/nexus/__tests__/nexus-e2e.test.d.ts +0 -12
- package/src/nexus/__tests__/permissions.test.d.ts +0 -7
- package/src/nexus/__tests__/query.test.d.ts +0 -7
- package/src/nexus/__tests__/reconcile.test.d.ts +0 -7
- package/src/nexus/__tests__/registry.test.d.ts +0 -7
- package/src/nexus/__tests__/transfer.test.d.ts +0 -8
- package/src/observability/__tests__/index.test.d.ts +0 -7
- package/src/observability/__tests__/log-filter.test.d.ts +0 -7
- package/src/observability/__tests__/log-parser.test.d.ts +0 -7
- package/src/observability/__tests__/log-reader.test.d.ts +0 -7
- package/src/orchestration/__tests__/autonomous-spec.test.d.ts +0 -9
- package/src/orchestration/__tests__/orchestration.test.d.ts +0 -7
- package/src/orchestration/__tests__/protocol-validators.test.d.ts +0 -9
- package/src/phases/__tests__/deps.test.d.ts +0 -7
- package/src/phases/__tests__/phases.test.d.ts +0 -7
- package/src/release/__tests__/artifacts.test.d.ts +0 -7
- package/src/release/__tests__/cancel-release.test.d.ts +0 -10
- package/src/release/__tests__/changelog-writer.test.d.ts +0 -6
- package/src/release/__tests__/push-policy.test.d.ts +0 -14
- package/src/release/__tests__/release.test.d.ts +0 -11
- package/src/sequence/__tests__/allocate.test.d.ts +0 -6
- package/src/sessions/__tests__/briefing-blocked.test.d.ts +0 -6
- package/src/sessions/__tests__/briefing.test.d.ts +0 -11
- package/src/sessions/__tests__/handoff-integration.test.d.ts +0 -8
- package/src/sessions/__tests__/handoff.test.d.ts +0 -11
- package/src/sessions/__tests__/index.test.d.ts +0 -2
- package/src/sessions/__tests__/session-cleanup.test.d.ts +0 -7
- package/src/sessions/__tests__/session-edge-cases.test.d.ts +0 -9
- package/src/sessions/__tests__/session-find.test.d.ts +0 -9
- package/src/sessions/__tests__/session-grade.integration.test.d.ts +0 -11
- package/src/sessions/__tests__/session-grade.test.d.ts +0 -6
- package/src/sessions/__tests__/session-memory-bridge.test.d.ts +0 -2
- package/src/sessions/__tests__/sessions.test.d.ts +0 -7
- package/src/skills/__tests__/discovery.test.d.ts +0 -6
- package/src/skills/__tests__/dispatch.test.d.ts +0 -6
- package/src/skills/__tests__/dynamic-skill-generator.test.d.ts +0 -2
- package/src/skills/__tests__/manifests.test.d.ts +0 -6
- package/src/skills/__tests__/precedence.test.d.ts +0 -6
- package/src/skills/__tests__/routing-table.test.d.ts +0 -2
- package/src/skills/__tests__/skill-paths.test.d.ts +0 -7
- package/src/skills/__tests__/test-utility.test.d.ts +0 -7
- package/src/skills/__tests__/token.test.d.ts +0 -6
- package/src/skills/__tests__/validation.test.d.ts +0 -6
- package/src/skills/__tests__/version.test.d.ts +0 -5
- package/src/skills/injection/__tests__/subagent.test.d.ts +0 -2
- package/src/skills/orchestrator/__tests__/spawn-tier.test.d.ts +0 -2
- package/src/spawn/__tests__/adapter-registry.test.d.ts +0 -2
- package/src/stats/__tests__/stats.test.d.ts +0 -7
- package/src/sticky/__tests__/purge.test.d.ts +0 -9
- package/src/store/__tests__/atomic.test.d.ts +0 -7
- package/src/store/__tests__/backup.test.d.ts +0 -7
- package/src/store/__tests__/brain-accessor-pageindex.test.d.ts +0 -12
- package/src/store/__tests__/brain-accessor.test.d.ts +0 -10
- package/src/store/__tests__/brain-pageindex.test.d.ts +0 -11
- package/src/store/__tests__/brain-schema.test.d.ts +0 -11
- package/src/store/__tests__/brain-vec.test.d.ts +0 -11
- package/src/store/__tests__/collision-detection.test.d.ts +0 -11
- package/src/store/__tests__/data-safety-central.test.d.ts +0 -20
- package/src/store/__tests__/db-helpers.test.d.ts +0 -7
- package/src/store/__tests__/e2e-safety-integration.test.d.ts +0 -13
- package/src/store/__tests__/git-checkpoint.test.d.ts +0 -7
- package/src/store/__tests__/idempotent-migration.test.d.ts +0 -5
- package/src/store/__tests__/import-logging.test.d.ts +0 -7
- package/src/store/__tests__/import-sort.test.d.ts +0 -7
- package/src/store/__tests__/json.test.d.ts +0 -7
- package/src/store/__tests__/lifecycle-schema-parity.test.d.ts +0 -2
- package/src/store/__tests__/migration-integration.test.d.ts +0 -15
- package/src/store/__tests__/migration-retry.test.d.ts +0 -10
- package/src/store/__tests__/migration-safety.test.d.ts +0 -21
- package/src/store/__tests__/migration-sqlite.test.d.ts +0 -11
- package/src/store/__tests__/performance-safety.test.d.ts +0 -17
- package/src/store/__tests__/project-detect.test.d.ts +0 -6
- package/src/store/__tests__/project-registry.test.d.ts +0 -7
- package/src/store/__tests__/provider.test.d.ts +0 -9
- package/src/store/__tests__/relations.test.d.ts +0 -9
- package/src/store/__tests__/safety-accessor.test.d.ts +0 -18
- package/src/store/__tests__/sequence-validation.test.d.ts +0 -11
- package/src/store/__tests__/session-store.test.d.ts +0 -11
- package/src/store/__tests__/sqlite-backup.test.d.ts +0 -14
- package/src/store/__tests__/sqlite.test.d.ts +0 -11
- package/src/store/__tests__/task-store.test.d.ts +0 -11
- package/src/store/__tests__/test-db-helper.d.ts +0 -61
- package/src/store/__tests__/write-verification.test.d.ts +0 -11
- package/src/system/__tests__/cleanup.test.d.ts +0 -2
- package/src/system/__tests__/health.test.d.ts +0 -2
- package/src/task-work/__tests__/start-deps.test.d.ts +0 -6
- package/src/tasks/__tests__/add.test.d.ts +0 -7
- package/src/tasks/__tests__/archive.test.d.ts +0 -7
- package/src/tasks/__tests__/assignee.test.d.ts +0 -14
- package/src/tasks/__tests__/atomicity.test.d.ts +0 -6
- package/src/tasks/__tests__/cancel-ops.test.d.ts +0 -7
- package/src/tasks/__tests__/complete-unblocks.test.d.ts +0 -6
- package/src/tasks/__tests__/complete.test.d.ts +0 -7
- package/src/tasks/__tests__/delete.test.d.ts +0 -7
- package/src/tasks/__tests__/dependency-check.test.d.ts +0 -7
- package/src/tasks/__tests__/deps-ready.test.d.ts +0 -6
- package/src/tasks/__tests__/epic-enforcement.test.d.ts +0 -15
- package/src/tasks/__tests__/find.test.d.ts +0 -7
- package/src/tasks/__tests__/graph-ops.test.d.ts +0 -7
- package/src/tasks/__tests__/hierarchy-policy.test.d.ts +0 -6
- package/src/tasks/__tests__/hierarchy.test.d.ts +0 -7
- package/src/tasks/__tests__/id-generator.test.d.ts +0 -2
- package/src/tasks/__tests__/labels.test.d.ts +0 -7
- package/src/tasks/__tests__/list.test.d.ts +0 -7
- package/src/tasks/__tests__/minimal-test.test.d.ts +0 -2
- package/src/tasks/__tests__/phase-tracking.test.d.ts +0 -7
- package/src/tasks/__tests__/pipeline-stage.test.d.ts +0 -14
- package/src/tasks/__tests__/plan-priority.test.d.ts +0 -10
- package/src/tasks/__tests__/priority-normalization.test.d.ts +0 -7
- package/src/tasks/__tests__/relates.test.d.ts +0 -9
- package/src/tasks/__tests__/show-deps.test.d.ts +0 -6
- package/src/tasks/__tests__/show.test.d.ts +0 -7
- package/src/tasks/__tests__/staleness.test.d.ts +0 -7
- package/src/tasks/__tests__/task-ops-depends.test.d.ts +0 -6
- package/src/tasks/__tests__/update.test.d.ts +0 -7
- package/src/validation/__tests__/chain-validation.test.d.ts +0 -7
- package/src/validation/__tests__/compliance.test.d.ts +0 -7
- package/src/validation/__tests__/docs-sync.test.d.ts +0 -7
- package/src/validation/__tests__/doctor-gitignore.test.d.ts +0 -7
- package/src/validation/__tests__/doctor-injection.test.d.ts +0 -11
- package/src/validation/__tests__/doctor.test.d.ts +0 -7
- package/src/validation/__tests__/engine.test.d.ts +0 -7
- package/src/validation/__tests__/manifest.test.d.ts +0 -7
- package/src/validation/__tests__/protocol-common.test.d.ts +0 -7
- package/src/validation/__tests__/verification.test.d.ts +0 -7
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* smart_outline — file structural skeleton via tree-sitter.
|
|
3
|
+
*
|
|
4
|
+
* Parses a source file and returns all top-level and nested symbols
|
|
5
|
+
* with signatures only (bodies collapsed). This gives agents a ~1-2K
|
|
6
|
+
* token overview of a file vs ~12K for a full Read.
|
|
7
|
+
*
|
|
8
|
+
* @task T151
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { relative } from 'node:path';
|
|
13
|
+
import type { CodeSymbol } from '@cleocode/contracts';
|
|
14
|
+
import { detectLanguage } from '../lib/tree-sitter-languages.js';
|
|
15
|
+
import { parseFile } from './parser.js';
|
|
16
|
+
|
|
17
|
+
/** A symbol node in the outline tree, with optional children. */
|
|
18
|
+
export interface OutlineNode {
|
|
19
|
+
/** Symbol name. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Symbol kind (function, class, method, etc.). */
|
|
22
|
+
kind: string;
|
|
23
|
+
/** Start line (1-based). */
|
|
24
|
+
startLine: number;
|
|
25
|
+
/** End line (1-based). */
|
|
26
|
+
endLine: number;
|
|
27
|
+
/** Signature line(s) — the declaration without the body. */
|
|
28
|
+
signature: string;
|
|
29
|
+
/** Whether this symbol is exported. */
|
|
30
|
+
exported: boolean;
|
|
31
|
+
/** Nested symbols (methods inside classes, etc.). */
|
|
32
|
+
children: OutlineNode[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Result of generating a smart outline for a file. */
|
|
36
|
+
export interface SmartOutlineResult {
|
|
37
|
+
/** Source file path (relative). */
|
|
38
|
+
filePath: string;
|
|
39
|
+
/** Detected language. */
|
|
40
|
+
language: string;
|
|
41
|
+
/** Top-level symbol tree. */
|
|
42
|
+
symbols: OutlineNode[];
|
|
43
|
+
/** Estimated token count for this outline. */
|
|
44
|
+
estimatedTokens: number;
|
|
45
|
+
/** Parse errors (non-fatal). */
|
|
46
|
+
errors: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Extract the signature line(s) from source for a symbol.
|
|
51
|
+
*
|
|
52
|
+
* Reads the opening lines of the symbol declaration up to the first
|
|
53
|
+
* opening brace or colon (for Python). This gives context without
|
|
54
|
+
* the full implementation body.
|
|
55
|
+
*/
|
|
56
|
+
function extractSignature(
|
|
57
|
+
lines: string[],
|
|
58
|
+
startLine: number,
|
|
59
|
+
endLine: number,
|
|
60
|
+
language: string,
|
|
61
|
+
): string {
|
|
62
|
+
const start = Math.max(0, startLine - 1); // 1-based to 0-based
|
|
63
|
+
const end = Math.min(lines.length, endLine);
|
|
64
|
+
|
|
65
|
+
// For short symbols (< 3 lines), return the whole thing
|
|
66
|
+
if (end - start <= 3) {
|
|
67
|
+
return lines.slice(start, end).join('\n');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Find the signature boundary (opening brace, colon for Python)
|
|
71
|
+
const sigLines: string[] = [];
|
|
72
|
+
for (let i = start; i < end && sigLines.length < 5; i++) {
|
|
73
|
+
const line = lines[i]!;
|
|
74
|
+
sigLines.push(line);
|
|
75
|
+
|
|
76
|
+
if (language === 'python') {
|
|
77
|
+
if (line.trimEnd().endsWith(':')) break;
|
|
78
|
+
} else {
|
|
79
|
+
if (line.includes('{')) break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const bodyLines = end - start - sigLines.length;
|
|
84
|
+
if (bodyLines > 0) {
|
|
85
|
+
sigLines.push(` // ... ${bodyLines} lines`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return sigLines.join('\n');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Build a tree from flat symbols by nesting methods inside their parent classes.
|
|
93
|
+
*/
|
|
94
|
+
function buildTree(symbols: CodeSymbol[], lines: string[], language: string): OutlineNode[] {
|
|
95
|
+
const nodes: OutlineNode[] = [];
|
|
96
|
+
const classNodes = new Map<string, OutlineNode>();
|
|
97
|
+
|
|
98
|
+
// First pass: create all nodes
|
|
99
|
+
for (const sym of symbols) {
|
|
100
|
+
const node: OutlineNode = {
|
|
101
|
+
name: sym.name,
|
|
102
|
+
kind: sym.kind,
|
|
103
|
+
startLine: sym.startLine,
|
|
104
|
+
endLine: sym.endLine,
|
|
105
|
+
signature: extractSignature(lines, sym.startLine, sym.endLine, language),
|
|
106
|
+
exported: sym.exported ?? false,
|
|
107
|
+
children: [],
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
sym.kind === 'class' ||
|
|
112
|
+
sym.kind === 'struct' ||
|
|
113
|
+
sym.kind === 'impl' ||
|
|
114
|
+
sym.kind === 'trait'
|
|
115
|
+
) {
|
|
116
|
+
classNodes.set(sym.name, node);
|
|
117
|
+
nodes.push(node);
|
|
118
|
+
} else if (sym.kind === 'method' && sym.parent) {
|
|
119
|
+
const parent = classNodes.get(sym.parent);
|
|
120
|
+
if (parent) {
|
|
121
|
+
parent.children.push(node);
|
|
122
|
+
} else {
|
|
123
|
+
nodes.push(node);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
// Check if this symbol is nested inside a class by line range
|
|
127
|
+
let nested = false;
|
|
128
|
+
for (const [, classNode] of classNodes) {
|
|
129
|
+
if (sym.startLine >= classNode.startLine && sym.endLine <= classNode.endLine) {
|
|
130
|
+
classNode.children.push(node);
|
|
131
|
+
nested = true;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!nested) nodes.push(node);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return nodes;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Estimate token count for an outline (rough: ~4 chars per token). */
|
|
143
|
+
function estimateTokens(nodes: OutlineNode[]): number {
|
|
144
|
+
let chars = 0;
|
|
145
|
+
for (const node of nodes) {
|
|
146
|
+
chars += node.signature.length + node.name.length + node.kind.length + 20; // overhead
|
|
147
|
+
chars += estimateTokens(node.children);
|
|
148
|
+
}
|
|
149
|
+
return Math.ceil(chars / 4);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generate a smart outline for a source file.
|
|
154
|
+
*
|
|
155
|
+
* Returns a tree of symbols with signatures only (bodies collapsed),
|
|
156
|
+
* suitable for giving agents a quick structural overview.
|
|
157
|
+
*
|
|
158
|
+
* @param filePath - Absolute path to source file
|
|
159
|
+
* @param projectRoot - Project root for relative path computation
|
|
160
|
+
* @returns Smart outline result with symbol tree and token estimate
|
|
161
|
+
*/
|
|
162
|
+
export function smartOutline(filePath: string, projectRoot?: string): SmartOutlineResult {
|
|
163
|
+
const root = projectRoot ?? process.cwd();
|
|
164
|
+
const relPath = relative(root, filePath);
|
|
165
|
+
const language = detectLanguage(filePath);
|
|
166
|
+
|
|
167
|
+
if (!language) {
|
|
168
|
+
return {
|
|
169
|
+
filePath: relPath,
|
|
170
|
+
language: 'unknown',
|
|
171
|
+
symbols: [],
|
|
172
|
+
estimatedTokens: 0,
|
|
173
|
+
errors: ['Unsupported language'],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Parse the file for symbols
|
|
178
|
+
const parseResult = parseFile(filePath, root);
|
|
179
|
+
if (parseResult.errors.length > 0 && parseResult.symbols.length === 0) {
|
|
180
|
+
return {
|
|
181
|
+
filePath: relPath,
|
|
182
|
+
language,
|
|
183
|
+
symbols: [],
|
|
184
|
+
estimatedTokens: 0,
|
|
185
|
+
errors: parseResult.errors,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Read source lines for signature extraction
|
|
190
|
+
let lines: string[];
|
|
191
|
+
try {
|
|
192
|
+
lines = readFileSync(filePath, 'utf-8').split('\n');
|
|
193
|
+
} catch (err) {
|
|
194
|
+
return {
|
|
195
|
+
filePath: relPath,
|
|
196
|
+
language,
|
|
197
|
+
symbols: [],
|
|
198
|
+
estimatedTokens: 0,
|
|
199
|
+
errors: [`Failed to read file: ${err instanceof Error ? err.message : String(err)}`],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Build symbol tree with signatures
|
|
204
|
+
const tree = buildTree(parseResult.symbols, lines, language);
|
|
205
|
+
const estimatedTokens = estimateTokens(tree);
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
filePath: relPath,
|
|
209
|
+
language,
|
|
210
|
+
symbols: tree,
|
|
211
|
+
estimatedTokens,
|
|
212
|
+
errors: parseResult.errors,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter AST parser — query execution engine for code analysis.
|
|
3
|
+
*
|
|
4
|
+
* Resolves grammar paths from node_modules, writes S-expression query
|
|
5
|
+
* patterns to temp files, executes tree-sitter CLI, and parses output
|
|
6
|
+
* into structured CodeSymbol objects.
|
|
7
|
+
*
|
|
8
|
+
* @task T149
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { execFileSync } from 'node:child_process';
|
|
12
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join, relative } from 'node:path';
|
|
15
|
+
import type {
|
|
16
|
+
BatchParseResult,
|
|
17
|
+
CodeSymbol,
|
|
18
|
+
CodeSymbolKind,
|
|
19
|
+
ParseResult,
|
|
20
|
+
} from '@cleocode/contracts';
|
|
21
|
+
import { detectLanguage, type TreeSitterLanguage } from '../lib/tree-sitter-languages.js';
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Tree-sitter CLI resolution
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/** Whether tree-sitter is available on this system. */
|
|
28
|
+
let _treeSitterAvailable: boolean | null = null;
|
|
29
|
+
|
|
30
|
+
/** Check if tree-sitter CLI is available and executable. Cached after first call. */
|
|
31
|
+
export function isTreeSitterAvailable(): boolean {
|
|
32
|
+
if (_treeSitterAvailable !== null) return _treeSitterAvailable;
|
|
33
|
+
try {
|
|
34
|
+
const bin = resolveTreeSitterBin();
|
|
35
|
+
// Verify the binary actually runs (broken symlinks pass existsSync)
|
|
36
|
+
execFileSync(bin, ['--version'], { timeout: 5000, stdio: 'pipe' });
|
|
37
|
+
_treeSitterAvailable = true;
|
|
38
|
+
} catch {
|
|
39
|
+
_treeSitterAvailable = false;
|
|
40
|
+
}
|
|
41
|
+
return _treeSitterAvailable;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Resolve the tree-sitter CLI binary from node_modules. */
|
|
45
|
+
function resolveTreeSitterBin(): string {
|
|
46
|
+
// Also check platform-specific binary extension for Windows
|
|
47
|
+
const ext = process.platform === 'win32' ? '.exe' : '';
|
|
48
|
+
const binName = `tree-sitter${ext}`;
|
|
49
|
+
const candidates = [
|
|
50
|
+
join(process.cwd(), 'packages', 'core', 'node_modules', '.bin', binName),
|
|
51
|
+
join(process.cwd(), 'node_modules', '.bin', binName),
|
|
52
|
+
// npm global install paths
|
|
53
|
+
join(process.cwd(), 'node_modules', 'tree-sitter-cli', binName),
|
|
54
|
+
];
|
|
55
|
+
// Also try without extension (npm .cmd shim on Windows)
|
|
56
|
+
if (ext) {
|
|
57
|
+
candidates.push(
|
|
58
|
+
join(process.cwd(), 'packages', 'core', 'node_modules', '.bin', 'tree-sitter'),
|
|
59
|
+
join(process.cwd(), 'node_modules', '.bin', 'tree-sitter'),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
for (const p of candidates) {
|
|
63
|
+
if (existsSync(p)) return p;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(
|
|
66
|
+
'tree-sitter CLI not found. Code analysis features (cleo code outline/search/unfold) ' +
|
|
67
|
+
'require tree-sitter. Install with: npm install tree-sitter-cli',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// S-expression query patterns per language family
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
/** Query patterns that match function/method/class/type declarations. */
|
|
76
|
+
const QUERY_PATTERNS: Record<string, string> = {
|
|
77
|
+
// TypeScript / JavaScript
|
|
78
|
+
typescript: `
|
|
79
|
+
(function_declaration name: (identifier) @name) @definition.function
|
|
80
|
+
(method_definition name: (property_identifier) @name) @definition.method
|
|
81
|
+
(class_declaration name: (type_identifier) @name) @definition.class
|
|
82
|
+
(interface_declaration name: (type_identifier) @name) @definition.interface
|
|
83
|
+
(type_alias_declaration name: (type_identifier) @name) @definition.type
|
|
84
|
+
(enum_declaration name: (identifier) @name) @definition.enum
|
|
85
|
+
(lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
|
|
86
|
+
(export_statement (function_declaration name: (identifier) @name)) @definition.function
|
|
87
|
+
(export_statement (class_declaration name: (type_identifier) @name)) @definition.class
|
|
88
|
+
(arrow_function) @definition.function
|
|
89
|
+
`,
|
|
90
|
+
javascript: `
|
|
91
|
+
(function_declaration name: (identifier) @name) @definition.function
|
|
92
|
+
(method_definition name: (property_identifier) @name) @definition.method
|
|
93
|
+
(class_declaration name: (identifier) @name) @definition.class
|
|
94
|
+
(lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
|
|
95
|
+
(export_statement (function_declaration name: (identifier) @name)) @definition.function
|
|
96
|
+
(export_statement (class_declaration name: (identifier) @name)) @definition.class
|
|
97
|
+
(arrow_function) @definition.function
|
|
98
|
+
`,
|
|
99
|
+
// Python
|
|
100
|
+
python: `
|
|
101
|
+
(function_definition name: (identifier) @name) @definition.function
|
|
102
|
+
(class_definition name: (identifier) @name) @definition.class
|
|
103
|
+
(decorated_definition (function_definition name: (identifier) @name)) @definition.function
|
|
104
|
+
(decorated_definition (class_definition name: (identifier) @name)) @definition.class
|
|
105
|
+
`,
|
|
106
|
+
// Go
|
|
107
|
+
go: `
|
|
108
|
+
(function_declaration name: (identifier) @name) @definition.function
|
|
109
|
+
(method_declaration name: (field_identifier) @name) @definition.method
|
|
110
|
+
(type_declaration (type_spec name: (type_identifier) @name)) @definition.type
|
|
111
|
+
`,
|
|
112
|
+
// Rust
|
|
113
|
+
rust: `
|
|
114
|
+
(function_item name: (identifier) @name) @definition.function
|
|
115
|
+
(impl_item type: (type_identifier) @name) @definition.impl
|
|
116
|
+
(struct_item name: (type_identifier) @name) @definition.struct
|
|
117
|
+
(enum_item name: (type_identifier) @name) @definition.enum
|
|
118
|
+
(trait_item name: (type_identifier) @name) @definition.trait
|
|
119
|
+
(type_item name: (type_identifier) @name) @definition.type
|
|
120
|
+
(mod_item name: (identifier) @name) @definition.module
|
|
121
|
+
`,
|
|
122
|
+
// Ruby
|
|
123
|
+
ruby: `
|
|
124
|
+
(method name: (identifier) @name) @definition.method
|
|
125
|
+
(class name: (constant) @name) @definition.class
|
|
126
|
+
(module name: (constant) @name) @definition.module
|
|
127
|
+
(singleton_method name: (identifier) @name) @definition.method
|
|
128
|
+
`,
|
|
129
|
+
// Java / C / C++
|
|
130
|
+
java: `
|
|
131
|
+
(method_declaration name: (identifier) @name) @definition.method
|
|
132
|
+
(class_declaration name: (identifier) @name) @definition.class
|
|
133
|
+
(interface_declaration name: (identifier) @name) @definition.interface
|
|
134
|
+
(enum_declaration name: (identifier) @name) @definition.enum
|
|
135
|
+
`,
|
|
136
|
+
c: `
|
|
137
|
+
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
|
|
138
|
+
(struct_specifier name: (type_identifier) @name) @definition.struct
|
|
139
|
+
(enum_specifier name: (type_identifier) @name) @definition.enum
|
|
140
|
+
(type_definition declarator: (type_identifier) @name) @definition.type
|
|
141
|
+
`,
|
|
142
|
+
cpp: `
|
|
143
|
+
(function_definition declarator: (function_declarator declarator: (qualified_identifier) @name)) @definition.function
|
|
144
|
+
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
|
|
145
|
+
(class_specifier name: (type_identifier) @name) @definition.class
|
|
146
|
+
(struct_specifier name: (type_identifier) @name) @definition.struct
|
|
147
|
+
(enum_specifier name: (type_identifier) @name) @definition.enum
|
|
148
|
+
(namespace_definition name: (identifier) @name) @definition.module
|
|
149
|
+
`,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** Map language to query pattern key. */
|
|
153
|
+
function queryKeyForLanguage(lang: TreeSitterLanguage): string {
|
|
154
|
+
if (lang === 'tsx') return 'typescript';
|
|
155
|
+
return lang;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Map capture name suffix to CodeSymbolKind. */
|
|
159
|
+
function captureToKind(capture: string): CodeSymbolKind {
|
|
160
|
+
const map: Record<string, CodeSymbolKind> = {
|
|
161
|
+
function: 'function',
|
|
162
|
+
method: 'method',
|
|
163
|
+
class: 'class',
|
|
164
|
+
interface: 'interface',
|
|
165
|
+
type: 'type',
|
|
166
|
+
enum: 'enum',
|
|
167
|
+
variable: 'variable',
|
|
168
|
+
constant: 'constant',
|
|
169
|
+
module: 'module',
|
|
170
|
+
import: 'import',
|
|
171
|
+
export: 'export',
|
|
172
|
+
struct: 'struct',
|
|
173
|
+
trait: 'trait',
|
|
174
|
+
impl: 'impl',
|
|
175
|
+
};
|
|
176
|
+
return map[capture] ?? 'function';
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// Output parsing
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Parse tree-sitter query output into CodeSymbol objects.
|
|
185
|
+
*
|
|
186
|
+
* tree-sitter query output format (one match per block):
|
|
187
|
+
* ```
|
|
188
|
+
* path/to/file.ts
|
|
189
|
+
* pattern: 0
|
|
190
|
+
* capture: 0 - name, start: (5, 9), end: (5, 20), text: `parseFile`
|
|
191
|
+
* capture: 1 - definition.function, start: (5, 0), end: (15, 1)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
function parseQueryOutput(output: string, filePath: string, language: string): CodeSymbol[] {
|
|
195
|
+
const symbols: CodeSymbol[] = [];
|
|
196
|
+
const lines = output.split('\n');
|
|
197
|
+
|
|
198
|
+
let currentName = '';
|
|
199
|
+
let currentKind: CodeSymbolKind = 'function';
|
|
200
|
+
let endLine = 0;
|
|
201
|
+
|
|
202
|
+
for (const line of lines) {
|
|
203
|
+
const nameMatch = line.match(
|
|
204
|
+
/capture: \d+ - name, start: \(\d+, \d+\), end: \(\d+, \d+\)(?:, text: `([^`]+)`)?/,
|
|
205
|
+
);
|
|
206
|
+
if (nameMatch) {
|
|
207
|
+
currentName = nameMatch[1] ?? '';
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const defMatch = line.match(
|
|
212
|
+
/capture: \d+ - definition\.(\w+), start: \((\d+), \d+\), end: \((\d+), \d+\)/,
|
|
213
|
+
);
|
|
214
|
+
if (defMatch && currentName) {
|
|
215
|
+
currentKind = captureToKind(defMatch[1]!);
|
|
216
|
+
const defStart = Number.parseInt(defMatch[2]!, 10) + 1;
|
|
217
|
+
endLine = Number.parseInt(defMatch[3]!, 10) + 1;
|
|
218
|
+
|
|
219
|
+
symbols.push({
|
|
220
|
+
name: currentName,
|
|
221
|
+
kind: currentKind,
|
|
222
|
+
startLine: defStart,
|
|
223
|
+
endLine,
|
|
224
|
+
filePath,
|
|
225
|
+
language,
|
|
226
|
+
});
|
|
227
|
+
currentName = '';
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return symbols;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
// Public API
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Parse a single file and extract code symbols.
|
|
240
|
+
*
|
|
241
|
+
* @param filePath - Absolute or relative path to source file
|
|
242
|
+
* @param projectRoot - Project root for relative path computation
|
|
243
|
+
* @returns Parse result with symbols and any errors
|
|
244
|
+
*/
|
|
245
|
+
export function parseFile(filePath: string, projectRoot?: string): ParseResult {
|
|
246
|
+
const root = projectRoot ?? process.cwd();
|
|
247
|
+
const relPath = relative(root, filePath);
|
|
248
|
+
const language = detectLanguage(filePath);
|
|
249
|
+
|
|
250
|
+
if (!language) {
|
|
251
|
+
return {
|
|
252
|
+
filePath: relPath,
|
|
253
|
+
language: 'unknown',
|
|
254
|
+
symbols: [],
|
|
255
|
+
errors: ['Unsupported language'],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const queryKey = queryKeyForLanguage(language);
|
|
260
|
+
const pattern = QUERY_PATTERNS[queryKey];
|
|
261
|
+
if (!pattern) {
|
|
262
|
+
return {
|
|
263
|
+
filePath: relPath,
|
|
264
|
+
language,
|
|
265
|
+
symbols: [],
|
|
266
|
+
errors: [`No query pattern for ${language}`],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const tmpDir = mkdtempSync(join(tmpdir(), 'cleo-ts-'));
|
|
271
|
+
const queryFile = join(tmpDir, 'query.scm');
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
writeFileSync(queryFile, pattern);
|
|
275
|
+
const bin = resolveTreeSitterBin();
|
|
276
|
+
|
|
277
|
+
const output = execFileSync(bin, ['query', queryFile, filePath], {
|
|
278
|
+
encoding: 'utf-8',
|
|
279
|
+
timeout: 30000,
|
|
280
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const symbols = parseQueryOutput(output, relPath, language);
|
|
284
|
+
return { filePath: relPath, language, symbols, errors: [] };
|
|
285
|
+
} catch (err) {
|
|
286
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
287
|
+
return { filePath: relPath, language, symbols: [], errors: [msg] };
|
|
288
|
+
} finally {
|
|
289
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Batch-parse multiple files, grouping by language for efficiency.
|
|
295
|
+
*
|
|
296
|
+
* Files with the same language share a single query pattern file
|
|
297
|
+
* but each file is parsed individually (tree-sitter CLI limitation).
|
|
298
|
+
*
|
|
299
|
+
* @param filePaths - Array of file paths to parse
|
|
300
|
+
* @param projectRoot - Project root for relative path computation
|
|
301
|
+
* @returns Aggregated results with per-file breakdowns
|
|
302
|
+
*/
|
|
303
|
+
export function batchParse(filePaths: string[], projectRoot?: string): BatchParseResult {
|
|
304
|
+
const root = projectRoot ?? process.cwd();
|
|
305
|
+
const results: ParseResult[] = [];
|
|
306
|
+
const skipped: string[] = [];
|
|
307
|
+
|
|
308
|
+
// Group files by language
|
|
309
|
+
const byLanguage = new Map<string, string[]>();
|
|
310
|
+
for (const fp of filePaths) {
|
|
311
|
+
const lang = detectLanguage(fp);
|
|
312
|
+
if (!lang) {
|
|
313
|
+
skipped.push(relative(root, fp));
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const key = queryKeyForLanguage(lang);
|
|
317
|
+
const group = byLanguage.get(key) ?? [];
|
|
318
|
+
group.push(fp);
|
|
319
|
+
byLanguage.set(key, group);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// Parse each group
|
|
323
|
+
for (const [_queryKey, files] of byLanguage) {
|
|
324
|
+
for (const fp of files) {
|
|
325
|
+
results.push(parseFile(fp, root));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const totalSymbols = results.reduce((sum, r) => sum + r.symbols.length, 0);
|
|
330
|
+
return { results, skipped, totalSymbols };
|
|
331
|
+
}
|