cclaw-cli 7.7.1 → 8.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/README.md +210 -134
- package/dist/artifact-frontmatter.d.ts +51 -0
- package/dist/artifact-frontmatter.js +131 -0
- package/dist/artifact-paths.d.ts +7 -27
- package/dist/artifact-paths.js +20 -249
- package/dist/cancel.d.ts +16 -0
- package/dist/cancel.js +66 -0
- package/dist/cli.d.ts +2 -27
- package/dist/cli.js +90 -508
- package/dist/compound.d.ts +26 -0
- package/dist/compound.js +96 -0
- package/dist/config.d.ts +14 -51
- package/dist/config.js +23 -359
- package/dist/constants.d.ts +11 -18
- package/dist/constants.js +19 -106
- package/dist/content/antipatterns.d.ts +1 -0
- package/dist/content/antipatterns.js +109 -0
- package/dist/content/artifact-templates.d.ts +10 -0
- package/dist/content/artifact-templates.js +550 -0
- package/dist/content/cancel-command.d.ts +2 -2
- package/dist/content/cancel-command.js +25 -17
- package/dist/content/core-agents.d.ts +9 -233
- package/dist/content/core-agents.js +39 -768
- package/dist/content/decision-protocol.d.ts +1 -12
- package/dist/content/decision-protocol.js +27 -20
- package/dist/content/examples.d.ts +8 -42
- package/dist/content/examples.js +293 -425
- package/dist/content/idea-command.d.ts +2 -0
- package/dist/content/idea-command.js +38 -0
- package/dist/content/iron-laws.d.ts +4 -138
- package/dist/content/iron-laws.js +18 -197
- package/dist/content/meta-skill.d.ts +1 -3
- package/dist/content/meta-skill.js +57 -134
- package/dist/content/node-hooks.d.ts +12 -8
- package/dist/content/node-hooks.js +188 -838
- package/dist/content/recovery.d.ts +8 -0
- package/dist/content/recovery.js +179 -0
- package/dist/content/reference-patterns.d.ts +4 -13
- package/dist/content/reference-patterns.js +260 -389
- package/dist/content/research-playbooks.d.ts +8 -8
- package/dist/content/research-playbooks.js +108 -121
- package/dist/content/review-loop.d.ts +6 -192
- package/dist/content/review-loop.js +29 -731
- package/dist/content/skills.d.ts +8 -38
- package/dist/content/skills.js +681 -732
- package/dist/content/specialist-prompts/architect.d.ts +1 -0
- package/dist/content/specialist-prompts/architect.js +225 -0
- package/dist/content/specialist-prompts/brainstormer.d.ts +1 -0
- package/dist/content/specialist-prompts/brainstormer.js +168 -0
- package/dist/content/specialist-prompts/index.d.ts +2 -0
- package/dist/content/specialist-prompts/index.js +14 -0
- package/dist/content/specialist-prompts/planner.d.ts +1 -0
- package/dist/content/specialist-prompts/planner.js +182 -0
- package/dist/content/specialist-prompts/reviewer.d.ts +1 -0
- package/dist/content/specialist-prompts/reviewer.js +193 -0
- package/dist/content/specialist-prompts/security-reviewer.d.ts +1 -0
- package/dist/content/specialist-prompts/security-reviewer.js +133 -0
- package/dist/content/specialist-prompts/slice-builder.d.ts +1 -0
- package/dist/content/specialist-prompts/slice-builder.js +232 -0
- package/dist/content/stage-playbooks.d.ts +8 -0
- package/dist/content/stage-playbooks.js +404 -0
- package/dist/content/start-command.d.ts +2 -12
- package/dist/content/start-command.js +221 -207
- package/dist/flow-state.d.ts +21 -178
- package/dist/flow-state.js +67 -170
- package/dist/fs-utils.d.ts +6 -26
- package/dist/fs-utils.js +29 -162
- package/dist/gitignore.d.ts +2 -1
- package/dist/gitignore.js +51 -34
- package/dist/harness-detect.d.ts +10 -0
- package/dist/harness-detect.js +29 -0
- package/dist/install.d.ts +27 -15
- package/dist/install.js +230 -1342
- package/dist/knowledge-store.d.ts +19 -163
- package/dist/knowledge-store.js +56 -590
- package/dist/logger.d.ts +8 -3
- package/dist/logger.js +13 -4
- package/dist/orchestrator-routing.d.ts +29 -0
- package/dist/orchestrator-routing.js +156 -0
- package/dist/run-persistence.d.ts +7 -118
- package/dist/run-persistence.js +29 -845
- package/dist/runtime/run-hook.entry.d.ts +1 -3
- package/dist/runtime/run-hook.entry.js +19 -4
- package/dist/runtime/run-hook.mjs +13 -1024
- package/dist/types.d.ts +25 -261
- package/dist/types.js +8 -36
- package/package.json +6 -3
- package/dist/artifact-linter/brainstorm.d.ts +0 -2
- package/dist/artifact-linter/brainstorm.js +0 -353
- package/dist/artifact-linter/design.d.ts +0 -18
- package/dist/artifact-linter/design.js +0 -444
- package/dist/artifact-linter/findings-dedup.d.ts +0 -56
- package/dist/artifact-linter/findings-dedup.js +0 -232
- package/dist/artifact-linter/plan.d.ts +0 -2
- package/dist/artifact-linter/plan.js +0 -826
- package/dist/artifact-linter/review-army.d.ts +0 -49
- package/dist/artifact-linter/review-army.js +0 -520
- package/dist/artifact-linter/review.d.ts +0 -2
- package/dist/artifact-linter/review.js +0 -113
- package/dist/artifact-linter/scope.d.ts +0 -2
- package/dist/artifact-linter/scope.js +0 -158
- package/dist/artifact-linter/shared.d.ts +0 -637
- package/dist/artifact-linter/shared.js +0 -2163
- package/dist/artifact-linter/ship.d.ts +0 -2
- package/dist/artifact-linter/ship.js +0 -250
- package/dist/artifact-linter/spec.d.ts +0 -2
- package/dist/artifact-linter/spec.js +0 -176
- package/dist/artifact-linter/tdd.d.ts +0 -118
- package/dist/artifact-linter/tdd.js +0 -1404
- package/dist/artifact-linter.d.ts +0 -15
- package/dist/artifact-linter.js +0 -517
- package/dist/codex-feature-flag.d.ts +0 -58
- package/dist/codex-feature-flag.js +0 -193
- package/dist/content/closeout-guidance.d.ts +0 -14
- package/dist/content/closeout-guidance.js +0 -44
- package/dist/content/diff-command.d.ts +0 -1
- package/dist/content/diff-command.js +0 -43
- package/dist/content/harness-doc.d.ts +0 -1
- package/dist/content/harness-doc.js +0 -65
- package/dist/content/hook-events.d.ts +0 -9
- package/dist/content/hook-events.js +0 -23
- package/dist/content/hook-manifest.d.ts +0 -81
- package/dist/content/hook-manifest.js +0 -156
- package/dist/content/hooks.d.ts +0 -11
- package/dist/content/hooks.js +0 -1972
- package/dist/content/idea.d.ts +0 -60
- package/dist/content/idea.js +0 -416
- package/dist/content/language-policy.d.ts +0 -2
- package/dist/content/language-policy.js +0 -13
- package/dist/content/learnings.d.ts +0 -6
- package/dist/content/learnings.js +0 -141
- package/dist/content/observe.d.ts +0 -19
- package/dist/content/observe.js +0 -86
- package/dist/content/opencode-plugin.d.ts +0 -1
- package/dist/content/opencode-plugin.js +0 -635
- package/dist/content/review-prompts.d.ts +0 -1
- package/dist/content/review-prompts.js +0 -104
- package/dist/content/runtime-shared-snippets.d.ts +0 -8
- package/dist/content/runtime-shared-snippets.js +0 -80
- package/dist/content/session-hooks.d.ts +0 -7
- package/dist/content/session-hooks.js +0 -107
- package/dist/content/skills-elicitation.d.ts +0 -1
- package/dist/content/skills-elicitation.js +0 -167
- package/dist/content/stage-command.d.ts +0 -2
- package/dist/content/stage-command.js +0 -17
- package/dist/content/stage-schema.d.ts +0 -117
- package/dist/content/stage-schema.js +0 -955
- package/dist/content/stages/_lint-metadata/index.d.ts +0 -2
- package/dist/content/stages/_lint-metadata/index.js +0 -97
- package/dist/content/stages/brainstorm.d.ts +0 -2
- package/dist/content/stages/brainstorm.js +0 -184
- package/dist/content/stages/design.d.ts +0 -2
- package/dist/content/stages/design.js +0 -288
- package/dist/content/stages/index.d.ts +0 -8
- package/dist/content/stages/index.js +0 -11
- package/dist/content/stages/plan.d.ts +0 -2
- package/dist/content/stages/plan.js +0 -191
- package/dist/content/stages/review.d.ts +0 -2
- package/dist/content/stages/review.js +0 -240
- package/dist/content/stages/schema-types.d.ts +0 -203
- package/dist/content/stages/schema-types.js +0 -1
- package/dist/content/stages/scope.d.ts +0 -2
- package/dist/content/stages/scope.js +0 -254
- package/dist/content/stages/ship.d.ts +0 -2
- package/dist/content/stages/ship.js +0 -159
- package/dist/content/stages/spec.d.ts +0 -2
- package/dist/content/stages/spec.js +0 -170
- package/dist/content/stages/tdd.d.ts +0 -4
- package/dist/content/stages/tdd.js +0 -273
- package/dist/content/state-contracts.d.ts +0 -1
- package/dist/content/state-contracts.js +0 -63
- package/dist/content/status-command.d.ts +0 -4
- package/dist/content/status-command.js +0 -109
- package/dist/content/subagent-context-skills.d.ts +0 -4
- package/dist/content/subagent-context-skills.js +0 -279
- package/dist/content/subagents.d.ts +0 -3
- package/dist/content/subagents.js +0 -997
- package/dist/content/templates.d.ts +0 -26
- package/dist/content/templates.js +0 -1692
- package/dist/content/track-render-context.d.ts +0 -18
- package/dist/content/track-render-context.js +0 -53
- package/dist/content/tree-command.d.ts +0 -1
- package/dist/content/tree-command.js +0 -64
- package/dist/content/utility-skills.d.ts +0 -30
- package/dist/content/utility-skills.js +0 -160
- package/dist/content/view-command.d.ts +0 -2
- package/dist/content/view-command.js +0 -92
- package/dist/delegation.d.ts +0 -649
- package/dist/delegation.js +0 -1539
- package/dist/early-loop.d.ts +0 -70
- package/dist/early-loop.js +0 -302
- package/dist/execution-topology.d.ts +0 -44
- package/dist/execution-topology.js +0 -95
- package/dist/gate-evidence.d.ts +0 -85
- package/dist/gate-evidence.js +0 -631
- package/dist/harness-adapters.d.ts +0 -151
- package/dist/harness-adapters.js +0 -756
- package/dist/harness-selection.d.ts +0 -31
- package/dist/harness-selection.js +0 -214
- package/dist/hook-schema.d.ts +0 -6
- package/dist/hook-schema.js +0 -114
- package/dist/hook-schemas/claude-hooks.v1.json +0 -10
- package/dist/hook-schemas/codex-hooks.v1.json +0 -10
- package/dist/hook-schemas/cursor-hooks.v1.json +0 -13
- package/dist/init-detect.d.ts +0 -2
- package/dist/init-detect.js +0 -50
- package/dist/internal/advance-stage/advance.d.ts +0 -89
- package/dist/internal/advance-stage/advance.js +0 -655
- package/dist/internal/advance-stage/cancel-run.d.ts +0 -8
- package/dist/internal/advance-stage/cancel-run.js +0 -19
- package/dist/internal/advance-stage/flow-state-coercion.d.ts +0 -3
- package/dist/internal/advance-stage/flow-state-coercion.js +0 -81
- package/dist/internal/advance-stage/helpers.d.ts +0 -14
- package/dist/internal/advance-stage/helpers.js +0 -145
- package/dist/internal/advance-stage/hook.d.ts +0 -8
- package/dist/internal/advance-stage/hook.js +0 -40
- package/dist/internal/advance-stage/parsers.d.ts +0 -72
- package/dist/internal/advance-stage/parsers.js +0 -357
- package/dist/internal/advance-stage/proactive-delegation-trace.d.ts +0 -24
- package/dist/internal/advance-stage/proactive-delegation-trace.js +0 -56
- package/dist/internal/advance-stage/review-loop.d.ts +0 -16
- package/dist/internal/advance-stage/review-loop.js +0 -199
- package/dist/internal/advance-stage/rewind.d.ts +0 -14
- package/dist/internal/advance-stage/rewind.js +0 -108
- package/dist/internal/advance-stage/start-flow.d.ts +0 -13
- package/dist/internal/advance-stage/start-flow.js +0 -241
- package/dist/internal/advance-stage/verify.d.ts +0 -21
- package/dist/internal/advance-stage/verify.js +0 -185
- package/dist/internal/advance-stage.d.ts +0 -7
- package/dist/internal/advance-stage.js +0 -138
- package/dist/internal/cohesion-contract-stub.d.ts +0 -24
- package/dist/internal/cohesion-contract-stub.js +0 -148
- package/dist/internal/compound-readiness.d.ts +0 -23
- package/dist/internal/compound-readiness.js +0 -102
- package/dist/internal/detect-public-api-changes.d.ts +0 -5
- package/dist/internal/detect-public-api-changes.js +0 -45
- package/dist/internal/detect-supply-chain-changes.d.ts +0 -6
- package/dist/internal/detect-supply-chain-changes.js +0 -138
- package/dist/internal/early-loop-status.d.ts +0 -7
- package/dist/internal/early-loop-status.js +0 -93
- package/dist/internal/envelope-validate.d.ts +0 -7
- package/dist/internal/envelope-validate.js +0 -66
- package/dist/internal/flow-state-repair.d.ts +0 -20
- package/dist/internal/flow-state-repair.js +0 -104
- package/dist/internal/plan-split-waves.d.ts +0 -190
- package/dist/internal/plan-split-waves.js +0 -764
- package/dist/internal/runtime-integrity.d.ts +0 -7
- package/dist/internal/runtime-integrity.js +0 -268
- package/dist/internal/slice-commit.d.ts +0 -7
- package/dist/internal/slice-commit.js +0 -619
- package/dist/internal/tdd-loop-status.d.ts +0 -14
- package/dist/internal/tdd-loop-status.js +0 -68
- package/dist/internal/tdd-red-evidence.d.ts +0 -7
- package/dist/internal/tdd-red-evidence.js +0 -153
- package/dist/internal/waiver-grant.d.ts +0 -62
- package/dist/internal/waiver-grant.js +0 -294
- package/dist/internal/wave-status.d.ts +0 -74
- package/dist/internal/wave-status.js +0 -506
- package/dist/managed-resources.d.ts +0 -53
- package/dist/managed-resources.js +0 -313
- package/dist/policy.d.ts +0 -10
- package/dist/policy.js +0 -167
- package/dist/retro-gate.d.ts +0 -9
- package/dist/retro-gate.js +0 -47
- package/dist/run-archive.d.ts +0 -61
- package/dist/run-archive.js +0 -391
- package/dist/runs.d.ts +0 -2
- package/dist/runs.js +0 -2
- package/dist/stack-detection.d.ts +0 -116
- package/dist/stack-detection.js +0 -489
- package/dist/streaming/event-stream.d.ts +0 -31
- package/dist/streaming/event-stream.js +0 -114
- package/dist/tdd-cycle.d.ts +0 -107
- package/dist/tdd-cycle.js +0 -289
- package/dist/tdd-verification-evidence.d.ts +0 -17
- package/dist/tdd-verification-evidence.js +0 -122
- package/dist/track-heuristics.d.ts +0 -27
- package/dist/track-heuristics.js +0 -154
- package/dist/util/slice-id.d.ts +0 -58
- package/dist/util/slice-id.js +0 -89
- package/dist/worktree-manager.d.ts +0 -20
- package/dist/worktree-manager.js +0 -108
package/dist/track-heuristics.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { FLOW_TRACKS } from "./types.js";
|
|
2
|
-
// Built-in vocabulary per track. Kept in one place so tests, docs, and the
|
|
3
|
-
// /cc skill prose can snapshot the exact same strings.
|
|
4
|
-
const DEFAULT_RULES = {
|
|
5
|
-
quick: {
|
|
6
|
-
triggers: [
|
|
7
|
-
"bug",
|
|
8
|
-
"bugfix",
|
|
9
|
-
"fix",
|
|
10
|
-
"hotfix",
|
|
11
|
-
"patch",
|
|
12
|
-
"typo",
|
|
13
|
-
"regression",
|
|
14
|
-
"copy change",
|
|
15
|
-
"rename",
|
|
16
|
-
"bump",
|
|
17
|
-
"upgrade dep",
|
|
18
|
-
"config tweak",
|
|
19
|
-
"docs only",
|
|
20
|
-
"comment",
|
|
21
|
-
"lint",
|
|
22
|
-
"format",
|
|
23
|
-
"small",
|
|
24
|
-
"tiny",
|
|
25
|
-
"one-liner",
|
|
26
|
-
"revert"
|
|
27
|
-
]
|
|
28
|
-
},
|
|
29
|
-
medium: {
|
|
30
|
-
triggers: [
|
|
31
|
-
"add endpoint",
|
|
32
|
-
"add field",
|
|
33
|
-
"extend existing",
|
|
34
|
-
"wire integration",
|
|
35
|
-
"small migration",
|
|
36
|
-
"new screen following existing pattern"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
standard: {
|
|
40
|
-
triggers: [
|
|
41
|
-
"new feature",
|
|
42
|
-
"refactor",
|
|
43
|
-
"migration",
|
|
44
|
-
"platform",
|
|
45
|
-
"architecture",
|
|
46
|
-
"schema",
|
|
47
|
-
"integrate",
|
|
48
|
-
"workflow",
|
|
49
|
-
"onboarding"
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
// Fixed evaluation order: narrow-to-broad. Overriding this was never wired
|
|
54
|
-
// into runtime, so cclaw no longer offers that knob.
|
|
55
|
-
const EVALUATION_ORDER = ["standard", "medium", "quick"];
|
|
56
|
-
const DEFAULT_FALLBACK = "standard";
|
|
57
|
-
const ADAPTIVE_ELICITATION_STAGES = new Set(["brainstorm", "scope", "design"]);
|
|
58
|
-
const QUESTION_BUDGET_HINTS_BY_DISCOVERY_MODE = {
|
|
59
|
-
lean: { min: 3, recommended: 4, hardCapWarning: 6 },
|
|
60
|
-
guided: { min: 5, recommended: 7, hardCapWarning: 10 },
|
|
61
|
-
deep: { min: 7, recommended: 10, hardCapWarning: 14 }
|
|
62
|
-
};
|
|
63
|
-
function hasToken(promptLower, token) {
|
|
64
|
-
return promptLower.includes(token.toLowerCase());
|
|
65
|
-
}
|
|
66
|
-
function matchRule(promptLower, rule) {
|
|
67
|
-
if (!rule)
|
|
68
|
-
return [];
|
|
69
|
-
const matches = [];
|
|
70
|
-
for (const trigger of rule.triggers ?? []) {
|
|
71
|
-
if (hasToken(promptLower, trigger)) {
|
|
72
|
-
matches.push(trigger);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return [...new Set(matches)];
|
|
76
|
-
}
|
|
77
|
-
function isValidTrack(value) {
|
|
78
|
-
return FLOW_TRACKS.includes(value);
|
|
79
|
-
}
|
|
80
|
-
function mergeRules(base, overrides) {
|
|
81
|
-
const merged = { ...base };
|
|
82
|
-
const over = overrides?.tracks;
|
|
83
|
-
if (!over)
|
|
84
|
-
return merged;
|
|
85
|
-
for (const track of FLOW_TRACKS) {
|
|
86
|
-
const rule = over[track];
|
|
87
|
-
if (!rule)
|
|
88
|
-
continue;
|
|
89
|
-
merged[track] = {
|
|
90
|
-
triggers: rule.triggers ?? merged[track].triggers,
|
|
91
|
-
veto: rule.veto ?? merged[track].veto
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return merged;
|
|
95
|
-
}
|
|
96
|
-
function resolveFallback(config) {
|
|
97
|
-
return config?.fallback && isValidTrack(config.fallback) ? config.fallback : DEFAULT_FALLBACK;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Reference implementation of the track classifier the /cc skill prose
|
|
101
|
-
* describes. Tests pin its behavior so the built-in defaults stay honest.
|
|
102
|
-
* This function is not called from cclaw runtime — `/cc` routing happens in
|
|
103
|
-
* the LLM. If you wire this in later, update README to drop the
|
|
104
|
-
* "advisory" language.
|
|
105
|
-
*/
|
|
106
|
-
export function resolveTrackFromPrompt(prompt, config) {
|
|
107
|
-
const promptLower = prompt.toLowerCase();
|
|
108
|
-
const rules = mergeRules(DEFAULT_RULES, config);
|
|
109
|
-
const fallback = resolveFallback(config);
|
|
110
|
-
for (const track of EVALUATION_ORDER) {
|
|
111
|
-
const rule = rules[track];
|
|
112
|
-
const vetoes = rule.veto ?? [];
|
|
113
|
-
if (vetoes.some((token) => hasToken(promptLower, token))) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const matched = matchRule(promptLower, rule);
|
|
117
|
-
if (matched.length > 0) {
|
|
118
|
-
return {
|
|
119
|
-
track,
|
|
120
|
-
reason: `matched ${track} heuristic (${matched.join(", ")})`,
|
|
121
|
-
matchedTokens: matched,
|
|
122
|
-
confidence: matched.length > 1 ? "high" : "medium",
|
|
123
|
-
overrideGuidance: track === "quick"
|
|
124
|
-
? "Use medium/standard instead when product framing, architecture, schema, migration, security, or unclear scope appears; quick skips ceremony, not safety."
|
|
125
|
-
: track === "medium"
|
|
126
|
-
? "Use standard if architecture, data model, security boundary, or migration risk is uncertain."
|
|
127
|
-
: "Use medium or quick only when the blast radius and architecture are already known."
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
track: fallback,
|
|
133
|
-
reason: `no explicit match, fallback=${fallback}`,
|
|
134
|
-
matchedTokens: [],
|
|
135
|
-
confidence: "low",
|
|
136
|
-
overrideGuidance: "Confirm or override before state is written; choose quick only for known low-blast-radius work, medium for known architecture with product framing, standard for uncertainty."
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export function questionBudgetHint(modeOrTrack, stage) {
|
|
140
|
-
if (!ADAPTIVE_ELICITATION_STAGES.has(stage)) {
|
|
141
|
-
return { min: 0, recommended: 0, hardCapWarning: 0 };
|
|
142
|
-
}
|
|
143
|
-
if (modeOrTrack === "lean" || modeOrTrack === "guided" || modeOrTrack === "deep") {
|
|
144
|
-
return QUESTION_BUDGET_HINTS_BY_DISCOVERY_MODE[modeOrTrack];
|
|
145
|
-
}
|
|
146
|
-
if (modeOrTrack === "quick")
|
|
147
|
-
return QUESTION_BUDGET_HINTS_BY_DISCOVERY_MODE.lean;
|
|
148
|
-
return QUESTION_BUDGET_HINTS_BY_DISCOVERY_MODE.guided;
|
|
149
|
-
}
|
|
150
|
-
export const TRACK_HEURISTICS_DEFAULTS = {
|
|
151
|
-
fallback: DEFAULT_FALLBACK,
|
|
152
|
-
evaluationOrder: EVALUATION_ORDER,
|
|
153
|
-
tracks: DEFAULT_RULES
|
|
154
|
-
};
|
package/dist/util/slice-id.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slice-ID helpers.
|
|
3
|
-
*
|
|
4
|
-
* 7.6.0 — relaxed strict `/^S-\d+$/` to allow lettered sub-slices
|
|
5
|
-
* (`S-36a`, `S-36b`, …) so plan amendments can insert work between
|
|
6
|
-
* existing numeric slices without renumbering.
|
|
7
|
-
*
|
|
8
|
-
* Canonical shape: `S-<integer>(<lowercase-letter>[<lowercase-or-digit>...])?`
|
|
9
|
-
*
|
|
10
|
-
* Sort order (used everywhere we list slice ids):
|
|
11
|
-
* 1. numeric chunk ascending
|
|
12
|
-
* 2. lexical suffix ascending (no suffix sorts before any suffix)
|
|
13
|
-
*
|
|
14
|
-
* So: `S-1 < S-2 < S-10 < S-36 < S-36a < S-36b < S-37`.
|
|
15
|
-
*
|
|
16
|
-
* Surface:
|
|
17
|
-
* - `SLICE_ID_PATTERN` — anchored regex source string for embedding
|
|
18
|
-
* - `SLICE_ID_REGEX` — anchored RegExp for tests
|
|
19
|
-
* - `parseSliceId` — strict parse → `{ numeric, suffix }` or null
|
|
20
|
-
* - `isSliceId` — boolean shape check
|
|
21
|
-
* - `compareSliceIds` — sort comparator
|
|
22
|
-
* - `sortSliceIds` — convenience wrapper around `compareSliceIds`
|
|
23
|
-
*/
|
|
24
|
-
/** Anchored, case-insensitive regex source for slice ids. */
|
|
25
|
-
export declare const SLICE_ID_PATTERN = "^S-(\\d+)([a-z][a-z0-9]*)?$";
|
|
26
|
-
/** Anchored, case-insensitive RegExp instance for slice ids. */
|
|
27
|
-
export declare const SLICE_ID_REGEX: RegExp;
|
|
28
|
-
export interface ParsedSliceId {
|
|
29
|
-
/** Canonical normalized form, e.g. `S-36a`. */
|
|
30
|
-
id: string;
|
|
31
|
-
/** Numeric chunk as a number (e.g. `S-36a` → `36`). */
|
|
32
|
-
numeric: number;
|
|
33
|
-
/** Lowercase suffix (e.g. `S-36a` → `"a"`). Empty string when absent. */
|
|
34
|
-
suffix: string;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Strict parse of a slice id token.
|
|
38
|
-
*
|
|
39
|
-
* Returns `null` when the input is not a slice id. Whitespace and
|
|
40
|
-
* surrounding markdown decorations (backticks, brackets, quotes) are
|
|
41
|
-
* stripped before parsing so callers can pass cells from markdown
|
|
42
|
-
* tables verbatim.
|
|
43
|
-
*/
|
|
44
|
-
export declare function parseSliceId(raw: unknown): ParsedSliceId | null;
|
|
45
|
-
/**
|
|
46
|
-
* Boolean shape check. Lowercase-or-uppercase `S-` prefix accepted; the
|
|
47
|
-
* canonical form is uppercase.
|
|
48
|
-
*/
|
|
49
|
-
export declare function isSliceId(raw: unknown): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Comparator that orders slice ids by numeric chunk first, then by
|
|
52
|
-
* suffix (no-suffix sorts before any suffix). Non-slice tokens fall
|
|
53
|
-
* back to a stable lexical comparison so callers can pass mixed input
|
|
54
|
-
* without crashing.
|
|
55
|
-
*/
|
|
56
|
-
export declare function compareSliceIds(a: string, b: string): number;
|
|
57
|
-
/** Convenience wrapper: returns a new sorted array using `compareSliceIds`. */
|
|
58
|
-
export declare function sortSliceIds(ids: readonly string[]): string[];
|
package/dist/util/slice-id.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slice-ID helpers.
|
|
3
|
-
*
|
|
4
|
-
* 7.6.0 — relaxed strict `/^S-\d+$/` to allow lettered sub-slices
|
|
5
|
-
* (`S-36a`, `S-36b`, …) so plan amendments can insert work between
|
|
6
|
-
* existing numeric slices without renumbering.
|
|
7
|
-
*
|
|
8
|
-
* Canonical shape: `S-<integer>(<lowercase-letter>[<lowercase-or-digit>...])?`
|
|
9
|
-
*
|
|
10
|
-
* Sort order (used everywhere we list slice ids):
|
|
11
|
-
* 1. numeric chunk ascending
|
|
12
|
-
* 2. lexical suffix ascending (no suffix sorts before any suffix)
|
|
13
|
-
*
|
|
14
|
-
* So: `S-1 < S-2 < S-10 < S-36 < S-36a < S-36b < S-37`.
|
|
15
|
-
*
|
|
16
|
-
* Surface:
|
|
17
|
-
* - `SLICE_ID_PATTERN` — anchored regex source string for embedding
|
|
18
|
-
* - `SLICE_ID_REGEX` — anchored RegExp for tests
|
|
19
|
-
* - `parseSliceId` — strict parse → `{ numeric, suffix }` or null
|
|
20
|
-
* - `isSliceId` — boolean shape check
|
|
21
|
-
* - `compareSliceIds` — sort comparator
|
|
22
|
-
* - `sortSliceIds` — convenience wrapper around `compareSliceIds`
|
|
23
|
-
*/
|
|
24
|
-
/** Anchored, case-insensitive regex source for slice ids. */
|
|
25
|
-
export const SLICE_ID_PATTERN = "^S-(\\d+)([a-z][a-z0-9]*)?$";
|
|
26
|
-
/** Anchored, case-insensitive RegExp instance for slice ids. */
|
|
27
|
-
export const SLICE_ID_REGEX = new RegExp(SLICE_ID_PATTERN, "iu");
|
|
28
|
-
/**
|
|
29
|
-
* Strict parse of a slice id token.
|
|
30
|
-
*
|
|
31
|
-
* Returns `null` when the input is not a slice id. Whitespace and
|
|
32
|
-
* surrounding markdown decorations (backticks, brackets, quotes) are
|
|
33
|
-
* stripped before parsing so callers can pass cells from markdown
|
|
34
|
-
* tables verbatim.
|
|
35
|
-
*/
|
|
36
|
-
export function parseSliceId(raw) {
|
|
37
|
-
if (typeof raw !== "string")
|
|
38
|
-
return null;
|
|
39
|
-
const stripped = raw.trim().replace(/^[`"'[\]()]+|[`"'[\]()]+$/gu, "");
|
|
40
|
-
const match = SLICE_ID_REGEX.exec(stripped);
|
|
41
|
-
if (!match)
|
|
42
|
-
return null;
|
|
43
|
-
const numericPart = match[1] ?? "";
|
|
44
|
-
const suffixPart = (match[2] ?? "").toLowerCase();
|
|
45
|
-
const numeric = Number(numericPart);
|
|
46
|
-
if (!Number.isFinite(numeric) || !Number.isInteger(numeric))
|
|
47
|
-
return null;
|
|
48
|
-
const id = suffixPart.length > 0 ? `S-${numericPart}${suffixPart}` : `S-${numericPart}`;
|
|
49
|
-
return { id, numeric, suffix: suffixPart };
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Boolean shape check. Lowercase-or-uppercase `S-` prefix accepted; the
|
|
53
|
-
* canonical form is uppercase.
|
|
54
|
-
*/
|
|
55
|
-
export function isSliceId(raw) {
|
|
56
|
-
return parseSliceId(raw) !== null;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Comparator that orders slice ids by numeric chunk first, then by
|
|
60
|
-
* suffix (no-suffix sorts before any suffix). Non-slice tokens fall
|
|
61
|
-
* back to a stable lexical comparison so callers can pass mixed input
|
|
62
|
-
* without crashing.
|
|
63
|
-
*/
|
|
64
|
-
export function compareSliceIds(a, b) {
|
|
65
|
-
const pa = parseSliceId(a);
|
|
66
|
-
const pb = parseSliceId(b);
|
|
67
|
-
if (pa && pb) {
|
|
68
|
-
if (pa.numeric !== pb.numeric)
|
|
69
|
-
return pa.numeric - pb.numeric;
|
|
70
|
-
if (pa.suffix === pb.suffix)
|
|
71
|
-
return 0;
|
|
72
|
-
if (pa.suffix === "")
|
|
73
|
-
return -1;
|
|
74
|
-
if (pb.suffix === "")
|
|
75
|
-
return 1;
|
|
76
|
-
return pa.suffix < pb.suffix ? -1 : 1;
|
|
77
|
-
}
|
|
78
|
-
if (pa)
|
|
79
|
-
return -1;
|
|
80
|
-
if (pb)
|
|
81
|
-
return 1;
|
|
82
|
-
if (a === b)
|
|
83
|
-
return 0;
|
|
84
|
-
return a < b ? -1 : 1;
|
|
85
|
-
}
|
|
86
|
-
/** Convenience wrapper: returns a new sorted array using `compareSliceIds`. */
|
|
87
|
-
export function sortSliceIds(ids) {
|
|
88
|
-
return [...ids].sort(compareSliceIds);
|
|
89
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface WorktreeManagerOptions {
|
|
2
|
-
projectRoot?: string;
|
|
3
|
-
worktreeRoot?: string;
|
|
4
|
-
}
|
|
5
|
-
export declare class WorktreeUnsupportedError extends Error {
|
|
6
|
-
readonly code = "worktree_unavailable";
|
|
7
|
-
constructor(message: string);
|
|
8
|
-
}
|
|
9
|
-
export declare class WorktreeMergeConflictError extends Error {
|
|
10
|
-
readonly code = "worktree_merge_conflict";
|
|
11
|
-
constructor(message: string);
|
|
12
|
-
}
|
|
13
|
-
export declare function createSliceWorktree(sliceId: string, baseRef: string, _claimedPaths: string[], options?: WorktreeManagerOptions): Promise<{
|
|
14
|
-
path: string;
|
|
15
|
-
ref: string;
|
|
16
|
-
}>;
|
|
17
|
-
export declare function commitAndMergeBack(worktreePath: string, _message: string, options?: WorktreeManagerOptions): Promise<{
|
|
18
|
-
commitSha: string;
|
|
19
|
-
}>;
|
|
20
|
-
export declare function cleanupWorktree(worktreePath: string, options?: WorktreeManagerOptions): Promise<void>;
|
package/dist/worktree-manager.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { DEFAULT_TDD_WORKTREE_ROOT } from "./config.js";
|
|
6
|
-
import { exists } from "./fs-utils.js";
|
|
7
|
-
const execFileAsync = promisify(execFile);
|
|
8
|
-
export class WorktreeUnsupportedError extends Error {
|
|
9
|
-
code = "worktree_unavailable";
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "WorktreeUnsupportedError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export class WorktreeMergeConflictError extends Error {
|
|
16
|
-
code = "worktree_merge_conflict";
|
|
17
|
-
constructor(message) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.name = "WorktreeMergeConflictError";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function sanitizeSliceId(sliceId) {
|
|
23
|
-
return sliceId.trim().replace(/[^A-Za-z0-9._-]+/gu, "-");
|
|
24
|
-
}
|
|
25
|
-
function resolveProjectRoot(options) {
|
|
26
|
-
return options?.projectRoot ?? process.cwd();
|
|
27
|
-
}
|
|
28
|
-
function resolveWorktreeRoot(projectRoot, options) {
|
|
29
|
-
const root = typeof options?.worktreeRoot === "string" && options.worktreeRoot.trim().length > 0
|
|
30
|
-
? options.worktreeRoot.trim()
|
|
31
|
-
: DEFAULT_TDD_WORKTREE_ROOT;
|
|
32
|
-
return path.resolve(projectRoot, root);
|
|
33
|
-
}
|
|
34
|
-
async function resolveMainRepoRootFromWorktree(worktreePath) {
|
|
35
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: worktreePath });
|
|
36
|
-
const commonDir = stdout.trim();
|
|
37
|
-
if (commonDir.length === 0) {
|
|
38
|
-
throw new Error(`Cannot resolve git common-dir from worktree ${worktreePath}`);
|
|
39
|
-
}
|
|
40
|
-
return path.dirname(commonDir);
|
|
41
|
-
}
|
|
42
|
-
export async function createSliceWorktree(sliceId, baseRef, _claimedPaths, options = {}) {
|
|
43
|
-
const projectRoot = resolveProjectRoot(options);
|
|
44
|
-
const ref = baseRef.trim().length > 0 ? baseRef.trim() : "HEAD";
|
|
45
|
-
const worktreeRoot = resolveWorktreeRoot(projectRoot, options);
|
|
46
|
-
const safeSliceId = sanitizeSliceId(sliceId);
|
|
47
|
-
if (safeSliceId.length === 0) {
|
|
48
|
-
throw new WorktreeUnsupportedError("Cannot create worktree: empty slice id.");
|
|
49
|
-
}
|
|
50
|
-
const worktreePath = path.join(worktreeRoot, safeSliceId);
|
|
51
|
-
try {
|
|
52
|
-
await execFileAsync("git", ["rev-parse", "--git-dir"], { cwd: projectRoot });
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
throw new WorktreeUnsupportedError("Cannot create worktree: repository has no .git metadata.");
|
|
56
|
-
}
|
|
57
|
-
await fs.mkdir(worktreeRoot, { recursive: true });
|
|
58
|
-
if (await exists(worktreePath)) {
|
|
59
|
-
if (await exists(path.join(worktreePath, ".git"))) {
|
|
60
|
-
return { path: worktreePath, ref };
|
|
61
|
-
}
|
|
62
|
-
await fs.rm(worktreePath, { recursive: true, force: true });
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
await execFileAsync("git", ["worktree", "add", "--detach", worktreePath, ref], {
|
|
66
|
-
cwd: projectRoot
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw new WorktreeUnsupportedError(`Cannot create worktree for ${sliceId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
71
|
-
}
|
|
72
|
-
return { path: worktreePath, ref };
|
|
73
|
-
}
|
|
74
|
-
export async function commitAndMergeBack(worktreePath, _message, options = {}) {
|
|
75
|
-
const projectRoot = options.projectRoot ?? await resolveMainRepoRootFromWorktree(worktreePath);
|
|
76
|
-
try {
|
|
77
|
-
const { stdout: mainHeadStdout } = await execFileAsync("git", ["rev-parse", "HEAD"], {
|
|
78
|
-
cwd: projectRoot
|
|
79
|
-
});
|
|
80
|
-
const mainHead = mainHeadStdout.trim();
|
|
81
|
-
await execFileAsync("git", ["rebase", mainHead], { cwd: worktreePath });
|
|
82
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "HEAD"], { cwd: worktreePath });
|
|
83
|
-
const commitSha = stdout.trim();
|
|
84
|
-
await execFileAsync("git", ["fetch", worktreePath, "HEAD"], { cwd: projectRoot });
|
|
85
|
-
await execFileAsync("git", ["merge", "--ff-only", "FETCH_HEAD"], { cwd: projectRoot });
|
|
86
|
-
return { commitSha };
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
throw new WorktreeMergeConflictError(`worktree_merge_conflict: ${error instanceof Error ? error.message : String(error)}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export async function cleanupWorktree(worktreePath, options = {}) {
|
|
93
|
-
if (!(await exists(worktreePath)))
|
|
94
|
-
return;
|
|
95
|
-
const projectRoot = options.projectRoot ?? await resolveMainRepoRootFromWorktree(worktreePath).catch(() => null);
|
|
96
|
-
if (projectRoot) {
|
|
97
|
-
try {
|
|
98
|
-
await execFileAsync("git", ["worktree", "remove", "--force", worktreePath], {
|
|
99
|
-
cwd: projectRoot
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
// fall through to rm fallback below
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
await fs.rm(worktreePath, { recursive: true, force: true });
|
|
108
|
-
}
|