sdtk-code-kit 0.2.0 → 0.3.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.
Files changed (42) hide show
  1. package/README.md +3 -3
  2. package/assets/manifest/toolkit-bundle.manifest.json +57 -57
  3. package/assets/manifest/toolkit-bundle.sha256.txt +28 -28
  4. package/assets/toolkit/toolkit/AGENTS.md +219 -219
  5. package/assets/toolkit/toolkit/install.ps1 +156 -156
  6. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +78 -78
  7. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +150 -150
  8. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +62 -62
  9. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +82 -82
  10. package/assets/toolkit/toolkit/sdtk-spec.config.json +6 -6
  11. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +12 -12
  12. package/assets/toolkit/toolkit/skills/code-brainstorm/SKILL.md +55 -55
  13. package/assets/toolkit/toolkit/skills/code-debug/SKILL.md +296 -296
  14. package/assets/toolkit/toolkit/skills/code-debug/references/root-cause-tracing.md +68 -68
  15. package/assets/toolkit/toolkit/skills/code-discover/SKILL.md +54 -54
  16. package/assets/toolkit/toolkit/skills/code-execute/SKILL.md +74 -74
  17. package/assets/toolkit/toolkit/skills/code-finish/SKILL.md +205 -205
  18. package/assets/toolkit/toolkit/skills/code-parallel/SKILL.md +64 -64
  19. package/assets/toolkit/toolkit/skills/code-parallel/references/code-quality-reviewer-prompt.md +26 -26
  20. package/assets/toolkit/toolkit/skills/code-parallel/references/implementer-prompt.md +113 -113
  21. package/assets/toolkit/toolkit/skills/code-parallel/references/spec-reviewer-prompt.md +61 -61
  22. package/assets/toolkit/toolkit/skills/code-plan/SKILL.md +85 -85
  23. package/assets/toolkit/toolkit/skills/code-review/SKILL.md +79 -79
  24. package/assets/toolkit/toolkit/skills/code-review/references/checklist.md +125 -125
  25. package/assets/toolkit/toolkit/skills/code-review/references/code-reviewer.md +146 -146
  26. package/assets/toolkit/toolkit/skills/code-ship/SKILL.md +52 -52
  27. package/assets/toolkit/toolkit/skills/code-tdd/SKILL.md +378 -378
  28. package/assets/toolkit/toolkit/skills/code-tdd/references/testing-anti-patterns.md +299 -299
  29. package/assets/toolkit/toolkit/skills/code-verify/SKILL.md +144 -144
  30. package/assets/toolkit/toolkit/skills/code-worktree/SKILL.md +228 -228
  31. package/assets/toolkit/toolkit/templates/CODE_WORKFLOW_TEMPLATE.md +140 -140
  32. package/package.json +2 -2
  33. package/src/commands/agent-team.js +174 -0
  34. package/src/commands/guardrails.js +94 -2
  35. package/src/commands/help.js +13 -0
  36. package/src/commands/sleep.js +132 -0
  37. package/src/index.js +8 -0
  38. package/src/lib/agent-team-export.js +409 -0
  39. package/src/lib/agent-team-plan.js +514 -0
  40. package/src/lib/sleep-plan.js +175 -0
  41. package/src/lib/sleep-report.js +229 -0
  42. package/src/lib/trust-events.js +20 -1
