@llm4ts/shell 4.12.0 → 4.14.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 (47) hide show
  1. package/dist/ChatNode.d.ts.map +1 -1
  2. package/dist/ChatNode.js +3 -2
  3. package/dist/ChatNode.js.map +1 -1
  4. package/dist/Cli.d.ts.map +1 -1
  5. package/dist/Cli.js +39 -1
  6. package/dist/Cli.js.map +1 -1
  7. package/dist/Inbox.d.ts +79 -0
  8. package/dist/Inbox.d.ts.map +1 -0
  9. package/dist/Inbox.js +91 -0
  10. package/dist/Inbox.js.map +1 -0
  11. package/dist/OperatorActTools.d.ts +132 -0
  12. package/dist/OperatorActTools.d.ts.map +1 -1
  13. package/dist/OperatorActTools.js +60 -2
  14. package/dist/OperatorActTools.js.map +1 -1
  15. package/dist/OperatorNode.d.ts +5 -0
  16. package/dist/OperatorNode.d.ts.map +1 -1
  17. package/dist/OperatorNode.js +14 -2
  18. package/dist/OperatorNode.js.map +1 -1
  19. package/dist/OperatorServer.d.ts +62 -0
  20. package/dist/OperatorServer.d.ts.map +1 -1
  21. package/dist/OperatorServer.js +5 -3
  22. package/dist/OperatorServer.js.map +1 -1
  23. package/dist/OperatorTools.d.ts +3 -0
  24. package/dist/OperatorTools.d.ts.map +1 -1
  25. package/dist/OperatorTools.js.map +1 -1
  26. package/dist/Profile.d.ts +1 -1
  27. package/dist/Profile.d.ts.map +1 -1
  28. package/dist/RunSupervisor.d.ts +10 -0
  29. package/dist/RunSupervisor.d.ts.map +1 -1
  30. package/dist/RunSupervisor.js +21 -1
  31. package/dist/RunSupervisor.js.map +1 -1
  32. package/dist/Watch.d.ts +1 -1
  33. package/dist/Watch.d.ts.map +1 -1
  34. package/dist/WebWatch.d.ts +2 -2
  35. package/dist/WebWatch.d.ts.map +1 -1
  36. package/flows/epic-retro.js +1 -0
  37. package/flows/lib/chief.js +1 -0
  38. package/flows/lib/epic-stories.js +28 -4
  39. package/package.json +4 -4
  40. package/src/ChatNode.ts +3 -2
  41. package/src/Cli.ts +93 -1
  42. package/src/Inbox.ts +143 -0
  43. package/src/OperatorActTools.ts +87 -2
  44. package/src/OperatorNode.ts +22 -3
  45. package/src/OperatorServer.ts +12 -2
  46. package/src/OperatorTools.ts +3 -0
  47. package/src/RunSupervisor.ts +32 -1
package/src/Cli.ts CHANGED
@@ -27,8 +27,18 @@ import {
27
27
  makeWatchProgram,
28
28
  nodeTraceSources,
29
29
  nodeWatchDependencies,
30
- type WatchOptions
30
+ type WatchOptions,
31
+ nodeListEpics
31
32
  } from "./Watch.ts"
33
+ import {
34
+ epicFor,
35
+ epicsOf,
36
+ inboxListing,
37
+ inboxOf,
38
+ renderInboxListing,
39
+ retryOf,
40
+ skipOf
41
+ } from "./Inbox.ts"
32
42
  import { nodeWebWatchDependencies, runWebWatch } from "./WebWatch.ts"
33
43
  import { makeProfileProgram, type ProfileOptions } from "./Profile.ts"
