@josstei/maestro 1.6.4-rc.1
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/.agents/plugins/marketplace.json +20 -0
- package/CHANGELOG.md +485 -0
- package/EXAMPLES.md +255 -0
- package/GEMINI.md +231 -0
- package/LICENSE +201 -0
- package/QWEN.md +241 -0
- package/README.md +220 -0
- package/agents/accessibility_specialist.md +20 -0
- package/agents/analytics_engineer.md +22 -0
- package/agents/api_designer.md +19 -0
- package/agents/architect.md +19 -0
- package/agents/cloud_architect.md +19 -0
- package/agents/cobol_engineer.md +22 -0
- package/agents/code_reviewer.md +17 -0
- package/agents/coder.md +22 -0
- package/agents/compliance_reviewer.md +19 -0
- package/agents/content_strategist.md +19 -0
- package/agents/copywriter.md +19 -0
- package/agents/data_engineer.md +22 -0
- package/agents/database_administrator.md +21 -0
- package/agents/db2_dba.md +21 -0
- package/agents/debugger.md +19 -0
- package/agents/design_system_engineer.md +22 -0
- package/agents/devops_engineer.md +23 -0
- package/agents/hlasm_assembler_specialist.md +22 -0
- package/agents/i18n_specialist.md +21 -0
- package/agents/ibm_i_specialist.md +22 -0
- package/agents/integration_engineer.md +23 -0
- package/agents/ml_engineer.md +23 -0
- package/agents/mlops_engineer.md +23 -0
- package/agents/mobile_engineer.md +23 -0
- package/agents/observability_engineer.md +23 -0
- package/agents/performance_engineer.md +21 -0
- package/agents/platform_engineer.md +24 -0
- package/agents/product_manager.md +20 -0
- package/agents/prompt_engineer.md +22 -0
- package/agents/refactor.md +22 -0
- package/agents/release_manager.md +22 -0
- package/agents/security_engineer.md +21 -0
- package/agents/seo_specialist.md +21 -0
- package/agents/site_reliability_engineer.md +21 -0
- package/agents/solutions_architect.md +19 -0
- package/agents/technical_writer.md +21 -0
- package/agents/tester.md +23 -0
- package/agents/ux_designer.md +20 -0
- package/agents/zos_sysprog.md +21 -0
- package/bin/maestro-mcp-server.js +10 -0
- package/claude/.claude-plugin/plugin.json +21 -0
- package/claude/.mcp.json +11 -0
- package/claude/README.md +191 -0
- package/claude/agents/accessibility-specialist.md +36 -0
- package/claude/agents/analytics-engineer.md +38 -0
- package/claude/agents/api-designer.md +33 -0
- package/claude/agents/architect.md +33 -0
- package/claude/agents/cloud-architect.md +33 -0
- package/claude/agents/cobol-engineer.md +38 -0
- package/claude/agents/code-reviewer.md +31 -0
- package/claude/agents/coder.md +38 -0
- package/claude/agents/compliance-reviewer.md +33 -0
- package/claude/agents/content-strategist.md +33 -0
- package/claude/agents/copywriter.md +33 -0
- package/claude/agents/data-engineer.md +37 -0
- package/claude/agents/database-administrator.md +37 -0
- package/claude/agents/db2-dba.md +37 -0
- package/claude/agents/debugger.md +32 -0
- package/claude/agents/design-system-engineer.md +38 -0
- package/claude/agents/devops-engineer.md +39 -0
- package/claude/agents/hlasm-assembler-specialist.md +38 -0
- package/claude/agents/i18n-specialist.md +37 -0
- package/claude/agents/ibm-i-specialist.md +38 -0
- package/claude/agents/integration-engineer.md +39 -0
- package/claude/agents/ml-engineer.md +39 -0
- package/claude/agents/mlops-engineer.md +39 -0
- package/claude/agents/mobile-engineer.md +39 -0
- package/claude/agents/observability-engineer.md +39 -0
- package/claude/agents/performance-engineer.md +34 -0
- package/claude/agents/platform-engineer.md +40 -0
- package/claude/agents/product-manager.md +34 -0
- package/claude/agents/prompt-engineer.md +38 -0
- package/claude/agents/refactor.md +38 -0
- package/claude/agents/release-manager.md +38 -0
- package/claude/agents/security-engineer.md +37 -0
- package/claude/agents/seo-specialist.md +37 -0
- package/claude/agents/site-reliability-engineer.md +37 -0
- package/claude/agents/solutions-architect.md +33 -0
- package/claude/agents/technical-writer.md +37 -0
- package/claude/agents/tester.md +39 -0
- package/claude/agents/ux-designer.md +34 -0
- package/claude/agents/zos-sysprog.md +37 -0
- package/claude/hooks/claude-hooks.json +48 -0
- package/claude/mcp/maestro-server.js +9 -0
- package/claude/mcp-config.example.json +9 -0
- package/claude/scripts/adapters/claude-adapter.js +7 -0
- package/claude/scripts/hook-runner.js +8 -0
- package/claude/scripts/policy-enforcer.js +294 -0
- package/claude/skills/a11y-audit/SKILL.md +26 -0
- package/claude/skills/archive/SKILL.md +24 -0
- package/claude/skills/code-review/SKILL.md +7 -0
- package/claude/skills/compliance-check/SKILL.md +26 -0
- package/claude/skills/debug-workflow/SKILL.md +27 -0
- package/claude/skills/delegation/SKILL.md +7 -0
- package/claude/skills/design-dialogue/SKILL.md +7 -0
- package/claude/skills/execute/SKILL.md +38 -0
- package/claude/skills/execution/SKILL.md +7 -0
- package/claude/skills/implementation-planning/SKILL.md +7 -0
- package/claude/skills/orchestrate/SKILL.md +38 -0
- package/claude/skills/perf-check/SKILL.md +26 -0
- package/claude/skills/resume-session/SKILL.md +38 -0
- package/claude/skills/review-code/SKILL.md +27 -0
- package/claude/skills/security-audit/SKILL.md +28 -0
- package/claude/skills/seo-audit/SKILL.md +26 -0
- package/claude/skills/session-management/SKILL.md +7 -0
- package/claude/skills/status/SKILL.md +22 -0
- package/claude/skills/validation/SKILL.md +7 -0
- package/claude/src/agents/accessibility-specialist.md +163 -0
- package/claude/src/agents/analytics-engineer.md +182 -0
- package/claude/src/agents/api-designer.md +124 -0
- package/claude/src/agents/architect.md +120 -0
- package/claude/src/agents/cloud-architect.md +134 -0
- package/claude/src/agents/cobol-engineer.md +127 -0
- package/claude/src/agents/code-reviewer.md +123 -0
- package/claude/src/agents/coder.md +132 -0
- package/claude/src/agents/compliance-reviewer.md +219 -0
- package/claude/src/agents/content-strategist.md +111 -0
- package/claude/src/agents/copywriter.md +113 -0
- package/claude/src/agents/data-engineer.md +130 -0
- package/claude/src/agents/database-administrator.md +126 -0
- package/claude/src/agents/db2-dba.md +124 -0
- package/claude/src/agents/debugger.md +133 -0
- package/claude/src/agents/design-system-engineer.md +258 -0
- package/claude/src/agents/devops-engineer.md +138 -0
- package/claude/src/agents/hlasm-assembler-specialist.md +134 -0
- package/claude/src/agents/i18n-specialist.md +241 -0
- package/claude/src/agents/ibm-i-specialist.md +132 -0
- package/claude/src/agents/integration-engineer.md +133 -0
- package/claude/src/agents/ml-engineer.md +115 -0
- package/claude/src/agents/mlops-engineer.md +116 -0
- package/claude/src/agents/mobile-engineer.md +115 -0
- package/claude/src/agents/observability-engineer.md +133 -0
- package/claude/src/agents/performance-engineer.md +139 -0
- package/claude/src/agents/platform-engineer.md +129 -0
- package/claude/src/agents/product-manager.md +170 -0
- package/claude/src/agents/prompt-engineer.md +129 -0
- package/claude/src/agents/refactor.md +138 -0
- package/claude/src/agents/release-manager.md +132 -0
- package/claude/src/agents/security-engineer.md +143 -0
- package/claude/src/agents/seo-specialist.md +129 -0
- package/claude/src/agents/site-reliability-engineer.md +131 -0
- package/claude/src/agents/solutions-architect.md +137 -0
- package/claude/src/agents/technical-writer.md +129 -0
- package/claude/src/agents/tester.md +135 -0
- package/claude/src/agents/ux-designer.md +168 -0
- package/claude/src/agents/zos-sysprog.md +134 -0
- package/claude/src/config/setting-resolver.js +32 -0
- package/claude/src/core/agent-registry.js +67 -0
- package/claude/src/core/canonical-source.js +39 -0
- package/claude/src/core/env-file-parser.js +82 -0
- package/claude/src/core/feature-blocks.js +34 -0
- package/claude/src/core/logger.js +12 -0
- package/claude/src/core/markdown-state.js +36 -0
- package/claude/src/core/policy-rules.js +32 -0
- package/claude/src/core/project-root-resolver.js +184 -0
- package/claude/src/core/stdin-reader.js +77 -0
- package/claude/src/core/version.js +50 -0
- package/claude/src/entry-points/core-command-registry.js +37 -0
- package/claude/src/entry-points/preamble-builders.js +54 -0
- package/claude/src/entry-points/registry.js +199 -0
- package/claude/src/entry-points/templates/claude-core-command.md.tmpl +38 -0
- package/claude/src/entry-points/templates/claude-skill.md.tmpl +18 -0
- package/claude/src/entry-points/templates/codex-core-command.md.tmpl +16 -0
- package/claude/src/entry-points/templates/codex-skill.md.tmpl +11 -0
- package/claude/src/entry-points/templates/gemini-command.toml.tmpl +17 -0
- package/claude/src/entry-points/templates/gemini-core-command.toml.tmpl +30 -0
- package/claude/src/generated/agent-registry.json +630 -0
- package/claude/src/generated/hook-registry.json +18 -0
- package/claude/src/generated/resource-registry.json +16 -0
- package/claude/src/hooks/logic/after-agent-logic.js +54 -0
- package/claude/src/hooks/logic/before-agent-logic.js +57 -0
- package/claude/src/hooks/logic/hook-state.js +127 -0
- package/claude/src/hooks/logic/session-end-logic.js +17 -0
- package/claude/src/hooks/logic/session-start-logic.js +25 -0
- package/claude/src/lib/discovery/index.js +172 -0
- package/claude/src/lib/errors/index.js +104 -0
- package/claude/src/lib/framework-detection.js +50 -0
- package/claude/src/lib/frontmatter/index.js +262 -0
- package/claude/src/lib/io/index.js +96 -0
- package/claude/src/lib/naming/index.js +94 -0
- package/claude/src/lib/validation/index.js +124 -0
- package/claude/src/lib/yaml-emit.js +38 -0
- package/claude/src/mcp/content/provider.js +68 -0
- package/claude/src/mcp/content/runtime-content.js +188 -0
- package/claude/src/mcp/contracts/cache-path-rejector.js +39 -0
- package/claude/src/mcp/contracts/downstream-context.js +106 -0
- package/claude/src/mcp/contracts/plan-schema.js +148 -0
- package/claude/src/mcp/contracts/workspace-marker.js +61 -0
- package/claude/src/mcp/core/create-server.js +76 -0
- package/claude/src/mcp/core/line-reader.js +35 -0
- package/claude/src/mcp/core/project-root-cache.js +120 -0
- package/claude/src/mcp/core/protocol-dispatcher.js +274 -0
- package/claude/src/mcp/core/recovery-hints.js +43 -0
- package/claude/src/mcp/core/tool-outcome.js +77 -0
- package/claude/src/mcp/core/tool-registry.js +82 -0
- package/claude/src/mcp/handlers/assess-task-complexity.js +108 -0
- package/claude/src/mcp/handlers/blocker-parser.js +34 -0
- package/claude/src/mcp/handlers/design-gate.js +393 -0
- package/claude/src/mcp/handlers/get-agent.js +54 -0
- package/claude/src/mcp/handlers/get-runtime-context.js +49 -0
- package/claude/src/mcp/handlers/get-skill-content.js +51 -0
- package/claude/src/mcp/handlers/initialize-workspace.js +45 -0
- package/claude/src/mcp/handlers/reconciliation.js +224 -0
- package/claude/src/mcp/handlers/resolve-settings.js +39 -0
- package/claude/src/mcp/handlers/session-state-core.js +108 -0
- package/claude/src/mcp/handlers/session-state-tools.js +562 -0
- package/claude/src/mcp/handlers/validate-plan.js +76 -0
- package/claude/src/mcp/maestro-server.js +122 -0
- package/claude/src/mcp/runtime/runtime-config-map.js +70 -0
- package/claude/src/mcp/tool-packs/content/index.js +80 -0
- package/claude/src/mcp/tool-packs/contracts.js +30 -0
- package/claude/src/mcp/tool-packs/index.js +15 -0
- package/claude/src/mcp/tool-packs/session/index.js +243 -0
- package/claude/src/mcp/tool-packs/workspace/index.js +98 -0
- package/claude/src/mcp/utils/extension-root.js +31 -0
- package/claude/src/mcp/validation/agent-checker.js +81 -0
- package/claude/src/mcp/validation/dag-checker.js +214 -0
- package/claude/src/mcp/validation/file-overlap-checker.js +63 -0
- package/claude/src/mcp/validation/schema-checker.js +108 -0
- package/claude/src/platforms/claude/runtime-config.js +60 -0
- package/claude/src/platforms/shared/adapters/claude-adapter.js +36 -0
- package/claude/src/platforms/shared/adapters/conventions.js +29 -0
- package/claude/src/platforms/shared/adapters/exit-codes.js +6 -0
- package/claude/src/platforms/shared/adapters/factory.js +40 -0
- package/claude/src/platforms/shared/agent-names.js +10 -0
- package/claude/src/platforms/shared/hook-runner.js +52 -0
- package/claude/src/references/architecture.md +139 -0
- package/claude/src/references/orchestration-steps.md +193 -0
- package/claude/src/skills/shared/code-review/SKILL.md +145 -0
- package/claude/src/skills/shared/delegation/SKILL.md +370 -0
- package/claude/src/skills/shared/delegation/protocols/agent-base-protocol.md +145 -0
- package/claude/src/skills/shared/delegation/protocols/filesystem-safety-protocol.md +31 -0
- package/claude/src/skills/shared/design-dialogue/SKILL.md +284 -0
- package/claude/src/skills/shared/execution/SKILL.md +258 -0
- package/claude/src/skills/shared/implementation-planning/SKILL.md +303 -0
- package/claude/src/skills/shared/session-management/SKILL.md +314 -0
- package/claude/src/skills/shared/validation/SKILL.md +204 -0
- package/claude/src/state/session-state.js +113 -0
- package/claude/src/templates/design-document.md +95 -0
- package/claude/src/templates/implementation-plan.md +86 -0
- package/claude/src/templates/session-state.md +68 -0
- package/claude/src/version.json +3 -0
- package/commands/maestro/a11y-audit.toml +22 -0
- package/commands/maestro/archive.toml +23 -0
- package/commands/maestro/compliance-check.toml +22 -0
- package/commands/maestro/debug.toml +23 -0
- package/commands/maestro/execute.toml +30 -0
- package/commands/maestro/orchestrate.toml +30 -0
- package/commands/maestro/perf-check.toml +22 -0
- package/commands/maestro/resume.toml +38 -0
- package/commands/maestro/review.toml +23 -0
- package/commands/maestro/security-audit.toml +24 -0
- package/commands/maestro/seo-audit.toml +22 -0
- package/commands/maestro/status.toml +21 -0
- package/docs/architecture.md +310 -0
- package/docs/cicd.md +647 -0
- package/docs/flow.md +255 -0
- package/docs/maestro-cheatsheet.md +199 -0
- package/docs/overview.md +141 -0
- package/docs/runtime-claude.md +190 -0
- package/docs/runtime-codex.md +197 -0
- package/docs/runtime-gemini.md +170 -0
- package/docs/runtime-qwen.md +147 -0
- package/docs/usage.md +312 -0
- package/gemini-extension.json +55 -0
- package/hooks/adapters/gemini-adapter.js +2 -0
- package/hooks/adapters/qwen-adapter.js +2 -0
- package/hooks/hook-runner.js +3 -0
- package/hooks/hooks.json +56 -0
- package/mcp/maestro-server.js +4 -0
- package/package.json +93 -0
- package/plugins/maestro/.app.json +3 -0
- package/plugins/maestro/.codex-plugin/plugin.json +41 -0
- package/plugins/maestro/.mcp.json +16 -0
- package/plugins/maestro/README.md +57 -0
- package/plugins/maestro/references/runtime-guide.md +125 -0
- package/plugins/maestro/skills/a11y-audit/SKILL.md +16 -0
- package/plugins/maestro/skills/archive/SKILL.md +16 -0
- package/plugins/maestro/skills/code-review/SKILL.md +6 -0
- package/plugins/maestro/skills/compliance-check/SKILL.md +16 -0
- package/plugins/maestro/skills/debug-workflow/SKILL.md +16 -0
- package/plugins/maestro/skills/delegation/SKILL.md +6 -0
- package/plugins/maestro/skills/design-dialogue/SKILL.md +6 -0
- package/plugins/maestro/skills/execute/SKILL.md +16 -0
- package/plugins/maestro/skills/execution/SKILL.md +6 -0
- package/plugins/maestro/skills/implementation-planning/SKILL.md +6 -0
- package/plugins/maestro/skills/orchestrate/SKILL.md +16 -0
- package/plugins/maestro/skills/perf-check/SKILL.md +16 -0
- package/plugins/maestro/skills/resume-session/SKILL.md +16 -0
- package/plugins/maestro/skills/review-code/SKILL.md +16 -0
- package/plugins/maestro/skills/security-audit/SKILL.md +16 -0
- package/plugins/maestro/skills/seo-audit/SKILL.md +16 -0
- package/plugins/maestro/skills/session-management/SKILL.md +6 -0
- package/plugins/maestro/skills/status/SKILL.md +14 -0
- package/plugins/maestro/skills/validation/SKILL.md +6 -0
- package/plugins/maestro/src/agents/accessibility-specialist.md +163 -0
- package/plugins/maestro/src/agents/analytics-engineer.md +182 -0
- package/plugins/maestro/src/agents/api-designer.md +124 -0
- package/plugins/maestro/src/agents/architect.md +120 -0
- package/plugins/maestro/src/agents/cloud-architect.md +134 -0
- package/plugins/maestro/src/agents/cobol-engineer.md +127 -0
- package/plugins/maestro/src/agents/code-reviewer.md +123 -0
- package/plugins/maestro/src/agents/coder.md +132 -0
- package/plugins/maestro/src/agents/compliance-reviewer.md +219 -0
- package/plugins/maestro/src/agents/content-strategist.md +111 -0
- package/plugins/maestro/src/agents/copywriter.md +113 -0
- package/plugins/maestro/src/agents/data-engineer.md +130 -0
- package/plugins/maestro/src/agents/database-administrator.md +126 -0
- package/plugins/maestro/src/agents/db2-dba.md +124 -0
- package/plugins/maestro/src/agents/debugger.md +133 -0
- package/plugins/maestro/src/agents/design-system-engineer.md +258 -0
- package/plugins/maestro/src/agents/devops-engineer.md +138 -0
- package/plugins/maestro/src/agents/hlasm-assembler-specialist.md +134 -0
- package/plugins/maestro/src/agents/i18n-specialist.md +241 -0
- package/plugins/maestro/src/agents/ibm-i-specialist.md +132 -0
- package/plugins/maestro/src/agents/integration-engineer.md +133 -0
- package/plugins/maestro/src/agents/ml-engineer.md +115 -0
- package/plugins/maestro/src/agents/mlops-engineer.md +116 -0
- package/plugins/maestro/src/agents/mobile-engineer.md +115 -0
- package/plugins/maestro/src/agents/observability-engineer.md +133 -0
- package/plugins/maestro/src/agents/performance-engineer.md +139 -0
- package/plugins/maestro/src/agents/platform-engineer.md +129 -0
- package/plugins/maestro/src/agents/product-manager.md +170 -0
- package/plugins/maestro/src/agents/prompt-engineer.md +129 -0
- package/plugins/maestro/src/agents/refactor.md +138 -0
- package/plugins/maestro/src/agents/release-manager.md +132 -0
- package/plugins/maestro/src/agents/security-engineer.md +143 -0
- package/plugins/maestro/src/agents/seo-specialist.md +129 -0
- package/plugins/maestro/src/agents/site-reliability-engineer.md +131 -0
- package/plugins/maestro/src/agents/solutions-architect.md +137 -0
- package/plugins/maestro/src/agents/technical-writer.md +129 -0
- package/plugins/maestro/src/agents/tester.md +135 -0
- package/plugins/maestro/src/agents/ux-designer.md +168 -0
- package/plugins/maestro/src/agents/zos-sysprog.md +134 -0
- package/plugins/maestro/src/config/setting-resolver.js +32 -0
- package/plugins/maestro/src/core/agent-registry.js +67 -0
- package/plugins/maestro/src/core/canonical-source.js +39 -0
- package/plugins/maestro/src/core/env-file-parser.js +82 -0
- package/plugins/maestro/src/core/feature-blocks.js +34 -0
- package/plugins/maestro/src/core/logger.js +12 -0
- package/plugins/maestro/src/core/markdown-state.js +36 -0
- package/plugins/maestro/src/core/policy-rules.js +32 -0
- package/plugins/maestro/src/core/project-root-resolver.js +184 -0
- package/plugins/maestro/src/core/stdin-reader.js +77 -0
- package/plugins/maestro/src/core/version.js +50 -0
- package/plugins/maestro/src/entry-points/core-command-registry.js +37 -0
- package/plugins/maestro/src/entry-points/preamble-builders.js +54 -0
- package/plugins/maestro/src/entry-points/registry.js +199 -0
- package/plugins/maestro/src/entry-points/templates/claude-core-command.md.tmpl +38 -0
- package/plugins/maestro/src/entry-points/templates/claude-skill.md.tmpl +18 -0
- package/plugins/maestro/src/entry-points/templates/codex-core-command.md.tmpl +16 -0
- package/plugins/maestro/src/entry-points/templates/codex-skill.md.tmpl +11 -0
- package/plugins/maestro/src/entry-points/templates/gemini-command.toml.tmpl +17 -0
- package/plugins/maestro/src/entry-points/templates/gemini-core-command.toml.tmpl +30 -0
- package/plugins/maestro/src/generated/agent-registry.json +630 -0
- package/plugins/maestro/src/generated/hook-registry.json +18 -0
- package/plugins/maestro/src/generated/resource-registry.json +16 -0
- package/plugins/maestro/src/hooks/logic/after-agent-logic.js +54 -0
- package/plugins/maestro/src/hooks/logic/before-agent-logic.js +57 -0
- package/plugins/maestro/src/hooks/logic/hook-state.js +127 -0
- package/plugins/maestro/src/hooks/logic/session-end-logic.js +17 -0
- package/plugins/maestro/src/hooks/logic/session-start-logic.js +25 -0
- package/plugins/maestro/src/lib/discovery/index.js +172 -0
- package/plugins/maestro/src/lib/errors/index.js +104 -0
- package/plugins/maestro/src/lib/framework-detection.js +50 -0
- package/plugins/maestro/src/lib/frontmatter/index.js +262 -0
- package/plugins/maestro/src/lib/io/index.js +96 -0
- package/plugins/maestro/src/lib/naming/index.js +94 -0
- package/plugins/maestro/src/lib/validation/index.js +124 -0
- package/plugins/maestro/src/lib/yaml-emit.js +38 -0
- package/plugins/maestro/src/mcp/content/provider.js +68 -0
- package/plugins/maestro/src/mcp/content/runtime-content.js +188 -0
- package/plugins/maestro/src/mcp/contracts/cache-path-rejector.js +39 -0
- package/plugins/maestro/src/mcp/contracts/downstream-context.js +106 -0
- package/plugins/maestro/src/mcp/contracts/plan-schema.js +148 -0
- package/plugins/maestro/src/mcp/contracts/workspace-marker.js +61 -0
- package/plugins/maestro/src/mcp/core/create-server.js +76 -0
- package/plugins/maestro/src/mcp/core/line-reader.js +35 -0
- package/plugins/maestro/src/mcp/core/project-root-cache.js +120 -0
- package/plugins/maestro/src/mcp/core/protocol-dispatcher.js +274 -0
- package/plugins/maestro/src/mcp/core/recovery-hints.js +43 -0
- package/plugins/maestro/src/mcp/core/tool-outcome.js +77 -0
- package/plugins/maestro/src/mcp/core/tool-registry.js +82 -0
- package/plugins/maestro/src/mcp/handlers/assess-task-complexity.js +108 -0
- package/plugins/maestro/src/mcp/handlers/blocker-parser.js +34 -0
- package/plugins/maestro/src/mcp/handlers/design-gate.js +393 -0
- package/plugins/maestro/src/mcp/handlers/get-agent.js +54 -0
- package/plugins/maestro/src/mcp/handlers/get-runtime-context.js +49 -0
- package/plugins/maestro/src/mcp/handlers/get-skill-content.js +51 -0
- package/plugins/maestro/src/mcp/handlers/initialize-workspace.js +45 -0
- package/plugins/maestro/src/mcp/handlers/reconciliation.js +224 -0
- package/plugins/maestro/src/mcp/handlers/resolve-settings.js +39 -0
- package/plugins/maestro/src/mcp/handlers/session-state-core.js +108 -0
- package/plugins/maestro/src/mcp/handlers/session-state-tools.js +562 -0
- package/plugins/maestro/src/mcp/handlers/validate-plan.js +76 -0
- package/plugins/maestro/src/mcp/maestro-server.js +122 -0
- package/plugins/maestro/src/mcp/runtime/runtime-config-map.js +70 -0
- package/plugins/maestro/src/mcp/tool-packs/content/index.js +80 -0
- package/plugins/maestro/src/mcp/tool-packs/contracts.js +30 -0
- package/plugins/maestro/src/mcp/tool-packs/index.js +15 -0
- package/plugins/maestro/src/mcp/tool-packs/session/index.js +243 -0
- package/plugins/maestro/src/mcp/tool-packs/workspace/index.js +98 -0
- package/plugins/maestro/src/mcp/utils/extension-root.js +31 -0
- package/plugins/maestro/src/mcp/validation/agent-checker.js +81 -0
- package/plugins/maestro/src/mcp/validation/dag-checker.js +214 -0
- package/plugins/maestro/src/mcp/validation/file-overlap-checker.js +63 -0
- package/plugins/maestro/src/mcp/validation/schema-checker.js +108 -0
- package/plugins/maestro/src/platforms/codex/runtime-config.js +58 -0
- package/plugins/maestro/src/platforms/shared/adapters/conventions.js +29 -0
- package/plugins/maestro/src/platforms/shared/adapters/exit-codes.js +6 -0
- package/plugins/maestro/src/platforms/shared/adapters/factory.js +40 -0
- package/plugins/maestro/src/platforms/shared/agent-names.js +10 -0
- package/plugins/maestro/src/platforms/shared/hook-runner.js +52 -0
- package/plugins/maestro/src/references/architecture.md +139 -0
- package/plugins/maestro/src/references/orchestration-steps.md +193 -0
- package/plugins/maestro/src/skills/shared/code-review/SKILL.md +145 -0
- package/plugins/maestro/src/skills/shared/delegation/SKILL.md +370 -0
- package/plugins/maestro/src/skills/shared/delegation/protocols/agent-base-protocol.md +145 -0
- package/plugins/maestro/src/skills/shared/delegation/protocols/filesystem-safety-protocol.md +31 -0
- package/plugins/maestro/src/skills/shared/design-dialogue/SKILL.md +284 -0
- package/plugins/maestro/src/skills/shared/execution/SKILL.md +258 -0
- package/plugins/maestro/src/skills/shared/implementation-planning/SKILL.md +303 -0
- package/plugins/maestro/src/skills/shared/session-management/SKILL.md +314 -0
- package/plugins/maestro/src/skills/shared/validation/SKILL.md +204 -0
- package/plugins/maestro/src/state/session-state.js +113 -0
- package/plugins/maestro/src/templates/design-document.md +95 -0
- package/plugins/maestro/src/templates/implementation-plan.md +86 -0
- package/plugins/maestro/src/templates/session-state.md +68 -0
- package/plugins/maestro/src/version.json +3 -0
- package/policies/maestro.toml +44 -0
- package/qwen/agents/accessibility_specialist.md +18 -0
- package/qwen/agents/analytics_engineer.md +20 -0
- package/qwen/agents/api_designer.md +17 -0
- package/qwen/agents/architect.md +17 -0
- package/qwen/agents/cloud_architect.md +17 -0
- package/qwen/agents/cobol_engineer.md +20 -0
- package/qwen/agents/code_reviewer.md +15 -0
- package/qwen/agents/coder.md +20 -0
- package/qwen/agents/compliance_reviewer.md +17 -0
- package/qwen/agents/content_strategist.md +17 -0
- package/qwen/agents/copywriter.md +17 -0
- package/qwen/agents/data_engineer.md +20 -0
- package/qwen/agents/database_administrator.md +19 -0
- package/qwen/agents/db2_dba.md +19 -0
- package/qwen/agents/debugger.md +17 -0
- package/qwen/agents/design_system_engineer.md +20 -0
- package/qwen/agents/devops_engineer.md +21 -0
- package/qwen/agents/hlasm_assembler_specialist.md +20 -0
- package/qwen/agents/i18n_specialist.md +19 -0
- package/qwen/agents/ibm_i_specialist.md +20 -0
- package/qwen/agents/integration_engineer.md +21 -0
- package/qwen/agents/ml_engineer.md +21 -0
- package/qwen/agents/mlops_engineer.md +21 -0
- package/qwen/agents/mobile_engineer.md +21 -0
- package/qwen/agents/observability_engineer.md +21 -0
- package/qwen/agents/performance_engineer.md +19 -0
- package/qwen/agents/platform_engineer.md +22 -0
- package/qwen/agents/product_manager.md +18 -0
- package/qwen/agents/prompt_engineer.md +20 -0
- package/qwen/agents/refactor.md +20 -0
- package/qwen/agents/release_manager.md +20 -0
- package/qwen/agents/security_engineer.md +19 -0
- package/qwen/agents/seo_specialist.md +19 -0
- package/qwen/agents/site_reliability_engineer.md +19 -0
- package/qwen/agents/solutions_architect.md +17 -0
- package/qwen/agents/technical_writer.md +19 -0
- package/qwen/agents/tester.md +21 -0
- package/qwen/agents/ux_designer.md +18 -0
- package/qwen/agents/zos_sysprog.md +19 -0
- package/qwen/hooks.json +56 -0
- package/qwen-extension.json +55 -0
- package/scripts/check-layer-boundaries.js +74 -0
- package/scripts/generate.js +155 -0
- package/scripts/install-codex-plugin.js +167 -0
- package/scripts/install-git-hooks.js +43 -0
- package/scripts/npm-publish-idempotent.js +150 -0
- package/scripts/package-release-artifacts.js +156 -0
- package/scripts/release-artifact-manifest.js +378 -0
- package/scripts/release-version-metadata.js +129 -0
- package/scripts/update-versions.js +33 -0
- package/scripts/verify-npm-pack.js +85 -0
- package/scripts/verify-release-artifacts.js +95 -0
- package/src/agents/accessibility-specialist.md +163 -0
- package/src/agents/analytics-engineer.md +182 -0
- package/src/agents/api-designer.md +124 -0
- package/src/agents/architect.md +120 -0
- package/src/agents/cloud-architect.md +134 -0
- package/src/agents/cobol-engineer.md +127 -0
- package/src/agents/code-reviewer.md +123 -0
- package/src/agents/coder.md +132 -0
- package/src/agents/compliance-reviewer.md +219 -0
- package/src/agents/content-strategist.md +111 -0
- package/src/agents/copywriter.md +113 -0
- package/src/agents/data-engineer.md +130 -0
- package/src/agents/database-administrator.md +126 -0
- package/src/agents/db2-dba.md +124 -0
- package/src/agents/debugger.md +133 -0
- package/src/agents/design-system-engineer.md +258 -0
- package/src/agents/devops-engineer.md +138 -0
- package/src/agents/hlasm-assembler-specialist.md +134 -0
- package/src/agents/i18n-specialist.md +241 -0
- package/src/agents/ibm-i-specialist.md +132 -0
- package/src/agents/integration-engineer.md +133 -0
- package/src/agents/ml-engineer.md +115 -0
- package/src/agents/mlops-engineer.md +116 -0
- package/src/agents/mobile-engineer.md +115 -0
- package/src/agents/observability-engineer.md +133 -0
- package/src/agents/performance-engineer.md +139 -0
- package/src/agents/platform-engineer.md +129 -0
- package/src/agents/product-manager.md +170 -0
- package/src/agents/prompt-engineer.md +129 -0
- package/src/agents/refactor.md +138 -0
- package/src/agents/release-manager.md +132 -0
- package/src/agents/security-engineer.md +143 -0
- package/src/agents/seo-specialist.md +129 -0
- package/src/agents/site-reliability-engineer.md +131 -0
- package/src/agents/solutions-architect.md +137 -0
- package/src/agents/technical-writer.md +129 -0
- package/src/agents/tester.md +135 -0
- package/src/agents/ux-designer.md +168 -0
- package/src/agents/zos-sysprog.md +134 -0
- package/src/config/setting-resolver.js +32 -0
- package/src/core/agent-registry.js +67 -0
- package/src/core/canonical-source.js +39 -0
- package/src/core/env-file-parser.js +82 -0
- package/src/core/feature-blocks.js +34 -0
- package/src/core/logger.js +12 -0
- package/src/core/markdown-state.js +36 -0
- package/src/core/policy-rules.js +32 -0
- package/src/core/project-root-resolver.js +184 -0
- package/src/core/stdin-reader.js +77 -0
- package/src/core/version.js +50 -0
- package/src/entry-points/core-command-registry.js +37 -0
- package/src/entry-points/preamble-builders.js +54 -0
- package/src/entry-points/registry.js +199 -0
- package/src/entry-points/templates/claude-core-command.md.tmpl +38 -0
- package/src/entry-points/templates/claude-skill.md.tmpl +18 -0
- package/src/entry-points/templates/codex-core-command.md.tmpl +16 -0
- package/src/entry-points/templates/codex-skill.md.tmpl +11 -0
- package/src/entry-points/templates/gemini-command.toml.tmpl +17 -0
- package/src/entry-points/templates/gemini-core-command.toml.tmpl +30 -0
- package/src/generated/agent-registry.json +630 -0
- package/src/generated/hook-registry.json +18 -0
- package/src/generated/resource-registry.json +16 -0
- package/src/generator/entry-point-expander.js +182 -0
- package/src/generator/file-writer.js +167 -0
- package/src/generator/generation-session.js +62 -0
- package/src/generator/manifest-curator.js +31 -0
- package/src/generator/manifest-expander.js +256 -0
- package/src/generator/payload-builder.js +217 -0
- package/src/generator/registry-scanner.js +130 -0
- package/src/generator/stale-pruner.js +101 -0
- package/src/hooks/logic/after-agent-logic.js +54 -0
- package/src/hooks/logic/before-agent-logic.js +57 -0
- package/src/hooks/logic/hook-state.js +127 -0
- package/src/hooks/logic/session-end-logic.js +17 -0
- package/src/hooks/logic/session-start-logic.js +25 -0
- package/src/lib/discovery/index.js +172 -0
- package/src/lib/errors/index.js +104 -0
- package/src/lib/framework-detection.js +50 -0
- package/src/lib/frontmatter/index.js +262 -0
- package/src/lib/io/index.js +96 -0
- package/src/lib/naming/index.js +94 -0
- package/src/lib/validation/index.js +124 -0
- package/src/lib/yaml-emit.js +38 -0
- package/src/manifest.js +11 -0
- package/src/mcp/content/provider.js +68 -0
- package/src/mcp/content/runtime-content.js +188 -0
- package/src/mcp/contracts/cache-path-rejector.js +39 -0
- package/src/mcp/contracts/downstream-context.js +106 -0
- package/src/mcp/contracts/plan-schema.js +148 -0
- package/src/mcp/contracts/workspace-marker.js +61 -0
- package/src/mcp/core/create-server.js +76 -0
- package/src/mcp/core/line-reader.js +35 -0
- package/src/mcp/core/project-root-cache.js +120 -0
- package/src/mcp/core/protocol-dispatcher.js +274 -0
- package/src/mcp/core/recovery-hints.js +43 -0
- package/src/mcp/core/tool-outcome.js +77 -0
- package/src/mcp/core/tool-registry.js +82 -0
- package/src/mcp/handlers/assess-task-complexity.js +108 -0
- package/src/mcp/handlers/blocker-parser.js +34 -0
- package/src/mcp/handlers/design-gate.js +393 -0
- package/src/mcp/handlers/get-agent.js +54 -0
- package/src/mcp/handlers/get-runtime-context.js +49 -0
- package/src/mcp/handlers/get-skill-content.js +51 -0
- package/src/mcp/handlers/initialize-workspace.js +45 -0
- package/src/mcp/handlers/reconciliation.js +224 -0
- package/src/mcp/handlers/resolve-settings.js +39 -0
- package/src/mcp/handlers/session-state-core.js +108 -0
- package/src/mcp/handlers/session-state-tools.js +562 -0
- package/src/mcp/handlers/validate-plan.js +76 -0
- package/src/mcp/maestro-server.js +122 -0
- package/src/mcp/runtime/runtime-config-map.js +70 -0
- package/src/mcp/tool-packs/content/index.js +80 -0
- package/src/mcp/tool-packs/contracts.js +30 -0
- package/src/mcp/tool-packs/index.js +15 -0
- package/src/mcp/tool-packs/session/index.js +243 -0
- package/src/mcp/tool-packs/workspace/index.js +98 -0
- package/src/mcp/utils/extension-root.js +31 -0
- package/src/mcp/validation/agent-checker.js +81 -0
- package/src/mcp/validation/dag-checker.js +214 -0
- package/src/mcp/validation/file-overlap-checker.js +63 -0
- package/src/mcp/validation/schema-checker.js +108 -0
- package/src/platforms/claude/metadata.js +96 -0
- package/src/platforms/claude/runtime-config.js +60 -0
- package/src/platforms/codex/metadata.js +107 -0
- package/src/platforms/codex/runtime-config.js +58 -0
- package/src/platforms/gemini/metadata.js +27 -0
- package/src/platforms/gemini/runtime-config.js +62 -0
- package/src/platforms/metadata-shared.js +131 -0
- package/src/platforms/metadata.js +29 -0
- package/src/platforms/qwen/metadata.js +27 -0
- package/src/platforms/qwen/runtime-config.js +62 -0
- package/src/platforms/shared/adapters/claude-adapter.js +36 -0
- package/src/platforms/shared/adapters/conventions.js +29 -0
- package/src/platforms/shared/adapters/exit-codes.js +6 -0
- package/src/platforms/shared/adapters/factory.js +40 -0
- package/src/platforms/shared/adapters/gemini-adapter.js +34 -0
- package/src/platforms/shared/adapters/qwen-adapter.js +93 -0
- package/src/platforms/shared/agent-names.js +10 -0
- package/src/platforms/shared/hook-runner.js +52 -0
- package/src/references/architecture.md +139 -0
- package/src/references/orchestration-steps.md +193 -0
- package/src/scripts/ensure-workspace.js +14 -0
- package/src/scripts/read-active-session.js +26 -0
- package/src/scripts/read-setting.js +18 -0
- package/src/scripts/read-state.js +17 -0
- package/src/scripts/write-state.js +22 -0
- package/src/skills/shared/code-review/SKILL.md +145 -0
- package/src/skills/shared/delegation/SKILL.md +370 -0
- package/src/skills/shared/delegation/protocols/agent-base-protocol.md +145 -0
- package/src/skills/shared/delegation/protocols/filesystem-safety-protocol.md +31 -0
- package/src/skills/shared/design-dialogue/SKILL.md +284 -0
- package/src/skills/shared/execution/SKILL.md +258 -0
- package/src/skills/shared/implementation-planning/SKILL.md +303 -0
- package/src/skills/shared/session-management/SKILL.md +314 -0
- package/src/skills/shared/validation/SKILL.md +204 -0
- package/src/state/session-state.js +113 -0
- package/src/templates/design-document.md +95 -0
- package/src/templates/implementation-plan.md +86 -0
- package/src/templates/session-state.md +68 -0
- package/src/transforms/agent-stub.js +29 -0
- package/src/transforms/extract-examples.js +63 -0
- package/src/transforms/index.js +35 -0
- package/src/transforms/parse-frontmatter.js +23 -0
- package/src/transforms/rebuild-frontmatter.js +147 -0
- package/src/transforms/skill-discovery-stub.js +27 -0
- package/src/transforms/skill-metadata.js +14 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { isAdapterFile, extractRuntime } = require('../platforms/shared/adapters/conventions');
|
|
6
|
+
|
|
7
|
+
const VERSION_JSON_FILENAME = 'version.json';
|
|
8
|
+
|
|
9
|
+
const ADAPTER_PATH_PREFIX = 'platforms/shared/adapters/';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Determine whether a relative path is an adapter file belonging to a
|
|
13
|
+
* different runtime. Returns true when the file is a foreign adapter that
|
|
14
|
+
* should be excluded from the payload.
|
|
15
|
+
* @param {string} relativePath - Posix-style relative path from src/
|
|
16
|
+
* @param {string} runtimeName - Target runtime name
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
function isForeignAdapter(relativePath, runtimeName) {
|
|
20
|
+
if (!relativePath.startsWith(ADAPTER_PATH_PREFIX)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const filename = relativePath.slice(ADAPTER_PATH_PREFIX.length);
|
|
24
|
+
if (!isAdapterFile(filename)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return extractRuntime(filename) !== runtimeName;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Base allowlist of src/ prefixes included in detached payloads.
|
|
32
|
+
* Each entry is a directory prefix (trailing slash) or a specific file path.
|
|
33
|
+
* @type {ReadonlyArray<string>}
|
|
34
|
+
*/
|
|
35
|
+
const DETACHED_PAYLOAD_BASE_ALLOWLIST = Object.freeze([
|
|
36
|
+
'core/',
|
|
37
|
+
'lib/',
|
|
38
|
+
'config/',
|
|
39
|
+
'hooks/',
|
|
40
|
+
'mcp/',
|
|
41
|
+
'platforms/shared/',
|
|
42
|
+
'state/',
|
|
43
|
+
'agents/',
|
|
44
|
+
'skills/',
|
|
45
|
+
'references/',
|
|
46
|
+
'templates/',
|
|
47
|
+
'entry-points/',
|
|
48
|
+
'generated/',
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build a payload allowlist for a specific runtime by extending the base
|
|
53
|
+
* allowlist with the runtime-specific config file entry.
|
|
54
|
+
* @param {string} runtimeName
|
|
55
|
+
* @returns {string[]}
|
|
56
|
+
*/
|
|
57
|
+
function buildPayloadAllowlist(runtimeName) {
|
|
58
|
+
return [
|
|
59
|
+
...DETACHED_PAYLOAD_BASE_ALLOWLIST,
|
|
60
|
+
`platforms/${runtimeName}/runtime-config.js`,
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Determine whether a file at the given relative path should be included
|
|
66
|
+
* in a detached payload based on the provided allowlist.
|
|
67
|
+
* @param {string} relativePath - Posix-style relative path from src/
|
|
68
|
+
* @param {string[]} [allowlist] - Allowlist to check against; defaults to base
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
function shouldIncludeInPayload(relativePath, allowlist) {
|
|
72
|
+
const list = allowlist || DETACHED_PAYLOAD_BASE_ALLOWLIST;
|
|
73
|
+
return list.some((prefix) => relativePath.startsWith(prefix));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Determine whether a directory walk should descend into the given directory.
|
|
78
|
+
* Returns true when the directory is either a parent of an allowlisted prefix
|
|
79
|
+
* or a child within an allowlisted prefix.
|
|
80
|
+
* @param {string} relativeDir - Posix-style relative directory path from src/
|
|
81
|
+
* @param {string[]} [allowlist] - Allowlist to check against; defaults to base
|
|
82
|
+
* @returns {boolean}
|
|
83
|
+
*/
|
|
84
|
+
function shouldDescendInto(relativeDir, allowlist) {
|
|
85
|
+
const dir = relativeDir.endsWith('/') ? relativeDir : `${relativeDir}/`;
|
|
86
|
+
const list = allowlist || DETACHED_PAYLOAD_BASE_ALLOWLIST;
|
|
87
|
+
return list.some(
|
|
88
|
+
(prefix) => prefix.startsWith(dir) || dir.startsWith(prefix)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Walk srcDir, copy allowed files into outputDir, then remove stale files
|
|
94
|
+
* from outputDir that are no longer present in the source.
|
|
95
|
+
* @param {string} srcDir - Absolute path to the source directory
|
|
96
|
+
* @param {string} outputDir - Absolute path to the output payload directory
|
|
97
|
+
* @param {string} [runtimeName] - Runtime name for allowlist extension
|
|
98
|
+
* @returns {{ copied: number, removed: number, skipped: number }}
|
|
99
|
+
*/
|
|
100
|
+
function buildDetachedPayload(srcDir, outputDir, runtimeName) {
|
|
101
|
+
const allowlist = runtimeName
|
|
102
|
+
? buildPayloadAllowlist(runtimeName)
|
|
103
|
+
: [...DETACHED_PAYLOAD_BASE_ALLOWLIST];
|
|
104
|
+
const stats = { copied: 0, removed: 0, skipped: 0 };
|
|
105
|
+
const keptOutputs = new Set();
|
|
106
|
+
|
|
107
|
+
function walkAndCopy(dir) {
|
|
108
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
const fullPath = path.join(dir, entry.name);
|
|
111
|
+
const relativePath = path
|
|
112
|
+
.relative(srcDir, fullPath)
|
|
113
|
+
.split(path.sep)
|
|
114
|
+
.join('/');
|
|
115
|
+
|
|
116
|
+
if (entry.isDirectory()) {
|
|
117
|
+
if (shouldDescendInto(relativePath, allowlist)) {
|
|
118
|
+
walkAndCopy(fullPath);
|
|
119
|
+
} else {
|
|
120
|
+
stats.skipped++;
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!entry.isFile()) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!shouldIncludeInPayload(relativePath, allowlist)) {
|
|
130
|
+
stats.skipped++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (runtimeName && isForeignAdapter(relativePath, runtimeName)) {
|
|
135
|
+
stats.skipped++;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
keptOutputs.add(relativePath);
|
|
140
|
+
const outputPath = path.join(outputDir, relativePath);
|
|
141
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
142
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
143
|
+
const existing = fs.existsSync(outputPath)
|
|
144
|
+
? fs.readFileSync(outputPath, 'utf8')
|
|
145
|
+
: null;
|
|
146
|
+
if (existing !== content) {
|
|
147
|
+
fs.writeFileSync(outputPath, content, 'utf8');
|
|
148
|
+
stats.copied++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function cleanStale(dir) {
|
|
154
|
+
if (!fs.existsSync(dir)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
159
|
+
for (const entry of entries) {
|
|
160
|
+
const fullPath = path.join(dir, entry.name);
|
|
161
|
+
const relativePath = path
|
|
162
|
+
.relative(outputDir, fullPath)
|
|
163
|
+
.split(path.sep)
|
|
164
|
+
.join('/');
|
|
165
|
+
if (entry.isDirectory()) {
|
|
166
|
+
cleanStale(fullPath);
|
|
167
|
+
if (
|
|
168
|
+
fs.existsSync(fullPath) &&
|
|
169
|
+
fs.readdirSync(fullPath).length === 0
|
|
170
|
+
) {
|
|
171
|
+
fs.rmdirSync(fullPath);
|
|
172
|
+
}
|
|
173
|
+
} else if (!keptOutputs.has(relativePath)) {
|
|
174
|
+
fs.unlinkSync(fullPath);
|
|
175
|
+
stats.removed++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
walkAndCopy(srcDir);
|
|
181
|
+
if (runtimeName) {
|
|
182
|
+
keptOutputs.add(VERSION_JSON_FILENAME);
|
|
183
|
+
}
|
|
184
|
+
cleanStale(outputDir);
|
|
185
|
+
return stats;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Write a version.json file to each payload directory.
|
|
190
|
+
* Only writes when the content has changed (avoids unnecessary churn).
|
|
191
|
+
* @param {string[]} payloadDirs - Absolute paths to payload output directories
|
|
192
|
+
* @param {string} version - Semantic version string to stamp
|
|
193
|
+
*/
|
|
194
|
+
function stampVersion(payloadDirs, version) {
|
|
195
|
+
const versionContent = JSON.stringify({ version }, null, 2) + '\n';
|
|
196
|
+
|
|
197
|
+
for (const payloadDir of payloadDirs) {
|
|
198
|
+
const versionPath = path.join(payloadDir, VERSION_JSON_FILENAME);
|
|
199
|
+
const existingContent = fs.existsSync(versionPath)
|
|
200
|
+
? fs.readFileSync(versionPath, 'utf8')
|
|
201
|
+
: null;
|
|
202
|
+
|
|
203
|
+
if (existingContent !== versionContent) {
|
|
204
|
+
fs.writeFileSync(versionPath, versionContent, 'utf8');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
module.exports = {
|
|
210
|
+
DETACHED_PAYLOAD_BASE_ALLOWLIST,
|
|
211
|
+
buildPayloadAllowlist,
|
|
212
|
+
shouldIncludeInPayload,
|
|
213
|
+
isForeignAdapter,
|
|
214
|
+
shouldDescendInto,
|
|
215
|
+
buildDetachedPayload,
|
|
216
|
+
stampVersion,
|
|
217
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { discover, generateRegistry } = require('../lib/discovery');
|
|
6
|
+
const { serializeRegistry } = require('../lib/discovery');
|
|
7
|
+
const { parse } = require('../lib/frontmatter');
|
|
8
|
+
const { toPascalCase } = require('../lib/naming');
|
|
9
|
+
|
|
10
|
+
function buildAgentRegistry(srcDir) {
|
|
11
|
+
const agentEntries = discover({
|
|
12
|
+
dir: path.join(srcDir, 'agents'),
|
|
13
|
+
pattern: '*.md',
|
|
14
|
+
identity: (filepath) => path.basename(filepath, '.md'),
|
|
15
|
+
metadata: (filepath, content) => {
|
|
16
|
+
const { frontmatter } = parse(content);
|
|
17
|
+
const name = frontmatter.name || path.basename(filepath, '.md');
|
|
18
|
+
const capabilities = frontmatter.capabilities || 'read_only';
|
|
19
|
+
const rawTools = frontmatter.tools || [];
|
|
20
|
+
const tools = Array.isArray(rawTools) ? rawTools : [rawTools];
|
|
21
|
+
return { name, capabilities, tools };
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return agentEntries.map(({ name, capabilities, tools }) => ({ name, capabilities, tools }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function buildResourceRegistry(srcDir) {
|
|
29
|
+
const skillsParentDir = path.join(srcDir, 'skills');
|
|
30
|
+
const skillEntries = discover({
|
|
31
|
+
dir: path.join(srcDir, 'skills', 'shared'),
|
|
32
|
+
pattern: '**/*.md',
|
|
33
|
+
identity: (filepath) => {
|
|
34
|
+
if (path.basename(filepath) === 'SKILL.md') {
|
|
35
|
+
return path.basename(path.dirname(filepath));
|
|
36
|
+
}
|
|
37
|
+
return path.basename(filepath, '.md');
|
|
38
|
+
},
|
|
39
|
+
metadata: (filepath) => {
|
|
40
|
+
const relativePath = 'skills/' + path.relative(skillsParentDir, filepath)
|
|
41
|
+
.split(path.sep)
|
|
42
|
+
.join('/');
|
|
43
|
+
return { relativePath };
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const templateEntries = discover({
|
|
48
|
+
dir: path.join(srcDir, 'templates'),
|
|
49
|
+
pattern: '*.md',
|
|
50
|
+
identity: (filepath) => path.basename(filepath, '.md'),
|
|
51
|
+
metadata: (filepath) => ({
|
|
52
|
+
relativePath: `templates/${path.basename(filepath)}`,
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const referenceEntries = discover({
|
|
57
|
+
dir: path.join(srcDir, 'references'),
|
|
58
|
+
pattern: '*.md',
|
|
59
|
+
identity: (filepath) => path.basename(filepath, '.md'),
|
|
60
|
+
metadata: (filepath) => ({
|
|
61
|
+
relativePath: `references/${path.basename(filepath)}`,
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const resources = {};
|
|
66
|
+
for (const entry of [...skillEntries, ...templateEntries, ...referenceEntries]) {
|
|
67
|
+
resources[entry.id] = entry.relativePath;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return resources;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function buildHookRegistry(srcDir) {
|
|
74
|
+
const hookEntries = discover({
|
|
75
|
+
dir: path.join(srcDir, 'hooks', 'logic'),
|
|
76
|
+
pattern: '*-logic.js',
|
|
77
|
+
identity: (filepath) => path.basename(filepath).replace(/-logic\.js$/, ''),
|
|
78
|
+
metadata: (filepath) => {
|
|
79
|
+
const file = path.basename(filepath);
|
|
80
|
+
const hookName = file.replace(/-logic\.js$/, '');
|
|
81
|
+
return {
|
|
82
|
+
module: `hooks/logic/${file}`,
|
|
83
|
+
fn: `handle${toPascalCase(hookName)}`,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const hooks = {};
|
|
89
|
+
for (const entry of hookEntries) {
|
|
90
|
+
hooks[entry.id] = { module: entry.module, fn: entry.fn };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return hooks;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildRegistries(srcDir) {
|
|
97
|
+
return [
|
|
98
|
+
{ fileName: 'agent-registry.json', data: buildAgentRegistry(srcDir) },
|
|
99
|
+
{ fileName: 'resource-registry.json', data: buildResourceRegistry(srcDir) },
|
|
100
|
+
{ fileName: 'hook-registry.json', data: buildHookRegistry(srcDir) },
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function collectRegistryOutputs(srcDir, rootDir = path.dirname(srcDir)) {
|
|
105
|
+
const generatedDir = path.join(srcDir, 'generated');
|
|
106
|
+
|
|
107
|
+
return buildRegistries(srcDir).map(({ fileName, data }) => ({
|
|
108
|
+
outputPath: path.relative(rootDir, path.join(generatedDir, fileName)),
|
|
109
|
+
content: serializeRegistry(data),
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Run all discovery scans and write the resulting JSON registry files to
|
|
115
|
+
* src/generated/.
|
|
116
|
+
* @param {string} srcDir - Absolute path to the src/ directory
|
|
117
|
+
*/
|
|
118
|
+
function generateRegistries(srcDir) {
|
|
119
|
+
const generatedDir = path.join(srcDir, 'generated');
|
|
120
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
121
|
+
|
|
122
|
+
for (const { fileName, data } of buildRegistries(srcDir)) {
|
|
123
|
+
generateRegistry(data, path.join(generatedDir, fileName));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
collectRegistryOutputs,
|
|
129
|
+
generateRegistries,
|
|
130
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recursively collect all file paths under a directory.
|
|
8
|
+
* Returns relative paths using forward-slash separators.
|
|
9
|
+
* @param {string} dir - Relative directory path (forward-slash separated)
|
|
10
|
+
* @param {string} rootDir - Absolute path to the project root
|
|
11
|
+
* @returns {string[]} Relative file paths within the directory
|
|
12
|
+
*/
|
|
13
|
+
function walkDir(dir, rootDir) {
|
|
14
|
+
const results = [];
|
|
15
|
+
const absDir = path.join(rootDir, dir);
|
|
16
|
+
if (!fs.existsSync(absDir)) {
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
const entries = fs.readdirSync(absDir, { withFileTypes: true });
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
const relPath = `${dir}/${entry.name}`;
|
|
22
|
+
if (entry.isDirectory()) {
|
|
23
|
+
results.push(...walkDir(relPath, rootDir));
|
|
24
|
+
} else {
|
|
25
|
+
results.push(relPath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return results;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Recursively collect all subdirectory paths under a directory.
|
|
33
|
+
* Returns leaf-first ordering suitable for bottom-up deletion.
|
|
34
|
+
* @param {string} dir - Relative directory path (forward-slash separated)
|
|
35
|
+
* @param {string} rootDir - Absolute path to the project root
|
|
36
|
+
* @returns {string[]} Relative subdirectory paths, deepest first within each subtree
|
|
37
|
+
*/
|
|
38
|
+
function walkSubdirs(dir, rootDir) {
|
|
39
|
+
const results = [];
|
|
40
|
+
const absDir = path.join(rootDir, dir);
|
|
41
|
+
if (!fs.existsSync(absDir)) {
|
|
42
|
+
return results;
|
|
43
|
+
}
|
|
44
|
+
const entries = fs.readdirSync(absDir, { withFileTypes: true });
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
if (!entry.isDirectory()) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const relPath = `${dir}/${entry.name}`;
|
|
50
|
+
results.push(...walkSubdirs(relPath, rootDir));
|
|
51
|
+
results.push(relPath);
|
|
52
|
+
}
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Prune stale generated files and empty directories from owned directories.
|
|
58
|
+
*
|
|
59
|
+
* Walks each owned directory, identifies files not present in the manifest path set,
|
|
60
|
+
* deletes them, then removes any empty directories left behind (deepest first).
|
|
61
|
+
*
|
|
62
|
+
* @param {Object} opts
|
|
63
|
+
* @param {string} opts.rootDir - Absolute path to the project root
|
|
64
|
+
* @param {Set<string>} opts.manifestPaths - Set of all valid manifest output paths (forward-slash relative)
|
|
65
|
+
* @param {string[]} opts.ownedDirs - Relative directory paths the generator owns
|
|
66
|
+
* @returns {{ pruned: string[], emptyDirsRemoved: string[] }}
|
|
67
|
+
*/
|
|
68
|
+
function pruneStaleFiles({ rootDir, manifestPaths, ownedDirs }) {
|
|
69
|
+
const pruned = [];
|
|
70
|
+
const emptyDirsRemoved = [];
|
|
71
|
+
|
|
72
|
+
const allOwnedFiles = [];
|
|
73
|
+
for (const dir of ownedDirs) {
|
|
74
|
+
allOwnedFiles.push(...walkDir(dir, rootDir));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const staleFiles = allOwnedFiles.filter((filePath) => !manifestPaths.has(filePath));
|
|
78
|
+
for (const filePath of staleFiles) {
|
|
79
|
+
fs.unlinkSync(path.join(rootDir, filePath));
|
|
80
|
+
pruned.push(filePath);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const ownedSubdirs = ownedDirs
|
|
84
|
+
.flatMap((dir) => walkSubdirs(dir, rootDir))
|
|
85
|
+
.sort((a, b) => b.length - a.length);
|
|
86
|
+
|
|
87
|
+
for (const dir of ownedSubdirs) {
|
|
88
|
+
const absDir = path.join(rootDir, dir);
|
|
89
|
+
if (!fs.existsSync(absDir)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (fs.readdirSync(absDir).length === 0) {
|
|
93
|
+
fs.rmdirSync(absDir);
|
|
94
|
+
emptyDirsRemoved.push(dir);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return { pruned, emptyDirsRemoved };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = { pruneStaleFiles };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { log } = require('../../core/logger');
|
|
4
|
+
const hookState = require('./hook-state');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* After-agent hook logic (runtime-agnostic).
|
|
8
|
+
*
|
|
9
|
+
* Field name mapping: the Gemini adapter maps ctx.promptResponse → ctx.agentResult
|
|
10
|
+
* before calling this function.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} ctx - Internal context contract
|
|
13
|
+
* @param {string} ctx.sessionId
|
|
14
|
+
* @param {string|null} ctx.agentResult - the agent response text
|
|
15
|
+
* @param {boolean} ctx.stopHookActive
|
|
16
|
+
* @returns {{ action: string, message: null, reason: string|null }}
|
|
17
|
+
*/
|
|
18
|
+
function handleAfterAgent(ctx) {
|
|
19
|
+
const agentName = hookState.getActiveAgent(ctx.sessionId);
|
|
20
|
+
if (!agentName) {
|
|
21
|
+
hookState.clearActiveAgent(ctx.sessionId);
|
|
22
|
+
return { action: 'allow', message: null, reason: null };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const agentResult = ctx.agentResult || '';
|
|
26
|
+
const hasTaskReport = agentResult.includes('## Task Report') || agentResult.includes('# Task Report');
|
|
27
|
+
const hasDownstream = agentResult.includes('## Downstream Context') || agentResult.includes('# Downstream Context');
|
|
28
|
+
|
|
29
|
+
const warnings = [];
|
|
30
|
+
if (!hasTaskReport) warnings.push('Missing Task Report section (expected ## Task Report heading)');
|
|
31
|
+
if (!hasDownstream) warnings.push('Missing Downstream Context section (expected ## Downstream Context heading)');
|
|
32
|
+
|
|
33
|
+
if (warnings.length > 0) {
|
|
34
|
+
const reason = warnings.join('; ');
|
|
35
|
+
if (ctx.stopHookActive) {
|
|
36
|
+
log('WARN', `AfterAgent [${agentName}]: Retry still malformed: ${reason} — allowing to prevent infinite loop`);
|
|
37
|
+
} else {
|
|
38
|
+
log('WARN', `AfterAgent [${agentName}]: WARN: ${reason} — requesting retry`);
|
|
39
|
+
hookState.clearActiveAgent(ctx.sessionId);
|
|
40
|
+
return {
|
|
41
|
+
action: 'deny',
|
|
42
|
+
message: null,
|
|
43
|
+
reason: `Handoff report validation failed: ${reason}. Please include both a ## Task Report section and a ## Downstream Context section in your response.`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
log('INFO', `AfterAgent [${agentName}]: Handoff report validated`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
hookState.clearActiveAgent(ctx.sessionId);
|
|
51
|
+
return { action: 'allow', message: null, reason: null };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = { handleAfterAgent };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { log } = require('../../core/logger');
|
|
4
|
+
const { detectAgentFromPrompt, normalizeAgentName } = require('../../core/agent-registry');
|
|
5
|
+
const { assertSessionId } = require('../../lib/validation');
|
|
6
|
+
const { readFileSafe } = require('../../lib/io');
|
|
7
|
+
const hookState = require('./hook-state');
|
|
8
|
+
const state = require('../../state/session-state');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Before-agent hook logic (runtime-agnostic).
|
|
12
|
+
*
|
|
13
|
+
* Field name mapping: the Gemini adapter maps ctx.prompt → ctx.agentInput
|
|
14
|
+
* before calling this function.
|
|
15
|
+
*
|
|
16
|
+
* @param {object} ctx - Internal context contract
|
|
17
|
+
* @param {string} ctx.sessionId
|
|
18
|
+
* @param {string} ctx.cwd
|
|
19
|
+
* @param {string|null} ctx.agentInput - the agent prompt text
|
|
20
|
+
* @param {string} [ctx.event] - hook event name (used in context message)
|
|
21
|
+
* @returns {{ action: string, message: string|null, reason: null }}
|
|
22
|
+
*/
|
|
23
|
+
function handleBeforeAgent(ctx) {
|
|
24
|
+
hookState.pruneStale();
|
|
25
|
+
|
|
26
|
+
const agentName = detectAgentFromPrompt(ctx.agentInput) || normalizeAgentName(ctx.agentName);
|
|
27
|
+
|
|
28
|
+
let validSession = false;
|
|
29
|
+
try { assertSessionId(ctx.sessionId); validSession = true; } catch (_) {}
|
|
30
|
+
|
|
31
|
+
if (agentName && validSession) {
|
|
32
|
+
hookState.setActiveAgent(ctx.sessionId, agentName);
|
|
33
|
+
log('INFO', `BeforeAgent: Detected agent '${agentName}' — set active agent [session=${ctx.sessionId}]`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const sessionPath = state.resolveActiveSessionPath(ctx.cwd);
|
|
37
|
+
let contextParts = '';
|
|
38
|
+
|
|
39
|
+
const content = readFileSafe(sessionPath, '');
|
|
40
|
+
if (content) {
|
|
41
|
+
const parts = [];
|
|
42
|
+
const phaseMatch = content.match(/current_phase:\s*(\S+)/);
|
|
43
|
+
if (phaseMatch) parts.push(`current_phase=${phaseMatch[1]}`);
|
|
44
|
+
const statusMatch = content.match(/status:\s*(\S+)/);
|
|
45
|
+
if (statusMatch) parts.push(`status=${statusMatch[1]}`);
|
|
46
|
+
if (parts.length > 0) {
|
|
47
|
+
contextParts = `Active session: ${parts.join(', ')}`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (contextParts) {
|
|
52
|
+
return { action: 'allow', message: contextParts, reason: null };
|
|
53
|
+
}
|
|
54
|
+
return { action: 'allow', message: null, reason: null };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = { handleBeforeAgent };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const { log } = require('../../core/logger');
|
|
7
|
+
const { assertSessionId } = require('../../lib/validation');
|
|
8
|
+
const { atomicWriteSync, readFileSafe } = require('../../lib/io');
|
|
9
|
+
|
|
10
|
+
const HOOK_STATE_TTL_MS = 2 * 60 * 60 * 1000;
|
|
11
|
+
|
|
12
|
+
const uid = process.getuid ? process.getuid() : 'default';
|
|
13
|
+
const DEFAULT_BASE_DIR = process.env.MAESTRO_HOOKS_DIR
|
|
14
|
+
|| path.join(os.tmpdir(), `maestro-hooks-${uid}`);
|
|
15
|
+
|
|
16
|
+
function ensureBaseDir(dir) {
|
|
17
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
18
|
+
const stats = fs.lstatSync(dir);
|
|
19
|
+
if (stats.isSymbolicLink()) {
|
|
20
|
+
throw new Error('Hook state directory must not be a symlink');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createHookState(baseDir = DEFAULT_BASE_DIR) {
|
|
25
|
+
function getBaseDir() {
|
|
26
|
+
return baseDir;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pruneStale() {
|
|
30
|
+
ensureBaseDir(baseDir);
|
|
31
|
+
if (!fs.existsSync(baseDir)) return;
|
|
32
|
+
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
let entries;
|
|
35
|
+
try {
|
|
36
|
+
entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const entry of entries) {
|
|
42
|
+
if (!entry.isDirectory()) continue;
|
|
43
|
+
const dirPath = path.join(baseDir, entry.name);
|
|
44
|
+
try {
|
|
45
|
+
const stat = fs.lstatSync(dirPath);
|
|
46
|
+
if (now - stat.mtimeMs > HOOK_STATE_TTL_MS) {
|
|
47
|
+
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function setActiveAgent(sessionId, agentName) {
|
|
54
|
+
try {
|
|
55
|
+
assertSessionId(sessionId);
|
|
56
|
+
} catch {
|
|
57
|
+
log('ERROR', 'Invalid session_id: contains unsafe characters');
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const agentFile = path.join(baseDir, sessionId, 'active-agent');
|
|
61
|
+
atomicWriteSync(agentFile, agentName);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getActiveAgent(sessionId) {
|
|
66
|
+
try {
|
|
67
|
+
assertSessionId(sessionId);
|
|
68
|
+
} catch {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
const agentFile = path.join(baseDir, sessionId, 'active-agent');
|
|
72
|
+
return readFileSafe(agentFile, '').trim();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function clearActiveAgent(sessionId) {
|
|
76
|
+
try {
|
|
77
|
+
assertSessionId(sessionId);
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const agentFile = path.join(baseDir, sessionId, 'active-agent');
|
|
82
|
+
try {
|
|
83
|
+
fs.unlinkSync(agentFile);
|
|
84
|
+
} catch {}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function ensureSessionDir(sessionId) {
|
|
88
|
+
try {
|
|
89
|
+
assertSessionId(sessionId);
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
ensureBaseDir(baseDir);
|
|
94
|
+
fs.mkdirSync(path.join(baseDir, sessionId), { recursive: true, mode: 0o700 });
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function removeSessionDir(sessionId) {
|
|
99
|
+
try {
|
|
100
|
+
assertSessionId(sessionId);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
fs.rmSync(path.join(baseDir, sessionId), { recursive: true, force: true });
|
|
106
|
+
} catch {}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
getBaseDir,
|
|
112
|
+
pruneStale,
|
|
113
|
+
setActiveAgent,
|
|
114
|
+
getActiveAgent,
|
|
115
|
+
clearActiveAgent,
|
|
116
|
+
ensureSessionDir,
|
|
117
|
+
removeSessionDir,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const defaultInstance = createHookState();
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
createHookState,
|
|
125
|
+
DEFAULT_BASE_DIR,
|
|
126
|
+
...defaultInstance,
|
|
127
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const hookState = require('./hook-state');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Session-end hook logic (runtime-agnostic).
|
|
7
|
+
*
|
|
8
|
+
* @param {object} ctx - Internal context contract
|
|
9
|
+
* @param {string} ctx.sessionId
|
|
10
|
+
* @returns {{ action: string, message: null, reason: null }}
|
|
11
|
+
*/
|
|
12
|
+
function handleSessionEnd(ctx) {
|
|
13
|
+
hookState.removeSessionDir(ctx.sessionId);
|
|
14
|
+
return { action: 'advisory', message: null, reason: null };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { handleSessionEnd };
|