@pmelab/gtd 35.0.0 → 37.0.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 (69) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +45 -29
  3. package/claude/hooks/context.ts +66 -0
  4. package/claude/hooks/drive.ts +3 -0
  5. package/claude/hooks/register.tsx +69 -6
  6. package/dist/chunks/{reserved-C8Fm3s72.mjs → reserved-zAfoJtR7.mjs} +62 -24
  7. package/dist/chunks/{tail-oaYewBN_.mjs → tail-BRC4DGdV.mjs} +1 -1
  8. package/dist/chunks/{wire-D3Rc5r22.mjs → wire-CSsa3Wxd.mjs} +117 -2
  9. package/dist/flows.mjs +15 -10
  10. package/dist/gtd.bundle.mjs +511 -64
  11. package/dist/testkit.mjs +158 -26
  12. package/dist/wire.mjs +2 -2
  13. package/dist/workflows/cleanup.mjs +2 -2
  14. package/dist/workflows/feature.mjs +138 -38
  15. package/dist/workflows/fix.mjs +2 -2
  16. package/dist/workflows/review.mjs +2 -2
  17. package/dist/workflows/rollout.mjs +1 -1
  18. package/dist/workflows.mjs +208 -66
  19. package/package.json +1 -1
  20. package/skills/authoring/SKILL.md +3 -3
  21. package/src/cli/Cli.test.ts +10 -3
  22. package/src/cli/Cli.ts +76 -1
  23. package/src/cli/Program.test.ts +1 -0
  24. package/src/cli/Program.ts +28 -0
  25. package/src/cli/ToolCommands.ts +3 -0
  26. package/src/edge/Edge.ts +11 -0
  27. package/src/flows/runtime.ts +11 -0
  28. package/src/flows/scripts.ts +31 -9
  29. package/src/replay/Replay.ts +51 -2
  30. package/src/testkit/FlowScripts.test.ts +58 -0
  31. package/src/testkit/FlowScripts.ts +61 -24
  32. package/src/testkit/Layers.ts +1 -0
  33. package/src/wire/BeatDocument.ts +12 -2
  34. package/src/wire/BeatStatus.ts +3 -0
  35. package/src/wire/ContextLimit.fixture.ts +30 -0
  36. package/src/wire/ContextLimit.test.ts +96 -0
  37. package/src/wire/ContextLimit.ts +169 -0
  38. package/src/wire/index.ts +1 -0
  39. package/src/wire/types.ts +7 -0
  40. package/src/workflow/Workflow.ts +9 -1
  41. package/src/workflows/feature/acceptance-criteria.feature +5 -1
  42. package/src/workflows/feature/context-limit.feature +37 -0
  43. package/src/workflows/feature/coverage.feature +6 -3
  44. package/src/workflows/feature/coverage.ts +8 -2
  45. package/src/workflows/feature/fast-path.feature +11 -19
  46. package/src/workflows/feature/feature.test.ts +24 -4
  47. package/src/workflows/feature/feature.ts +14 -10
  48. package/src/workflows/feature/flag-mode.feature +17 -9
  49. package/src/workflows/feature/lens-models.feature +7 -1
  50. package/src/workflows/feature/naive-acceptance.feature +2 -2
  51. package/src/workflows/feature/one-step-land.feature +10 -12
  52. package/src/workflows/feature/quality-unresolved.feature +7 -1
  53. package/src/workflows/feature/refactor-absorbs.feature +12 -5
  54. package/src/workflows/feature/refactor-first.feature +11 -2
  55. package/src/workflows/feature/refactor-lens-models.feature +4 -0
  56. package/src/workflows/feature/refactor-rebuild.feature +269 -0
  57. package/src/workflows/feature/refactor-review.feature +45 -1
  58. package/src/workflows/feature/refactor.ts +9 -3
  59. package/src/workflows/feature/risk-tier.feature +12 -4
  60. package/src/workflows/feature/seam-rejection.feature +4 -9
  61. package/src/workflows/feature/seam.feature +29 -26
  62. package/src/workflows/feature/seam.test.ts +117 -6
  63. package/src/workflows/feature/seam.ts +158 -39
  64. package/src/workflows/review/review-door.feature +12 -4
  65. package/src/workflows/shared/options.test.ts +11 -2
  66. package/src/workflows/shared/options.ts +18 -4
  67. package/src/workflows/shared/steps.ts +1 -0
  68. package/src/workflows/shared/text.test.ts +8 -0
  69. package/src/workflows/shared/text.ts +91 -22