34
44
  import {
@@ -887,6 +897,87 @@ const rosterCommand = Command.make("roster", { repo: rosterRepo }, (config) =>
887
897
  Command.withSubcommands([rosterPauseCommand, rosterResumeCommand])
888
898
  )
889
899
 
900
+ // ---- inbox (ADR 0057) -------------------------------------------------------
901
+
902
+ const inboxRepo = Flag.String("repo").pipe(
903
+ Flag.optional,
904
+ Flag.withDescription("Repository whose epic to steer (defaults to the current directory)")
905
+ )
906
+ const inboxEpic = Flag.String("epic").pipe(
907
+ Flag.optional,
908
+ Flag.withDescription("The epic, when the repository has more than one")
909
+ )
910
+
911
+ /** The checkout's inbox and the epic a command line means. */
912
+ const inboxTarget = (flags: {
913
+ readonly repo: Option.Option<string>
914
+ readonly epic: Option.Option<string>
915
+ }) =>
916
+ Effect.gen(function* () {
917
+ const repoPath = resolve(Option.getOrElse(flags.repo, () => process.cwd()))
918
+ const epic = yield* epicFor(epicsOf(nodeListEpics, repoPath), Option.getOrUndefined(flags.epic))
919
+ return { epic, inbox: inboxOf(nodePlainFileStore, process.env, repoPath) }
920
+ })
921
+
922
+ const written = (what: string, epic: string, id: string): string =>
923
+ `${what} written to epic ${epic} (${id}). A live run applies it within two seconds; \`llm4ts inbox\` shows the outcome. With no run live, the next run expires it.`
924
+
925
+ const inboxRetryCommand = Command.make(
926
+ "retry",
927
+ {
928
+ story: Argument.String("story").pipe(Argument.withDescription("Story id")),
929
+ repo: inboxRepo,
930
+ epic: inboxEpic
931
+ },
932
+ (config) =>
933
+ Effect.gen(function* () {
934
+ const { epic, inbox } = yield* inboxTarget(config)
935
+ const command = yield* inbox.submit(epic, { by: "cli", command: retryOf(config.story) })
936
+ yield* Console.log(written(`retry of story ${config.story}`, epic, command.id))
937
+ })
938
+ ).pipe(
939
+ Command.withDescription(
940
+ "Run a story that failed in the live run again; stories held behind it are freed"
941
+ )
942
+ )
943
+
944
+ const inboxSkipCommand = Command.make(
945
+ "skip",
946
+ {
947
+ story: Argument.String("story").pipe(Argument.withDescription("Story id")),
948
+ reason: Flag.String("reason").pipe(
949
+ Flag.withDescription("Why the story is left out; recorded on the board and the report")
950
+ ),
951
+ repo: inboxRepo,
952
+ epic: inboxEpic
953
+ },
954
+ (config) =>
955
+ Effect.gen(function* () {
956
+ const { epic, inbox } = yield* inboxTarget(config)
957
+ const command = yield* inbox.submit(epic, {
958
+ by: "cli",
959
+ command: skipOf(config.story, config.reason)
960
+ })
961
+ yield* Console.log(written(`skip of story ${config.story}`, epic, command.id))
962
+ })
963
+ ).pipe(
964
+ Command.withDescription(
965
+ "Leave a story out of the live run: not launched, or interrupted if it runs; its dependents wait"
966
+ )
967
+ )
968
+
969
+ const inboxCommand = Command.make("inbox", { repo: inboxRepo, epic: inboxEpic }, (config) =>
970
+ Effect.gen(function* () {
971
+ const { epic, inbox } = yield* inboxTarget(config)
972
+ yield* Console.log(renderInboxListing(yield* inboxListing(inbox, epic)))
973
+ })
974
+ ).pipe(
975
+ Command.withDescription(
976
+ "The control inbox of a running epic (ADR 0057): pending and answered commands; retry or skip a story"
977
+ ),
978
+ Command.withSubcommands([inboxRetryCommand, inboxSkipCommand])
979
+ )
980
+
890
981
  // ---- graph (ADR 0030) -------------------------------------------------------
891
982
 
892
983
  const graphFormats: ReadonlyArray<GraphFormat> = ["text", "json", "mermaid", "dot"]
@@ -1307,6 +1398,7 @@ export const shellCommand = Command.make("llm4ts", {}, () =>
1307
1398
  profileCommand,
1308
1399
  graphCommand,
1309
1400
  rosterCommand,
1401
+ inboxCommand,
1310
1402
  geminiBridgeCommand,
1311
1403
  mcpCommand,
1312
1404
  chatCommand,
package/src/Inbox.ts ADDED
@@ -0,0 +1,143 @@
1
+ import { join, resolve } from "node:path"
2
+ import * as Effect from "effect/Effect"
3
+ import * as Schema from "effect/Schema"
4
+ import {
5
+ makeControlInbox,
6
+ RetryStory,
7
+ SkipStory,
8
+ type ControlAction,
9
+ type ControlCommand,
10
+ type ControlInboxShape,
11
+ type ControlReceipt
12
+ } from "@llm4ts/flow/Control"
13
+ import type { PersistenceError } from "@llm4ts/flow/FlowError"
14
+ import type { PlainFileStoreShape } from "@llm4ts/flow/Persistence"
15
+ import { controlRoot } from "@llm4ts/runner/CheckoutState"
16
+ import { ShellUsageError } from "./ShellErrors.ts"
17
+
18
+ /**
19
+ * The control inbox as a person and the operator server use it (ADR 0057):
20
+ * `llm4ts inbox` and the `story_retry`, `story_skip` and `control_list` tools
21
+ * call the same functions. Neither needs a server running: the log is a file.
22
+ */
23
+
24
+ type Environment = Readonly<Record<string, string | undefined>>
25
+
26
+ /** A checkout's inbox on a file store. */
27
+ export const inboxOf = (
28
+ files: PlainFileStoreShape,
29
+ environment: Environment,
30
+ repoPath: string
31
+ ): ControlInboxShape => makeControlInbox({ files, root: controlRoot(environment, repoPath) })
32
+
33
+ /** One command as a listing shows it. */
34
+ export const ControlEntry = Schema.Struct({
35
+ id: Schema.String,
36
+ /** ISO time the command was written. */
37
+ at: Schema.String,
38
+ by: Schema.String,
39
+ command: Schema.Literals(["retry", "skip"]),
40
+ story: Schema.String,
41
+ reason: Schema.optionalKey(Schema.String),
42
+ /** Absent while the command is pending. */
43
+ outcome: Schema.optionalKey(Schema.Literals(["applied", "refused", "expired"])),
44
+ /** Why it was refused. */
45
+ refusal: Schema.optionalKey(Schema.String),
46
+ /** The run that answered. */
47
+ runId: Schema.optionalKey(Schema.String)
48
+ })
49
+ export type ControlEntry = typeof ControlEntry.Type
50
+
51
+ export const InboxListing = Schema.Struct({
52
+ epic: Schema.String,
53
+ pending: Schema.Array(ControlEntry),
54
+ /** The last answered commands, newest first. */
55
+ answered: Schema.Array(ControlEntry)
56
+ })
57
+ export type InboxListing = typeof InboxListing.Type
58
+
59
+ const entryOf = (command: ControlCommand, receipt?: ControlReceipt): ControlEntry => ({
60
+ id: command.id,
61
+ at: new Date(command.at).toISOString(),
62
+ by: command.by,
63
+ command: command.command._tag === "RetryStory" ? "retry" : "skip",
64
+ story: command.command.story,
65
+ ...(command.command._tag === "SkipStory" ? { reason: command.command.reason } : {}),
66
+ ...(receipt === undefined ? {} : { outcome: receipt.outcome, runId: receipt.runId }),
67
+ ...(receipt?.reason === undefined ? {} : { refusal: receipt.reason })
68
+ })
69
+
70
+ export const inboxListing = (
71
+ inbox: ControlInboxShape,
72
+ epic: string,
73
+ last = 10
74
+ ): Effect.Effect<InboxListing, PersistenceError> =>
75
+ Effect.map(inbox.log(epic), ({ commands, receipts }) => ({
76
+ epic,
77
+ pending: commands.filter((command) => !receipts.has(command.id)).map((c) => entryOf(c)),
78
+ answered: commands
79
+ .filter((command) => receipts.has(command.id))
80
+ .slice(-last)
81
+ .reverse()
82
+ .map((command) => entryOf(command, receipts.get(command.id)))
83
+ }))
84
+
85
+ const lineOf = (entry: ControlEntry): string => {
86
+ const what = `${entry.command} ${entry.story}${entry.reason === undefined ? "" : ` (${entry.reason})`}`
87
+ const how =
88
+ entry.outcome === undefined
89
+ ? "pending"
90
+ : `${entry.outcome}${entry.refusal === undefined ? "" : `: ${entry.refusal}`}`
91
+ return ` ${entry.at} ${what} — ${how} [${entry.id}, by ${entry.by}]`
92
+ }
93
+
94
+ export const renderInboxListing = (listing: InboxListing): string =>
95
+ [
96
+ `epic ${listing.epic}`,
97
+ listing.pending.length === 0
98
+ ? "pending: none"
99
+ : `pending (a live run applies them within two seconds; with none live, the next run expires them):`,
100
+ ...listing.pending.map(lineOf),
101
+ ...(listing.answered.length === 0 ? [] : ["answered, newest first:"]),
102
+ ...listing.answered.map(lineOf)
103
+ ].join("\n")
104
+
105
+ export const retryOf = (story: string): ControlAction => RetryStory.make({ story })
106
+ export const skipOf = (story: string, reason: string): ControlAction =>
107
+ SkipStory.make({ story, reason })
108
+
109
+ /** The epics of a checkout, by the folders under `.llm4ts/epics/`. */
110
+ export const epicsOf = (
111
+ listEpics: (directory: string) => ReadonlyArray<string>,
112
+ repoPath: string
113
+ ): ReadonlyArray<string> => listEpics(join(resolve(repoPath), ".llm4ts", "epics"))
114
+
115
+ /**
116
+ * The epic a command line means: the one named, which must be a folder on
117
+ * disk so no text becomes a path, or the only one the checkout has.
118
+ */
119
+ export const epicFor = (
120
+ epics: ReadonlyArray<string>,
121
+ named: string | undefined
122
+ ): Effect.Effect<string, ShellUsageError> => {
123
+ if (named !== undefined) {
124
+ return epics.includes(named)
125
+ ? Effect.succeed(named)
126
+ : Effect.fail(
127
+ new ShellUsageError({
128
+ message: `unknown epic '${named}'${epics.length === 0 ? ": this repository has none" : `; this repository has ${epics.join(", ")}`}`
129
+ })
130
+ )
131
+ }
132
+ const [only] = epics
133
+ return only !== undefined && epics.length === 1
134
+ ? Effect.succeed(only)
135
+ : Effect.fail(
136
+ new ShellUsageError({
137
+ message:
138
+ epics.length === 0
139
+ ? "this repository has no epic under .llm4ts/epics/"
140
+ : `--epic is needed: this repository has ${epics.join(", ")}`
141
+ })
142
+ )
143
+ }
@@ -29,6 +29,8 @@ import {
29
29
  type TraceFold
30
30
  } from "./RunReaders.ts"
31
31
  import { FlowLaunchError } from "./FlowProcess.ts"
32
+ import { InboxListing, inboxListing, retryOf, skipOf } from "./Inbox.ts"
33
+ import type { ControlAction } from "@llm4ts/flow/Control"
32
34
  import { resolveRepo, type OperatorDeps } from "./OperatorTools.ts"
33
35
  import {
34
36
  epicDirOf,
@@ -66,7 +68,17 @@ export const runWaitTool = Tool.make("run_wait", {
66
68
  .annotate(Tool.Readonly, true)
67
69
  .annotate(Tool.Destructive, false)
68
70
 
69
- export const waitToolkit = Toolkit.make(runWaitTool)
71
+ export const controlListTool = Tool.make("control_list", {
72
+ description:
73
+ "An epic's control inbox (ADR 0057): the retry and skip commands still pending and the last ones answered, each with its outcome (applied, refused with a reason, or expired).",
74
+ parameters: Schema.Struct({ repo: repoParam, epic: Schema.String }),
75
+ success: InboxListing,
76
+ failure: Schema.Union([UnknownRepo, UnknownEpic, PersistenceError])
77
+ })
78
+ .annotate(Tool.Readonly, true)
79
+ .annotate(Tool.Destructive, false)
80
+
81
+ export const waitToolkit = Toolkit.make(runWaitTool, controlListTool)
70
82
 
71
83
  const pollInterval = "500 millis"
72
84
  const defaultWaitSeconds = 120
@@ -114,6 +126,13 @@ export const waitHandlers = (
114
126
  }
115
127
  yield* Effect.sleep(pollInterval)
116
128
  }
129
+ }),
130
+
131
+ control_list: ({ repo: repoId, epic }) =>
132
+ Effect.gen(function* () {
133
+ const repo = yield* resolveRepo(deps.config, repoId)
134
+ yield* epicDirOf(deps, repo, epic)
135
+ return yield* inboxListing(deps.control(repo.path), epic)
117
136
  })
118
137
  })