@@ -1,140 +1,140 @@
1
- # CODE_WORKFLOW __FEATURE_KEY__
2
-
3
- <!-- SDTK-CODE:METADATA:START -->
4
- ## 1. Metadata
5
- - Feature key: `__FEATURE_KEY__`
6
- - Lane: `__LANE__`
7
- - Current phase: `start`
8
- - Phase status: `__PHASE_STATUS__`
9
- - Intake outcome: `__INTAKE_OUTCOME__`
10
- - Last updated: `__LAST_UPDATED__`
11
- <!-- SDTK-CODE:METADATA:END -->
12
-
13
- <!-- SDTK-CODE:INPUTS:START -->
14
- ## 2. Inputs
15
- ### Required Inputs
16
- __REQUIRED_INPUTS__
17
-
18
- ### Additional Discovered Inputs
19
- __ADDITIONAL_INPUTS__
20
-
21
- ### Missing Required Inputs
22
- __MISSING_INPUTS__
23
- <!-- SDTK-CODE:INPUTS:END -->
24
-
25
- <!-- SDTK-CODE:PLAN:START -->
26
- ## 3. Scope Lock
27
- ### In Scope
28
- - Pending confirmation during workflow planning.
29
-
30
- ### Out Of Scope
31
- - Pending confirmation during workflow planning.
32
-
33
- ### Assumptions
34
- - No explicit planning assumptions recorded.
35
-
36
- ### Risks
37
- - No explicit planning risks recorded.
38
-
39
- ## 4. Plan / Slices
40
- - Pending lane-specific planning or build guidance.
41
-
42
- ### Planning Notes
43
- - No additional planning notes recorded.
44
- <!-- SDTK-CODE:PLAN:END -->
45
-
46
-
47
- ## Provenance
48
-
49
- When external references are consulted for this workflow batch, include the full provenance log below:
50
-
51
- ### Source References Consulted
52
- | # | Source | URL or Path | Consulted Date | Purpose |
53
- |---|---|---|---|---|
54
- | 1 | <reference name> | <url or relative path> | <YYYY-MM-DD> | <why consulted> |
55
-
56
- ### Behavioral Ideas Extracted
57
- | # | Source Ref | Behavioral Idea Extracted | SDTK-Native Contract Written | High-Risk Material? |
58
- |---|---|---|---|---|
59
- | 1 | <ref #> | <plain description of idea> | <yes/no + what was written> | <yes/no> |
60
-
61
- ### High-Risk Surfaces Reviewed
62
- | # | Source Ref | Material Reviewed | Decision | Reason |
63
- |---|---|---|---|---|
64
- | 1 | <ref #> | <what was reviewed> | REJECTED / REDESIGNED | <reason> |
65
-
66
- ### Controller Provenance Sign-Off
67
- - Reviewed by: <controller name or alias>
68
- - Date: <YYYY-MM-DD>
69
- - Decision: APPROVED / NEEDS REVISION
70
- - Notes: <any additional controller notes>
71
-
72
- If no external material was consulted, keep this section and record only the no-reference declaration:
73
- - No external source references were consulted for this batch.
74
- <!-- SDTK-CODE:BUILD:START -->
75
- ### Build Progress
76
- - Build status: `pending`
77
- - Execution mode: `sequential`
78
-
79
- ### Active Slices
80
- - Pending build-phase execution.
81
-
82
- ### Build Notes
83
- - No build notes recorded yet.
84
-
85
- ### Debug Notes
86
- - No debug notes recorded.
87
-
88
- ### Parallelization Justification
89
- - Not using explicit parallel execution in this build pass.
90
- <!-- SDTK-CODE:BUILD:END -->
91
-
92
- <!-- SDTK-CODE:STATUS:START -->
93
- ## 5. Status Checklist
94
- - Current phase: `start`
95
- - Next recommended phase: `__NEXT_PHASE__`
96
- - Suggested engine entrypoints: __SUGGESTED_ENGINE__
97
- - Blocking state: `__BLOCKING_STATE__`
98
- <!-- SDTK-CODE:STATUS:END -->
99
-
100
- <!-- SDTK-CODE:VERIFY:START -->
101
- ## 6. Evidence And Review Notes
102
- ### Evidence Summary
103
- - No summarized verification evidence recorded yet.
104
-
105
- ### Raw Output References
106
- - Store raw command output under `docs/dev/evidence/__FEATURE_KEY__/` and reference it from this section.
107
-
108
- ### Review Gate Status
109
- - Evidence gate: `pending`
110
- - Spec/compliance gate: `pending`
111
- - Quality gate: `pending`
112
-
113
- ### Spec / Compliance Notes
114
- - No spec/compliance notes recorded yet.
115
-
116
- ### Quality Notes
117
- - No quality review notes recorded yet.
118
-
119
- ### Debug Follow-Up
120
- - No reactive debug follow-up recorded.
121
- <!-- SDTK-CODE:VERIFY:END -->
122
-
123
- <!-- SDTK-CODE:SHIP:START -->
124
- ## 7. Ship / Finish Decision
125
- ### Final Decision
126
- - Decision: `pending`
127
- - Ship status: `pending`
128
-
129
- ### Preflight Summary
130
- - No ship preflight entries recorded yet.
131
-
132
- ### Follow-Up Items
133
- - No follow-up items recorded.
134
-
135
- ### Ship Notes
136
- - No additional ship notes recorded.
137
-
138
- ### Debug Follow-Up
139
- - No reactive debug follow-up recorded.
140
- <!-- SDTK-CODE:SHIP:END -->
1
+ # CODE_WORKFLOW __FEATURE_KEY__
2
+
3
+ <!-- SDTK-CODE:METADATA:START -->
4
+ ## 1. Metadata
5
+ - Feature key: `__FEATURE_KEY__`
6
+ - Lane: `__LANE__`
7
+ - Current phase: `start`
8
+ - Phase status: `__PHASE_STATUS__`
9
+ - Intake outcome: `__INTAKE_OUTCOME__`
10
+ - Last updated: `__LAST_UPDATED__`
11
+ <!-- SDTK-CODE:METADATA:END -->
12
+
13
+ <!-- SDTK-CODE:INPUTS:START -->
14
+ ## 2. Inputs
15
+ ### Required Inputs
16
+ __REQUIRED_INPUTS__
17
+
18
+ ### Additional Discovered Inputs
19
+ __ADDITIONAL_INPUTS__
20
+
21
+ ### Missing Required Inputs
22
+ __MISSING_INPUTS__
23
+ <!-- SDTK-CODE:INPUTS:END -->
24
+
25
+ <!-- SDTK-CODE:PLAN:START -->
26
+ ## 3. Scope Lock
27
+ ### In Scope
28
+ - Pending confirmation during workflow planning.
29
+
30
+ ### Out Of Scope
31
+ - Pending confirmation during workflow planning.
32
+
33
+ ### Assumptions
34
+ - No explicit planning assumptions recorded.
35
+
36
+ ### Risks
37
+ - No explicit planning risks recorded.
38
+
39
+ ## 4. Plan / Slices
40
+ - Pending lane-specific planning or build guidance.
41
+
42
+ ### Planning Notes
43
+ - No additional planning notes recorded.
44
+ <!-- SDTK-CODE:PLAN:END -->
45
+
46
+
47
+ ## Provenance
48
+
49
+ When external references are consulted for this workflow batch, include the full provenance log below:
50
+
51
+ ### Source References Consulted
52
+ | # | Source | URL or Path | Consulted Date | Purpose |
53
+ |---|---|---|---|---|
54
+ | 1 | <reference name> | <url or relative path> | <YYYY-MM-DD> | <why consulted> |
55
+
56
+ ### Behavioral Ideas Extracted
57
+ | # | Source Ref | Behavioral Idea Extracted | SDTK-Native Contract Written | High-Risk Material? |
58
+ |---|---|---|---|---|
59
+ | 1 | <ref #> | <plain description of idea> | <yes/no + what was written> | <yes/no> |
60
+
61
+ ### High-Risk Surfaces Reviewed
62
+ | # | Source Ref | Material Reviewed | Decision | Reason |
63
+ |---|---|---|---|---|
64
+ | 1 | <ref #> | <what was reviewed> | REJECTED / REDESIGNED | <reason> |
65
+
66
+ ### Controller Provenance Sign-Off
67
+ - Reviewed by: <controller name or alias>
68
+ - Date: <YYYY-MM-DD>
69
+ - Decision: APPROVED / NEEDS REVISION
70
+ - Notes: <any additional controller notes>
71
+
72
+ If no external material was consulted, keep this section and record only the no-reference declaration:
73
+ - No external source references were consulted for this batch.
74
+ <!-- SDTK-CODE:BUILD:START -->
75
+ ### Build Progress
76
+ - Build status: `pending`
77
+ - Execution mode: `sequential`
78
+
79
+ ### Active Slices
80
+ - Pending build-phase execution.
81
+
82
+ ### Build Notes
83
+ - No build notes recorded yet.
84
+
85
+ ### Debug Notes
86
+ - No debug notes recorded.
87
+
88
+ ### Parallelization Justification
89
+ - Not using explicit parallel execution in this build pass.
90
+ <!-- SDTK-CODE:BUILD:END -->
91
+
92
+ <!-- SDTK-CODE:STATUS:START -->
93
+ ## 5. Status Checklist
94
+ - Current phase: `start`
95
+ - Next recommended phase: `__NEXT_PHASE__`
96
+ - Suggested engine entrypoints: __SUGGESTED_ENGINE__
97
+ - Blocking state: `__BLOCKING_STATE__`
98
+ <!-- SDTK-CODE:STATUS:END -->
99
+
100
+ <!-- SDTK-CODE:VERIFY:START -->
101
+ ## 6. Evidence And Review Notes
102
+ ### Evidence Summary
103
+ - No summarized verification evidence recorded yet.
104
+
105
+ ### Raw Output References
106
+ - Store raw command output under `docs/dev/evidence/__FEATURE_KEY__/` and reference it from this section.
107
+
108
+ ### Review Gate Status
109
+ - Evidence gate: `pending`
110
+ - Spec/compliance gate: `pending`
111
+ - Quality gate: `pending`
112
+
113
+ ### Spec / Compliance Notes
114
+ - No spec/compliance notes recorded yet.
115
+
116
+ ### Quality Notes
117
+ - No quality review notes recorded yet.
118
+
119
+ ### Debug Follow-Up
120
+ - No reactive debug follow-up recorded.
121
+ <!-- SDTK-CODE:VERIFY:END -->
122
+
123
+ <!-- SDTK-CODE:SHIP:START -->
124
+ ## 7. Ship / Finish Decision
125
+ ### Final Decision
126
+ - Decision: `pending`
127
+ - Ship status: `pending`
128
+
129
+ ### Preflight Summary
130
+ - No ship preflight entries recorded yet.
131
+
132
+ ### Follow-Up Items
133
+ - No follow-up items recorded.
134
+
135
+ ### Ship Notes
136
+ - No additional ship notes recorded.
137
+
138
+ ### Debug Follow-Up
139
+ - No reactive debug follow-up recorded.
140
+ <!-- SDTK-CODE:SHIP:END -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdtk-code-kit",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Workflow-first coding process toolkit: start, plan, build, verify, ship, and runtime setup.",
5
5
  "bin": {
6
6
  "sdtk-code": "bin/sdtk-code.js"
@@ -13,7 +13,7 @@
13
13
  "assets/"
14
14
  ],