@@ -1,6 +1,14 @@
1
1
  import type { BeatKind, Demand, DemandSession } from "./Demand.js"
2
2
  import type { BeatStatus, NextMatch, StatusChange } from "./BeatStatus.js"
3
- import type { Actor, ApprovalEntry, ModelCost, StateMode, StateName, StepAccess } from "./types.js"
3
+ import type {
4
+ Actor,
5
+ ApprovalEntry,
6
+ ModelCost,
7
+ StateMode,
8
+ StateName,
9
+ StepAccess,
10
+ StepContextLimit,
11
+ } from "./types.js"
4
12
  import { WIRE_SCHEMA } from "./constants.js"
5
13
 
6
14
  /** `gtd next --json`'s `next` key — `null` when landing would commit nothing. */
@@ -56,6 +64,7 @@ export interface BeatDocument {
56
64
  readonly session: DemandSession | undefined
57
65
  readonly model: string | undefined
58
66
  readonly system: string | undefined
67
+ readonly context: StepContextLimit | undefined
59
68
  readonly validate: string | undefined
60
69
  readonly log: string
61
70
  readonly state: StateName
@@ -76,7 +85,7 @@ export interface BeatDocument {
76
85
  }
77
86
 
78
87
  /**
79
- * Flatten a `Demand` plus its `BeatStatus` into the single 25-key document
88
+ * Flatten a `Demand` plus its `BeatStatus` into the single 26-key document
80
89
  * `gtd next --json` emits — the ONLY place the two are joined. `cost`/
81
90
  * `costByModel` are omitted together, exactly when no cost was recorded
82
91
  * (`cost <= 0`).
@@ -93,6 +102,7 @@ export const beatDocument = (demand: Demand, status: BeatStatus): BeatDocument =
93
102
  session,
94
103
  model: status.model,
95
104
  system: status.system,
105
+ context: status.context,
96
106
  validate,
97
107
  log: status.log,
98
108
  state: status.state,
@@ -5,6 +5,7 @@ import type {
5
5
  RenderedDemandSource,
6
6
  StateMode,
7
7
  StateName,
8
+ StepContextLimit,
8
9
  } from "./types.js"
9
10
 
10
11
  /** One pending change — `gtd next --json`'s `changes` entries. */
@@ -32,6 +33,7 @@ export interface BeatStatus {
32
33
  readonly initial: boolean
33
34
  readonly model: string | undefined
34
35
  readonly system: string | undefined
36
+ readonly context: StepContextLimit | undefined
35
37
  readonly log: string
36
38
  readonly state: StateName
37
39
  readonly actor: Actor
@@ -74,6 +76,7 @@ export const statusOf = (input: {
74
76
  initial,
75
77
  model: rendered.model,
76
78
  system: rendered.system !== undefined && rendered.system !== "" ? rendered.system : undefined,
79
+ context: rendered.context,
77
80
  log,
78
81
  state: rendered.state,
79
82
  actor: rendered.actor,
@@ -0,0 +1,30 @@
1
+ /** A Claude Code transcript whose latest assistant message used `tokens` of context, as the hook reads it from `transcript_path`. */
2
+ export const transcriptAt = (tokens: number): string =>
3
+ [
4
+ { type: "user", message: { role: "user", content: "build it" } },
5
+ {
6
+ type: "assistant",
7
+ message: {
8
+ id: "msg_1",
9
+ role: "assistant",
10
+ usage: { input_tokens: 3, cache_read_input_tokens: 10, cache_creation_input_tokens: 7 },
11
+ },
12
+ },
13
+ { type: "user", message: { role: "user", content: [{ type: "tool_result" }] } },
14
+ {
15
+ type: "assistant",
16
+ message: {
17
+ id: "msg_2",
18
+ role: "assistant",
19
+ usage: {
20
+ input_tokens: 1,
21
+ cache_read_input_tokens: tokens - 1001,
22
+ cache_creation_input_tokens: 1000,
23
+ output_tokens: 500,
24
+ },
25
+ },
26
+ },
27
+ { type: "attachment", attachment: { type: "hook_success" } },
28
+ ]
29
+ .map((entry) => JSON.stringify(entry))
30
+ .join("\n") + "\n"
@@ -0,0 +1,96 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import {
3
+ CONTEXT_LIMIT_MARKER,
4
+ DEFAULT_CONTEXT_LIMIT,
5
+ contextHook,
6
+ contextLimitFault,
7
+ contextWindowFor,
8
+ hookOutput,
9
+ subagentTranscriptPath,
10
+ transcriptTokens,
11
+ } from "./ContextLimit.js"
12
+ import { transcriptAt } from "./ContextLimit.fixture.js"
13
+
14
+ const at = (tokens: number, event: "PostToolUse" | "PreCompact" = "PostToolUse") =>
15
+ contextHook({
16
+ event,
17
+ tokens: transcriptTokens(transcriptAt(tokens)),
18
+ window: 200_000,
19
+ limit: DEFAULT_CONTEXT_LIMIT,
20
+ })
21
+
22
+ describe("transcriptTokens", () => {
23
+ it("counts the latest assistant message's input, cache-read and cache-creation tokens", () => {
24
+ expect(transcriptTokens(transcriptAt(50_000))).toBe(50_000)
25
+ })
26
+
27
+ it("is undefined for a transcript with no assistant usage yet", () => {
28
+ expect(transcriptTokens('{"type":"user"}\nnot json\n')).toBeUndefined()
29
+ })
30
+ })
31
+
32
+ describe("contextHook", () => {
33
+ it("lets a run below the soft limit go on", () => {
34
+ expect(at(119_999)).toBeUndefined()
35
+ })
36
+
37
+ it("blocks with a handoff-note request at the soft limit", () => {
38
+ const decision = at(120_000)
39
+ expect(decision?.kind).toBe("soft")
40
+ expect(hookOutput(decision!)).toEqual({
41
+ decision: "block",
42
+ reason: expect.stringContaining("short handoff note"),
43
+ })
44
+ })
45
+
46
+ it("stops the run at the hard limit, behind the marker", () => {
47
+ const decision = at(140_000)
48
+ expect(hookOutput(decision!)).toEqual({
49
+ continue: false,
50
+ stopReason: expect.stringMatching(new RegExp(`^${CONTEXT_LIMIT_MARKER}: 140000 of 200000`)),
51
+ })
52
+ })
53
+
54
+ it("stops the run on PreCompact, whatever the count", () => {
55
+ expect(hookOutput(at(1_000, "PreCompact")!)).toEqual({
56
+ continue: false,
57
+ stopReason: expect.stringContaining(
58
+ `${CONTEXT_LIMIT_MARKER}: the context is about to be compacted`,
59
+ ),
60
+ })
61
+ })
62
+
63
+ it("lets a run with no usage yet go on", () => {
64
+ const limit = DEFAULT_CONTEXT_LIMIT
65
+ expect(
66
+ contextHook({ event: "PostToolUse", tokens: undefined, window: 1, limit }),
67
+ ).toBeUndefined()
68
+ })
69
+ })
70
+
71
+ describe("contextLimitFault", () => {
72
+ it("accepts shares in (0, 1] with soft below hard", () => {
73
+ expect(contextLimitFault({ soft: 0.5, hard: 1 })).toBeUndefined()
74
+ expect(contextLimitFault({ hard: 0.9 })).toBeUndefined()
75
+ })
76
+
77
+ it("refuses a share outside (0, 1] and a soft limit at or above the hard one", () => {
78
+ expect(contextLimitFault({ soft: 0 })).toMatch(/context\.soft must be/)
79
+ expect(contextLimitFault({ hard: 70 })).toMatch(/context\.hard must be/)
80
+ expect(contextLimitFault({ soft: 0.8 })).toMatch(/below context\.hard \(0\.7\)/)
81
+ const misspelt: { hard: number } = Object.assign({ hard: 0.8 }, { sotf: 0.5 })
82
+ expect(contextLimitFault(misspelt)).toBe("unknown key(s) sotf in context")
83
+ })
84
+ })
85
+
86
+ it("reads the long window from Claude Code's [1m] suffix only", () => {
87
+ expect(contextWindowFor("opus[1m]")).toBe(1_000_000)
88
+ expect(contextWindowFor("opus")).toBe(200_000)
89
+ expect(contextWindowFor(undefined)).toBe(200_000)
90
+ })
91
+
92
+ it("finds a worker's own transcript beside the main session's", () => {
93
+ expect(subagentTranscriptPath("/p/session.jsonl", "a1")).toBe(
94
+ "/p/session/subagents/agent-a1.jsonl",
95
+ )
96
+ })
@@ -0,0 +1,169 @@
1
+ // The context-limit decision every driver shares: the loop's `gtd context-hook`
2
+ // and the Claude Code mod both answer a hook event through `contextHook`, so
3
+ // the two cannot drift on thresholds, wording or which tokens count.
4
+
5
+ /** A share of the model's context window, each in (0, 1]; `soft` below `hard`. */
6
+ export interface ContextLimit {
7
+ readonly soft: number
8
+ readonly hard: number
9
+ }
10
+
11
+ export const DEFAULT_CONTEXT_LIMIT: ContextLimit = { soft: 0.6, hard: 0.7 }
12
+
13
+ const DEFAULT_WINDOW = 200_000
14
+ const LONG_WINDOW = 1_000_000
15
+
16
+ /** Claude Code's `[1m]` suffix selects the long window; a transcript never names it, so the driver decides from the model it passed. */
17
+ export const contextWindowFor = (model: string | undefined): number =>
18
+ model !== undefined && /\[1m\]/i.test(model) ? LONG_WINDOW : DEFAULT_WINDOW
19
+
20
+ /** A positive whole number of tokens, or `undefined` for anything else. */
21
+ export const parseContextWindow = (raw: string | undefined): number | undefined => {
22
+ const n = Number(raw)
23
+ return raw !== undefined && raw.trim() !== "" && Number.isInteger(n) && n > 0 ? n : undefined
24
+ }
25
+
26
+ /** `gtd context-hook`'s request: the hook's stdin and the limits its flags set. */
27
+ export interface ContextHookRequest {
28
+ readonly input: string
29
+ readonly soft?: number
30
+ readonly hard?: number
31
+ readonly window?: number
32
+ }
33
+
34
+ /**
35
+ * Where a driver asks `gtd context-hook` to record a hard stop's `stopReason`:
36
+ * Claude Code prints it nowhere a driver reads, and `hook_stopped` alone would
37
+ * also name any other hook that stopped the turn.
38
+ */
39
+ export const CONTEXT_STOP_FILE_ENV = "GTD_LOOP_CONTEXT_STOP_FILE"
40
+
41
+ /**
42
+ * Why one layer of a limit (a scope's, a step's) is malformed, ignoring how its
43
+ * two shares relate: layers merge key by key, so only the merged limit has to
44
+ * keep `soft` below `hard`. Config is evaluated untyped, so anything may arrive.
45
+ */
46
+ export const contextShapeFault = (limit: unknown): string | undefined => {
47
+ if (typeof limit !== "object" || limit === null || Array.isArray(limit)) {
48
+ return `context must be an object { soft, hard }, got ${JSON.stringify(limit)}`
49
+ }
50
+ const unknown = Object.keys(limit).filter((key) => key !== "soft" && key !== "hard")
51
+ if (unknown.length > 0) return `unknown key(s) ${unknown.join(", ")} in context`
52
+ const shares = limit as { readonly soft?: unknown; readonly hard?: unknown }
53
+ for (const key of ["soft", "hard"] as const) {
54
+ const value = shares[key]
55
+ if (value === undefined) continue
56
+ if (typeof value !== "number" || !(value > 0 && value <= 1)) {
57
+ return `context.${key} must be a share of the context window in (0, 1], got ${JSON.stringify(value)}`
58
+ }
59
+ }
60
+ return undefined
61
+ }
62
+
63
+ /** Why a whole limit is unusable, or `undefined` when it is fine. */
64
+ export const contextLimitFault = (limit: unknown): string | undefined => {
65
+ const shape = contextShapeFault(limit)
66
+ if (shape !== undefined) return shape
67
+ const shares = limit as { readonly soft?: unknown; readonly hard?: unknown }
68
+ const soft = (shares.soft as number | undefined) ?? DEFAULT_CONTEXT_LIMIT.soft
69
+ const hard = (shares.hard as number | undefined) ?? DEFAULT_CONTEXT_LIMIT.hard
70
+ return soft < hard ? undefined : `context.soft (${soft}) must be below context.hard (${hard})`
71
+ }
72
+
73
+ const record = (value: unknown): Record<string, unknown> | undefined =>
74
+ typeof value === "object" && value !== null ? (value as Record<string, unknown>) : undefined
75
+
76
+ const count = (value: unknown): number => (typeof value === "number" && value > 0 ? value : 0)
77
+
78
+ /** What a message's usage puts in the context window: its whole input, cached or not. */
79
+ export const usageTokens = (usage: unknown): number | undefined => {
80
+ const u = record(usage)
81
+ if (u === undefined) return undefined
82
+ return (
83
+ count(u["input_tokens"]) +
84
+ count(u["cache_read_input_tokens"]) +
85
+ count(u["cache_creation_input_tokens"])
86
+ )
87
+ }
88
+
89
+ /**
90
+ * The context size of the latest assistant message in a Claude Code transcript
91
+ * (one JSON entry per line). Usage is per message, not a running sum, so the
92
+ * last entry alone is the window's fill.
93
+ */
94
+ export const transcriptTokens = (transcript: string): number | undefined => {
95
+ const lines = transcript.split("\n")
96
+ for (let i = lines.length - 1; i >= 0; i--) {
97
+ const line = lines[i]!.trim()
98
+ if (line === "") continue
99
+ let entry: unknown
100
+ try {
101
+ entry = JSON.parse(line)
102
+ } catch {
103
+ continue
104
+ }
105
+ if (record(entry)?.["type"] !== "assistant") continue
106
+ const tokens = usageTokens(record(record(entry)?.["message"])?.["usage"])
107
+ if (tokens !== undefined) return tokens
108
+ }
109
+ return undefined
110
+ }
111
+
112
+ /**
113
+ * A worker subagent's own transcript. A hook its tool call fires is handed the
114
+ * MAIN session's `transcript_path`; the worker's sits beside it.
115
+ */
116
+ export const subagentTranscriptPath = (transcriptPath: string, agentId: string): string =>
117
+ `${transcriptPath.replace(/\.jsonl$/, "")}/subagents/agent-${agentId}.jsonl`
118
+
119
+ /** Every hard stop's `stopReason` starts with this: the driver's context-limit marker. */
120
+ export const CONTEXT_LIMIT_MARKER = "gtd: context limit"
121
+
122
+ export type ContextEvent = "PostToolUse" | "PreCompact"
123
+
124
+ export type ContextDecision =
125
+ | { readonly kind: "soft"; readonly reason: string }
126
+ | { readonly kind: "hard"; readonly stopReason: string }
127
+
128
+ const percent = (share: number): string => `${Math.round(share * 100)}%`
129
+
130
+ /**
131
+ * What a hook answers, or `undefined` to let the run go on. Compaction about
132
+ * to happen means the limit was missed, so `PreCompact` is a hard stop whatever
133
+ * the count says.
134
+ */
135
+ export const contextHook = (input: {
136
+ readonly event: ContextEvent
137
+ readonly tokens: number | undefined
138
+ readonly window: number
139
+ readonly limit: ContextLimit
140
+ }): ContextDecision | undefined => {
141
+ const { event, tokens, window, limit } = input
142
+ if (event === "PreCompact") {
143
+ return {
144
+ kind: "hard",
145
+ stopReason: `${CONTEXT_LIMIT_MARKER}: the context is about to be compacted — the run is too big for one turn`,
146
+ }
147
+ }
148
+ if (tokens === undefined) return undefined
149
+ const used = `${tokens} of ${window} tokens`
150
+ if (tokens >= limit.hard * window) {
151
+ return {
152
+ kind: "hard",
153
+ stopReason: `${CONTEXT_LIMIT_MARKER}: ${used}, past the ${percent(limit.hard)} hard limit`,
154
+ }
155
+ }
156
+ if (tokens >= limit.soft * window) {
157
+ return {
158
+ kind: "soft",
159
+ reason: `Context limit: ${used} used, past the ${percent(limit.soft)} soft limit. Stop working now. Do not start anything new; end your turn with a short handoff note as your answer: what you touched, and what was next.`,
160
+ }
161
+ }
162
+ return undefined
163
+ }
164
+
165
+ /** A decision as Claude Code's settings-hook JSON output. */
166
+ export const hookOutput = (decision: ContextDecision): Record<string, unknown> =>
167
+ decision.kind === "soft"
168
+ ? { decision: "block", reason: decision.reason }
169
+ : { continue: false, stopReason: decision.stopReason }
package/src/wire/index.ts CHANGED
@@ -11,3 +11,4 @@ export { selectPath } from "./Select.js"
11
11
  export { resolveSession } from "./Sessions.js"
12
12
  export { globMatches } from "./Glob.js"
13
13
  export * from "./Slices.js"
14
+ export * from "./ContextLimit.js"
package/src/wire/types.ts CHANGED
@@ -38,6 +38,12 @@ export interface ApprovalEntry {
38
38
  readonly commit: string
39
39
  }
40
40
 
41
+ /** The context-limit shares a step sets; a driver fills an absent one from its defaults. */
42
+ export interface StepContextLimit {
43
+ readonly soft?: number
44
+ readonly hard?: number
45
+ }
46
+
41
47
  export interface RenderedDemandSource {
42
48
  readonly state: StateName
43
49
  readonly actor: Actor
@@ -51,4 +57,5 @@ export interface RenderedDemandSource {
51
57
  readonly judge?: string
52
58
  readonly skills?: readonly string[]
53
59
  readonly access?: StepAccess
60
+ readonly context?: StepContextLimit
54
61
  }
@@ -1,5 +1,12 @@
1
1
  import type { WorkflowBase, Flow, ScopeAccess, Summary } from "../flows/index.js"
2
- import type { Actor, ContentKind, StateMode, StateName, StepAccess } from "../wire/index.js"
2
+ import type {
3
+ Actor,
4
+ ContentKind,
5
+ StateMode,
6
+ StateName,
7
+ StepAccess,
8
+ StepContextLimit,
9
+ } from "../wire/index.js"
3
10
 
4
11
  export type { Actor, ContentKind, StateMode, StateName }
5
12
 
@@ -44,6 +51,7 @@ export interface StepDef {
44
51
  readonly approve?: boolean
45
52
  readonly skills?: readonly string[]
46
53
  readonly access?: StepAccess
54
+ readonly context?: StepContextLimit
47
55
  }
48
56
 
49
57
  /**
@@ -86,7 +86,6 @@ Feature: acceptance criteria carry stable IDs, and a sketch that states clear on
86
86
  - AC-1: `greeting` reads "Hello, world".
87
87
  """
88
88
  And step "design.gate.answer" changes nothing
89
- And step "seam.check" changes nothing
90
89
  And step "seam.naive" writes "src/acceptance.test.ts" with:
91
90
  """
92
91
  it("[AC-1] holds", () => {})
@@ -98,10 +97,15 @@ Feature: acceptance criteria carry stable IDs, and a sketch that states clear on
98
97
  """
99
98
  export const greeting = "Hello, world"
100
99
  """
100
+ And step "seam.check" writes "src/acceptance.test.ts" with:
101
+ """
102
+ it("[AC-1] holds elsewhere", () => {})
103
+ """
101
104
  And judge step "seam.judge" answers:
102
105
  """
103
106
  [{"id":"shape","answer":"land","p":0.9}]
104
107
  """
108
+ And step "implement.applying" runs its script
105
109
  And step "implement.building" writes ".gtd/REQUIREMENTS.md" with:
106
110
  """
107
111
  # Requirements
@@ -0,0 +1,37 @@
1
+ @inmem
2
+ Feature: the shipped workflows take a context limit as an option
3
+
4
+ `contextLimit: { soft, hard }` is a factory option: every agent step of the
5
+ workflow runs under it, carried as `gtd next --json`'s `context`. Without it a
6
+ step carries none and the driver's defaults apply.
7
+
8
+ Scenario Outline: every agent step carries the configured limit, or none
9
+ Given a gtd config with:
10
+ """
11
+ import { feature } from "@pmelab/gtd/workflows/feature"
12
+ export { summary, steering, skills, access } from "@pmelab/gtd/workflows/feature"
13
+ export default feature(<options>)
14
+ """
15
+ And a file "src/calc.ts" with:
16
+ """
17
+ export const add = (a: number, b: number) => a + b
18
+ """
19
+ And the working tree is committed as "feat: add calculator"
20
+ And a file "TODO.md" with:
21
+ """
22
+ # Add subtract
23
+
24
+ subtract(a, b) returns the difference.
25
+ """
26
+ And step "unwind" changes nothing
27
+ And step "start-gate.check" changes nothing
28
+ When the process is driven
29
+ Then the process rests at "design.triage"
30
+ And the output of gtd "next --json" <carries>
31
+
32
+ Examples:
33
+ | options | carries |
34
+ | { contextLimit: { soft: 0.5, hard: 0.65 } } | contains "\"context\":{\"soft\":0.5,\"hard\":0.65}" |
35
+ | { contextLimit: { hard: 0.8 } } | contains "\"context\":{\"hard\":0.8}" |
36
+ | {} | does not contain "\"context\"" |
37
+
@@ -34,15 +34,18 @@ Feature: a feature is done only when every acceptance criterion has a passing te
34
34
  - AC-2: add is unchanged.
35
35
  """
36
36
  And step "design.gate.answer" changes nothing
37
- And step "implement.building" writes "src/calc.ts" with:
37
+ And step "seam.naive" writes "src/calc.ts" with:
38
38
  """
39
39
  export const add = (a: number, b: number) => a + b
40
40
  export const subtract = (a: number, b: number) => a - b
41
41
  """
42
- And step "implement.building" writes "src/calc.test.ts" with:
42
+ And step "seam.naive" writes "src/calc.test.ts" with:
43
43
  """
44
44
  it("[AC-1] subtracts", () => expect(subtract(3, 1)).toBe(2))
45
+ // AC-2: add is untouched
45
46
  """
47
+ And step "seam.check" changes nothing
48
+ And step "implement.applying" runs its script
46
49
  And step "implement.health.check" changes nothing
47
50
  And step "implement.closing" runs its script
48
51
 
@@ -61,7 +64,7 @@ Feature: a feature is done only when every acceptance criterion has a passing te
61
64
  Then the process rests at "idle"
62
65
  And the commit subjects end with:
63
66
  """
64
- gtd(agent): implement.building → implement.health.check
67
+ gtd(check): implement.applying → implement.health.check
65
68
  gtd(check): implement.health.check → implement.coverage
66
69
  gtd(judge): implement.coverage → implement.closing
67
70
  gtd(check): implement.closing → idle
@@ -23,7 +23,7 @@ const COVERING_RETRIES = 2
23
23
 
24
24
  const frozen = (): void => requireCriteriaFrozen(REQUIREMENTS)
25
25
 
26
- export const green = (): Promise<void> =>
26
+ export const green = (guard?: () => void): Promise<void> =>
27
27
  healthy(
28
28
  () =>
29
29
  t.agentWithSkills("fix.suite.fixing", t.implementFixPrompt(), {
@@ -32,7 +32,13 @@ export const green = (): Promise<void> =>
32
32
  model: coder(),
33
33
  system: t.builderSystem(),
34
34
  }),
35
- { guard: frozen, guardRests: false },
35
+ {
36
+ guard: () => {
37
+ frozen()
38
+ guard?.()
39
+ },
40
+ guardRests: false,
41
+ },
36
42
  )
37
43
 
38
44
  // A budget cut keeps the end, so the files naming a criterion ID go last.
@@ -1,10 +1,10 @@
1
1
  @inmem
2
- Feature: a trivial change takes the same few beats at either risk tier, flag-free at low
2
+ Feature: a trivial change takes the same few beats at either risk tier
3
3
 
4
4
  With GTD_FLAG_RISK_TIER on, a one-line copy fix goes
5
- from idle through the naive pass, the seam judge's land, implement and the
6
- quality lap back to idle. Low tier walks exactly the steps high does; only the
7
- implementation prompt and the summary differ.
5
+ from idle through the naive pass, the seam judge's land, the applied pass and
6
+ the quality lap back to idle. Low tier walks exactly the steps high does; only
7
+ the summary differs.
8
8
 
9
9
  Background:
10
10
  Given the shipped workflows, as gtd install scaffolds them
@@ -62,18 +62,10 @@ Feature: a trivial change takes the same few beats at either risk tier, flag-fre
62
62
  """
63
63
  [{"id":"shape","answer":"land","p":0.9}]
64
64
  """
65
- When the process is driven
66
- Then the process rests at "implement.building"
67
- And the resting step's content contains "<demand>"
68
- And the resting step's content does not contain "<absent>"
69
-
70
- Given step "implement.building" writes "src/greeting.ts" with:
71
- """
72
- export const greeting = "Hello, world!"
73
- """
65
+ And step "implement.applying" runs its script
74
66
  When the process is driven
75
67
  Then the process rests at "idle"
76
- And "src/greeting.ts" contains "Hello, world!"
68
+ And "src/greeting.ts" contains "Hello, world"
77
69
  And the commit subjects end with:
78
70
  """
79
71
  gtd(human): idle → unwind
@@ -83,8 +75,8 @@ Feature: a trivial change takes the same few beats at either risk tier, flag-fre
83
75
  gtd(human): design.gate.answer → seam.naive
84
76
  gtd(agent): seam.naive → seam.check
85
77
  gtd(check): seam.check → seam.judge
86
- gtd(judge): seam.judge → implement.building
87
- gtd(agent): implement.building → implement.health.check
78
+ gtd(judge): seam.judge → implement.applying
79
+ gtd(check): implement.applying → implement.health.check
88
80
  gtd(check): implement.health.check → implement.coverage
89
81
  gtd(judge): implement.coverage → implement.closing
90
82
  gtd(check): implement.closing → build.quality.correctness.reviewing
@@ -93,6 +85,6 @@ Feature: a trivial change takes the same few beats at either risk tier, flag-fre
93
85
  And the output of gtd "summary" <summary> "needs a human reviewer"
94
86
 
95
87
  Examples:
96
- | tier | demand | absent | summary |
97
- | low | Add no release flag | new release flag | does not contain |
98
- | high | Put the new behaviour behind a new release flag | Add no release flag | contains |
88
+ | tier | summary |
89
+ | low | does not contain |
90
+ | high | contains |
@@ -365,10 +365,30 @@ describe("flagMode", () => {
365
365
  expect((await designed(config("feature({ flagMode: true })"))).state).toBe("seam.naive")
366
366
  })
367
367
 
368
- it("off through GTD_FLAGMODE=false, skips the naive pass and the seam judge", async () => {
369
- const rest = await designed(CONFIG_SCAFFOLD, { GTD_FLAGMODE: "false" })
370
- expect(rest.state).toBe("implement.building")
371
- expect(rest.content).toContain("this project ships without release flags")
368
+ it("off through GTD_FLAGMODE=false, lands the naive pass with no seam judge", async () => {
369
+ const repo = testRepo({ workflow: CONFIG_SCAFFOLD, env: { GTD_FLAGMODE: "false" } })
370
+ repo.write("src/calc.ts", CALC)
371
+ repo.commit("feat: add calculator")
372
+ repo.write("TODO.md", "# Add subtract\n")
373
+ const rest = await repo.drive({
374
+ unwind: () => undefined,
375
+ "start-gate.check": () => undefined,
376
+ "design.triage": (_, r) =>
377
+ r.write(
378
+ ".gtd/REQUIREMENTS.md",
379
+ "# Requirements\n\n## Concerns\n\n### S\n\n- `s`\n\n## Acceptance Criteria\n\n- AC-1: done\n",
380
+ ),
381
+ "design.gate.answer": () => undefined,
382
+ "seam.naive": (_, r) => {
383
+ r.write("src/calc.ts", `${CALC}// naive\n`)
384
+ r.write("src/calc.test.ts", ACCEPTANCE)
385
+ },
386
+ "seam.check": () => undefined,
387
+ "implement.applying": runsItsScript,
388
+ })
389
+ expect(rest.state).toBe("implement.health.check")
390
+ expect(repo.read("src/calc.ts")).toBe(`${CALC}// naive\n`)
391
+ expect(repo.subjects().some((subject) => subject.includes("seam.judge"))).toBe(false)
372
392
  })
373
393
 
374
394
  it("refuses a value other than true or false before the process starts", async () => {