119
138
 
@@ -201,7 +220,49 @@ export const approveTool = Tool.make("approve", {
201
220
  ])
202
221
  }).annotate(Tool.Destructive, false)
203
222
 
204
- export const actToolkit = Toolkit.make(startRunTool, stopRunTool, retroStartTool, approveTool)
223
+ const steerFailures = Schema.Union([NotAllowed, UnknownRepo, UnknownEpic, PersistenceError])
224
+ const Steered = Schema.Struct({
225
+ /** The command's id: `control_list` and the run's events name it. */
226
+ id: Schema.String,
227
+ epic: Schema.String,
228
+ story: Schema.String
229
+ })
230
+
231
+ export const storyRetryTool = Tool.make("story_retry", {
232
+ description:
233
+ "Ask a live epic run to run a failed story again; stories held behind it are freed. Returns once the command is written: the outcome (applied, refused, expired) is in control_list and in the run's events. With no run live the command expires.",
234
+ parameters: Schema.Struct({
235
+ repo: repoParam,
236
+ epic: Schema.String,
237
+ story: Schema.String,
238
+ requestId: Schema.optional(Schema.String)
239
+ }),
240
+ success: Steered,
241
+ failure: steerFailures
242
+ }).annotate(Tool.Destructive, false)
243
+
244
+ export const storySkipTool = Tool.make("story_skip", {
245
+ description:
246
+ "Ask a live epic run to leave a story out: one not started is not launched, a running one is interrupted, and its dependents wait as they do for a failed story. Returns once the command is written; see control_list for the outcome.",
247
+ parameters: Schema.Struct({
248
+ repo: repoParam,
249
+ epic: Schema.String,
250
+ story: Schema.String,
251
+ reason: Schema.optional(Schema.String),
252
+ requestId: Schema.optional(Schema.String)
253
+ }),
254
+ success: Steered,
255
+ failure: steerFailures
256
+ }).annotate(Tool.Destructive, true)
257
+
258
+ export const actToolkit = Toolkit.make(
259
+ startRunTool,
260
+ stopRunTool,
261
+ retroStartTool,
262
+ storyRetryTool,
263
+ storySkipTool,
264
+ approveTool
265
+ )
205
266
 
