@nathanstephenson/flow 0.1.0 → 0.1.2
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 +10 -2
- package/dist/backend/fake/index.js +3 -1
- package/dist/backend/pi/effort-capabilities.js +12 -0
- package/dist/backend/pi/index.js +25 -36
- package/dist/backend/pi/workflow-subagent.js +8 -3
- package/dist/build-id +1 -1
- package/dist/cli/application.js +9 -1
- package/dist/cli/bootstrap.js +424 -37
- package/dist/cli/host-control.js +2 -2
- package/dist/cli/install-guard.js +57 -11
- package/dist/cli/systemd-update.js +129 -0
- package/dist/cli/update.js +64 -17
- package/dist/cli/web-update.js +376 -0
- package/dist/client/model-choices.js +22 -4
- package/dist/client/reduce.js +18 -6
- package/dist/client/status.js +34 -20
- package/dist/client/workflow-effort.js +30 -0
- package/dist/daemon/credential-redaction.js +97 -4
- package/dist/daemon/host-control-routes.js +18 -2
- package/dist/daemon/host.js +341 -74
- package/dist/daemon/release-checker.js +104 -0
- package/dist/daemon/runtime.js +12 -4
- package/dist/daemon/server.js +98 -15
- package/dist/daemon/summariser.js +81 -15
- package/dist/daemon/update-api.js +3 -0
- package/dist/daemon/workflow-executions.js +146 -15
- package/dist/protocol/update.js +1 -0
- package/dist/tui/app.js +104 -10
- package/dist/tui/keys.js +46 -10
- package/dist/tui/render.js +58 -13
- package/dist/workflows/records.js +3 -1
- package/dist/workflows/scheduler.js +15 -1
- package/package.json +1 -1
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/index-BlZBshi8.js +170 -0
- package/web/dist/assets/index-DWF4-3Fh.css +2 -0
- package/web/dist/assets/{settings-mcp-CcT0ADJR.js → settings-mcp-ZMIfuuZU.js} +1 -1
- package/web/dist/assets/{settings-secrets-CK4uF7fd.js → settings-secrets-CgTrBpi2.js} +1 -1
- package/web/dist/assets/settings-workflows-1DMYfZtn.js +23 -0
- package/web/dist/assets/{workflows-D4T4Gy_7.css → workflows-9aO6cptD.css} +1 -1
- package/web/dist/assets/workflows-CBuB_bva.js +7 -0
- package/web/dist/assets/workflows-pane-DPXGg0na.js +1 -0
- package/web/dist/favicon-16x16.png +0 -0
- package/web/dist/favicon-32x32.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +8 -3
- package/web/dist/safari-pinned-tab.svg +4 -0
- package/web/dist/assets/index-BC0gLS53.js +0 -106
- package/web/dist/assets/index-CCeZYKES.css +0 -2
- package/web/dist/assets/settings-workflows-CrbZF-nM.js +0 -23
- package/web/dist/assets/workflow-editors-naPqAmYO.js +0 -65
- package/web/dist/assets/workflows-hh6ioeEA.js +0 -7
- package/web/dist/assets/workflows-pane-Db-MHf7Z.js +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const packageName = '@nathanstephenson/flow';
|
|
2
|
+
const STABLE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
3
|
+
const SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
4
|
+
function parsed(version) {
|
|
5
|
+
const match = SEMVER.exec(version);
|
|
6
|
+
if (!match)
|
|
7
|
+
return undefined;
|
|
8
|
+
return {
|
|
9
|
+
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
10
|
+
prerelease: match[4]?.split('.') ?? [],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function compareIdentifiers(left, right) {
|
|
14
|
+
const leftNumber = /^\d+$/.test(left) ? Number(left) : undefined;
|
|
15
|
+
const rightNumber = /^\d+$/.test(right) ? Number(right) : undefined;
|
|
16
|
+
if (leftNumber !== undefined && rightNumber !== undefined)
|
|
17
|
+
return Math.sign(leftNumber - rightNumber);
|
|
18
|
+
if (leftNumber !== undefined)
|
|
19
|
+
return -1;
|
|
20
|
+
if (rightNumber !== undefined)
|
|
21
|
+
return 1;
|
|
22
|
+
return left.localeCompare(right);
|
|
23
|
+
}
|
|
24
|
+
export function compareVersions(left, right) {
|
|
25
|
+
const a = parsed(left), b = parsed(right);
|
|
26
|
+
if (!a || !b)
|
|
27
|
+
throw new Error('Invalid semantic version');
|
|
28
|
+
for (let index = 0; index < 3; index += 1) {
|
|
29
|
+
const difference = a.core[index] - b.core[index];
|
|
30
|
+
if (difference)
|
|
31
|
+
return Math.sign(difference);
|
|
32
|
+
}
|
|
33
|
+
if (!a.prerelease.length && !b.prerelease.length)
|
|
34
|
+
return 0;
|
|
35
|
+
if (!a.prerelease.length)
|
|
36
|
+
return 1;
|
|
37
|
+
if (!b.prerelease.length)
|
|
38
|
+
return -1;
|
|
39
|
+
for (let index = 0; index < Math.max(a.prerelease.length, b.prerelease.length); index += 1) {
|
|
40
|
+
const av = a.prerelease[index], bv = b.prerelease[index];
|
|
41
|
+
if (av === undefined)
|
|
42
|
+
return -1;
|
|
43
|
+
if (bv === undefined)
|
|
44
|
+
return 1;
|
|
45
|
+
const difference = compareIdentifiers(av, bv);
|
|
46
|
+
if (difference)
|
|
47
|
+
return difference;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
/** `latest` must itself be stable, and must advance rather than select a channel or downgrade. */
|
|
52
|
+
export function newerStableVersion(installed, latest) {
|
|
53
|
+
return STABLE.test(latest) && compareVersions(latest, installed) > 0;
|
|
54
|
+
}
|
|
55
|
+
export class ReleaseChecker {
|
|
56
|
+
cached;
|
|
57
|
+
inFlight;
|
|
58
|
+
options;
|
|
59
|
+
constructor(options = {}) { this.options = options; }
|
|
60
|
+
check(refresh = false) {
|
|
61
|
+
const now = (this.options.now ?? Date.now)();
|
|
62
|
+
const cacheMs = this.options.cacheMs ?? 15 * 60 * 1000;
|
|
63
|
+
if (!refresh && this.cached && now - this.cached.at < cacheMs)
|
|
64
|
+
return Promise.resolve(this.cached.result);
|
|
65
|
+
if (this.inFlight)
|
|
66
|
+
return this.inFlight;
|
|
67
|
+
this.inFlight = this.fetchLatest().then(result => {
|
|
68
|
+
this.cached = { at: (this.options.now ?? Date.now)(), result };
|
|
69
|
+
return result;
|
|
70
|
+
}).finally(() => { this.inFlight = undefined; });
|
|
71
|
+
return this.inFlight;
|
|
72
|
+
}
|
|
73
|
+
async fetchLatest() {
|
|
74
|
+
const checkedAt = new Date((this.options.now ?? Date.now)()).toISOString();
|
|
75
|
+
try {
|
|
76
|
+
const response = await (this.options.fetch ?? fetch)(this.options.registryUrl ?? `https://registry.npmjs.org/${packageName.replace('/', '%2F')}/latest`, {
|
|
77
|
+
headers: { accept: 'application/json' },
|
|
78
|
+
signal: AbortSignal.timeout(this.options.timeoutMs ?? 5000),
|
|
79
|
+
});
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw new Error(`npm registry answered ${response.status}`);
|
|
82
|
+
const length = Number(response.headers.get('content-length'));
|
|
83
|
+
if (Number.isFinite(length) && length > 64 * 1024)
|
|
84
|
+
throw new Error('npm registry response was too large');
|
|
85
|
+
const text = await response.text();
|
|
86
|
+
if (Buffer.byteLength(text) > 64 * 1024)
|
|
87
|
+
throw new Error('npm registry response was too large');
|
|
88
|
+
const body = JSON.parse(text);
|
|
89
|
+
const latestVersion = body && typeof body === 'object' && 'version' in body
|
|
90
|
+
? body.version
|
|
91
|
+
: undefined;
|
|
92
|
+
if (typeof latestVersion !== 'string' || !STABLE.test(latestVersion)) {
|
|
93
|
+
throw new Error('npm latest tag is not a stable semantic version');
|
|
94
|
+
}
|
|
95
|
+
return { checkedAt, latestVersion };
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
const message = error instanceof Error && error.name === 'TimeoutError'
|
|
99
|
+
? 'The npm registry check timed out. Try again.'
|
|
100
|
+
: `Could not check the npm registry: ${error instanceof Error ? error.message : String(error)}`;
|
|
101
|
+
return { checkedAt, error: message };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
package/dist/daemon/runtime.js
CHANGED
|
@@ -10,6 +10,7 @@ import { serve } from "./server.js";
|
|
|
10
10
|
import { ShellRegistry } from "./shell.js";
|
|
11
11
|
import { TranscriptStore } from "./store.js";
|
|
12
12
|
import { acquireHost, readHost, oidcFingerprint } from "./ownership.js";
|
|
13
|
+
import { WebUpdateController } from "../cli/web-update.js";
|
|
13
14
|
export async function startRuntime(options) {
|
|
14
15
|
const ownership = acquireHost(options.root);
|
|
15
16
|
const root = ownership.root;
|
|
@@ -77,11 +78,18 @@ export async function startRuntime(options) {
|
|
|
77
78
|
instanceId: ownership.instanceId, pid: process.pid, version: options.version, url: '', token, mode: options.mode,
|
|
78
79
|
settings: { port: options.port ?? 0, address: options.address ?? '127.0.0.1', cwd: process.cwd(), oidc: oidcFingerprint() },
|
|
79
80
|
};
|
|
81
|
+
const hasActiveWork = () => host.hasActiveWork() || shells.hasLiveShells() || host.list().some(session => workflowExecutions.list(session.id).occupied);
|
|
82
|
+
const updates = new WebUpdateController({
|
|
83
|
+
root,
|
|
84
|
+
installedVersion: options.version,
|
|
85
|
+
mode: options.mode,
|
|
86
|
+
hasActiveWork,
|
|
87
|
+
...(options.updateInstallation === undefined ? {} : options.updateInstallation),
|
|
88
|
+
...(options.updateUnsupportedReason === undefined ? {} : { unsupportedReason: options.updateUnsupportedReason }),
|
|
89
|
+
});
|
|
80
90
|
running = await serve({
|
|
81
|
-
control: {
|
|
82
|
-
|
|
83
|
-
hasActiveWork: () => host.hasActiveWork() || shells.hasLiveShells() || host.list().some(session => workflowExecutions.list(session.id).occupied),
|
|
84
|
-
},
|
|
91
|
+
control: { identity, stop, hasActiveWork },
|
|
92
|
+
updates,
|
|
85
93
|
host, token, shells, config, mcpAuth, store, workflows, secrets, workflowExecutions,
|
|
86
94
|
assets: options.assets(), scope: process.cwd(),
|
|
87
95
|
...(oidc === undefined ? {} : { oidc }),
|
package/dist/daemon/server.js
CHANGED
|
@@ -9,9 +9,26 @@ import { discoverProjects, includedProjects, searchDirectories } from "./project
|
|
|
9
9
|
import { gitAvailable, head, isRepository, localBranches, MAX_BRANCHES } from "./git.js";
|
|
10
10
|
import { tokenMatches } from "./auth.js";
|
|
11
11
|
import { CommandRefused } from "./host.js";
|
|
12
|
+
import { UpdateRefusal } from "./update-api.js";
|
|
13
|
+
const PUBLIC_ICON_PATHS = new Set([
|
|
14
|
+
"/favicon.svg",
|
|
15
|
+
"/favicon-16x16.png",
|
|
16
|
+
"/favicon-32x32.png",
|
|
17
|
+
"/favicon.ico",
|
|
18
|
+
"/safari-pinned-tab.svg",
|
|
19
|
+
"/apple-touch-icon.png",
|
|
20
|
+
]);
|
|
21
|
+
const PUBLIC_ICON_CACHE = "public, max-age=3600, must-revalidate";
|
|
22
|
+
const ICON_LINKS = `<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
23
|
+
<link rel="icon" href="/favicon-32x32.png" type="image/png" sizes="32x32">
|
|
24
|
+
<link rel="icon" href="/favicon-16x16.png" type="image/png" sizes="16x16">
|
|
25
|
+
<link rel="icon" href="/favicon.ico" type="image/x-icon" sizes="16x16 32x32 48x48">
|
|
26
|
+
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5f6368">
|
|
27
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" sizes="180x180">`;
|
|
12
28
|
export async function serve(options) {
|
|
13
29
|
const address = options.address ?? "127.0.0.1";
|
|
14
30
|
let stopping = false;
|
|
31
|
+
let quiesced = false;
|
|
15
32
|
const pending = new Set();
|
|
16
33
|
const sockets = new Set();
|
|
17
34
|
const track = (work) => { pending.add(work); void work.finally(() => pending.delete(work)); };
|
|
@@ -34,7 +51,19 @@ export async function serve(options) {
|
|
|
34
51
|
return;
|
|
35
52
|
}
|
|
36
53
|
void hostControlRoute(request, response, path, options.control, {
|
|
37
|
-
isStopping: () => stopping, hasPending: () => pending.size > 0,
|
|
54
|
+
isStopping: () => stopping, hasPending: () => pending.size > 0,
|
|
55
|
+
stop: () => { stopping = true; quiesced = false; },
|
|
56
|
+
quiesce: () => { if (!stopping) {
|
|
57
|
+
stopping = true;
|
|
58
|
+
quiesced = true;
|
|
59
|
+
} },
|
|
60
|
+
resume: () => {
|
|
61
|
+
if (!quiesced)
|
|
62
|
+
return false;
|
|
63
|
+
stopping = false;
|
|
64
|
+
quiesced = false;
|
|
65
|
+
return true;
|
|
66
|
+
},
|
|
38
67
|
});
|
|
39
68
|
return;
|
|
40
69
|
}
|
|
@@ -69,6 +98,7 @@ export async function serve(options) {
|
|
|
69
98
|
...(options.oidc === undefined ? {} : { oidc: options.oidc }),
|
|
70
99
|
stopAdmission: async (interrupt, timeoutMs = 10000) => {
|
|
71
100
|
stopping = true;
|
|
101
|
+
quiesced = false;
|
|
72
102
|
for (const socket of sockets)
|
|
73
103
|
socket.destroy();
|
|
74
104
|
let timer;
|
|
@@ -83,6 +113,8 @@ export async function serve(options) {
|
|
|
83
113
|
}
|
|
84
114
|
},
|
|
85
115
|
close: () => {
|
|
116
|
+
stopping = true;
|
|
117
|
+
quiesced = false;
|
|
86
118
|
for (const socket of sockets)
|
|
87
119
|
socket.destroy();
|
|
88
120
|
options.mcpAuth?.dispose();
|
|
@@ -93,13 +125,33 @@ export async function serve(options) {
|
|
|
93
125
|
}
|
|
94
126
|
async function handle(request, response, options) {
|
|
95
127
|
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
128
|
+
// Browser chrome asks for icons before there is a browser session. Keep that exception exact: the
|
|
129
|
+
// six root paths below are public for GET/HEAD only, while every other asset remains behind the
|
|
130
|
+
// same authentication gate as the app. A missing icon is a real 404, never the SPA Entry Document.
|
|
131
|
+
if ((request.method === "GET" || request.method === "HEAD") && PUBLIC_ICON_PATHS.has(url.pathname)) {
|
|
132
|
+
const icon = options.assets[url.pathname];
|
|
133
|
+
if (!icon) {
|
|
134
|
+
send(response, 404, { error: "Not found" });
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
sendAsset(response, icon, request.method === "HEAD", PUBLIC_ICON_CACHE);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
96
140
|
if (request.method === "GET" && url.pathname === "/api/mcp/callback") {
|
|
97
141
|
try {
|
|
98
142
|
if (!options.mcpAuth)
|
|
99
143
|
throw new Error("MCP auth unavailable");
|
|
100
144
|
const location = await options.mcpAuth.callback(url);
|
|
101
|
-
|
|
102
|
-
|
|
145
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Return to Flow</title>
|
|
146
|
+
${ICON_LINKS}</head><body><script>window.location.replace(${JSON.stringify(location).replace(/</g, "\\u003c")})</script></body></html>`;
|
|
147
|
+
response.writeHead(200, {
|
|
148
|
+
"content-type": "text/html; charset=utf-8",
|
|
149
|
+
"content-length": Buffer.byteLength(html),
|
|
150
|
+
"cache-control": "no-store",
|
|
151
|
+
"referrer-policy": "no-referrer",
|
|
152
|
+
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; img-src 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
153
|
+
});
|
|
154
|
+
response.end(html);
|
|
103
155
|
}
|
|
104
156
|
catch {
|
|
105
157
|
send(response, 400, { error: "Invalid or expired MCP sign-in. Return to Flow and try again." });
|
|
@@ -193,6 +245,38 @@ async function handle(request, response, options) {
|
|
|
193
245
|
}
|
|
194
246
|
return;
|
|
195
247
|
}
|
|
248
|
+
if (url.pathname === '/api/update') {
|
|
249
|
+
response.setHeader('cache-control', 'no-store');
|
|
250
|
+
if (!options.updates) {
|
|
251
|
+
send(response, 404, { error: 'Update status is unavailable' });
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (request.method === 'GET') {
|
|
255
|
+
send(response, 200, await options.updates.status(url.searchParams.get('refresh') === '1'));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (request.method === 'POST') {
|
|
259
|
+
try {
|
|
260
|
+
const body = JSON.parse(await readBody(request, 1024));
|
|
261
|
+
const confirmation = body;
|
|
262
|
+
if (!body || typeof body !== 'object' || Array.isArray(body) || confirmation.confirmed !== true ||
|
|
263
|
+
typeof confirmation.version !== 'string' || confirmation.version.length > 100 ||
|
|
264
|
+
Object.keys(body).some(key => key !== 'confirmed' && key !== 'version')) {
|
|
265
|
+
send(response, 400, { error: 'An explicit update confirmation for the displayed version is required' });
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
send(response, 202, await options.updates.start(confirmation.version));
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
if (!(error instanceof UpdateRefusal))
|
|
272
|
+
throw error;
|
|
273
|
+
send(response, 409, { error: error.message });
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
send(response, 405, { error: 'Method not allowed' });
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
196
280
|
if (options.oidc && request.method === "POST" && url.pathname === "/oauth/logout") {
|
|
197
281
|
options.oidc.logout(request.headers.cookie);
|
|
198
282
|
response.writeHead(303, {
|
|
@@ -664,18 +748,17 @@ function refuse(socket, status) {
|
|
|
664
748
|
socket.write(`HTTP/1.1 ${status} ${text}\r\nConnection: close\r\n\r\n`);
|
|
665
749
|
socket.destroy();
|
|
666
750
|
}
|
|
667
|
-
function sendAsset(response, asset) {
|
|
751
|
+
function sendAsset(response, asset, headOnly = false, cacheControl = asset.immutable ? "public, max-age=31536000, immutable" : "no-store") {
|
|
668
752
|
const body = Buffer.from(asset.body, asset.encoding);
|
|
669
753
|
response.writeHead(200, {
|
|
670
754
|
"content-type": asset.type,
|
|
671
755
|
"content-length": body.byteLength,
|
|
672
|
-
//
|
|
673
|
-
//
|
|
674
|
-
//
|
|
675
|
-
|
|
676
|
-
"cache-control": asset.immutable ? "public, max-age=31536000, immutable" : "no-store",
|
|
756
|
+
// Hashed assets are immutable. Public icons keep a short revalidation window instead: their
|
|
757
|
+
// stable browser-known paths cannot carry Vite hashes, so a deployment must be able to replace
|
|
758
|
+
// them without leaving old browser chrome cached indefinitely.
|
|
759
|
+
"cache-control": cacheControl,
|
|
677
760
|
});
|
|
678
|
-
response.end(body);
|
|
761
|
+
response.end(headOnly ? undefined : body);
|
|
679
762
|
}
|
|
680
763
|
/**
|
|
681
764
|
* One Attachment's bytes.
|
|
@@ -752,15 +835,15 @@ function documentNavigation(request, pathname) {
|
|
|
752
835
|
return destination === "document" || accept?.includes("text/html") === true || pathname === "/";
|
|
753
836
|
}
|
|
754
837
|
function sendLoginRedirectPage(response) {
|
|
755
|
-
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Signing in · Flow</title
|
|
756
|
-
|
|
838
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Signing in · Flow</title>
|
|
839
|
+
${ICON_LINKS}</head><body><script>location.replace("/oauth/login?return_to="+encodeURIComponent(location.pathname+location.search+location.hash))</script>
|
|
757
840
|
<noscript><a href="/oauth/login">Sign in</a></noscript></body></html>`;
|
|
758
841
|
response.writeHead(200, {
|
|
759
842
|
"content-type": "text/html; charset=utf-8",
|
|
760
843
|
"content-length": Buffer.byteLength(html),
|
|
761
844
|
"cache-control": "no-store",
|
|
762
845
|
"referrer-policy": "no-referrer",
|
|
763
|
-
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
846
|
+
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
764
847
|
});
|
|
765
848
|
response.end(html);
|
|
766
849
|
}
|
|
@@ -778,7 +861,7 @@ function unauthorized(response, login) {
|
|
|
778
861
|
function sendAuthPage(response, status, title, detail, action) {
|
|
779
862
|
const html = `<!doctype html>
|
|
780
863
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
781
|
-
<title>${title} · Flow</title
|
|
864
|
+
<title>${title} · Flow</title>${ICON_LINKS}<style>
|
|
782
865
|
:root{color-scheme:light dark;font-family:Inter,ui-sans-serif,system-ui,sans-serif;background:#f6f6f4;color:#181817}
|
|
783
866
|
*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px;background:radial-gradient(circle at 50% 0,#fff 0,#f6f6f4 52%)}
|
|
784
867
|
main{width:min(100%,430px);border:1px solid #deded9;border-radius:18px;background:rgba(255,255,255,.9);padding:30px;box-shadow:0 18px 55px rgba(28,28,24,.08)}
|
|
@@ -791,7 +874,7 @@ a{display:inline-flex;align-items:center;justify-content:center;width:100%;heigh
|
|
|
791
874
|
"content-length": Buffer.byteLength(html),
|
|
792
875
|
"cache-control": "no-store",
|
|
793
876
|
"referrer-policy": "no-referrer",
|
|
794
|
-
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
877
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
795
878
|
});
|
|
796
879
|
response.end(html);
|
|
797
880
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tmpdir } from "node:os";
|
|
2
|
-
import {
|
|
2
|
+
import { credentialJsonSerializer } from "./credential-redaction.js";
|
|
3
3
|
/**
|
|
4
4
|
* Naming an Agent Session with the Summary Model (ADR 0020).
|
|
5
5
|
*
|
|
@@ -118,21 +118,37 @@ ${text}`;
|
|
|
118
118
|
/**
|
|
119
119
|
* Naming context for a workflow-launched Agent Session.
|
|
120
120
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
* A Workflow Execution waits until it knows the work an Agent Step will actually receive. The
|
|
122
|
+
* original launch remains useful background, but it is deliberately the first thing truncated:
|
|
123
|
+
* mapped upstream results and resolved instructions say what the work is, while launch inputs only
|
|
124
|
+
* say where the execution began.
|
|
125
|
+
*
|
|
126
|
+
* `credentials` contains values already resolved for this execution. Credential-shaped keys are
|
|
127
|
+
* omitted and known values are replaced before serialisation and truncation. In particular, callers
|
|
128
|
+
* pass the Step's resolved instructions, never the final backend prompt containing injected private
|
|
129
|
+
* named secrets.
|
|
124
130
|
*/
|
|
125
|
-
export function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
export function workflowAgentNameInput(options, credentials = []) {
|
|
132
|
+
return boundedWorkflowContext([
|
|
133
|
+
{ label: "Resolved task instructions", value: options.instructions, priority: 3 },
|
|
134
|
+
{ label: "Resolved task input", value: options.input, priority: 3 },
|
|
135
|
+
{ label: "Workflow", value: options.workflowName, priority: 3, cap: 200 },
|
|
136
|
+
{ label: "Agent step", value: options.stepName, priority: 3, cap: 200 },
|
|
137
|
+
{ label: "Validated launch inputs", value: options.workflowInput, priority: 1 },
|
|
138
|
+
], credentials);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Context used only when an eligible execution reaches an outcome before any Agent Step starts.
|
|
142
|
+
* Results and errors outrank launch inputs because they describe what the execution actually did.
|
|
143
|
+
*/
|
|
144
|
+
export function workflowOutcomeNameInput(options, credentials = []) {
|
|
145
|
+
return boundedWorkflowContext([
|
|
146
|
+
{ label: "Outcome", value: options.outcome, priority: 3 },
|
|
147
|
+
...(options.results === undefined ? [] : [{ label: "Available results", value: options.results, priority: 3 }]),
|
|
148
|
+
...(options.errors === undefined ? [] : [{ label: "Available errors", value: options.errors, priority: 3 }]),
|
|
149
|
+
{ label: "Workflow", value: options.workflowName, priority: 3, cap: 200 },
|
|
150
|
+
{ label: "Validated launch inputs", value: options.workflowInput, priority: 1 },
|
|
151
|
+
], credentials);
|
|
136
152
|
}
|
|
137
153
|
/**
|
|
138
154
|
* Where a throwaway session runs.
|
|
@@ -433,6 +449,56 @@ function boundedNameInput(whole) {
|
|
|
433
449
|
const half = Math.floor(MAX_INPUT_LENGTH / 2);
|
|
434
450
|
return `${whole.slice(0, half)}\n\n…\n\n${whole.slice(-half)}`;
|
|
435
451
|
}
|
|
452
|
+
/**
|
|
453
|
+
* Bound labelled workflow data while spending space on high-priority sections first.
|
|
454
|
+
*
|
|
455
|
+
* Every field keeps its label and at least an ellipsis, so a model can distinguish missing data
|
|
456
|
+
* from data that lost the size contest. Sections at the same priority share space rather than one
|
|
457
|
+
* giant instruction starving the resolved input beside it.
|
|
458
|
+
*/
|
|
459
|
+
function boundedWorkflowContext(sections, credentials) {
|
|
460
|
+
const serialise = credentialJsonSerializer(credentials);
|
|
461
|
+
const serialised = sections.map(section => {
|
|
462
|
+
const text = serialise(section.value, section.cap ?? MAX_INPUT_LENGTH);
|
|
463
|
+
return { ...section, text };
|
|
464
|
+
});
|
|
465
|
+
const separators = Math.max(0, serialised.length - 1);
|
|
466
|
+
const labels = serialised.reduce((length, section) => length + section.label.length + 2, 0);
|
|
467
|
+
const available = Math.max(0, MAX_INPUT_LENGTH - labels - separators);
|
|
468
|
+
const allocations = serialised.map(section => Math.min(1, section.text.length));
|
|
469
|
+
let remaining = available - allocations.reduce((sum, length) => sum + length, 0);
|
|
470
|
+
for (const priority of [...new Set(serialised.map(section => section.priority))].sort((a, b) => b - a)) {
|
|
471
|
+
const indexes = serialised.map((section, index) => section.priority === priority ? index : -1).filter(index => index >= 0);
|
|
472
|
+
while (remaining > 0) {
|
|
473
|
+
const open = indexes.filter(index => allocations[index] < serialised[index].text.length);
|
|
474
|
+
if (!open.length)
|
|
475
|
+
break;
|
|
476
|
+
const share = Math.max(1, Math.floor(remaining / open.length));
|
|
477
|
+
let spent = 0;
|
|
478
|
+
for (const index of open) {
|
|
479
|
+
const addition = Math.min(share, remaining - spent, serialised[index].text.length - allocations[index]);
|
|
480
|
+
allocations[index] += addition;
|
|
481
|
+
spent += addition;
|
|
482
|
+
if (spent === remaining)
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
if (!spent)
|
|
486
|
+
break;
|
|
487
|
+
remaining -= spent;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return serialised.map((section, index) => `${section.label}: ${clipContext(section.text, allocations[index])}`).join("\n");
|
|
491
|
+
}
|
|
492
|
+
function clipContext(text, length) {
|
|
493
|
+
if (text.length <= length)
|
|
494
|
+
return text;
|
|
495
|
+
if (length <= 0)
|
|
496
|
+
return "";
|
|
497
|
+
if (length === 1)
|
|
498
|
+
return "…";
|
|
499
|
+
const head = Math.ceil((length - 1) / 2);
|
|
500
|
+
return text.slice(0, head) + "…" + text.slice(text.length - (length - 1 - head));
|
|
501
|
+
}
|
|
436
502
|
/**
|
|
437
503
|
* A Presentation Transcript as something to name — what a `rename` reads.
|
|
438
504
|
*
|