@nathanstephenson/flow 0.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.
Files changed (141) hide show
  1. package/README.md +641 -0
  2. package/build/workflow-runtime.cjs +213964 -0
  3. package/dist/backend/claude/async-queue.js +44 -0
  4. package/dist/backend/claude/auto-compaction.js +10 -0
  5. package/dist/backend/claude/background-calls.js +116 -0
  6. package/dist/backend/claude/enquiries.js +162 -0
  7. package/dist/backend/claude/index.js +1138 -0
  8. package/dist/backend/claude/mcp.js +55 -0
  9. package/dist/backend/claude/permissions.js +106 -0
  10. package/dist/backend/claude/streamed-message.js +120 -0
  11. package/dist/backend/claude/subagents.js +128 -0
  12. package/dist/backend/claude/workflow-parent.js +12 -0
  13. package/dist/backend/claude/workflow-processes.js +95 -0
  14. package/dist/backend/claude/workflow-subagent.js +234 -0
  15. package/dist/backend/effort.js +30 -0
  16. package/dist/backend/fake/index.js +570 -0
  17. package/dist/backend/mcp.js +190 -0
  18. package/dist/backend/pi/auto-compaction.js +16 -0
  19. package/dist/backend/pi/background-calls.js +56 -0
  20. package/dist/backend/pi/enquiries.js +63 -0
  21. package/dist/backend/pi/index.js +597 -0
  22. package/dist/backend/pi/mcp.js +35 -0
  23. package/dist/backend/pi/subagents.js +23 -0
  24. package/dist/backend/pi/work.js +104 -0
  25. package/dist/backend/pi/workflow-parent.js +21 -0
  26. package/dist/backend/pi/workflow-subagent.js +199 -0
  27. package/dist/backend/registry.js +34 -0
  28. package/dist/backend/types.js +1 -0
  29. package/dist/backend/workflow-tools.js +25 -0
  30. package/dist/build-id +1 -0
  31. package/dist/cli/application.js +397 -0
  32. package/dist/cli/bootstrap.js +535 -0
  33. package/dist/cli/host-control.js +100 -0
  34. package/dist/cli/install-guard.js +270 -0
  35. package/dist/cli/install-process.js +52 -0
  36. package/dist/cli/main.js +12 -0
  37. package/dist/cli/update.js +128 -0
  38. package/dist/client/connection.js +183 -0
  39. package/dist/client/context-usage.js +66 -0
  40. package/dist/client/diff.js +36 -0
  41. package/dist/client/enquiry.js +105 -0
  42. package/dist/client/markdown.js +192 -0
  43. package/dist/client/model-choices.js +32 -0
  44. package/dist/client/permission.js +60 -0
  45. package/dist/client/project-name.js +19 -0
  46. package/dist/client/reduce.js +463 -0
  47. package/dist/client/relative-time.js +30 -0
  48. package/dist/client/scope-kind.js +28 -0
  49. package/dist/client/search.js +136 -0
  50. package/dist/client/session-label.js +9 -0
  51. package/dist/client/status.js +84 -0
  52. package/dist/client/tool-chains.js +52 -0
  53. package/dist/client/tool-summary.js +98 -0
  54. package/dist/daemon/auth.js +590 -0
  55. package/dist/daemon/config-store.js +183 -0
  56. package/dist/daemon/config.js +687 -0
  57. package/dist/daemon/credential-redaction.js +9 -0
  58. package/dist/daemon/git.js +312 -0
  59. package/dist/daemon/host-control-routes.js +29 -0
  60. package/dist/daemon/host.js +2343 -0
  61. package/dist/daemon/http.js +19 -0
  62. package/dist/daemon/log.js +44 -0
  63. package/dist/daemon/mcp-auth.js +164 -0
  64. package/dist/daemon/models.js +85 -0
  65. package/dist/daemon/ownership.js +104 -0
  66. package/dist/daemon/projects.js +317 -0
  67. package/dist/daemon/publish.js +289 -0
  68. package/dist/daemon/pull-request.js +198 -0
  69. package/dist/daemon/runtime.js +100 -0
  70. package/dist/daemon/secret-store.js +65 -0
  71. package/dist/daemon/server.js +827 -0
  72. package/dist/daemon/shell.js +220 -0
  73. package/dist/daemon/skills.js +104 -0
  74. package/dist/daemon/stack-metadata.js +24 -0
  75. package/dist/daemon/stack.js +743 -0
  76. package/dist/daemon/store.js +130 -0
  77. package/dist/daemon/summariser.js +476 -0
  78. package/dist/daemon/workflow-execution-routes.js +105 -0
  79. package/dist/daemon/workflow-executions.js +1018 -0
  80. package/dist/daemon/workflow-mcp.js +20 -0
  81. package/dist/daemon/workflow-routes.js +102 -0
  82. package/dist/protocol/attachments.js +59 -0
  83. package/dist/protocol/commands.js +1 -0
  84. package/dist/protocol/events.js +20 -0
  85. package/dist/protocol/fonts.js +26 -0
  86. package/dist/protocol/git.js +12 -0
  87. package/dist/protocol/mcp.js +51 -0
  88. package/dist/protocol/projects.js +21 -0
  89. package/dist/protocol/publish.js +1 -0
  90. package/dist/protocol/pull-request.js +1 -0
  91. package/dist/protocol/secrets.js +4 -0
  92. package/dist/protocol/settings.js +63 -0
  93. package/dist/protocol/shells.js +8 -0
  94. package/dist/protocol/skills.js +16 -0
  95. package/dist/protocol/stack.js +41 -0
  96. package/dist/protocol/workflow-executions.js +1 -0
  97. package/dist/protocol/workflows.js +1 -0
  98. package/dist/tui/app.js +518 -0
  99. package/dist/tui/keys.js +54 -0
  100. package/dist/tui/render.js +366 -0
  101. package/dist/web/assets.js +10 -0
  102. package/dist/web/embedded.js +12 -0
  103. package/dist/web/manifest.js +70 -0
  104. package/dist/workflows/decisions.js +65 -0
  105. package/dist/workflows/executors.js +132 -0
  106. package/dist/workflows/graph.js +276 -0
  107. package/dist/workflows/json-schema.js +49 -0
  108. package/dist/workflows/loops.js +102 -0
  109. package/dist/workflows/mcp.js +18 -0
  110. package/dist/workflows/records.js +111 -0
  111. package/dist/workflows/recovery.js +25 -0
  112. package/dist/workflows/runtime-asset.js +17 -0
  113. package/dist/workflows/runtime-libs.js +1 -0
  114. package/dist/workflows/runtime-settings.js +23 -0
  115. package/dist/workflows/runtime.js +343 -0
  116. package/dist/workflows/scheduler.js +573 -0
  117. package/dist/workflows/schema.js +161 -0
  118. package/dist/workflows/store.js +93 -0
  119. package/package.json +87 -0
  120. package/web/dist/assets/__vite-browser-external-2447137e-BvRk9kiK.js +0 -0
  121. package/web/dist/assets/ghostty-vt-DOMeXDrv.wasm +0 -0
  122. package/web/dist/assets/index-BC0gLS53.js +106 -0
  123. package/web/dist/assets/index-CCeZYKES.css +2 -0
  124. package/web/dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  125. package/web/dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  126. package/web/dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  127. package/web/dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  128. package/web/dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  129. package/web/dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  130. package/web/dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  131. package/web/dist/assets/rolldown-runtime-B0Z9INg1.js +1 -0
  132. package/web/dist/assets/select-6i3wxovH.js +1 -0
  133. package/web/dist/assets/settings-mcp-CcT0ADJR.js +1 -0
  134. package/web/dist/assets/settings-secrets-CK4uF7fd.js +1 -0
  135. package/web/dist/assets/settings-workflows-CrbZF-nM.js +23 -0
  136. package/web/dist/assets/switch-ftZleVB8.js +6 -0
  137. package/web/dist/assets/workflow-editors-naPqAmYO.js +65 -0
  138. package/web/dist/assets/workflows-D4T4Gy_7.css +1 -0
  139. package/web/dist/assets/workflows-hh6ioeEA.js +7 -0
  140. package/web/dist/assets/workflows-pane-Db-MHf7Z.js +1 -0
  141. package/web/dist/index.html +31 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The rules both front-ends need for turning a status into affordances. Shared because they are