15
15
  "scripts": {
16
- "test": "powershell -ExecutionPolicy Bypass -Command \"$ErrorActionPreference = 'Stop'; Set-Location '..\\..\\..\\..'; python -m unittest tests.test_sdtk_code_cli tests.test_sdtk_code_product tests.test_sdtk_code_workflow_regressions tests.test_sdtk_code_trust_events tests.test_sdtk_code_guardrails tests.test_sdtk_code_file_scope tests.test_sdtk_code_trust_trace tests.test_sdtk_code_readiness\"",
16
+ "test": "powershell -ExecutionPolicy Bypass -Command \"$ErrorActionPreference = 'Stop'; Set-Location '..\\..\\..\\..'; python -m unittest tests.test_sdtk_code_cli tests.test_sdtk_code_product tests.test_sdtk_code_workflow_regressions tests.test_sdtk_code_trust_events tests.test_sdtk_code_guardrails tests.test_sdtk_code_file_scope tests.test_sdtk_code_trust_trace tests.test_sdtk_code_readiness tests.test_sdtk_code_guardrails_scope_trace tests.test_sdtk_code_sleep tests.test_sdtk_code_sleep_report\"",
17
17
  "build:payload": "powershell -ExecutionPolicy Bypass -Command \"$ErrorActionPreference = 'Stop'; & 'scripts/sync-toolkit-assets.ps1'; & 'scripts/build-toolkit-manifest.ps1'\"",
18
18
  "verify:payload": "node -e \"require('./src/lib/toolkit-payload').verify()\"",
19
19
  "pack:smoke": "npm pack --dry-run",
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+ const { parseFlags, requireFlag, validateChoice } = require("../lib/args");
5
+ const { ValidationError } = require("../lib/errors");
6
+ const {
7
+ assembleAgentTeamPlan,
8
+ writeAgentTeamPlan,
9
+ writeTaskPackets,
10
+ loadAgentTeamPlan,
11
+ projectAgentTeamPreview,
12
+ renderPreviewMarkdown,
13
+ writeAgentTeamPreview,
14
+ gatherPreviewReadiness,
15
+ } = require("../lib/agent-team-plan");
16
+ const {
17
+ EXPORT_RUNTIMES,
18
+ projectExport,
19
+ writeExportBundle,
20
+ } = require("../lib/agent-team-export");
21
+ const { appendEvent } = require("../lib/trust-events");
22
+
23
+ const FLAG_DEFS = {
24
+ "feature-key": { type: "string" },
25
+ "project-path": { type: "string" },
26
+ };
27
+
28
+ const EXPORT_FLAG_DEFS = {
29
+ "feature-key": { type: "string" },
30
+ "project-path": { type: "string" },
31
+ runtime: { type: "string" },
32
+ };
33
+
34
+ function resolveProjectPath(flags) {
35
+ return flags["project-path"] ? path.resolve(flags["project-path"]) : process.cwd();
36
+ }
37
+
38
+ function cmdAgentTeamPlan(args) {
39
+ const { flags, positional } = parseFlags(args, FLAG_DEFS);
40
+ if (positional.length > 0) {
41
+ throw new ValidationError('Unexpected positional arguments. Use flags only for "agent-team plan".');
42
+ }
43
+ const featureKey = requireFlag(flags, "feature-key", "feature-key");
44
+ const projectPath = resolveProjectPath(flags);
45
+
46
+ const plan = assembleAgentTeamPlan(projectPath, featureKey);
47
+ const planPath = writeAgentTeamPlan(projectPath, plan);
48
+ const packetPaths = writeTaskPackets(projectPath, plan);
49
+
50
+ appendEvent(projectPath, {
51
+ toolkit: "sdtk-code",
52
+ event_type: "agent_team_plan",
53
+ command: `sdtk-code agent-team plan --feature-key ${featureKey}`,
54
+ status: "ok",
55
+ feature_key: featureKey,
56
+ run_id: plan.run_id,
57
+ output_path: planPath,
58
+ });
59
+
60
+ console.log(`agent-team plan written: ${planPath}`);
61
+ console.log(` feature_key: ${plan.feature_key}`);
62
+ console.log(` run_id: ${plan.run_id}`);
63
+ console.log(` roles: ${plan.roles.map((role) => role.role).join(", ")}`);
64
+ console.log(` task packets: ${packetPaths.length}`);
65
+ console.log(` stop_conditions: ${plan.stop_conditions.length}`);
66
+ console.log(" preview only — agents are not executed and Sleep execution is not available in this phase.");
67
+ return 0;
68
+ }
69
+
70
+ function cmdAgentTeamPreview(args) {
71
+ const { flags, positional } = parseFlags(args, FLAG_DEFS);
72
+ if (positional.length > 0) {
73
+ throw new ValidationError('Unexpected positional arguments. Use flags only for "agent-team preview".');
74
+ }
75
+ const featureKey = requireFlag(flags, "feature-key", "feature-key");
76
+ const projectPath = resolveProjectPath(flags);
77
+
78
+ const plan = loadAgentTeamPlan(projectPath, featureKey);
79
+ if (plan.feature_key !== featureKey) {
80
+ throw new ValidationError(
81
+ `agent-team plan feature_key "${plan.feature_key}" does not match --feature-key "${featureKey}".`
82
+ );
83
+ }
84
+
85
+ const readiness = gatherPreviewReadiness(projectPath, featureKey);
86
+ const preview = projectAgentTeamPreview(plan, readiness);
87
+ const markdown = renderPreviewMarkdown(plan, preview);
88
+ const outPath = writeAgentTeamPreview(projectPath, featureKey, markdown);
89
+
90
+ appendEvent(projectPath, {
91
+ toolkit: "sdtk-code",
92
+ event_type: "agent_team_preview",
93
+ command: `sdtk-code agent-team preview --feature-key ${featureKey}`,
94
+ status: preview.verdict,
95
+ feature_key: featureKey,
96
+ run_id: plan.run_id,
97
+ output_path: outPath,
98
+ });
99
+
100
+ console.log(`Agent Team Preview: ${preview.verdict}`);
101
+ console.log(` run_id: ${preview.run_id}`);
102
+ console.log(` roles: ${preview.roles.map((role) => role.role).join(", ")}`);
103
+ console.log(` report: ${outPath}`);
104
+ console.log(" preview only — agents are not executed and Sleep execution is not available in this phase.");
105
+ return 0;
106
+ }
107
+
108
+ function cmdAgentTeamExport(args) {
109
+ const { flags, positional } = parseFlags(args, EXPORT_FLAG_DEFS);
110
+ if (positional.length > 0) {
111
+ throw new ValidationError('Unexpected positional arguments. Use flags only for "agent-team export".');
112
+ }
113
+ const featureKey = requireFlag(flags, "feature-key", "feature-key");
114
+ const runtime = requireFlag(flags, "runtime", "runtime");
115
+ validateChoice(runtime, EXPORT_RUNTIMES, "runtime");
116
+ const projectPath = resolveProjectPath(flags);
117
+
118
+ const plan = loadAgentTeamPlan(projectPath, featureKey);
119
+ if (plan.feature_key !== featureKey) {
120
+ throw new ValidationError(
121
+ `agent-team plan feature_key "${plan.feature_key}" does not match --feature-key "${featureKey}".`
122
+ );
123
+ }
124
+
125
+ const exported = projectExport(plan, runtime);
126
+ const written = writeExportBundle(projectPath, exported);
127
+
128
+ appendEvent(projectPath, {
129
+ toolkit: "sdtk-code",
130
+ event_type: "agent_team_export",
131
+ command: `sdtk-code agent-team export --feature-key ${featureKey} --runtime ${runtime}`,
132
+ status: "ok",
133
+ feature_key: featureKey,
134
+ run_id: exported.run_id,
135
+ output_path: written[written.length - 1],
136
+ });
137
+
138
+ console.log(`agent-team export written (${runtime}): ${path.dirname(written[0])}`);
139
+ console.log(` feature_key: ${exported.feature_key}`);
140
+ console.log(` run_id: ${exported.run_id}`);
141
+ console.log(` roles: ${exported.roles.map((role) => role.role).join(", ")}`);
142
+ console.log(` files: ${written.length}`);
143
+ console.log(" export/preview only — agents are not executed and Sleep execution is not available in this phase.");
144
+ return 0;
145
+ }
146
+
147
+ function cmdAgentTeam(args) {
148
+ if (!args || args.length === 0) {
149
+ throw new ValidationError(
150
+ "Usage: sdtk-code agent-team <subcommand> [flags]\nSubcommands: plan, preview, export\n(run is not available in this phase.)"
151
+ );
152
+ }
153
+
154
+ const [subcommand, ...rest] = args;
155
+
156
+ switch (subcommand) {
157
+ case "plan":
158
+ return cmdAgentTeamPlan(rest);
159
+ case "preview":
160
+ return cmdAgentTeamPreview(rest);
161
+ case "export":
162
+ return cmdAgentTeamExport(rest);
163
+ case "run":
164
+ throw new ValidationError(
165
+ `"agent-team run" is not available in this phase. Supported: plan, preview, export (export/preview only).`
166
+ );
167
+ default:
168
+ throw new ValidationError(
169
+ `Unknown agent-team subcommand: "${subcommand}". Available: plan, preview, export`
170
+ );
171
+ }
172
+ }
173
+
174
+ module.exports = { cmdAgentTeam };
@@ -6,6 +6,8 @@ const { parseFlags, requireFlag } = require("../lib/args");
6
6
  const { ValidationError } = require("../lib/errors");
7
7
  const { DEFAULT_POLICY, loadPolicy, classifyCommand, policyFile } = require("../lib/trust-policy");
8
8
  const { appendEvent } = require("../lib/trust-events");
9
+ const { loadScopes, getChangedFiles, checkFiles } = require("../lib/trust-file-scope");
10
+ const { writeTraceReport } = require("../lib/trust-trace");
9
11
 
10
12
  const CHECK_FLAG_DEFS = {
11
13
  command: { type: "string" },
@@ -18,6 +20,18 @@ const INIT_FLAG_DEFS = {
18
20
  force: { type: "boolean" },
19
21
  };
20
22
 
23
+ const SCOPE_FLAG_DEFS = {
24
+ "feature-key": { type: "string" },
25
+ "project-path": { type: "string" },
26
+ base: { type: "string" },
27
+ changed: { type: "string", multiple: true },
28
+ };
29
+
30
+ const TRACE_FLAG_DEFS = {
31
+ "feature-key": { type: "string" },
32
+ "project-path": { type: "string" },
33
+ };
34
+
21
35
  // allow/ask are advisory observations (info); deny is recorded as blocked.
22
36
  function statusForVerdict(verdict) {
23
37
  return verdict === "deny" ? "blocked" : "info";
@@ -98,11 +112,85 @@ function runInit(args) {
98
112
  return 0;
99
113
  }
100
114
 
115
+ // file-scope verdict -> trust event status. fail is a blocking observation.
116
+ function statusForScope(verdict) {
117
+ return verdict === "fail" ? "blocked" : "info";
118
+ }
119
+
120
+ function runScope(args) {
121
+ const { flags, positional } = parseFlags(args, SCOPE_FLAG_DEFS);
122
+ if (positional.length > 0) {
123
+ throw new ValidationError('Unexpected positional arguments for "guardrails scope".');
124
+ }
125
+
126
+ const featureKey = requireFlag(flags, "feature-key", "feature-key");
127
+ const projectPath = resolveProjectPath(flags);
128
+ const scopes = loadScopes(projectPath, featureKey);
129
+
130
+ // Explicit --changed entries take precedence; otherwise diff against base via git.
131
+ let changed = Array.isArray(flags.changed) ? flags.changed.filter(Boolean) : [];
132
+ if (changed.length === 0) {
133
+ try {
134
+ changed = getChangedFiles(projectPath, flags.base || "HEAD");
135
+ } catch (error) {
136
+ throw new ValidationError(
137
+ `Could not determine changed files (git): ${error.message}. ` +
138
+ "Run inside a git repo, or pass --changed <file> entries explicitly."
139
+ );
140
+ }
141
+ }
142
+
143
+ const result = checkFiles(scopes, changed);
144
+
145
+ appendEvent(projectPath, {
146
+ toolkit: "sdtk-code",
147
+ event_type: "file_scope_check",
148
+ phase: "verify",
149
+ status: statusForScope(result.verdict),
150
+ files: result.outOfScope.concat(result.blockedHits),
151
+ });
152
+
153
+ console.log("SDTK-CODE guardrails scope");
154
+ console.log(` Feature key: ${featureKey}`);
155
+ console.log(` Scope source: ${scopes.source}${scopes.declared ? "" : " (no scope declared)"}`);
156
+ console.log(` Verdict: ${result.verdict}`);
157
+ console.log(` In scope: ${result.inScope.length}`);
158
+ if (result.outOfScope.length > 0) {
159
+ console.log(` Out of scope: ${result.outOfScope.join(", ")}`);
160
+ }
161
+ if (result.blockedHits.length > 0) {
162
+ console.log(` Blocked: ${result.blockedHits.join(", ")}`);
163
+ }
164
+ // Advisory gate: verdict is reported in stdout, not enforced via exit code.
165
+ return 0;
166
+ }
167
+
168
+ function runTrace(args) {
169
+ const { flags, positional } = parseFlags(args, TRACE_FLAG_DEFS);
170
+ if (positional.length > 0) {
171
+ throw new ValidationError('Unexpected positional arguments for "guardrails trace".');
172
+ }
173
+
174
+ const featureKey = requireFlag(flags, "feature-key", "feature-key");
175
+ const projectPath = resolveProjectPath(flags);
176
+ const result = writeTraceReport(projectPath, featureKey);
177
+ const totals = result.trace.totals;
178
+
179
+ console.log("SDTK-CODE guardrails trace");
180
+ console.log(` Feature key: ${featureKey}`);
181
+ console.log(` Report: ${result.path}`);
182
+ console.log(` Events: ${totals.events}`);
183
+ console.log(` Failures: ${totals.failures}`);
184
+ console.log(` Blocked: ${totals.blocked}`);
185
+ console.log(` Decision gates: ${totals.decisionGates}`);
186
+ return 0;
187
+ }
188
+
101
189
  function cmdGuardrails(args) {
102
190
  const list = Array.isArray(args) ? args : [];
103
191
  const subcommand = list[0];
104
192
  if (!subcommand || subcommand.startsWith("-")) {
105
- throw new ValidationError('Missing guardrails subcommand. Use one of: check, init.');
193
+ throw new ValidationError('Missing guardrails subcommand. Use one of: check, init, scope, trace.');
106
194
  }
107
195
 
108
196
  const rest = list.slice(1);
@@ -111,9 +199,13 @@ function cmdGuardrails(args) {
111
199
  return runCheck(rest);
112
200
  case "init":
113
201
  return runInit(rest);
202
+ case "scope":
203
+ return runScope(rest);
204
+ case "trace":
205
+ return runTrace(rest);
114
206
  default:
115
207
  throw new ValidationError(
116
- `Unknown guardrails subcommand: "${subcommand}". Use one of: check, init.`
208
+ `Unknown guardrails subcommand: "${subcommand}". Use one of: check, init, scope, trace.`
117
209
  );
118
210
  }
119
211
  }
@@ -19,6 +19,7 @@ function cmdHelp() {
19
19
  " update Refresh the npm package and optionally re-apply managed project/runtime assets",
20
20
  " init Initialize SDTK-CODE workspace",
21
21
  " runtime Manage runtime asset installation (install, uninstall, status)",
22
+ " agent-team Preview/export agent-team contract (plan, preview, export) — no execution",
22
23
  "",
23
24
  "Workflow status:",
24
25
  " Implemented now: start, plan, build, verify, ship, status, doctor, resume",
@@ -155,6 +156,18 @@ function cmdHelp() {
155
156
  " Maintainer-root guard: init/update refuse the SDTK maintainer monorepo root as a managed project target.",
156
157
  " Use a consumer project path, or use --skip-project-files when update should avoid project-file refresh.",
157
158
  "",
159
+ "Agent-team subcommands (preview/export only, no execution):",
160
+ " sdtk-code agent-team plan --feature-key <KEY> [--project-path <path>]",
161
+ " sdtk-code agent-team preview --feature-key <KEY> [--project-path <path>]",
162
+ " sdtk-code agent-team export --feature-key <KEY> --runtime <codex|claude> [--project-path <path>]",
163
+ " Reads docs/dev/CODE_HANDOFF_<KEY>.json + .sdtk/trust/sleep-plan.json (fail-closed).",
164
+ " plan/preview write .sdtk/agent-team/AGENT_TEAM_PLAN_<KEY>.json, task packets, and",
165
+ " docs/trust/AGENT_TEAM_PREVIEW_<KEY>.md.",
166
+ " export turns the plan into runtime bundles under .sdtk/agent-team/exports/<runtime>/<KEY>/:",
167
+ " <ROLE>.goal.txt, adapter-metadata.json, RUN_BRIEF.md, and (codex only) <ROLE>.toml.preview review draft.",
168
+ " export/preview only — agents are not executed, no .codex/agents or .claude files are written,",
169
+ " and Sleep execution is not available. run is not available in this phase.",
170
+ "",
158
171
  "Runtime options:",
159
172
  " --runtime <codex|claude> Target runtime (required)",
160
173
  " --scope <project|user> Install scope (default: project for claude, user for codex)",