@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.
- package/README.md +641 -0
- package/build/workflow-runtime.cjs +213964 -0
- package/dist/backend/claude/async-queue.js +44 -0
- package/dist/backend/claude/auto-compaction.js +10 -0
- package/dist/backend/claude/background-calls.js +116 -0
- package/dist/backend/claude/enquiries.js +162 -0
- package/dist/backend/claude/index.js +1138 -0
- package/dist/backend/claude/mcp.js +55 -0
- package/dist/backend/claude/permissions.js +106 -0
- package/dist/backend/claude/streamed-message.js +120 -0
- package/dist/backend/claude/subagents.js +128 -0
- package/dist/backend/claude/workflow-parent.js +12 -0
- package/dist/backend/claude/workflow-processes.js +95 -0
- package/dist/backend/claude/workflow-subagent.js +234 -0
- package/dist/backend/effort.js +30 -0
- package/dist/backend/fake/index.js +570 -0
- package/dist/backend/mcp.js +190 -0
- package/dist/backend/pi/auto-compaction.js +16 -0
- package/dist/backend/pi/background-calls.js +56 -0
- package/dist/backend/pi/enquiries.js +63 -0
- package/dist/backend/pi/index.js +597 -0
- package/dist/backend/pi/mcp.js +35 -0
- package/dist/backend/pi/subagents.js +23 -0
- package/dist/backend/pi/work.js +104 -0
- package/dist/backend/pi/workflow-parent.js +21 -0
- package/dist/backend/pi/workflow-subagent.js +199 -0
- package/dist/backend/registry.js +34 -0
- package/dist/backend/types.js +1 -0
- package/dist/backend/workflow-tools.js +25 -0
- package/dist/build-id +1 -0
- package/dist/cli/application.js +397 -0
- package/dist/cli/bootstrap.js +535 -0
- package/dist/cli/host-control.js +100 -0
- package/dist/cli/install-guard.js +270 -0
- package/dist/cli/install-process.js +52 -0
- package/dist/cli/main.js +12 -0
- package/dist/cli/update.js +128 -0
- package/dist/client/connection.js +183 -0
- package/dist/client/context-usage.js +66 -0
- package/dist/client/diff.js +36 -0
- package/dist/client/enquiry.js +105 -0
- package/dist/client/markdown.js +192 -0
- package/dist/client/model-choices.js +32 -0
- package/dist/client/permission.js +60 -0
- package/dist/client/project-name.js +19 -0
- package/dist/client/reduce.js +463 -0
- package/dist/client/relative-time.js +30 -0
- package/dist/client/scope-kind.js +28 -0
- package/dist/client/search.js +136 -0
- package/dist/client/session-label.js +9 -0
- package/dist/client/status.js +84 -0
- package/dist/client/tool-chains.js +52 -0
- package/dist/client/tool-summary.js +98 -0
- package/dist/daemon/auth.js +590 -0
- package/dist/daemon/config-store.js +183 -0
- package/dist/daemon/config.js +687 -0
- package/dist/daemon/credential-redaction.js +9 -0
- package/dist/daemon/git.js +312 -0
- package/dist/daemon/host-control-routes.js +29 -0
- package/dist/daemon/host.js +2343 -0
- package/dist/daemon/http.js +19 -0
- package/dist/daemon/log.js +44 -0
- package/dist/daemon/mcp-auth.js +164 -0
- package/dist/daemon/models.js +85 -0
- package/dist/daemon/ownership.js +104 -0
- package/dist/daemon/projects.js +317 -0
- package/dist/daemon/publish.js +289 -0
- package/dist/daemon/pull-request.js +198 -0
- package/dist/daemon/runtime.js +100 -0
- package/dist/daemon/secret-store.js +65 -0
- package/dist/daemon/server.js +827 -0
- package/dist/daemon/shell.js +220 -0
- package/dist/daemon/skills.js +104 -0
- package/dist/daemon/stack-metadata.js +24 -0
- package/dist/daemon/stack.js +743 -0
- package/dist/daemon/store.js +130 -0
- package/dist/daemon/summariser.js +476 -0
- package/dist/daemon/workflow-execution-routes.js +105 -0
- package/dist/daemon/workflow-executions.js +1018 -0
- package/dist/daemon/workflow-mcp.js +20 -0
- package/dist/daemon/workflow-routes.js +102 -0
- package/dist/protocol/attachments.js +59 -0
- package/dist/protocol/commands.js +1 -0
- package/dist/protocol/events.js +20 -0
- package/dist/protocol/fonts.js +26 -0
- package/dist/protocol/git.js +12 -0
- package/dist/protocol/mcp.js +51 -0
- package/dist/protocol/projects.js +21 -0
- package/dist/protocol/publish.js +1 -0
- package/dist/protocol/pull-request.js +1 -0
- package/dist/protocol/secrets.js +4 -0
- package/dist/protocol/settings.js +63 -0
- package/dist/protocol/shells.js +8 -0
- package/dist/protocol/skills.js +16 -0
- package/dist/protocol/stack.js +41 -0
- package/dist/protocol/workflow-executions.js +1 -0
- package/dist/protocol/workflows.js +1 -0
- package/dist/tui/app.js +518 -0
- package/dist/tui/keys.js +54 -0
- package/dist/tui/render.js +366 -0
- package/dist/web/assets.js +10 -0
- package/dist/web/embedded.js +12 -0
- package/dist/web/manifest.js +70 -0
- package/dist/workflows/decisions.js +65 -0
- package/dist/workflows/executors.js +132 -0
- package/dist/workflows/graph.js +276 -0
- package/dist/workflows/json-schema.js +49 -0
- package/dist/workflows/loops.js +102 -0
- package/dist/workflows/mcp.js +18 -0
- package/dist/workflows/records.js +111 -0
- package/dist/workflows/recovery.js +25 -0
- package/dist/workflows/runtime-asset.js +17 -0
- package/dist/workflows/runtime-libs.js +1 -0
- package/dist/workflows/runtime-settings.js +23 -0
- package/dist/workflows/runtime.js +343 -0
- package/dist/workflows/scheduler.js +573 -0
- package/dist/workflows/schema.js +161 -0
- package/dist/workflows/store.js +93 -0
- package/package.json +87 -0
- package/web/dist/assets/__vite-browser-external-2447137e-BvRk9kiK.js +0 -0
- package/web/dist/assets/ghostty-vt-DOMeXDrv.wasm +0 -0
- package/web/dist/assets/index-BC0gLS53.js +106 -0
- package/web/dist/assets/index-CCeZYKES.css +2 -0
- package/web/dist/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/web/dist/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/web/dist/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/web/dist/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/web/dist/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/web/dist/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/web/dist/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/web/dist/assets/rolldown-runtime-B0Z9INg1.js +1 -0
- package/web/dist/assets/select-6i3wxovH.js +1 -0
- package/web/dist/assets/settings-mcp-CcT0ADJR.js +1 -0
- package/web/dist/assets/settings-secrets-CK4uF7fd.js +1 -0
- package/web/dist/assets/settings-workflows-CrbZF-nM.js +23 -0
- package/web/dist/assets/switch-ftZleVB8.js +6 -0
- package/web/dist/assets/workflow-editors-naPqAmYO.js +65 -0
- package/web/dist/assets/workflows-D4T4Gy_7.css +1 -0
- package/web/dist/assets/workflows-hh6ioeEA.js +7 -0
- package/web/dist/assets/workflows-pane-Db-MHf7Z.js +1 -0
- package/web/dist/index.html +31 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { applyPatch, formatDuration, loadConfig, } from "./config.js";
|
|
4
|
+
import { DEFAULT_WORKFLOW_RUNTIME } from "../protocol/settings.js";
|
|
5
|
+
import { expandHome } from "./projects.js";
|
|
6
|
+
import { defaultStateRoot } from "./store.js";
|
|
7
|
+
/**
|
|
8
|
+
* The one owner of `<stateRoot>/config.json`.
|
|
9
|
+
*
|
|
10
|
+
* Everything that needs a setting reads *through* this rather than being handed a copy at startup.
|
|
11
|
+
* That is the whole point: the reaper asks for the retention window at each sweep and the HTTP
|
|
12
|
+
* surface asks for the Settings on each request, so an edit takes effect without restarting the
|
|
13
|
+
* daemon — and there is no second copy to go stale. Shaped after TranscriptStore, its neighbour:
|
|
14
|
+
* a root in the constructor, synchronous fs, no cleverness.
|
|
15
|
+
*
|
|
16
|
+
* Reading is lenient and writing is strict, and the asymmetry is deliberate — see `applyPatch` in
|
|
17
|
+
* ./config.ts for why.
|
|
18
|
+
*/
|
|
19
|
+
export class ConfigStore {
|
|
20
|
+
path;
|
|
21
|
+
root;
|
|
22
|
+
config;
|
|
23
|
+
/** Why part of the file on disk was ignored, for the daemon to print on the way up. */
|
|
24
|
+
warning;
|
|
25
|
+
constructor(root = defaultStateRoot()) {
|
|
26
|
+
this.root = root;
|
|
27
|
+
this.path = join(root, "config.json");
|
|
28
|
+
const loaded = loadConfig(root);
|
|
29
|
+
this.config = loaded.config;
|
|
30
|
+
this.warning = loaded.warning;
|
|
31
|
+
}
|
|
32
|
+
/** The current Config, in the file's own units. Cheap: held in memory, not re-read. */
|
|
33
|
+
current() {
|
|
34
|
+
return this.config;
|
|
35
|
+
}
|
|
36
|
+
/** The current Settings, in the wire's units — a duration a person can read and edit. */
|
|
37
|
+
view() {
|
|
38
|
+
return settingsOf(this.config);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* How long a Settled Agent Session survives, asked fresh. This is what the SessionHost is given.
|
|
42
|
+
*
|
|
43
|
+
* A bound method rather than the store itself, so `SessionHost` needs to know nothing about
|
|
44
|
+
* config.json — it owns Agent Sessions, and a file full of typefaces is not its business.
|
|
45
|
+
*/
|
|
46
|
+
retention = () => this.config.retention.settled;
|
|
47
|
+
/**
|
|
48
|
+
* The Project Root as an absolute path, asked fresh, or undefined when none is configured.
|
|
49
|
+
*
|
|
50
|
+
* The expanded counterpart to `view().projects.root`, which reports the string as typed. Both are
|
|
51
|
+
* needed and they are not interchangeable: the Settings page has to read back the `~` its reader
|
|
52
|
+
* wrote, and the walk has to be given a path the filesystem understands. Retention makes exactly
|
|
53
|
+
* the same split for the same reason — milliseconds for the reaper, `"1d"` for the person.
|
|
54
|
+
*/
|
|
55
|
+
projectRoot = () => {
|
|
56
|
+
const root = this.config.projects?.root;
|
|
57
|
+
return root === undefined ? undefined : expandHome(root);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The Project Root exactly as it was written, unexpanded, for resolving `include` entries against.
|
|
61
|
+
*
|
|
62
|
+
* Separate from `projectRoot()` because the resolver in ./projects.ts expands as it goes and
|
|
63
|
+
* handing it an already-expanded root would be harmless but would put the same rule in two
|
|
64
|
+
* places.
|
|
65
|
+
*/
|
|
66
|
+
rawProjectRoot = () => this.config.projects?.root;
|
|
67
|
+
/** The opted-in Projects, as configured. Empty when none — see `Projects.include`. */
|
|
68
|
+
projectInclude = () => this.config.projects?.include ?? [];
|
|
69
|
+
/**
|
|
70
|
+
* The Standing Authorisations, asked fresh. Empty when none has been granted.
|
|
71
|
+
*
|
|
72
|
+
* Read at Backend Session create time rather than watched, which is why this is a getter and not a
|
|
73
|
+
* subscription: ADR 0009 rejected the observer shape, and a grant made in one Agent Session
|
|
74
|
+
* reaching every other live one would be exactly that. A session that has not asked does not care,
|
|
75
|
+
* and one that asks again after a grant elsewhere prompts once more and then picks the list up on
|
|
76
|
+
* its next Revive.
|
|
77
|
+
*/
|
|
78
|
+
standingAuthorisations = () => this.config.permissions?.allow ?? [];
|
|
79
|
+
mcpConnections = () => structuredClone(this.config.mcp ?? []);
|
|
80
|
+
/**
|
|
81
|
+
* The Default Model for one Backend Adapter, asked fresh, or undefined when none is configured.
|
|
82
|
+
*
|
|
83
|
+
* Read once when an Agent Session is created and never again — see `SessionHost.create`. A bound
|
|
84
|
+
* method rather than the store itself, for the reason `retention` is one.
|
|
85
|
+
*/
|
|
86
|
+
defaultModel = (backend) => this.config.providers?.defaults?.[backend];
|
|
87
|
+
autoCompaction = (backend) => structuredClone(this.config.providers?.autoCompaction?.[backend] ?? {});
|
|
88
|
+
defaultBackend = () => this.config.providers?.defaultBackend;
|
|
89
|
+
/** The Summary Model, asked fresh. Undefined means no Agent Session is named by a model. */
|
|
90
|
+
summaryModel = (backend) => {
|
|
91
|
+
const providers = this.config.providers;
|
|
92
|
+
if (backend === undefined)
|
|
93
|
+
return providers?.summary;
|
|
94
|
+
const summary = providers?.summaries?.[backend];
|
|
95
|
+
if (summary)
|
|
96
|
+
return { backend, ...summary };
|
|
97
|
+
return providers?.summary?.backend === backend ? providers.summary : undefined;
|
|
98
|
+
};
|
|
99
|
+
defaultEffort = (backend) => this.config.providers?.efforts?.[backend];
|
|
100
|
+
/**
|
|
101
|
+
* Grant a Standing Authorisation for one tool — what an Always decision leaves behind.
|
|
102
|
+
*
|
|
103
|
+
* Additive, and the one write on this store that is: `update` replaces the list wholesale, which is
|
|
104
|
+
* right for a client sending the list it wants but wrong for a single click, where two sessions
|
|
105
|
+
* granting different tools at once would each erase the other's. Idempotent, so a second click on
|
|
106
|
+
* a tool already granted writes nothing.
|
|
107
|
+
*
|
|
108
|
+
* A bound method rather than the store itself, for the reason `retention` is one: `SessionHost`
|
|
109
|
+
* owns Agent Sessions, and it must not become the owner of config.json to do this.
|
|
110
|
+
*/
|
|
111
|
+
allowTool = (name) => {
|
|
112
|
+
const granted = this.standingAuthorisations();
|
|
113
|
+
if (granted.includes(name))
|
|
114
|
+
return;
|
|
115
|
+
this.update({ permissions: { allow: [...granted, name] } });
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Merge a patch in, write it out, and report the result. Throws ConfigError on anything unusable,
|
|
119
|
+
* having changed nothing.
|
|
120
|
+
*
|
|
121
|
+
* Read-modify-write against the file rather than against `this.config`, so a key no version of
|
|
122
|
+
* this daemon has heard of survives being edited around. Someone who hand-wrote a field we do not
|
|
123
|
+
* parse yet should not lose it because they later changed a font in a browser.
|
|
124
|
+
*/
|
|
125
|
+
update(patch) {
|
|
126
|
+
const next = applyPatch(this.config, patch);
|
|
127
|
+
const document = { ...this.readRaw(), ...settingsOf(next) };
|
|
128
|
+
// A section that is now *absent* has to be deleted, not merely left unwritten. The merge above
|
|
129
|
+
// preserves whatever the file already holds — which is what keeps a hand-written key this
|
|
130
|
+
// daemon has never heard of alive, and would otherwise keep a Project Root that the patch just
|
|
131
|
+
// cleared. Both optional sections can be cleared, so both are deleted when absent — and for
|
|
132
|
+
// `permissions` that is not tidiness: a section left behind would keep a Standing Authorisation
|
|
133
|
+
// the human had just revoked.
|
|
134
|
+
if (next.projects === undefined)
|
|
135
|
+
delete document["projects"];
|
|
136
|
+
if (next.permissions === undefined)
|
|
137
|
+
delete document["permissions"];
|
|
138
|
+
if (next.providers === undefined)
|
|
139
|
+
delete document["providers"];
|
|
140
|
+
mkdirSync(this.root, { recursive: true });
|
|
141
|
+
// Written beside the target and renamed over it: a crash mid-write leaves the old config intact
|
|
142
|
+
// rather than a truncated one, and `loadConfig` treats a truncated file as "use the defaults" —
|
|
143
|
+
// which would silently reset every setting on the next start.
|
|
144
|
+
const scratch = `${this.path}.${process.pid}.tmp`;
|
|
145
|
+
writeFileSync(scratch, `${JSON.stringify(document, null, 2)}\n`);
|
|
146
|
+
renameSync(scratch, this.path);
|
|
147
|
+
this.config = next;
|
|
148
|
+
return this.view();
|
|
149
|
+
}
|
|
150
|
+
/** The file as it stands, verbatim. An unreadable or non-object file contributes nothing. */
|
|
151
|
+
readRaw() {
|
|
152
|
+
try {
|
|
153
|
+
const parsed = JSON.parse(readFileSync(this.path, "utf8"));
|
|
154
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
155
|
+
return {};
|
|
156
|
+
return parsed;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A Config as Settings: durations back in the form they were written in.
|
|
165
|
+
*
|
|
166
|
+
* One function for both the wire and the file, because they *are* the same shape — the file is the
|
|
167
|
+
* thing a person edits and the wire carries what they typed. Two functions here would be two chances
|
|
168
|
+
* for `/api/config` to report a value the file does not hold.
|
|
169
|
+
*/
|
|
170
|
+
function settingsOf(config) {
|
|
171
|
+
const { settled } = config.retention;
|
|
172
|
+
return {
|
|
173
|
+
retention: { settled: settled === "never" ? "never" : formatDuration(settled) },
|
|
174
|
+
fonts: config.fonts,
|
|
175
|
+
mcp: config.mcp ?? [],
|
|
176
|
+
workflowRuntime: { ...DEFAULT_WORKFLOW_RUNTIME, ...config.workflowRuntime },
|
|
177
|
+
// Omitted rather than defaulted when there is no Project Root, which is what
|
|
178
|
+
// `Settings["projects"]` being optional means — see src/protocol/settings.ts.
|
|
179
|
+
...(config.projects === undefined ? {} : { projects: config.projects }),
|
|
180
|
+
...(config.permissions === undefined ? {} : { permissions: config.permissions }),
|
|
181
|
+
...(config.providers === undefined ? {} : { providers: config.providers }),
|
|
182
|
+
};
|
|
183
|
+
}
|