3
+ * assertions about the Session Host's behaviour, not about any one UI: getting them wrong means
4
+ * offering an action the host will refuse.
5
+ */
6
+ /**
7
+ * The one place an Agent Session's activity is worked out.
8
+ *
9
+ * Called by the Session Host and by the client reducer against the same three inputs, so the rail
10
+ * and the pane agree by construction rather than by two hand-maintained switch statements happening
11
+ * to line up — which is the bug `retention.test.ts` exists to catch.
12
+ *
13
+ * A backgrounded Subagent is deliberately absent from the inputs. It is not occupancy (ADR 0016):
14
+ * the model is idle and the Steering Queue may dispatch, so saying `running` here would be a lie
15
+ * that also blocks steering. It travels as `SessionSummary.activeSubagents` instead.
16
+ */
17
+ export function deriveStatus(of) {
18
+ if (of.lifecycle !== "live")
19
+ return of.lifecycle;
20
+ if (of.awaiting)
21
+ return "awaiting";
22
+ return of.turnInFlight ? "running" : "idle";
23
+ }
24
+ /**
25
+ * Whether a turn holds this Agent Session — the question almost every caller comparing against
26
+ * `"running"` was really asking.
27
+ *
28
+ * Awaiting is a turn held open on a person rather than on a model, so everything that must not
29
+ * happen mid-turn must not happen then either. Written as a predicate because widening
30
+ * `SessionStatus` cannot be caught by the compiler at a `=== "running"`: the comparison stays valid
31
+ * and quietly starts returning false.
32
+ */
33
+ export function occupied(status) {
34
+ return status === "running" || status === "awaiting";
35
+ }
36
+ /**
37
+ * Which band of the rail an Agent Session belongs to, most alive first.
38
+ *
39
+ * The rail is banded rather than ordered by one timestamp, because a single recency key put a
40
+ * finished Agent Session above one that was still working — and the top of a list is where a reader
41
+ * looks for what is happening. Banding fixes that without reintroducing churn: a row moves when its
42
+ * band changes and at no other time, so a turn can stream for an hour without touching the order.
43
+ *
44
+ * Ended has no band of its own. An Ended Agent Session is not reaped and stays in the list, and it
45
+ * is as finished as a Settled one, so it sits with them at the bottom.
46
+ */
47
+ export function railBand(of) {
48
+ if (of.status === "awaiting")
49
+ return 0;
50
+ if (of.status === "running" || working(of))
51
+ return 1;
52
+ if (of.status === "idle")
53
+ return 2;
54
+ if (of.status === "dormant")
55
+ return 3;
56
+ return 4;
57
+ }
58
+ /**
59
+ * Working, but not occupancy. A backgrounded Subagent or an open Background Call leaves the status
60
+ * `idle` (ADR 0016, ADR 0021) and must not change it — the Steering Queue really will dispatch — but
61
+ * something *is* running, and both the rail's banding and its status dot answer "is it working?"
62
+ * rather than "is the model holding a turn?".
63
+ *
64
+ * The independent-work counts are summed here and nowhere else: this is the only question that does
65
+ * not care which kind is working.
66
+ *
67
+ * Only `idle` is liftable. Neither a Subagent nor a Background Call can outlive its Backend Session,
68
+ * and a running Workflow Execution owns a live one, so a count on anything else is stale rather than
69
+ * live work.
70
+ */
71
+ export function working(of) {
72
+ return of.status === "idle" && of.activeSubagents + of.activeBackgroundCalls + (of.activeWorkflows ?? 0) > 0;
73
+ }
74
+ /** Nothing to Settle once it is Settled, and an Ended Agent Session cannot be. */
75
+ export function canSettle(status) {
76
+ return status !== "settled" && status !== "ended";
77
+ }
78
+ /**
79
+ * Dormant and Settled both take a Revive; Ended refuses one outright, and any of the derived
80
+ * activities means the Lifecycle is `live` and a Backend Session is already attached (ADR 0003).
81
+ */
82
+ export function canRevive(status) {
83
+ return status === "dormant" || status === "settled";
84
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Where a run of adjacent tool calls sits in a Presentation Transcript.
3
+ *
4
+ * A **Tool Chain** is three or more Entries with nothing but tool calls and thinking in them. It is
5
+ * adjacency and nothing more — the transcript records no causal link between two calls, and a
6
+ * model's parallel tool block lands here the same way a sequential burst does. What it buys is a
7
+ * document that stops
8
+ * growing while a turn greps twenty files: the run collapses to one line, and the prose after it
9
+ * stays on screen.
10
+ *
11
+ * Keys alone answer this, the way `ownKeys` answers its own question: a tool Entry's key is
12
+ * `tool:<id>` (`entryKey`), so no Entry is read and nothing here touches the DOM. Kept in
13
+ * `src/client/` beside `diff.ts` and `tool-summary.ts` rather than in the web client's presentation
14
+ * folder, because the TUI draws this same transcript and should not have to re-derive the rule.
15
+ *
16
+ * The caller passes the keys a reader can actually see — after `ownKeys`, after any search filter,
17
+ * after the tail window — because a grouping can only honestly describe the list it was given.
18
+ */
19
+ const TOOL_PREFIX = "tool:";
20
+ const THINKING_PREFIX = "thinking:";
21
+ /** Below this many adjacent tool calls a run is just some rows, and hiding them helps nobody. */
22
+ const MIN_CHAIN = 3;
23
+ export const isToolKey = (key) => key.startsWith(TOOL_PREFIX);
24
+ /**
25
+ * Thinking rides along. A model reasoning between two calls is one turn working, not the reader
26
+ * getting their prose back, so breaking the run there would leave the flood the chain exists to
27
+ * fold — three greps with a thought between each is exactly the shape that stayed expanded before.
28
+ * A run of thinking alone is not a chain, though: there is no tool in it to name.
29
+ */
30
+ const isChainable = (key) => isToolKey(key) || key.startsWith(THINKING_PREFIX);
31
+ export function toolChains(keys, min = MIN_CHAIN) {
32
+ const segments = [];
33
+ let run = [];
34
+ const flush = () => {
35
+ if (run.length >= min && run.some(isToolKey))
36
+ segments.push({ kind: "chain", keys: run });
37
+ else
38
+ for (const key of run)
39
+ segments.push({ kind: "entry", key });
40
+ run = [];
41
+ };
42
+ for (const key of keys) {
43
+ if (isChainable(key)) {
44
+ run.push(key);
45
+ continue;
46
+ }
47
+ flush();
48
+ segments.push({ kind: "entry", key });
49
+ }
50
+ flush();
51
+ return segments;
52
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A one-line précis of a tool call's arguments.
3
+ *
4
+ * A collapsed tool call that says only `[complete] Edit` withholds the one thing a reader wants —
5
+ * which file, which command, which pattern. The TUI prints exactly that today (`render.ts:79`), so
6
+ * this lives beside the reducer and stays DOM-free: it returns a string, and both front-ends can
7
+ * print a string.
8
+ */
9
+ /**
10
+ * About a line in a narrow terminal, which is the tighter of the two front-ends. A précis that needs
11
+ * scrolling is not a précis.
12
+ */
13
+ const MAX = 60;
14
+ /**
15
+ * Ordered, because a tool's input usually carries several of these and the first is the one the
16
+ * question is about: a Bash call's `command` before its `description`, a Grep's `pattern` before the
17
+ * directory it searched.
18
+ *
19
+ * Keyed on the shape of the arguments rather than on the tool's name, because the name is the part
20
+ * that varies: Claude's `Edit` and a pi tool that edits a file are not called the same thing, while
21
+ * `file_path` means the same in both. An unrecognised tool with a recognisable argument still reads.
22
+ */
23
+ const ARGUMENTS = [
24
+ { key: "command", shape: "text" },
25
+ // Ahead of `description` and `prompt`, which an AskUserQuestion call does not carry but a future
26
+ // asking tool might. Keyed on the argument rather than the tool's name, which is this list's rule.
27
+ { key: "questions", shape: "questions" },
28
+ { key: "file_path", shape: "path" },
29
+ { key: "notebook_path", shape: "path" },
30
+ { key: "pattern", shape: "text" },
31
+ { key: "url", shape: "text" },
32
+ { key: "query", shape: "text" },
33
+ { key: "path", shape: "path" },
34
+ { key: "description", shape: "text" },
35
+ { key: "prompt", shape: "text" },
36
+ ];
37
+ /**
38
+ * Returns undefined when there is nothing worth saying, so a caller renders the tool's name alone
39
+ * rather than a padded blank. `input` is `unknown` on the wire (`events.ts` — a Backend Adapter
40
+ * passes its backend's arguments through), so every access is narrowed rather than trusted.
41
+ */
42
+ export function toolSummary(input) {
43
+ if (!input || typeof input !== "object")
44
+ return undefined;
45
+ const record = input;
46
+ for (const argument of ARGUMENTS) {
47
+ const value = record[argument.key];
48
+ if (argument.shape === "questions") {
49
+ const asked = clipQuestions(value);
50
+ if (asked !== undefined)
51
+ return asked;
52
+ continue;
53
+ }
54
+ if (typeof value !== "string" || value.trim() === "")
55
+ continue;
56
+ return argument.shape === "path" ? clipPath(value.trim()) : clipText(value);
57
+ }
58
+ // The fallback: a tool nobody here has heard of, whose input is a single string, is describing
59
+ // itself with that string. Two or more and there is no way to know which one matters, so say
60
+ // nothing rather than pick.
61
+ const strings = Object.values(record).filter((value) => typeof value === "string");
62
+ const only = strings.length === 1 ? strings[0] : undefined;
63
+ return only && only.trim() !== "" ? clipText(only) : undefined;
64
+ }
65
+ /**
66
+ * The first question asked, and how many others came with it.
67
+ *
68
+ * Without this an `AskUserQuestion` call precises to nothing — `questions` is an array, so no key
69
+ * above matches it and the single-string fallback finds none — and the row reads `[complete]
70
+ * AskUserQuestion`, which is exactly the withholding this file exists to stop.
71
+ *
72
+ * The front-ends suppress this row where an Enquiry Entry stands beside it, so what this actually
73
+ * serves is the case where one does not: a Subagent's Enquiry, seen from the Agents tab.
74
+ */
75
+ function clipQuestions(value) {
76
+ if (!Array.isArray(value) || value.length === 0)
77
+ return undefined;
78
+ const first = value[0];
79
+ if (!first || typeof first !== "object")
80
+ return undefined;
81
+ const asked = first.question;
82
+ if (typeof asked !== "string" || asked.trim() === "")
83
+ return undefined;
84
+ const rest = value.length - 1;
85
+ // Clipped after the count is appended, not before, so the whole précis obeys MAX rather than
86
+ // MAX-plus-however-long-the-suffix-turned-out-to-be.
87
+ return clipText(rest > 0 ? `${asked} (+${rest} more)` : asked);
88
+ }
89
+ /** Whitespace collapsed so a heredoc or a multi-line prompt still occupies one line. */
90
+ function clipText(value) {
91
+ const text = value.replace(/\s+/g, " ").trim();
92
+ return text.length <= MAX ? text : `${text.slice(0, MAX - 1)}…`;
93
+ }
94
+ function clipPath(path) {
95
+ // The tail of a path is what identifies the file; the leading directories are what a reader can
96
+ // afford to lose, which is the opposite of how everything else here truncates.
97
+ return path.length <= MAX ? path : `…${path.slice(-(MAX - 1))}`;
98
+ }