206
267
  const knobsOf = (params: typeof StartRunParams.Type): OperatorKnobs => ({
207
268
  ...(params.task === undefined ? {} : { task: params.task }),
@@ -358,6 +419,25 @@ export const actHandlers = (
358
419
  }
359
420
  })
360
421
 
422
+ // Whoever may start and stop a run may steer it (ADR 0057).
423
+ const steer = (
424
+ repoId: string | undefined,
425
+ epic: string,
426
+ command: ControlAction,
427
+ requestId: string | undefined
428
+ ) =>
429
+ Effect.gen(function* () {
430
+ yield* requireRun
431
+ const repo = yield* resolveRepo(deps.config, repoId)
432
+ yield* epicDirOf(deps, repo, epic)
433
+ const written = yield* deps.control(repo.path).submit(epic, {
434
+ by: "mcp",
435
+ command,
436
+ ...(requestId === undefined ? {} : { id: requestId })
437
+ })
438
+ return { id: written.id, epic, story: written.command.story }
439
+ })
440
+
361
441
  return actToolkit.of({
362
442
  start_run: (params) =>
363
443
  Effect.gen(function* () {
@@ -389,6 +469,11 @@ export const actHandlers = (
389
469
  })
390
470
  }),
391
471
 
472
+ story_retry: ({ repo, epic, story, requestId }) => steer(repo, epic, retryOf(story), requestId),
473
+
474
+ story_skip: ({ repo, epic, story, reason, requestId }) =>
475
+ steer(repo, epic, skipOf(story, reason ?? "skipped by the operator"), requestId),
476
+
392
477
  approve: ({ repo: repoId, epic, id }) =>
393
478
  Effect.gen(function* () {
394
479
  yield* requireApprove
@@ -12,14 +12,16 @@ import { collectDoctorReport } from "@llm4ts/runner/Doctor"
12
12
  import { httpProbe, rosterReport } from "@llm4ts/runner/ExecutorRoster"
13
13
  import { interruptOnSignal, type SignalSource } from "@llm4ts/runner/FlowRunner"
14
14
  import { nodePlainFileStore } from "@llm4ts/runner/NodePlainFileStore"
15
+ import { nodeWriterLock, writerLockPath } from "@llm4ts/runner/NodeWriterLock"
15
16
  import { nodeTranscriptFiles } from "@llm4ts/runner/Transcripts"
16
17
  import { nodeListEpics } from "./Watch.ts"
17
18
  import { discoverFlows, type FlowTierPaths } from "./FlowCatalog.ts"
18
19
  import { nodeFlowProcess, type FlowProcessShape } from "./FlowProcess.ts"
20
+ import { inboxOf } from "./Inbox.ts"
19
21
  import type { OperatorConfig } from "./OperatorConfig.ts"
20
22
  import { runOperatorServer } from "./OperatorServer.ts"
21
23
  import type { OperatorDeps } from "./OperatorTools.ts"
22
- import { makeRunSupervisor } from "./RunSupervisor.ts"
24
+ import { makeRunSupervisor, type SupervisorOptions } from "./RunSupervisor.ts"
23
25
 
24
26
  /**
25
27
  * The Node side of `llm4ts mcp` (ADR 0041): the operator's dependencies over
@@ -36,6 +38,8 @@ export interface McpRuntime<E> {
36
38
  readonly serve: (config: OperatorConfig, deps: OperatorDeps) => Effect.Effect<never, E>
37
39
  /** How long stopping a run waits after SIGINT before SIGTERM; the supervisor's default when absent. */
38
40
  readonly graceMs?: number
41
+ /** Who holds a checkout's writer lock; the supervisor consults only its registry when absent. */
42
+ readonly writerHolder?: SupervisorOptions["writerHolder"]
39
43
  }
40
44
 
41
45
  /**
@@ -58,6 +62,7 @@ export const runMcp = <E>(
58
62
  files: runtime.operator.files,
59
63
  process: runtime.flowProcess,
60
64
  parallelRuns: config.parallelRuns,
65
+ ...(runtime.writerHolder === undefined ? {} : { writerHolder: runtime.writerHolder }),
61
66
  ...(runtime.graceMs === undefined ? {} : { graceMs: runtime.graceMs })
62
67
  })
63
68
  const fiber = yield* Effect.forkScoped(
@@ -76,6 +81,18 @@ export const runMcp = <E>(
76
81
  )
77
82
  }
78
83
 
84
+ /** The writer lock on disk, as the supervisor asks for it. */
85
+ export const nodeWriterHolder =
86
+ (
87
+ environment: Readonly<Record<string, string | undefined>>
88
+ ): NonNullable<SupervisorOptions["writerHolder"]> =>
89
+ (repoPath) => {
90
+ const path = writerLockPath(environment, repoPath)
91
+ return nodeWriterLock
92
+ .holder(path)
93
+ .pipe(Effect.map((live) => (live === undefined ? undefined : { path, live })))
94
+ }
95
+
79
96
  /** A file's text, or `undefined` when it cannot be read (the `mcp` config and token file). */
80
97
  export const nodeRead = (path: string): Effect.Effect<string | undefined> =>
81
98
  Effect.sync(() => {
@@ -140,8 +157,10 @@ export const nodeOperatorRuntime = (
140
157
  flows: (repoPath) =>
141
158
  discoverFlows(tierPaths(repoPath)).pipe(Effect.provide(NodeFileSystem.layer)),
142
159
  now: Clock.currentTimeMillis,
143
- environment
160
+ environment,
161
+ control: (repoPath) => inboxOf(nodePlainFileStore, environment, repoPath)
144
162
  },
145
163
  flowProcess: nodeFlowProcess,
146
- serve: runOperatorServer
164
+ serve: runOperatorServer,
165
+ writerHolder: nodeWriterHolder(environment)
147
166
  })
@@ -19,6 +19,8 @@ import * as HttpServerResponse from "effect/http/HttpServerResponse"
19
19
  import {
20
20
  actHandlers,
21
21
  actToolkit,
22
+ storyRetryTool,
23
+ storySkipTool,
22
24
  approveTool,
23
25
  retroStartTool,
24
26
  startRunTool,
@@ -49,7 +51,13 @@ const serverInfo = {
49
51
  protocols: [McpProtocol.v2025_06_18]
50
52
  } as const
51
53
 
52
- const runToolkit = Toolkit.make(startRunTool, stopRunTool, retroStartTool)
54
+ const runToolkit = Toolkit.make(
55
+ startRunTool,
56
+ stopRunTool,
57
+ retroStartTool,
58
+ storyRetryTool,
59
+ storySkipTool
60
+ )
53
61
  const approveToolkit = Toolkit.make(approveTool)
54
62
 
55
63
  /** The act tools a configuration allows: `--allow-run` and `--allow-approve` each add their own. */
@@ -74,7 +82,9 @@ const actLayer = (
74
82
  const handlers = runToolkit.of({
75
83
  start_run: act.start_run,
76
84
  stop_run: act.stop_run,
77
- retro_start: act.retro_start
85
+ retro_start: act.retro_start,
86
+ story_retry: act.story_retry,
87
+ story_skip: act.story_skip
78
88
  })
79
89
  return McpServer.toolkit(runToolkit).pipe(Layer.provide(runToolkit.toLayer(handlers)))
80
90
  }
@@ -1,3 +1,4 @@
1
+ import type { ControlInboxShape } from "@llm4ts/flow/Control"
1
2
  import { join } from "node:path"
2
3
  import * as Duration from "effect/Duration"
3
4
  import * as Effect from "effect/Effect"
@@ -83,6 +84,8 @@ export interface OperatorDeps extends RunLookupDeps {
83
84
  readonly flows: (repoPath: string) => Effect.Effect<ReadonlyArray<DiscoveredFlow>, unknown>
84
85
  readonly now: Effect.Effect<number>
85
86
  readonly environment: Readonly<Record<string, string | undefined>>
87
+ /** A checkout's control inbox (ADR 0057). */
88
+ readonly control: (repoPath: string) => ControlInboxShape
86
89
  }
87
90
 
88
91
  /** The repository a tool call means; the id may be left out when the server serves one. */
@@ -17,6 +17,7 @@ import {
17
17
  } from "@llm4ts/flow/OperatorSchemas"
18
18
  import type { OperatorKnobs } from "@llm4ts/flow/OperatorSchemas"
19
19
  import type { PlainFileStoreShape } from "@llm4ts/flow/Persistence"
20
+ import { checkoutBusy, type LiveHolder } from "@llm4ts/flow/WriterLock"
20
21
  import { prepareLaunch, type FlagAssignment } from "./Config.ts"
21
22
  import { FlowLaunchError, type FlowProcessHandle, type FlowProcessShape } from "./FlowProcess.ts"
22
23
 
@@ -71,6 +72,17 @@ export interface SupervisorOptions {
71
72
  readonly readOnlyFlows?: ReadonlySet<string>
72
73
  /** The 4-hex run id suffix; injectable so tests are deterministic. */
73
74
  readonly random?: () => string
75
+ /**
76
+ * Who holds a checkout's writer lock (ADR 0058): a run this registry does
77
+ * not know, started from a terminal or by another server, or processes
78
+ * such a run left behind. Absent, only the registry is consulted.
79
+ */
80
+ readonly writerHolder?: (
81
+ repoPath: string
82
+ ) => Effect.Effect<
83
+ { readonly path: string; readonly live: LiveHolder } | undefined,
84
+ PersistenceError
85
+ >
74
86
  }
75
87
 
76
88
  /** Knobs that become the flow's argv, in a fixed order; `flags` come last. */
@@ -124,6 +136,7 @@ export const makeRunSupervisor = (
124
136
  const graceMs = options.graceMs ?? 30_000
125
137
  const readOnlyFlows = options.readOnlyFlows ?? new Set(["epic-retro", "chief"])
126
138
  const random = options.random ?? randomHex
139
+ const writesAlone = options.parallelRuns === 1
127
140
  const stateDir = (repoId: string) => operatorStateDir(options.environment, repoId)
128
141
  const registryPath = (repoId: string) => join(stateDir(repoId), "runs.jsonl")
129
142
 
@@ -228,6 +241,19 @@ export const makeRunSupervisor = (
228
241
  runId: newest.runId
229
242
  })
230
243
  }
244
+ // The flow takes the lock itself; asking first refuses the run
245
+ // before anything is recorded or spawned.
246
+ if (writesAlone && options.writerHolder !== undefined) {
247
+ const held = yield* options
248
+ .writerHolder(request.repo.path)
249
+ .pipe(Effect.catch(() => Effect.succeed(undefined)))
250
+ if (held !== undefined) {
251
+ return yield* new RunInProgress({
252
+ message: checkoutBusy(held.path, held.live).message,
253
+ runId: held.live.holder.runId
254
+ })
255
+ }
256
+ }
231
257
  }
232
258
  const startedAt = yield* Clock.currentTimeMillis
233
259
  const taken = (id: string) => live.has(id) || existing.some((run) => run.runId === id)
@@ -259,7 +285,12 @@ export const makeRunSupervisor = (
259
285
  base: childEnvironment(request.baseEnvironment),
260
286
  flags: knobAssignments(request.knobs),
261
287
  files: options.files,
262
- extra: { LLM4TS_RUN_ID: runId, LLM4TS_TRACE_PATH: tracePath }
288
+ extra: {
289
+ LLM4TS_RUN_ID: runId,
290
+ LLM4TS_TRACE_PATH: tracePath,
291
+ // Several writing runs were asked for: they do not lock each other out.
292
+ ...(writesAlone ? {} : { LLM4TS_WRITER_LOCK: "off" })
293
+ }
263
294
  }).pipe(Effect.mapError((error) => new FlowLaunchError({ message: error.message })))
264
295
  launching.add(runId)
265
296
  return yield* Effect.gen(function* () {