@pmelab/gtd 27.9.0 → 28.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/.claude-plugin/plugin.json +1 -1
- package/README.md +53 -27
- package/claude/hooks/doors.ts +12 -0
- package/claude/hooks/register.tsx +2 -4
- package/claude/hooks/ship.ts +115 -20
- package/dist/chunks/{reserved-UdSuHDUJ.mjs → reserved-DeBS4Ymh.mjs} +178 -32
- package/dist/chunks/{tail-fj60rQ3y.mjs → tail-B2SER2Ih.mjs} +1 -1
- package/dist/gtd.bundle.mjs +209 -72
- package/dist/testkit.mjs +209 -72
- package/dist/workflows/cleanup.mjs +3 -4
- package/dist/workflows/feature.mjs +2 -2
- package/dist/workflows/fix.mjs +2 -2
- package/dist/workflows/review.mjs +2 -2
- package/dist/workflows/rollout.mjs +19 -4
- package/dist/workflows.mjs +196 -132
- package/package.json +1 -1
- package/skills/authoring/SKILL.md +4 -3
- package/src/cli/Cli.test.ts +39 -0
- package/src/cli/Cli.ts +41 -9
- package/src/cli/Program.test.ts +31 -0
- package/src/cli/Program.ts +14 -7
- package/src/edge/Edge.test.ts +259 -3
- package/src/edge/Edge.ts +175 -58
- package/src/flows/runtime.ts +20 -1
- package/src/install/ConfigScaffold.ts +4 -1
- package/src/install/Install.test.ts +10 -0
- package/src/install/Install.ts +5 -2
- package/src/workflow/load.test.ts +82 -5
- package/src/workflow/load.ts +40 -16
- package/src/workflows/cleanup/cleanup.feature +21 -0
- package/src/workflows/cleanup/cleanup.ts +1 -1
- package/src/workflows/index.ts +2 -1
- package/src/workflows/rollout/rollout.feature +282 -2
- package/src/workflows/rollout/rollout.test.ts +96 -2
- package/src/workflows/rollout/rollout.ts +41 -3
- package/src/workflows/shared/options.test.ts +25 -2
- package/src/workflows/shared/options.ts +7 -4
- package/src/workflows/shared/registry.test.ts +41 -1
- package/src/workflows/shared/registry.ts +26 -1
- package/src/workflows/shared/text.test.ts +377 -2
- package/src/workflows/shared/text.ts +65 -7
- package/src/workflows/shared/vars.ts +2 -0
- package/dist/chunks/registry-CP3YuV9j.mjs +0 -101
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest"
|
|
2
2
|
import { CONFIG_SCAFFOLD } from "../../install/index.js"
|
|
3
|
-
import { testRepo } from "../../testkit/index.js"
|
|
3
|
+
import { runsItsScript, testRepo } from "../../testkit/index.js"
|
|
4
4
|
|
|
5
5
|
const CONFIG = `${CONFIG_SCAFFOLD}export { rollout } from "@pmelab/gtd/workflows"\n`
|
|
6
6
|
|
|
@@ -30,9 +30,13 @@ describe("the rollout workflow", () => {
|
|
|
30
30
|
r.write("src/flags/index.ts", FLIPPED)
|
|
31
31
|
},
|
|
32
32
|
"rollout.suite.check": () => undefined,
|
|
33
|
+
"rollout.mentions": runsItsScript,
|
|
33
34
|
})
|
|
34
35
|
expect(rest.state).toBe("idle")
|
|
35
|
-
expect(repo.subjects().
|
|
36
|
+
expect(repo.subjects().slice(-2)).toEqual([
|
|
37
|
+
"gtd(check): rollout.suite.check → rollout.mentions",
|
|
38
|
+
"gtd(check): rollout.mentions → idle",
|
|
39
|
+
])
|
|
36
40
|
})
|
|
37
41
|
|
|
38
42
|
it("lands a flip when the tree was already dirty at the start", async () => {
|
|
@@ -42,6 +46,7 @@ describe("the rollout workflow", () => {
|
|
|
42
46
|
const rest = await repo.drive({
|
|
43
47
|
"rollout.flipping": (_, r) => r.write("src/flags/index.ts", FLIPPED),
|
|
44
48
|
"rollout.suite.check": () => undefined,
|
|
49
|
+
"rollout.mentions": runsItsScript,
|
|
45
50
|
})
|
|
46
51
|
expect(rest.state).toBe("idle")
|
|
47
52
|
})
|
|
@@ -160,8 +165,97 @@ describe("the rollout workflow", () => {
|
|
|
160
165
|
),
|
|
161
166
|
),
|
|
162
167
|
"rollout.suite.check": () => undefined,
|
|
168
|
+
"rollout.mentions": runsItsScript,
|
|
163
169
|
})
|
|
164
170
|
expect(rest.state).toBe("idle")
|
|
165
171
|
})
|
|
166
172
|
})
|
|
167
173
|
})
|
|
174
|
+
|
|
175
|
+
describe("rollout.mentions", () => {
|
|
176
|
+
const flip = {
|
|
177
|
+
"rollout.flipping": (_: unknown, r: { write: (p: string, c: string) => void }) =>
|
|
178
|
+
r.write("src/flags/index.ts", FLIPPED),
|
|
179
|
+
}
|
|
180
|
+
const finish = async (
|
|
181
|
+
files: Record<string, string>,
|
|
182
|
+
mentions: typeof runsItsScript = runsItsScript,
|
|
183
|
+
) => {
|
|
184
|
+
const repo = testRepo({
|
|
185
|
+
workflow: CONFIG,
|
|
186
|
+
files: { "src/flags/index.ts": REGISTRY, "src/a.ts": "a\n", ...files },
|
|
187
|
+
})
|
|
188
|
+
await repo.start("rollout", "--var", "flag=alpha")
|
|
189
|
+
const rest = await repo.drive({
|
|
190
|
+
...flip,
|
|
191
|
+
"rollout.suite.check": () => undefined,
|
|
192
|
+
"rollout.mentions": mentions,
|
|
193
|
+
})
|
|
194
|
+
expect(rest.state).toBe("idle")
|
|
195
|
+
const marks = (repo.messages().at(-1) ?? "")
|
|
196
|
+
.split("\n")
|
|
197
|
+
.filter((l) => l.startsWith("Gtd-Mark: "))
|
|
198
|
+
.map((l) => l.slice("Gtd-Mark: ".length))
|
|
199
|
+
return { repo, marks }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
it("lists mentions outside the registry and under no .gtd/ path", async () => {
|
|
203
|
+
const { marks } = await finish({
|
|
204
|
+
"README.md": "intro\non under GTD_FLAG_ALPHA=1\n",
|
|
205
|
+
"src/help.ts": 'export const h = "alpha help"\n',
|
|
206
|
+
".gtd/NOTES.md": "alpha\n",
|
|
207
|
+
})
|
|
208
|
+
expect(marks).toEqual([
|
|
209
|
+
"flag-mentions=2",
|
|
210
|
+
"flag-mention=README.md:2",
|
|
211
|
+
"flag-mention=src/help.ts:1",
|
|
212
|
+
])
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("the mentions script removes a feedback file present at the step; marks list the tree", async () => {
|
|
216
|
+
const { repo, marks } = await finish({ "README.md": "alpha\n" }, (beat, r) => {
|
|
217
|
+
r.write(".gtd/FEEDBACK.md", "alpha\n")
|
|
218
|
+
runsItsScript(beat, r)
|
|
219
|
+
})
|
|
220
|
+
expect(repo.read(".gtd/FEEDBACK.md")).toBeUndefined()
|
|
221
|
+
expect(marks).toEqual(["flag-mentions=1", "flag-mention=README.md:1"])
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it("refuses a stray file written by the mentions script", async () => {
|
|
225
|
+
await expect(
|
|
226
|
+
finish({}, (beat, r) => {
|
|
227
|
+
runsItsScript(beat, r)
|
|
228
|
+
r.write("src/stray.ts", "x\n")
|
|
229
|
+
}),
|
|
230
|
+
).rejects.toThrow("gtd land: rollout-only: src/stray.ts changed")
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it("refuses a registry edit beyond the flip made by the mentions script", async () => {
|
|
234
|
+
await expect(
|
|
235
|
+
finish({}, (beat, r) => {
|
|
236
|
+
runsItsScript(beat, r)
|
|
237
|
+
r.write("src/flags/index.ts", FLIPPED.replace('owner: "b"', 'owner: "z"'))
|
|
238
|
+
}),
|
|
239
|
+
).rejects.toThrow("rollout-only: other edits in src/flags/index.ts")
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it("marks 0 when nothing names the flag", async () => {
|
|
243
|
+
const { marks } = await finish({})
|
|
244
|
+
expect(marks).toEqual(["flag-mentions=0"])
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it("marks the total for 60 mentions but only the first 50 lines", async () => {
|
|
248
|
+
const text = Array.from({ length: 60 }, (_, i) => `alpha ${i}`).join("\n")
|
|
249
|
+
const { marks } = await finish({ "docs/many.md": `${text}\n` })
|
|
250
|
+
expect(marks[0]).toBe("flag-mentions=60")
|
|
251
|
+
expect(marks.filter((m) => m.startsWith("flag-mention="))).toHaveLength(50)
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it("counts a path the mark grammar rejects without marking it, and never throws", async () => {
|
|
255
|
+
const { marks } = await finish({
|
|
256
|
+
"docs/bad\u0001name.md": "alpha\n",
|
|
257
|
+
"README.md": "alpha\n",
|
|
258
|
+
})
|
|
259
|
+
expect(marks).toEqual(["flag-mentions=2", "flag-mention=README.md:1"])
|
|
260
|
+
})
|
|
261
|
+
})
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
agent,
|
|
3
|
+
changesSince,
|
|
4
|
+
glob,
|
|
5
|
+
head,
|
|
6
|
+
mark,
|
|
7
|
+
read,
|
|
8
|
+
refuse,
|
|
9
|
+
removeScript,
|
|
10
|
+
run,
|
|
11
|
+
scope,
|
|
12
|
+
vars,
|
|
13
|
+
} from "../../flows/index.js"
|
|
2
14
|
import { gate } from "../shared/health.js"
|
|
3
15
|
import { flagShipped } from "../shared/options.js"
|
|
4
|
-
import { flipProblems, requireFlag } from "../shared/registry.js"
|
|
16
|
+
import { flagMentions, flipProblems, requireFlag } from "../shared/registry.js"
|
|
5
17
|
import { coder, FEEDBACK } from "../shared/steps.js"
|
|
6
18
|
|
|
7
19
|
const flippingPrompt = (name: string, registry: string): string =>
|
|
@@ -10,6 +22,31 @@ const flippingPrompt = (name: string, registry: string): string =>
|
|
|
10
22
|
const suiteBlockedMessage = (): string =>
|
|
11
23
|
"The suite is red after the rollout. Fix it by hand — a rollout may only touch the flag's registry entry — then land."
|
|
12
24
|
|
|
25
|
+
// Marks past this many are dropped; the summary points at grep for the rest.
|
|
26
|
+
const MARKED_MENTIONS = 50
|
|
27
|
+
|
|
28
|
+
// Lists, never edits: the human fixes the now-stale prose, or cleanup does. The
|
|
29
|
+
// list rides in marks only: a state file left at idle would be published by
|
|
30
|
+
// ship and read as a failed unwind by the next process.
|
|
31
|
+
const listMentions = async (registry: string, name: string, guard: () => void): Promise<void> => {
|
|
32
|
+
await run("mentions", removeScript([FEEDBACK]), { label: "Listing flag mentions" })
|
|
33
|
+
guard()
|
|
34
|
+
const files = glob("**")
|
|
35
|
+
.filter((path) => path !== registry && path !== ".gtd" && !path.startsWith(".gtd/"))
|
|
36
|
+
.sort()
|
|
37
|
+
.map((path) => ({ path, text: read(path) ?? "" }))
|
|
38
|
+
const mentions = flagMentions(files, name)
|
|
39
|
+
mark("flag-mentions", String(mentions.length))
|
|
40
|
+
for (const m of mentions.slice(0, MARKED_MENTIONS)) {
|
|
41
|
+
// A path the mark grammar rejects stays counted above, just unlisted here.
|
|
42
|
+
try {
|
|
43
|
+
mark("flag-mention", `${m.path}:${m.line}`)
|
|
44
|
+
} catch {
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
13
50
|
// No review gate — a one-field change needs no review lap.
|
|
14
51
|
export const rolloutFlow = async (): Promise<void> => {
|
|
15
52
|
const registry = vars.flagRegistry ?? ""
|
|
@@ -38,7 +75,8 @@ export const rolloutFlow = async (): Promise<void> => {
|
|
|
38
75
|
})
|
|
39
76
|
guard()
|
|
40
77
|
await gate("suite", suiteBlockedMessage(), guard)
|
|
78
|
+
await listMentions(registry, name, guard)
|
|
41
79
|
})
|
|
42
80
|
}
|
|
43
81
|
|
|
44
|
-
export const rollout = flagShipped(rolloutFlow)
|
|
82
|
+
export const rollout = flagShipped(rolloutFlow, "rollout")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest"
|
|
2
|
-
import { configure } from "../../flows/index.js"
|
|
2
|
+
import { configure, type WorkflowDoors } from "../../flows/index.js"
|
|
3
3
|
import * as workflows from "../index.js"
|
|
4
4
|
import * as options from "./options.js"
|
|
5
5
|
|
|
@@ -85,7 +85,7 @@ describe("the shipped workflow factories", () => {
|
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
describe("flagShipped", () => {
|
|
88
|
-
const factory = flagShipped(async () => {})
|
|
88
|
+
const factory = flagShipped(async () => {}, "rollout")
|
|
89
89
|
|
|
90
90
|
it("declare flag and flagRegistry as process settings, so --var flag= is accepted", () => {
|
|
91
91
|
expect(configure(factory)).toMatchObject({
|
|
@@ -97,6 +97,29 @@ describe("the shipped workflow factories", () => {
|
|
|
97
97
|
})
|
|
98
98
|
})
|
|
99
99
|
|
|
100
|
+
it.each(["rollout", "cleanup"] as const)(
|
|
101
|
+
"%s declares one door named after it, with one required flag arg",
|
|
102
|
+
(name) => {
|
|
103
|
+
const result = configure(workflows[name]())
|
|
104
|
+
expect(result).toMatchObject({
|
|
105
|
+
ok: true,
|
|
106
|
+
build: { doors: { [name]: { args: [{ name: "flag" }] } } },
|
|
107
|
+
})
|
|
108
|
+
const build = (result as { build?: { doors?: WorkflowDoors } }).build
|
|
109
|
+
expect(Object.keys(build?.doors ?? {})).toEqual([name])
|
|
110
|
+
expect(build?.doors?.[name]?.vars?.({ flag: "x" })).toEqual({ flag: "x" })
|
|
111
|
+
},
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
it.each(["rollout", "cleanup"] as const)("%s builds one door of that name", (name) => {
|
|
115
|
+
const result = configure(flagShipped(async () => {}, name))
|
|
116
|
+
const doors = (result as { build?: { doors?: WorkflowDoors } }).build?.doors
|
|
117
|
+
expect(Object.keys(doors ?? {})).toEqual([name])
|
|
118
|
+
expect(doors?.[name]?.args).toEqual([{ name: "flag" }])
|
|
119
|
+
expect(doors?.[name]?.vars?.({ flag: "x" })).toEqual({ flag: "x" })
|
|
120
|
+
expect(doors?.[name]?.vars?.({})).toEqual({ flag: "" })
|
|
121
|
+
})
|
|
122
|
+
|
|
100
123
|
it("fail the load on an unknown option", () => {
|
|
101
124
|
// @ts-expect-error — `flag` is a --var, not an option
|
|
102
125
|
const result = configure(factory({ flag: "x" }))
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type WorkflowDoors,
|
|
7
7
|
type WorkflowFactory,
|
|
8
8
|
} from "../../flows/index.js"
|
|
9
|
-
import { defaults, envDefaults } from "./vars.js"
|
|
9
|
+
import { defaultFlagRegistry, defaults, envDefaults } from "./vars.js"
|
|
10
10
|
|
|
11
11
|
const setting = Schema.optionalWith(Schema.String, { exact: true })
|
|
12
12
|
|
|
@@ -55,16 +55,19 @@ export const FlagOptions = Schema.Struct({ ...ShippedOptions.fields, flagRegistr
|
|
|
55
55
|
|
|
56
56
|
export type FlagOptions = Schema.Schema.Encoded<typeof FlagOptions>
|
|
57
57
|
|
|
58
|
-
export const flagShipped = (
|
|
58
|
+
export const flagShipped = (
|
|
59
|
+
flow: Flow,
|
|
60
|
+
name: "rollout" | "cleanup",
|
|
61
|
+
): WorkflowFactory<FlagOptions> =>
|
|
59
62
|
defineWorkflow(
|
|
60
63
|
Schema.standardSchemaV1(FlagOptions, { onExcessProperty: "error", errors: "all" }),
|
|
61
64
|
(options) => {
|
|
62
|
-
const flagDefaults = { ...defaults, flag: "", flagRegistry:
|
|
65
|
+
const flagDefaults = { ...defaults, flag: "", flagRegistry: defaultFlagRegistry }
|
|
63
66
|
return {
|
|
64
67
|
flow,
|
|
65
68
|
defaults: over(flagDefaults, options),
|
|
66
69
|
envDefaults: over(envDefaults, options),
|
|
67
|
-
doors: {},
|
|
70
|
+
doors: { [name]: { args: [{ name: "flag" }], vars: ({ flag }) => ({ flag: flag ?? "" }) } },
|
|
68
71
|
base: undefined,
|
|
69
72
|
}
|
|
70
73
|
},
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from "vitest"
|
|
2
2
|
import { installContext } from "../../flows/index.js"
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
flagMentions,
|
|
5
|
+
flagReferences,
|
|
6
|
+
flipProblems,
|
|
7
|
+
registryEntry,
|
|
8
|
+
requireFlag,
|
|
9
|
+
} from "./registry.js"
|
|
4
10
|
|
|
5
11
|
const ONE_LINE = `export const FLAGS = [
|
|
6
12
|
{ name: "alpha", owner: "a", expiry: "2027-01-01", kind: "release" },
|
|
@@ -303,3 +309,37 @@ describe("flagReferences", () => {
|
|
|
303
309
|
expect(flagReferences(files, "a(b")).toEqual([])
|
|
304
310
|
})
|
|
305
311
|
})
|
|
312
|
+
|
|
313
|
+
describe("flagMentions", () => {
|
|
314
|
+
it("matches the env var, the flag_ form and the bare name, any case, 1-based", () => {
|
|
315
|
+
const files = [
|
|
316
|
+
{
|
|
317
|
+
path: "README.md",
|
|
318
|
+
text: "intro\non under GTD_FLAG_ALPHA=1\nflag_alpha helper\nThe Alpha flag\nnone\n",
|
|
319
|
+
},
|
|
320
|
+
]
|
|
321
|
+
expect(flagMentions(files, "alpha")).toEqual([
|
|
322
|
+
{ path: "README.md", line: 2 },
|
|
323
|
+
{ path: "README.md", line: 3 },
|
|
324
|
+
{ path: "README.md", line: 4 },
|
|
325
|
+
])
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it("never matches inside a longer identifier", () => {
|
|
329
|
+
const text = "alphabet\nalpha_two\nGTD_FLAG_ALPHA_TWO\nxalpha\nflag_alphabet\n"
|
|
330
|
+
expect(flagMentions([{ path: "a.md", text }], "alpha")).toEqual([])
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it("keeps test files, and skips a file holding a NUL byte", () => {
|
|
334
|
+
const files = [
|
|
335
|
+
{ path: "src/a.test.ts", text: "GTD_FLAG_ALPHA\n" },
|
|
336
|
+
{ path: "bin.dat", text: "alpha\u0000alpha\n" },
|
|
337
|
+
]
|
|
338
|
+
expect(flagMentions(files, "alpha").map((m) => m.path)).toEqual(["src/a.test.ts"])
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
it("matches regex metacharacters in the name literally", () => {
|
|
342
|
+
const files = [{ path: "a.md", text: "a.b\naxb\n" }]
|
|
343
|
+
expect(flagMentions(files, "a.b").map((m) => m.line)).toEqual([1])
|
|
344
|
+
})
|
|
345
|
+
})
|
|
@@ -47,7 +47,7 @@ const mask = (text: string): string => {
|
|
|
47
47
|
return out
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
50
|
+
export const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
51
51
|
|
|
52
52
|
// Entries are flat object literals, so the nearest braces around the name delimit one.
|
|
53
53
|
const entrySpan = (text: string, name: string) => {
|
|
@@ -136,6 +136,31 @@ export const flagReferences = (
|
|
|
136
136
|
)
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
export interface FlagMention {
|
|
140
|
+
readonly path: string
|
|
141
|
+
readonly line: number
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Every line naming flag `name` as `GTD_FLAG_<NAME>`, `flag_<name>` or bare
|
|
146
|
+
* `<name>` — case-insensitive, never inside a longer identifier. Unlike
|
|
147
|
+
* `flagReferences`, test files count; a file holding a NUL byte is skipped.
|
|
148
|
+
*/
|
|
149
|
+
export const flagMentions = (
|
|
150
|
+
files: readonly { readonly path: string; readonly text: string }[],
|
|
151
|
+
name: string,
|
|
152
|
+
): readonly FlagMention[] => {
|
|
153
|
+
const pattern = new RegExp(
|
|
154
|
+
`(?<![A-Za-z0-9_])(?:GTD_FLAG_|flag_)?${escapeRegExp(name)}(?![A-Za-z0-9_])`,
|
|
155
|
+
"i",
|
|
156
|
+
)
|
|
157
|
+
return files
|
|
158
|
+
.filter(({ text }) => !text.includes("\u0000"))
|
|
159
|
+
.flatMap(({ path, text }) =>
|
|
160
|
+
text.split("\n").flatMap((line, i) => (pattern.test(line) ? [{ path, line: i + 1 }] : [])),
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
|
|
139
164
|
export const requireFlag = (
|
|
140
165
|
workflow: "rollout" | "cleanup",
|
|
141
166
|
registryPath: string,
|