squadfoundry 0.1.0
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.md +76 -0
- package/PROJECT.md +79 -0
- package/README.md +255 -0
- package/dist/orchestrator/adapters/context/IContextAdapter.d.ts +65 -0
- package/dist/orchestrator/adapters/context/IContextAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/context/IContextAdapter.js +12 -0
- package/dist/orchestrator/adapters/context/IContextAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/context/filesystem.context-adapter.d.ts +33 -0
- package/dist/orchestrator/adapters/context/filesystem.context-adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/context/filesystem.context-adapter.js +179 -0
- package/dist/orchestrator/adapters/context/filesystem.context-adapter.js.map +1 -0
- package/dist/orchestrator/adapters/deploy/IDeployAdapter.d.ts +78 -0
- package/dist/orchestrator/adapters/deploy/IDeployAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/deploy/IDeployAdapter.js +14 -0
- package/dist/orchestrator/adapters/deploy/IDeployAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/deploy/vercel.adapter.d.ts +31 -0
- package/dist/orchestrator/adapters/deploy/vercel.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/deploy/vercel.adapter.js +83 -0
- package/dist/orchestrator/adapters/deploy/vercel.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/IHostAdapter.d.ts +89 -0
- package/dist/orchestrator/adapters/host/IHostAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/IHostAdapter.js +10 -0
- package/dist/orchestrator/adapters/host/IHostAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/anthropic.adapter.d.ts +27 -0
- package/dist/orchestrator/adapters/host/anthropic.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/anthropic.adapter.js +118 -0
- package/dist/orchestrator/adapters/host/anthropic.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/antigravity.adapter.d.ts +53 -0
- package/dist/orchestrator/adapters/host/antigravity.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/antigravity.adapter.js +148 -0
- package/dist/orchestrator/adapters/host/antigravity.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/claude-code.adapter.d.ts +13 -0
- package/dist/orchestrator/adapters/host/claude-code.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/claude-code.adapter.js +27 -0
- package/dist/orchestrator/adapters/host/claude-code.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/command-model-invoker.d.ts +8 -0
- package/dist/orchestrator/adapters/host/command-model-invoker.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/command-model-invoker.js +46 -0
- package/dist/orchestrator/adapters/host/command-model-invoker.js.map +1 -0
- package/dist/orchestrator/adapters/host/ide.adapter.d.ts +61 -0
- package/dist/orchestrator/adapters/host/ide.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/ide.adapter.js +173 -0
- package/dist/orchestrator/adapters/host/ide.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/local.adapter.d.ts +26 -0
- package/dist/orchestrator/adapters/host/local.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/local.adapter.js +82 -0
- package/dist/orchestrator/adapters/host/local.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/openai.adapter.d.ts +26 -0
- package/dist/orchestrator/adapters/host/openai.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/openai.adapter.js +77 -0
- package/dist/orchestrator/adapters/host/openai.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/host/opencode.adapter.d.ts +13 -0
- package/dist/orchestrator/adapters/host/opencode.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/host/opencode.adapter.js +27 -0
- package/dist/orchestrator/adapters/host/opencode.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/model/IModelAdapter.d.ts +68 -0
- package/dist/orchestrator/adapters/model/IModelAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/model/IModelAdapter.js +11 -0
- package/dist/orchestrator/adapters/model/IModelAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/publishing/ISocialMediaAdapter.d.ts +93 -0
- package/dist/orchestrator/adapters/publishing/ISocialMediaAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/publishing/ISocialMediaAdapter.js +10 -0
- package/dist/orchestrator/adapters/publishing/ISocialMediaAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/publishing/instagram.adapter.d.ts +34 -0
- package/dist/orchestrator/adapters/publishing/instagram.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/publishing/instagram.adapter.js +105 -0
- package/dist/orchestrator/adapters/publishing/instagram.adapter.js.map +1 -0
- package/dist/orchestrator/adapters/tools/IToolAdapter.d.ts +52 -0
- package/dist/orchestrator/adapters/tools/IToolAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/tools/IToolAdapter.js +10 -0
- package/dist/orchestrator/adapters/tools/IToolAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/vcs/IVCSAdapter.d.ts +89 -0
- package/dist/orchestrator/adapters/vcs/IVCSAdapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/vcs/IVCSAdapter.js +11 -0
- package/dist/orchestrator/adapters/vcs/IVCSAdapter.js.map +1 -0
- package/dist/orchestrator/adapters/vcs/github.adapter.d.ts +36 -0
- package/dist/orchestrator/adapters/vcs/github.adapter.d.ts.map +1 -0
- package/dist/orchestrator/adapters/vcs/github.adapter.js +110 -0
- package/dist/orchestrator/adapters/vcs/github.adapter.js.map +1 -0
- package/dist/orchestrator/artifacts/artifact-store.d.ts +47 -0
- package/dist/orchestrator/artifacts/artifact-store.d.ts.map +1 -0
- package/dist/orchestrator/artifacts/artifact-store.js +135 -0
- package/dist/orchestrator/artifacts/artifact-store.js.map +1 -0
- package/dist/orchestrator/builder/domain-classifier.d.ts +24 -0
- package/dist/orchestrator/builder/domain-classifier.d.ts.map +1 -0
- package/dist/orchestrator/builder/domain-classifier.js +156 -0
- package/dist/orchestrator/builder/domain-classifier.js.map +1 -0
- package/dist/orchestrator/builder/interview-questions.d.ts +13 -0
- package/dist/orchestrator/builder/interview-questions.d.ts.map +1 -0
- package/dist/orchestrator/builder/interview-questions.js +127 -0
- package/dist/orchestrator/builder/interview-questions.js.map +1 -0
- package/dist/orchestrator/builder/squad-builder.d.ts +53 -0
- package/dist/orchestrator/builder/squad-builder.d.ts.map +1 -0
- package/dist/orchestrator/builder/squad-builder.js +107 -0
- package/dist/orchestrator/builder/squad-builder.js.map +1 -0
- package/dist/orchestrator/builder/squad-generator.d.ts +33 -0
- package/dist/orchestrator/builder/squad-generator.d.ts.map +1 -0
- package/dist/orchestrator/builder/squad-generator.js +360 -0
- package/dist/orchestrator/builder/squad-generator.js.map +1 -0
- package/dist/orchestrator/cli/index.d.ts +3 -0
- package/dist/orchestrator/cli/index.d.ts.map +1 -0
- package/dist/orchestrator/cli/index.js +8 -0
- package/dist/orchestrator/cli/index.js.map +1 -0
- package/dist/orchestrator/context/context-index.d.ts +48 -0
- package/dist/orchestrator/context/context-index.d.ts.map +1 -0
- package/dist/orchestrator/context/context-index.js +116 -0
- package/dist/orchestrator/context/context-index.js.map +1 -0
- package/dist/orchestrator/context/context-loader.d.ts +49 -0
- package/dist/orchestrator/context/context-loader.d.ts.map +1 -0
- package/dist/orchestrator/context/context-loader.js +111 -0
- package/dist/orchestrator/context/context-loader.js.map +1 -0
- package/dist/orchestrator/core/guardrails.d.ts +33 -0
- package/dist/orchestrator/core/guardrails.d.ts.map +1 -0
- package/dist/orchestrator/core/guardrails.js +272 -0
- package/dist/orchestrator/core/guardrails.js.map +1 -0
- package/dist/orchestrator/core/state-machine.d.ts +65 -0
- package/dist/orchestrator/core/state-machine.d.ts.map +1 -0
- package/dist/orchestrator/core/state-machine.js +227 -0
- package/dist/orchestrator/core/state-machine.js.map +1 -0
- package/dist/orchestrator/core/types.d.ts +364 -0
- package/dist/orchestrator/core/types.d.ts.map +1 -0
- package/dist/orchestrator/core/types.js +10 -0
- package/dist/orchestrator/core/types.js.map +1 -0
- package/dist/orchestrator/index.d.ts +75 -0
- package/dist/orchestrator/index.d.ts.map +1 -0
- package/dist/orchestrator/index.js +64 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/orchestrator/mcp/server.d.ts +35 -0
- package/dist/orchestrator/mcp/server.d.ts.map +1 -0
- package/dist/orchestrator/mcp/server.js +378 -0
- package/dist/orchestrator/mcp/server.js.map +1 -0
- package/dist/orchestrator/runtime/agent-dispatcher.d.ts +25 -0
- package/dist/orchestrator/runtime/agent-dispatcher.d.ts.map +1 -0
- package/dist/orchestrator/runtime/agent-dispatcher.js +82 -0
- package/dist/orchestrator/runtime/agent-dispatcher.js.map +1 -0
- package/dist/orchestrator/runtime/approval-gate.d.ts +55 -0
- package/dist/orchestrator/runtime/approval-gate.d.ts.map +1 -0
- package/dist/orchestrator/runtime/approval-gate.js +104 -0
- package/dist/orchestrator/runtime/approval-gate.js.map +1 -0
- package/dist/orchestrator/runtime/handoff-manager.d.ts +29 -0
- package/dist/orchestrator/runtime/handoff-manager.d.ts.map +1 -0
- package/dist/orchestrator/runtime/handoff-manager.js +80 -0
- package/dist/orchestrator/runtime/handoff-manager.js.map +1 -0
- package/dist/orchestrator/runtime/job-manager.d.ts +39 -0
- package/dist/orchestrator/runtime/job-manager.d.ts.map +1 -0
- package/dist/orchestrator/runtime/job-manager.js +132 -0
- package/dist/orchestrator/runtime/job-manager.js.map +1 -0
- package/dist/orchestrator/runtime/squad-runtime.d.ts +70 -0
- package/dist/orchestrator/runtime/squad-runtime.d.ts.map +1 -0
- package/dist/orchestrator/runtime/squad-runtime.js +249 -0
- package/dist/orchestrator/runtime/squad-runtime.js.map +1 -0
- package/dist/orchestrator/shell/cli.d.ts +4 -0
- package/dist/orchestrator/shell/cli.d.ts.map +1 -0
- package/dist/orchestrator/shell/cli.js +27 -0
- package/dist/orchestrator/shell/cli.js.map +1 -0
- package/dist/orchestrator/shell/commands/create.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/create.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/create.command.js +41 -0
- package/dist/orchestrator/shell/commands/create.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/edit.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/edit.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/edit.command.js +49 -0
- package/dist/orchestrator/shell/commands/edit.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/hosts.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/hosts.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/hosts.command.js +27 -0
- package/dist/orchestrator/shell/commands/hosts.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/init.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/init.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/init.command.js +13 -0
- package/dist/orchestrator/shell/commands/init.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/list.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/list.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/list.command.js +18 -0
- package/dist/orchestrator/shell/commands/list.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/run.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/run.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/run.command.js +71 -0
- package/dist/orchestrator/shell/commands/run.command.js.map +1 -0
- package/dist/orchestrator/shell/commands/status.command.d.ts +3 -0
- package/dist/orchestrator/shell/commands/status.command.d.ts.map +1 -0
- package/dist/orchestrator/shell/commands/status.command.js +29 -0
- package/dist/orchestrator/shell/commands/status.command.js.map +1 -0
- package/dist/orchestrator/shell/services/active-host-detector.service.d.ts +25 -0
- package/dist/orchestrator/shell/services/active-host-detector.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/active-host-detector.service.js +128 -0
- package/dist/orchestrator/shell/services/active-host-detector.service.js.map +1 -0
- package/dist/orchestrator/shell/services/host-resolution.service.d.ts +42 -0
- package/dist/orchestrator/shell/services/host-resolution.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/host-resolution.service.js +108 -0
- package/dist/orchestrator/shell/services/host-resolution.service.js.map +1 -0
- package/dist/orchestrator/shell/services/host-runtime.service.d.ts +23 -0
- package/dist/orchestrator/shell/services/host-runtime.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/host-runtime.service.js +167 -0
- package/dist/orchestrator/shell/services/host-runtime.service.js.map +1 -0
- package/dist/orchestrator/shell/services/interview-host-bridge.service.d.ts +14 -0
- package/dist/orchestrator/shell/services/interview-host-bridge.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/interview-host-bridge.service.js +16 -0
- package/dist/orchestrator/shell/services/interview-host-bridge.service.js.map +1 -0
- package/dist/orchestrator/shell/services/job-execution.service.d.ts +22 -0
- package/dist/orchestrator/shell/services/job-execution.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/job-execution.service.js +39 -0
- package/dist/orchestrator/shell/services/job-execution.service.js.map +1 -0
- package/dist/orchestrator/shell/services/project-bootstrap.service.d.ts +6 -0
- package/dist/orchestrator/shell/services/project-bootstrap.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/project-bootstrap.service.js +111 -0
- package/dist/orchestrator/shell/services/project-bootstrap.service.js.map +1 -0
- package/dist/orchestrator/shell/services/squad-scaffold.service.d.ts +3 -0
- package/dist/orchestrator/shell/services/squad-scaffold.service.d.ts.map +1 -0
- package/dist/orchestrator/shell/services/squad-scaffold.service.js +30 -0
- package/dist/orchestrator/shell/services/squad-scaffold.service.js.map +1 -0
- package/dist/tests/integration/instagram-squad.test.d.ts +8 -0
- package/dist/tests/integration/instagram-squad.test.d.ts.map +1 -0
- package/dist/tests/integration/instagram-squad.test.js +187 -0
- package/dist/tests/integration/instagram-squad.test.js.map +1 -0
- package/dist/tests/integration/shell/cli-run-host-native.test.d.ts +2 -0
- package/dist/tests/integration/shell/cli-run-host-native.test.d.ts.map +1 -0
- package/dist/tests/integration/shell/cli-run-host-native.test.js +42 -0
- package/dist/tests/integration/shell/cli-run-host-native.test.js.map +1 -0
- package/dist/tests/integration/software-squad.test.d.ts +8 -0
- package/dist/tests/integration/software-squad.test.d.ts.map +1 -0
- package/dist/tests/integration/software-squad.test.js +207 -0
- package/dist/tests/integration/software-squad.test.js.map +1 -0
- package/dist/tests/unit/artifact-store.test.d.ts +2 -0
- package/dist/tests/unit/artifact-store.test.d.ts.map +1 -0
- package/dist/tests/unit/artifact-store.test.js +137 -0
- package/dist/tests/unit/artifact-store.test.js.map +1 -0
- package/dist/tests/unit/context-loader.test.d.ts +2 -0
- package/dist/tests/unit/context-loader.test.d.ts.map +1 -0
- package/dist/tests/unit/context-loader.test.js +109 -0
- package/dist/tests/unit/context-loader.test.js.map +1 -0
- package/dist/tests/unit/docs/host-native-docs.test.d.ts +2 -0
- package/dist/tests/unit/docs/host-native-docs.test.d.ts.map +1 -0
- package/dist/tests/unit/docs/host-native-docs.test.js +18 -0
- package/dist/tests/unit/docs/host-native-docs.test.js.map +1 -0
- package/dist/tests/unit/guardrails.test.d.ts +2 -0
- package/dist/tests/unit/guardrails.test.d.ts.map +1 -0
- package/dist/tests/unit/guardrails.test.js +202 -0
- package/dist/tests/unit/guardrails.test.js.map +1 -0
- package/dist/tests/unit/host/host-adapter-contract.test.d.ts +2 -0
- package/dist/tests/unit/host/host-adapter-contract.test.d.ts.map +1 -0
- package/dist/tests/unit/host/host-adapter-contract.test.js +53 -0
- package/dist/tests/unit/host/host-adapter-contract.test.js.map +1 -0
- package/dist/tests/unit/host/ide.adapter.test.d.ts +2 -0
- package/dist/tests/unit/host/ide.adapter.test.d.ts.map +1 -0
- package/dist/tests/unit/host/ide.adapter.test.js +17 -0
- package/dist/tests/unit/host/ide.adapter.test.js.map +1 -0
- package/dist/tests/unit/host/native-ide-adapters.test.d.ts +2 -0
- package/dist/tests/unit/host/native-ide-adapters.test.d.ts.map +1 -0
- package/dist/tests/unit/host/native-ide-adapters.test.js +26 -0
- package/dist/tests/unit/host/native-ide-adapters.test.js.map +1 -0
- package/dist/tests/unit/runtime/squad-runtime-host-metadata.test.d.ts +2 -0
- package/dist/tests/unit/runtime/squad-runtime-host-metadata.test.d.ts.map +1 -0
- package/dist/tests/unit/runtime/squad-runtime-host-metadata.test.js +128 -0
- package/dist/tests/unit/runtime/squad-runtime-host-metadata.test.js.map +1 -0
- package/dist/tests/unit/shell/active-host-detector.test.d.ts +2 -0
- package/dist/tests/unit/shell/active-host-detector.test.d.ts.map +1 -0
- package/dist/tests/unit/shell/active-host-detector.test.js +85 -0
- package/dist/tests/unit/shell/active-host-detector.test.js.map +1 -0
- package/dist/tests/unit/shell/host-resolution.service.test.d.ts +2 -0
- package/dist/tests/unit/shell/host-resolution.service.test.d.ts.map +1 -0
- package/dist/tests/unit/shell/host-resolution.service.test.js +252 -0
- package/dist/tests/unit/shell/host-resolution.service.test.js.map +1 -0
- package/dist/tests/unit/shell/interview-host-bridge.test.d.ts +2 -0
- package/dist/tests/unit/shell/interview-host-bridge.test.d.ts.map +1 -0
- package/dist/tests/unit/shell/interview-host-bridge.test.js +58 -0
- package/dist/tests/unit/shell/interview-host-bridge.test.js.map +1 -0
- package/dist/tests/unit/shell/project-bootstrap.service.test.d.ts +2 -0
- package/dist/tests/unit/shell/project-bootstrap.service.test.d.ts.map +1 -0
- package/dist/tests/unit/shell/project-bootstrap.service.test.js +58 -0
- package/dist/tests/unit/shell/project-bootstrap.service.test.js.map +1 -0
- package/dist/tests/unit/shell/squad-scaffold.service.test.d.ts +2 -0
- package/dist/tests/unit/shell/squad-scaffold.service.test.d.ts.map +1 -0
- package/dist/tests/unit/shell/squad-scaffold.service.test.js +40 -0
- package/dist/tests/unit/shell/squad-scaffold.service.test.js.map +1 -0
- package/dist/tests/unit/squad-builder.test.d.ts +2 -0
- package/dist/tests/unit/squad-builder.test.d.ts.map +1 -0
- package/dist/tests/unit/squad-builder.test.js +126 -0
- package/dist/tests/unit/squad-builder.test.js.map +1 -0
- package/dist/tests/unit/state-machine.test.d.ts +2 -0
- package/dist/tests/unit/state-machine.test.d.ts.map +1 -0
- package/dist/tests/unit/state-machine.test.js +133 -0
- package/dist/tests/unit/state-machine.test.js.map +1 -0
- package/docs/architecture/overview.md +115 -0
- package/docs/development/adding-agents.md +75 -0
- package/docs/development/adding-hosts.md +104 -0
- package/docs/development/adding-integrations.md +83 -0
- package/docs/development/host-detection-and-resolution.md +59 -0
- package/docs/squads/how-to-create.md +85 -0
- package/docs/squads/how-to-execute.md +139 -0
- package/docs/superpowers/plans/2026-04-01-host-native-cli-shell-implementation.md +617 -0
- package/docs/superpowers/specs/2026-04-01-host-native-cli-shell-design.md +253 -0
- package/package.json +103 -0
- package/squads/examples/instagram-content/AGENTS.md +63 -0
- package/squads/examples/instagram-content/POLICIES.md +45 -0
- package/squads/examples/instagram-content/SQUAD.md +63 -0
- package/squads/examples/instagram-content/WORKFLOW.md +58 -0
- package/squads/examples/instagram-content/config/squad.json +474 -0
- package/squads/examples/software-development/AGENTS.md +88 -0
- package/squads/examples/software-development/POLICIES.md +44 -0
- package/squads/examples/software-development/SQUAD.md +65 -0
- package/squads/examples/software-development/WORKFLOW.md +78 -0
- package/squads/examples/software-development/config/squad.json +442 -0
- package/templates/AGENTS.md +46 -0
- package/templates/POLICIES.md +24 -0
- package/templates/PROJECT.md +52 -0
- package/templates/SQUAD.md +52 -0
- package/templates/TASKS.md +31 -0
- package/templates/WORKFLOW.md +35 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContextIndex
|
|
3
|
+
*
|
|
4
|
+
* In-memory index of loaded context files with fast lookup by category and path.
|
|
5
|
+
* Constructed from a LoadedContext object and provides query methods used
|
|
6
|
+
* by the Squad Builder (during squad generation) and Squad Runtime (during execution).
|
|
7
|
+
*/
|
|
8
|
+
export class ContextIndex {
|
|
9
|
+
files = [];
|
|
10
|
+
projectMd;
|
|
11
|
+
tasksMd;
|
|
12
|
+
agentsMd;
|
|
13
|
+
readmeMd;
|
|
14
|
+
constructor(ctx) {
|
|
15
|
+
this.projectMd = ctx.projectMd;
|
|
16
|
+
this.tasksMd = ctx.tasksMd;
|
|
17
|
+
this.agentsMd = ctx.agentsMd;
|
|
18
|
+
this.readmeMd = ctx.readmeMd;
|
|
19
|
+
// Index named files
|
|
20
|
+
if (ctx.projectMd) {
|
|
21
|
+
this.files.push(this.makeEntry('PROJECT.md', 'project', ctx.projectMd));
|
|
22
|
+
}
|
|
23
|
+
if (ctx.tasksMd) {
|
|
24
|
+
this.files.push(this.makeEntry('TASKS.md', 'tasks', ctx.tasksMd));
|
|
25
|
+
}
|
|
26
|
+
if (ctx.agentsMd) {
|
|
27
|
+
this.files.push(this.makeEntry('AGENTS.md', 'agents', ctx.agentsMd));
|
|
28
|
+
}
|
|
29
|
+
if (ctx.readmeMd) {
|
|
30
|
+
this.files.push(this.makeEntry('README.md', 'readme', ctx.readmeMd));
|
|
31
|
+
}
|
|
32
|
+
// Index category arrays
|
|
33
|
+
for (const f of ctx.docs)
|
|
34
|
+
this.files.push(this.fromFileContent(f, 'docs'));
|
|
35
|
+
for (const f of ctx.specs)
|
|
36
|
+
this.files.push(this.fromFileContent(f, 'specs'));
|
|
37
|
+
for (const f of ctx.playbooks)
|
|
38
|
+
this.files.push(this.fromFileContent(f, 'playbooks'));
|
|
39
|
+
for (const f of ctx.policies)
|
|
40
|
+
this.files.push(this.fromFileContent(f, 'policies'));
|
|
41
|
+
for (const f of ctx.templates)
|
|
42
|
+
this.files.push(this.fromFileContent(f, 'templates'));
|
|
43
|
+
for (const f of ctx.custom)
|
|
44
|
+
this.files.push(this.fromFileContent(f, 'custom'));
|
|
45
|
+
}
|
|
46
|
+
makeEntry(path, category, content) {
|
|
47
|
+
return {
|
|
48
|
+
path,
|
|
49
|
+
category,
|
|
50
|
+
content,
|
|
51
|
+
loadedAt: new Date().toISOString(),
|
|
52
|
+
sizeChars: content.length,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
fromFileContent(f, category) {
|
|
56
|
+
return {
|
|
57
|
+
path: f.path,
|
|
58
|
+
category,
|
|
59
|
+
content: f.content,
|
|
60
|
+
loadedAt: f.loadedAt,
|
|
61
|
+
sizeChars: f.content.length,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ─── Query Methods ─────────────────────────────────────────────────────────
|
|
65
|
+
/** Get all indexed files */
|
|
66
|
+
all() {
|
|
67
|
+
return this.files;
|
|
68
|
+
}
|
|
69
|
+
/** Get files by category */
|
|
70
|
+
byCategory(category) {
|
|
71
|
+
return this.files.filter((f) => f.category === category);
|
|
72
|
+
}
|
|
73
|
+
/** Get a file by its path */
|
|
74
|
+
byPath(path) {
|
|
75
|
+
return this.files.find((f) => f.path === path);
|
|
76
|
+
}
|
|
77
|
+
/** Get PROJECT.md content */
|
|
78
|
+
getProjectMd() {
|
|
79
|
+
return this.projectMd;
|
|
80
|
+
}
|
|
81
|
+
/** Get TASKS.md content */
|
|
82
|
+
getTasksMd() {
|
|
83
|
+
return this.tasksMd;
|
|
84
|
+
}
|
|
85
|
+
/** Get AGENTS.md content */
|
|
86
|
+
getAgentsMd() {
|
|
87
|
+
return this.agentsMd;
|
|
88
|
+
}
|
|
89
|
+
/** Get README.md content */
|
|
90
|
+
getReadmeMd() {
|
|
91
|
+
return this.readmeMd;
|
|
92
|
+
}
|
|
93
|
+
/** Search all indexed content for a keyword */
|
|
94
|
+
search(keyword) {
|
|
95
|
+
const lower = keyword.toLowerCase();
|
|
96
|
+
return this.files.filter((f) => f.path.toLowerCase().includes(lower) ||
|
|
97
|
+
f.content.toLowerCase().includes(lower));
|
|
98
|
+
}
|
|
99
|
+
/** Return a compact stats object */
|
|
100
|
+
stats() {
|
|
101
|
+
const counts = { total: this.files.length };
|
|
102
|
+
for (const f of this.files) {
|
|
103
|
+
counts[f.category] = (counts[f.category] ?? 0) + 1;
|
|
104
|
+
}
|
|
105
|
+
return counts;
|
|
106
|
+
}
|
|
107
|
+
/** Return whether any context was loaded */
|
|
108
|
+
isEmpty() {
|
|
109
|
+
return this.files.length === 0;
|
|
110
|
+
}
|
|
111
|
+
/** Check whether core context files are present */
|
|
112
|
+
hasCoreContext() {
|
|
113
|
+
return !!(this.projectMd ?? this.tasksMd ?? this.readmeMd);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=context-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-index.js","sourceRoot":"","sources":["../../../orchestrator/context/context-index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,MAAM,OAAO,YAAY;IACf,KAAK,GAAkB,EAAE,CAAA;IACzB,SAAS,CAAoB;IAC7B,OAAO,CAAoB;IAC3B,QAAQ,CAAoB;IAC5B,QAAQ,CAAoB;IAEpC,YAAY,GAAkB;QAC5B,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAA;QAC1B,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAA;QAE5B,oBAAoB;QACpB,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YAClB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAA;QACzE,CAAC;QACD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;QACnE,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,EAAE,C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/C,MAAM,CAAC,OAAe;QACpB,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACnC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CACtB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAC1C,CAAA;IACH,CAAC;IAED,oCAAoC;IACpC,KAAK;QACH,MAAM,MAAM,GAA2B,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;QACnE,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;QACpD,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,4CAA4C;IAC5C,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;IAChC,CAAC;IAED,mDAAmD;IACnD,cAAc;QACZ,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5D,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContextLoader
|
|
3
|
+
*
|
|
4
|
+
* High-level service that coordinates context discovery and loading.
|
|
5
|
+
* Uses an IContextAdapter under the hood, defaulting to the filesystem adapter.
|
|
6
|
+
*
|
|
7
|
+
* This is what the Squad Builder and Squad Runtime call to ingest
|
|
8
|
+
* PROJECT.md, TASKS.md, docs/**, etc. before starting any job.
|
|
9
|
+
*/
|
|
10
|
+
import type { IContextAdapter } from '../adapters/context/IContextAdapter.js';
|
|
11
|
+
import type { LoadedContext, ContextDiscoveryResult } from '../core/types.js';
|
|
12
|
+
export interface ContextLoaderOptions {
|
|
13
|
+
/** Root path to scan. Defaults to process.cwd() */
|
|
14
|
+
rootPath?: string;
|
|
15
|
+
/** Max file size in bytes. Defaults to 500KB */
|
|
16
|
+
maxFileSizeBytes?: number;
|
|
17
|
+
/** Custom context adapter. Defaults to FilesystemContextAdapter */
|
|
18
|
+
adapter?: IContextAdapter;
|
|
19
|
+
}
|
|
20
|
+
export declare class ContextLoader {
|
|
21
|
+
private adapter;
|
|
22
|
+
private rootPath;
|
|
23
|
+
private maxFileSizeBytes;
|
|
24
|
+
constructor(options?: ContextLoaderOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Discover all context files without loading their contents.
|
|
27
|
+
* Useful for showing the user what context is available.
|
|
28
|
+
*/
|
|
29
|
+
discover(): Promise<ContextDiscoveryResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Load all discovered context files into a structured LoadedContext.
|
|
32
|
+
* This is the main method called before job execution.
|
|
33
|
+
*/
|
|
34
|
+
load(): Promise<LoadedContext>;
|
|
35
|
+
/**
|
|
36
|
+
* Summarize available context (file counts, missing recommended files, etc.)
|
|
37
|
+
*/
|
|
38
|
+
summarize(): Promise<import("../index.js").ContextSummary>;
|
|
39
|
+
/**
|
|
40
|
+
* Format a LoadedContext into a human-readable summary string.
|
|
41
|
+
* Used to inject context into agent prompts.
|
|
42
|
+
*/
|
|
43
|
+
static formatContextForPrompt(ctx: LoadedContext): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get a compact summary string suitable for display in CLI output.
|
|
46
|
+
*/
|
|
47
|
+
static describeContext(ctx: LoadedContext): string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=context-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-loader.d.ts","sourceRoot":"","sources":["../../../orchestrator/context/context-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAE7E,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,mEAAmE;IACnE,OAAO,CAAC,EAAE,eAAe,CAAA;CAC1B;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,gBAAgB,CAAQ;gBAEpB,OAAO,GAAE,oBAAyB;IAM9C;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,sBAAsB,CAAC;IAOjD;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC;IAOpC;;OAEG;IACG,SAAS;IAIf;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM;IAoCzD;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM;CAcnD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContextLoader
|
|
3
|
+
*
|
|
4
|
+
* High-level service that coordinates context discovery and loading.
|
|
5
|
+
* Uses an IContextAdapter under the hood, defaulting to the filesystem adapter.
|
|
6
|
+
*
|
|
7
|
+
* This is what the Squad Builder and Squad Runtime call to ingest
|
|
8
|
+
* PROJECT.md, TASKS.md, docs/**, etc. before starting any job.
|
|
9
|
+
*/
|
|
10
|
+
import { FilesystemContextAdapter } from '../adapters/context/filesystem.context-adapter.js';
|
|
11
|
+
export class ContextLoader {
|
|
12
|
+
adapter;
|
|
13
|
+
rootPath;
|
|
14
|
+
maxFileSizeBytes;
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.adapter = options.adapter ?? new FilesystemContextAdapter();
|
|
17
|
+
this.rootPath = options.rootPath ?? process.cwd();
|
|
18
|
+
this.maxFileSizeBytes = options.maxFileSizeBytes ?? 512 * 1024;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Discover all context files without loading their contents.
|
|
22
|
+
* Useful for showing the user what context is available.
|
|
23
|
+
*/
|
|
24
|
+
async discover() {
|
|
25
|
+
return this.adapter.discover({
|
|
26
|
+
rootPath: this.rootPath,
|
|
27
|
+
maxFileSizeBytes: this.maxFileSizeBytes,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Load all discovered context files into a structured LoadedContext.
|
|
32
|
+
* This is the main method called before job execution.
|
|
33
|
+
*/
|
|
34
|
+
async load() {
|
|
35
|
+
return this.adapter.load({
|
|
36
|
+
rootPath: this.rootPath,
|
|
37
|
+
maxFileSizeBytes: this.maxFileSizeBytes,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Summarize available context (file counts, missing recommended files, etc.)
|
|
42
|
+
*/
|
|
43
|
+
async summarize() {
|
|
44
|
+
return this.adapter.summarize(this.rootPath);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Format a LoadedContext into a human-readable summary string.
|
|
48
|
+
* Used to inject context into agent prompts.
|
|
49
|
+
*/
|
|
50
|
+
static formatContextForPrompt(ctx) {
|
|
51
|
+
const parts = [];
|
|
52
|
+
if (ctx.projectMd) {
|
|
53
|
+
parts.push(`## PROJECT.md\n${ctx.projectMd}`);
|
|
54
|
+
}
|
|
55
|
+
if (ctx.tasksMd) {
|
|
56
|
+
parts.push(`## TASKS.md\n${ctx.tasksMd}`);
|
|
57
|
+
}
|
|
58
|
+
if (ctx.agentsMd) {
|
|
59
|
+
parts.push(`## AGENTS.md\n${ctx.agentsMd}`);
|
|
60
|
+
}
|
|
61
|
+
if (ctx.readmeMd) {
|
|
62
|
+
parts.push(`## README.md\n${ctx.readmeMd}`);
|
|
63
|
+
}
|
|
64
|
+
for (const doc of ctx.docs) {
|
|
65
|
+
parts.push(`## ${doc.path}\n${doc.content}`);
|
|
66
|
+
}
|
|
67
|
+
for (const spec of ctx.specs) {
|
|
68
|
+
parts.push(`## ${spec.path}\n${spec.content}`);
|
|
69
|
+
}
|
|
70
|
+
for (const pb of ctx.playbooks) {
|
|
71
|
+
parts.push(`## ${pb.path}\n${pb.content}`);
|
|
72
|
+
}
|
|
73
|
+
for (const pol of ctx.policies) {
|
|
74
|
+
parts.push(`## ${pol.path}\n${pol.content}`);
|
|
75
|
+
}
|
|
76
|
+
for (const tmpl of ctx.templates) {
|
|
77
|
+
parts.push(`## ${tmpl.path}\n${tmpl.content}`);
|
|
78
|
+
}
|
|
79
|
+
return parts.length > 0
|
|
80
|
+
? `# Loaded Context\n\n${parts.join('\n\n---\n\n')}`
|
|
81
|
+
: '# Loaded Context\n\n_(No context files found)_';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get a compact summary string suitable for display in CLI output.
|
|
85
|
+
*/
|
|
86
|
+
static describeContext(ctx) {
|
|
87
|
+
const items = [];
|
|
88
|
+
if (ctx.projectMd)
|
|
89
|
+
items.push('PROJECT.md');
|
|
90
|
+
if (ctx.tasksMd)
|
|
91
|
+
items.push('TASKS.md');
|
|
92
|
+
if (ctx.agentsMd)
|
|
93
|
+
items.push('AGENTS.md');
|
|
94
|
+
if (ctx.readmeMd)
|
|
95
|
+
items.push('README.md');
|
|
96
|
+
if (ctx.docs.length)
|
|
97
|
+
items.push(`${ctx.docs.length} doc(s)`);
|
|
98
|
+
if (ctx.specs.length)
|
|
99
|
+
items.push(`${ctx.specs.length} spec(s)`);
|
|
100
|
+
if (ctx.playbooks.length)
|
|
101
|
+
items.push(`${ctx.playbooks.length} playbook(s)`);
|
|
102
|
+
if (ctx.policies.length)
|
|
103
|
+
items.push(`${ctx.policies.length} polic(ies)`);
|
|
104
|
+
if (ctx.templates.length)
|
|
105
|
+
items.push(`${ctx.templates.length} template(s)`);
|
|
106
|
+
if (ctx.custom.length)
|
|
107
|
+
items.push(`${ctx.custom.length} custom file(s)`);
|
|
108
|
+
return items.length > 0 ? items.join(', ') : 'none';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=context-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-loader.js","sourceRoot":"","sources":["../../../orchestrator/context/context-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAa5F,MAAM,OAAO,aAAa;IAChB,OAAO,CAAiB;IACxB,QAAQ,CAAQ;IAChB,gBAAgB,CAAQ;IAEhC,YAAY,UAAgC,EAAE;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,wBAAwB,EAAE,CAAA;QAChE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;QACjD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,GAAG,GAAG,IAAI,CAAA;IAChE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;SACxC,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;SACxC,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,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AAA;QAC3E,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,aAAa,CAAC,CAAA;QACxE,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,MAAM,cAAc,CAAC,CAAA;QAC3E,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,iBAAiB,CAAC,CAAA;QACxE,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Squad Foundry — Guardrail Engine
|
|
3
|
+
*
|
|
4
|
+
* Guardrails are first-class policy constraints enforced at runtime.
|
|
5
|
+
* They are NOT just text in a prompt — they are evaluated programmatically
|
|
6
|
+
* before each step transition.
|
|
7
|
+
*
|
|
8
|
+
* Built-in guardrails cover common patterns. Squads can register custom ones.
|
|
9
|
+
*/
|
|
10
|
+
import type { GuardrailRule, GuardrailResult, GuardrailEvaluationContext } from './types.js';
|
|
11
|
+
export type GuardrailEvaluatorFn = (ctx: GuardrailEvaluationContext, params: Record<string, unknown>) => GuardrailResult;
|
|
12
|
+
export declare class GuardrailEngine {
|
|
13
|
+
private customEvaluators;
|
|
14
|
+
/**
|
|
15
|
+
* Register a custom guardrail evaluator.
|
|
16
|
+
*/
|
|
17
|
+
register(key: string, fn: GuardrailEvaluatorFn): void;
|
|
18
|
+
/**
|
|
19
|
+
* Evaluate a single guardrail rule against the current context.
|
|
20
|
+
*/
|
|
21
|
+
evaluate(rule: GuardrailRule, ctx: GuardrailEvaluationContext): GuardrailResult;
|
|
22
|
+
/**
|
|
23
|
+
* Evaluate all guardrails for a step. Returns all results.
|
|
24
|
+
* Any result with severity 'block' and passed=false will block execution.
|
|
25
|
+
*/
|
|
26
|
+
evaluateAll(rules: GuardrailRule[], ctx: GuardrailEvaluationContext): {
|
|
27
|
+
results: GuardrailResult[];
|
|
28
|
+
blocked: boolean;
|
|
29
|
+
warnings: GuardrailResult[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function createGuardrailEngine(): GuardrailEngine;
|
|
33
|
+
//# sourceMappingURL=guardrails.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guardrails.d.ts","sourceRoot":"","sources":["../../../orchestrator/core/guardrails.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,0BAA0B,EAE3B,MAAM,YAAY,CAAA;AAMnB,MAAM,MAAM,oBAAoB,GAAG,CACjC,GAAG,EAAE,0BAA0B,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,eAAe,CAAA;AAsQpB,qBAAa,eAAe;IAC1B,OAAO,CAAC,gBAAgB,CAA+C;IAEvE;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,oBAAoB,GAAG,IAAI;IAIrD;;OAEG;IACH,QAAQ,CACN,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,0BAA0B,GAC9B,eAAe;IAoBlB;;;OAGG;IACH,WAAW,CACT,KAAK,EAAE,aAAa,EAAE,EACtB,GAAG,EAAE,0BAA0B,GAC9B;QAAE,OAAO,EAAE,eAAe,EAAE,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE;CAMjF;AAED,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Squad Foundry — Guardrail Engine
|
|
3
|
+
*
|
|
4
|
+
* Guardrails are first-class policy constraints enforced at runtime.
|
|
5
|
+
* They are NOT just text in a prompt — they are evaluated programmatically
|
|
6
|
+
* before each step transition.
|
|
7
|
+
*
|
|
8
|
+
* Built-in guardrails cover common patterns. Squads can register custom ones.
|
|
9
|
+
*/
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
|
+
// Built-in Guardrail Evaluators
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
const builtinEvaluators = {
|
|
14
|
+
require_minimum_context(ctx, params) {
|
|
15
|
+
const minFields = params['requiredFields'] ?? ['projectMd'];
|
|
16
|
+
const context = ctx.job.loadedContext;
|
|
17
|
+
const missing = [];
|
|
18
|
+
for (const field of minFields) {
|
|
19
|
+
if (field === 'projectMd' && !context.projectMd)
|
|
20
|
+
missing.push('PROJECT.md');
|
|
21
|
+
if (field === 'tasksMd' && !context.tasksMd)
|
|
22
|
+
missing.push('TASKS.md');
|
|
23
|
+
if (field === 'agentsMd' && !context.agentsMd)
|
|
24
|
+
missing.push('AGENTS.md');
|
|
25
|
+
if (field === 'readmeMd' && !context.readmeMd)
|
|
26
|
+
missing.push('README.md');
|
|
27
|
+
}
|
|
28
|
+
if (missing.length > 0) {
|
|
29
|
+
return {
|
|
30
|
+
guardrailId: 'require_minimum_context',
|
|
31
|
+
passed: false,
|
|
32
|
+
severity: 'block',
|
|
33
|
+
message: `Missing required context files: ${missing.join(', ')}`,
|
|
34
|
+
blockedTransition: true,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
guardrailId: 'require_minimum_context',
|
|
39
|
+
passed: true,
|
|
40
|
+
severity: 'block',
|
|
41
|
+
message: 'All required context files present',
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
require_artifact_before_step(ctx, params) {
|
|
45
|
+
const requiredArtifactNames = params['artifactNames'] ??
|
|
46
|
+
ctx.step.requiredArtifacts;
|
|
47
|
+
const existingArtifactPaths = ctx.job.artifacts.map((a) => a.name);
|
|
48
|
+
const missing = requiredArtifactNames.filter((name) => !existingArtifactPaths.includes(name));
|
|
49
|
+
if (missing.length > 0) {
|
|
50
|
+
return {
|
|
51
|
+
guardrailId: 'require_artifact_before_step',
|
|
52
|
+
passed: false,
|
|
53
|
+
severity: 'block',
|
|
54
|
+
message: `Cannot run step '${ctx.step.name}' — missing artifacts: ${missing.join(', ')}`,
|
|
55
|
+
blockedTransition: true,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
guardrailId: 'require_artifact_before_step',
|
|
60
|
+
passed: true,
|
|
61
|
+
severity: 'block',
|
|
62
|
+
message: 'All required artifacts present',
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
require_approval_before_publish(ctx, _params) {
|
|
66
|
+
const isPublishStep = ctx.step.name.toLowerCase().includes('publish') ||
|
|
67
|
+
ctx.agent.role.toLowerCase().includes('publish');
|
|
68
|
+
if (!isPublishStep) {
|
|
69
|
+
return {
|
|
70
|
+
guardrailId: 'require_approval_before_publish',
|
|
71
|
+
passed: true,
|
|
72
|
+
severity: 'block',
|
|
73
|
+
message: 'Not a publish step — guardrail does not apply',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const hasPendingApproval = ctx.job.approvals.some((a) => a.stepId === ctx.step.id && a.status === 'pending');
|
|
77
|
+
const hasApproval = ctx.job.approvals.some((a) => a.stepId === ctx.step.id && a.status === 'approved');
|
|
78
|
+
if (!hasApproval && !hasPendingApproval) {
|
|
79
|
+
return {
|
|
80
|
+
guardrailId: 'require_approval_before_publish',
|
|
81
|
+
passed: false,
|
|
82
|
+
severity: 'block',
|
|
83
|
+
message: `Publishing step '${ctx.step.name}' requires human approval before execution`,
|
|
84
|
+
blockedTransition: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (hasPendingApproval) {
|
|
88
|
+
return {
|
|
89
|
+
guardrailId: 'require_approval_before_publish',
|
|
90
|
+
passed: false,
|
|
91
|
+
severity: 'block',
|
|
92
|
+
message: `Waiting for human approval before publishing — step '${ctx.step.name}'`,
|
|
93
|
+
blockedTransition: true,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
guardrailId: 'require_approval_before_publish',
|
|
98
|
+
passed: true,
|
|
99
|
+
severity: 'block',
|
|
100
|
+
message: 'Approval received — may proceed with publishing',
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
require_human_before_deploy(ctx, _params) {
|
|
104
|
+
const isDeployStep = ctx.step.name.toLowerCase().includes('deploy') ||
|
|
105
|
+
ctx.agent.role.toLowerCase().includes('deploy');
|
|
106
|
+
if (!isDeployStep) {
|
|
107
|
+
return {
|
|
108
|
+
guardrailId: 'require_human_before_deploy',
|
|
109
|
+
passed: true,
|
|
110
|
+
severity: 'block',
|
|
111
|
+
message: 'Not a deploy step — guardrail does not apply',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const hasApproval = ctx.job.approvals.some((a) => a.stepId === ctx.step.id && a.status === 'approved');
|
|
115
|
+
if (!hasApproval) {
|
|
116
|
+
return {
|
|
117
|
+
guardrailId: 'require_human_before_deploy',
|
|
118
|
+
passed: false,
|
|
119
|
+
severity: 'block',
|
|
120
|
+
message: `Deploy step '${ctx.step.name}' ALWAYS requires explicit human confirmation. No automated deploys.`,
|
|
121
|
+
blockedTransition: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
guardrailId: 'require_human_before_deploy',
|
|
126
|
+
passed: true,
|
|
127
|
+
severity: 'block',
|
|
128
|
+
message: 'Human deploy confirmation received',
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
block_invalid_state_transition(ctx, params) {
|
|
132
|
+
const allowedFromStates = params['allowedFromStates'] ??
|
|
133
|
+
ctx.agent.allowedStates;
|
|
134
|
+
if (!allowedFromStates.includes(ctx.job.status)) {
|
|
135
|
+
return {
|
|
136
|
+
guardrailId: 'block_invalid_state_transition',
|
|
137
|
+
passed: false,
|
|
138
|
+
severity: 'block',
|
|
139
|
+
message: `Agent '${ctx.agent.name}' cannot act in state '${ctx.job.status}'. Allowed: ${allowedFromStates.join(', ')}`,
|
|
140
|
+
blockedTransition: true,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
guardrailId: 'block_invalid_state_transition',
|
|
145
|
+
passed: true,
|
|
146
|
+
severity: 'block',
|
|
147
|
+
message: `Agent '${ctx.agent.name}' is allowed to act in state '${ctx.job.status}'`,
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
require_pr_criteria(ctx, params) {
|
|
151
|
+
const criteria = params['criteria'] ?? [
|
|
152
|
+
'tests_passed',
|
|
153
|
+
'review_complete',
|
|
154
|
+
'branch_clean',
|
|
155
|
+
];
|
|
156
|
+
const reviewArtifact = ctx.job.artifacts.find((a) => a.name.toLowerCase().includes('review') ||
|
|
157
|
+
a.name.toLowerCase().includes('findings'));
|
|
158
|
+
const testArtifact = ctx.job.artifacts.find((a) => a.name.toLowerCase().includes('test'));
|
|
159
|
+
const missing = [];
|
|
160
|
+
if (criteria.includes('review_complete') && !reviewArtifact) {
|
|
161
|
+
missing.push('Review artifacts');
|
|
162
|
+
}
|
|
163
|
+
if (criteria.includes('tests_passed') && !testArtifact) {
|
|
164
|
+
missing.push('Test results');
|
|
165
|
+
}
|
|
166
|
+
if (missing.length > 0) {
|
|
167
|
+
return {
|
|
168
|
+
guardrailId: 'require_pr_criteria',
|
|
169
|
+
passed: false,
|
|
170
|
+
severity: 'block',
|
|
171
|
+
message: `PR cannot be created — missing: ${missing.join(', ')}`,
|
|
172
|
+
blockedTransition: true,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
guardrailId: 'require_pr_criteria',
|
|
177
|
+
passed: true,
|
|
178
|
+
severity: 'block',
|
|
179
|
+
message: 'All PR criteria satisfied',
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
no_agent_outside_allowed_states(ctx, _params) {
|
|
183
|
+
const allowed = ctx.agent.allowedStates;
|
|
184
|
+
if (!allowed.includes(ctx.job.status)) {
|
|
185
|
+
return {
|
|
186
|
+
guardrailId: 'no_agent_outside_allowed_states',
|
|
187
|
+
passed: false,
|
|
188
|
+
severity: 'block',
|
|
189
|
+
message: `Agent '${ctx.agent.id}' is not permitted to run in status '${ctx.job.status}'`,
|
|
190
|
+
blockedTransition: true,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
guardrailId: 'no_agent_outside_allowed_states',
|
|
195
|
+
passed: true,
|
|
196
|
+
severity: 'block',
|
|
197
|
+
message: 'Agent is operating within its allowed states',
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
require_artifact_produced(ctx, params) {
|
|
201
|
+
const expectedName = params['artifactName'];
|
|
202
|
+
if (!expectedName) {
|
|
203
|
+
return {
|
|
204
|
+
guardrailId: 'require_artifact_produced',
|
|
205
|
+
passed: true,
|
|
206
|
+
severity: 'warn',
|
|
207
|
+
message: 'No artifact name specified — guardrail skipped',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const produced = ctx.job.artifacts.find((a) => a.name === expectedName);
|
|
211
|
+
if (!produced) {
|
|
212
|
+
return {
|
|
213
|
+
guardrailId: 'require_artifact_produced',
|
|
214
|
+
passed: false,
|
|
215
|
+
severity: 'warn',
|
|
216
|
+
message: `Expected artifact '${expectedName}' was not produced by step '${ctx.step.name}'`,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
guardrailId: 'require_artifact_produced',
|
|
221
|
+
passed: true,
|
|
222
|
+
severity: 'warn',
|
|
223
|
+
message: `Artifact '${expectedName}' confirmed`,
|
|
224
|
+
};
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
228
|
+
// Guardrail Engine
|
|
229
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
230
|
+
export class GuardrailEngine {
|
|
231
|
+
customEvaluators = new Map();
|
|
232
|
+
/**
|
|
233
|
+
* Register a custom guardrail evaluator.
|
|
234
|
+
*/
|
|
235
|
+
register(key, fn) {
|
|
236
|
+
this.customEvaluators.set(key, fn);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Evaluate a single guardrail rule against the current context.
|
|
240
|
+
*/
|
|
241
|
+
evaluate(rule, ctx) {
|
|
242
|
+
const key = rule.ruleKey;
|
|
243
|
+
const builtin = builtinEvaluators[key];
|
|
244
|
+
const custom = this.customEvaluators.get(rule.ruleKey);
|
|
245
|
+
const evaluator = builtin ?? custom;
|
|
246
|
+
if (!evaluator) {
|
|
247
|
+
return {
|
|
248
|
+
guardrailId: rule.id,
|
|
249
|
+
passed: false,
|
|
250
|
+
severity: 'warn',
|
|
251
|
+
message: `Unknown guardrail rule key: '${rule.ruleKey}'`,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const result = evaluator(ctx, rule.params ?? {});
|
|
255
|
+
// Override the guardrailId with the rule's configured ID
|
|
256
|
+
return { ...result, guardrailId: rule.id, severity: rule.severity };
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Evaluate all guardrails for a step. Returns all results.
|
|
260
|
+
* Any result with severity 'block' and passed=false will block execution.
|
|
261
|
+
*/
|
|
262
|
+
evaluateAll(rules, ctx) {
|
|
263
|
+
const results = rules.map((rule) => this.evaluate(rule, ctx));
|
|
264
|
+
const blocked = results.some((r) => r.severity === 'block' && !r.passed);
|
|
265
|
+
const warnings = results.filter((r) => r.severity === 'warn' && !r.passed);
|
|
266
|
+
return { results, blocked, warnings };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export function createGuardrailEngine() {
|
|
270
|
+
return new GuardrailEngine();
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=guardr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