@nathanstephenson/flow 0.1.0 → 0.1.1
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 +6 -1
- 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 +258 -22
- package/dist/cli/install-guard.js +52 -9
- package/dist/cli/update.js +30 -13
- package/dist/cli/web-update.js +357 -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.js +341 -74
- package/dist/daemon/release-checker.js +104 -0
- package/dist/daemon/runtime.js +12 -4
- package/dist/daemon/server.js +81 -14
- 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-CaJfF2tQ.js +170 -0
- package/web/dist/assets/index-DWF4-3Fh.css +2 -0
- package/web/dist/assets/{settings-mcp-CcT0ADJR.js → settings-mcp-COi1p_1o.js} +1 -1
- package/web/dist/assets/{settings-secrets-CK4uF7fd.js → settings-secrets-C599riFl.js} +1 -1
- package/web/dist/assets/settings-workflows-BPjeFoaT.js +23 -0
- package/web/dist/assets/{workflows-D4T4Gy_7.css → workflows-9aO6cptD.css} +1 -1
- package/web/dist/assets/workflows-Bmsrl5kE.js +7 -0
- package/web/dist/assets/workflows-pane-DJ3UwHjd.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,6 +9,22 @@ 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;
|
|
@@ -93,13 +109,33 @@ export async function serve(options) {
|
|
|
93
109
|
}
|
|
94
110
|
async function handle(request, response, options) {
|
|
95
111
|
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
112
|
+
// Browser chrome asks for icons before there is a browser session. Keep that exception exact: the
|
|
113
|
+
// six root paths below are public for GET/HEAD only, while every other asset remains behind the
|
|
114
|
+
// same authentication gate as the app. A missing icon is a real 404, never the SPA Entry Document.
|
|
115
|
+
if ((request.method === "GET" || request.method === "HEAD") && PUBLIC_ICON_PATHS.has(url.pathname)) {
|
|
116
|
+
const icon = options.assets[url.pathname];
|
|
117
|
+
if (!icon) {
|
|
118
|
+
send(response, 404, { error: "Not found" });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
sendAsset(response, icon, request.method === "HEAD", PUBLIC_ICON_CACHE);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
96
124
|
if (request.method === "GET" && url.pathname === "/api/mcp/callback") {
|
|
97
125
|
try {
|
|
98
126
|
if (!options.mcpAuth)
|
|
99
127
|
throw new Error("MCP auth unavailable");
|
|
100
128
|
const location = await options.mcpAuth.callback(url);
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Return to Flow</title>
|
|
130
|
+
${ICON_LINKS}</head><body><script>window.location.replace(${JSON.stringify(location).replace(/</g, "\\u003c")})</script></body></html>`;
|
|
131
|
+
response.writeHead(200, {
|
|
132
|
+
"content-type": "text/html; charset=utf-8",
|
|
133
|
+
"content-length": Buffer.byteLength(html),
|
|
134
|
+
"cache-control": "no-store",
|
|
135
|
+
"referrer-policy": "no-referrer",
|
|
136
|
+
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; img-src 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
137
|
+
});
|
|
138
|
+
response.end(html);
|
|
103
139
|
}
|
|
104
140
|
catch {
|
|
105
141
|
send(response, 400, { error: "Invalid or expired MCP sign-in. Return to Flow and try again." });
|
|
@@ -193,6 +229,38 @@ async function handle(request, response, options) {
|
|
|
193
229
|
}
|
|
194
230
|
return;
|
|
195
231
|
}
|
|
232
|
+
if (url.pathname === '/api/update') {
|
|
233
|
+
response.setHeader('cache-control', 'no-store');
|
|
234
|
+
if (!options.updates) {
|
|
235
|
+
send(response, 404, { error: 'Update status is unavailable' });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (request.method === 'GET') {
|
|
239
|
+
send(response, 200, await options.updates.status(url.searchParams.get('refresh') === '1'));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (request.method === 'POST') {
|
|
243
|
+
try {
|
|
244
|
+
const body = JSON.parse(await readBody(request, 1024));
|
|
245
|
+
const confirmation = body;
|
|
246
|
+
if (!body || typeof body !== 'object' || Array.isArray(body) || confirmation.confirmed !== true ||
|
|
247
|
+
typeof confirmation.version !== 'string' || confirmation.version.length > 100 ||
|
|
248
|
+
Object.keys(body).some(key => key !== 'confirmed' && key !== 'version')) {
|
|
249
|
+
send(response, 400, { error: 'An explicit update confirmation for the displayed version is required' });
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
send(response, 202, await options.updates.start(confirmation.version));
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
if (!(error instanceof UpdateRefusal))
|
|
256
|
+
throw error;
|
|
257
|
+
send(response, 409, { error: error.message });
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
send(response, 405, { error: 'Method not allowed' });
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
196
264
|
if (options.oidc && request.method === "POST" && url.pathname === "/oauth/logout") {
|
|
197
265
|
options.oidc.logout(request.headers.cookie);
|
|
198
266
|
response.writeHead(303, {
|
|
@@ -664,18 +732,17 @@ function refuse(socket, status) {
|
|
|
664
732
|
socket.write(`HTTP/1.1 ${status} ${text}\r\nConnection: close\r\n\r\n`);
|
|
665
733
|
socket.destroy();
|
|
666
734
|
}
|
|
667
|
-
function sendAsset(response, asset) {
|
|
735
|
+
function sendAsset(response, asset, headOnly = false, cacheControl = asset.immutable ? "public, max-age=31536000, immutable" : "no-store") {
|
|
668
736
|
const body = Buffer.from(asset.body, asset.encoding);
|
|
669
737
|
response.writeHead(200, {
|
|
670
738
|
"content-type": asset.type,
|
|
671
739
|
"content-length": body.byteLength,
|
|
672
|
-
//
|
|
673
|
-
//
|
|
674
|
-
//
|
|
675
|
-
|
|
676
|
-
"cache-control": asset.immutable ? "public, max-age=31536000, immutable" : "no-store",
|
|
740
|
+
// Hashed assets are immutable. Public icons keep a short revalidation window instead: their
|
|
741
|
+
// stable browser-known paths cannot carry Vite hashes, so a deployment must be able to replace
|
|
742
|
+
// them without leaving old browser chrome cached indefinitely.
|
|
743
|
+
"cache-control": cacheControl,
|
|
677
744
|
});
|
|
678
|
-
response.end(body);
|
|
745
|
+
response.end(headOnly ? undefined : body);
|
|
679
746
|
}
|
|
680
747
|
/**
|
|
681
748
|
* One Attachment's bytes.
|
|
@@ -752,15 +819,15 @@ function documentNavigation(request, pathname) {
|
|
|
752
819
|
return destination === "document" || accept?.includes("text/html") === true || pathname === "/";
|
|
753
820
|
}
|
|
754
821
|
function sendLoginRedirectPage(response) {
|
|
755
|
-
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Signing in · Flow</title
|
|
756
|
-
|
|
822
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><title>Signing in · Flow</title>
|
|
823
|
+
${ICON_LINKS}</head><body><script>location.replace("/oauth/login?return_to="+encodeURIComponent(location.pathname+location.search+location.hash))</script>
|
|
757
824
|
<noscript><a href="/oauth/login">Sign in</a></noscript></body></html>`;
|
|
758
825
|
response.writeHead(200, {
|
|
759
826
|
"content-type": "text/html; charset=utf-8",
|
|
760
827
|
"content-length": Buffer.byteLength(html),
|
|
761
828
|
"cache-control": "no-store",
|
|
762
829
|
"referrer-policy": "no-referrer",
|
|
763
|
-
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
830
|
+
"content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
764
831
|
});
|
|
765
832
|
response.end(html);
|
|
766
833
|
}
|
|
@@ -778,7 +845,7 @@ function unauthorized(response, login) {
|
|
|
778
845
|
function sendAuthPage(response, status, title, detail, action) {
|
|
779
846
|
const html = `<!doctype html>
|
|
780
847
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
781
|
-
<title>${title} · Flow</title
|
|
848
|
+
<title>${title} · Flow</title>${ICON_LINKS}<style>
|
|
782
849
|
:root{color-scheme:light dark;font-family:Inter,ui-sans-serif,system-ui,sans-serif;background:#f6f6f4;color:#181817}
|
|
783
850
|
*{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
851
|
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 +858,7 @@ a{display:inline-flex;align-items:center;justify-content:center;width:100%;heigh
|
|
|
791
858
|
"content-length": Buffer.byteLength(html),
|
|
792
859
|
"cache-control": "no-store",
|
|
793
860
|
"referrer-policy": "no-referrer",
|
|
794
|
-
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
861
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
795
862
|
});
|
|
796
863
|
response.end(html);
|
|
797
864
|
}
|
|
@@ -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
|
*
|