@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.
Files changed (54) hide show
  1. package/README.md +10 -2
  2. package/dist/backend/fake/index.js +3 -1
  3. package/dist/backend/pi/effort-capabilities.js +12 -0
  4. package/dist/backend/pi/index.js +25 -36
  5. package/dist/backend/pi/workflow-subagent.js +8 -3
  6. package/dist/build-id +1 -1
  7. package/dist/cli/application.js +9 -1
  8. package/dist/cli/bootstrap.js +424 -37
  9. package/dist/cli/host-control.js +2 -2
  10. package/dist/cli/install-guard.js +57 -11
  11. package/dist/cli/systemd-update.js +129 -0
  12. package/dist/cli/update.js +64 -17
  13. package/dist/cli/web-update.js +376 -0
  14. package/dist/client/model-choices.js +22 -4
  15. package/dist/client/reduce.js +18 -6
  16. package/dist/client/status.js +34 -20
  17. package/dist/client/workflow-effort.js +30 -0
  18. package/dist/daemon/credential-redaction.js +97 -4
  19. package/dist/daemon/host-control-routes.js +18 -2
  20. package/dist/daemon/host.js +341 -74
  21. package/dist/daemon/release-checker.js +104 -0
  22. package/dist/daemon/runtime.js +12 -4
  23. package/dist/daemon/server.js +98 -15
  24. package/dist/daemon/summariser.js +81 -15
  25. package/dist/daemon/update-api.js +3 -0
  26. package/dist/daemon/workflow-executions.js +146 -15
  27. package/dist/protocol/update.js +1 -0
  28. package/dist/tui/app.js +104 -10
  29. package/dist/tui/keys.js +46 -10
  30. package/dist/tui/render.js +58 -13
  31. package/dist/workflows/records.js +3 -1
  32. package/dist/workflows/scheduler.js +15 -1
  33. package/package.json +1 -1
  34. package/web/dist/apple-touch-icon.png +0 -0
  35. package/web/dist/assets/index-BlZBshi8.js +170 -0
  36. package/web/dist/assets/index-DWF4-3Fh.css +2 -0
  37. package/web/dist/assets/{settings-mcp-CcT0ADJR.js → settings-mcp-ZMIfuuZU.js} +1 -1
  38. package/web/dist/assets/{settings-secrets-CK4uF7fd.js → settings-secrets-CgTrBpi2.js} +1 -1
  39. package/web/dist/assets/settings-workflows-1DMYfZtn.js +23 -0
  40. package/web/dist/assets/{workflows-D4T4Gy_7.css → workflows-9aO6cptD.css} +1 -1
  41. package/web/dist/assets/workflows-CBuB_bva.js +7 -0
  42. package/web/dist/assets/workflows-pane-DPXGg0na.js +1 -0
  43. package/web/dist/favicon-16x16.png +0 -0
  44. package/web/dist/favicon-32x32.png +0 -0
  45. package/web/dist/favicon.ico +0 -0
  46. package/web/dist/favicon.svg +8 -0
  47. package/web/dist/index.html +8 -3
  48. package/web/dist/safari-pinned-tab.svg +4 -0
  49. package/web/dist/assets/index-BC0gLS53.js +0 -106
  50. package/web/dist/assets/index-CCeZYKES.css +0 -2
  51. package/web/dist/assets/settings-workflows-CrbZF-nM.js +0 -23
  52. package/web/dist/assets/workflow-editors-naPqAmYO.js +0 -65
  53. package/web/dist/assets/workflows-hh6ioeEA.js +0 -7
  54. package/web/dist/assets/workflows-pane-Db-MHf7Z.js +0 -1
@@ -1,9 +1,102 @@
1
1
  // Known credential values are replaced in keys as well as values, including common
2
2
  // escaped/URL-encoded spellings. Never persist transport configuration in a workflow.
3
3
  export function redactCredentials(value, credentials) {
4
- const patterns = credentials.filter(Boolean).flatMap(secret => [secret, encodeURIComponent(secret), JSON.stringify(secret).slice(1, -1), JSON.stringify(JSON.stringify(secret).slice(1, -1)).slice(1, -1)]).sort((a, b) => b.length - a.length);
5
- const text = (value) => patterns.reduce((result, secret) => result.split(secret).join('[REDACTED]'), value);
6
- const visit = (item) => typeof item === 'string' ? text(item) : Array.isArray(item) ? item.map(visit) : item && typeof item === 'object' ? Object.fromEntries(Object.entries(item).map(([key, value]) => [text(key), visit(value)])) : item;
4
+ const { redact } = credentialTextRedactor(credentials);
5
+ const visit = (item) => typeof item === 'string' ? redact(item) : Array.isArray(item) ? item.map(visit) : item && typeof item === 'object' ? Object.fromEntries(Object.entries(item).map(([key, value]) => [redact(key), visit(value)])) : item;
7
6
  return visit(value);
8
7
  }
9
- export const credentialKey = /(?:authorization|cookie|password|passphrase|credential|secret|api[-_]?key|access[-_]?token|refresh[-_]?token|bearer|auth[-_]?token)/i;
8
+ function credentialTextRedactor(credentials) {
9
+ const patterns = [...new Set(credentials.filter(Boolean).flatMap(secret => [secret, encodeURIComponent(secret), JSON.stringify(secret).slice(1, -1), JSON.stringify(JSON.stringify(secret).slice(1, -1)).slice(1, -1)]))]
10
+ .sort((a, b) => b.length - a.length);
11
+ // A replacement must not itself contain a credential. This matters for credentials such as
12
+ // "REDACTED", which would otherwise survive inside the conventional marker.
13
+ const replacement = ["[REDACTED]", "[FILTERED]", "<hidden>", ""].find(candidate => patterns.every(pattern => !candidate.includes(pattern)));
14
+ const lookahead = patterns.reduce((maximum, pattern) => Math.max(maximum, pattern.length - 1), 0);
15
+ return {
16
+ redact: value => patterns.reduce((result, secret) => result.split(secret).join(replacement), value),
17
+ inspect: (value, work) => {
18
+ if (value.length <= work)
19
+ return value;
20
+ const inspected = value.slice(0, work + lookahead);
21
+ // Include a credential which straddles the work boundary, but nothing after it. Redacting
22
+ // the entire lookahead is unsafe: several long matches can shrink enough that output reaches
23
+ // a credential fragment at the end of that lookahead.
24
+ let end = work;
25
+ for (;;) {
26
+ let extended = end;
27
+ for (const pattern of patterns) {
28
+ const start = inspected.lastIndexOf(pattern, end - 1);
29
+ if (start >= 0 && start < end && start + pattern.length > extended)
30
+ extended = start + pattern.length;
31
+ }
32
+ if (extended === end)
33
+ break;
34
+ end = Math.min(extended, inspected.length);
35
+ }
36
+ return inspected.slice(0, end);
37
+ },
38
+ };
39
+ }
40
+ export const credentialKey = /(?:authorization|cookie|password|passphrase|credential|secret|api[-_]?key|private[-_]?key|access[-_]?token|refresh[-_]?token|bearer|auth[-_]?token)/i;
41
+ const namingCredentialKey = /(?:authorization|cookie|password|passphrase|credential|secret|api[-_]?key|private[-_]?key|access[-_]?token|refresh[-_]?token|auth[-_]?token|bearer|token)/i;
42
+ export function credentialJsonSerializer(credentials) {
43
+ const { redact, inspect } = credentialTextRedactor(credentials);
44
+ return (value, limit) => {
45
+ let remaining = limit;
46
+ // Output limits do not bound omitted fields or the input scanned before encoding.
47
+ let work = Math.max(4_096, limit * 4);
48
+ const consume = (size) => {
49
+ if (work <= 0)
50
+ return false;
51
+ work -= Math.max(1, size);
52
+ return true;
53
+ };
54
+ const emit = (text) => {
55
+ if (text.length <= remaining) {
56
+ remaining -= text.length;
57
+ return text;
58
+ }
59
+ const clipped = text.slice(0, Math.max(0, remaining - 1)) + (remaining ? "…" : "");
60
+ remaining = 0;
61
+ return clipped;
62
+ };
63
+ const visit = (item) => {
64
+ if (!remaining || work <= 0)
65
+ return "";
66
+ if (typeof item === "string") {
67
+ const inspected = inspect(item, work);
68
+ consume(Math.min(item.length, work));
69
+ return emit(JSON.stringify(redact(inspected)));
70
+ }
71
+ if (item === null || typeof item !== "object") {
72
+ consume(1);
73
+ return emit(redact(JSON.stringify(item) ?? "null"));
74
+ }
75
+ if (Array.isArray(item) || Symbol.iterator in item) {
76
+ let result = emit("[");
77
+ let index = 0;
78
+ for (const nested of item) {
79
+ if (!remaining || !consume(1))
80
+ break;
81
+ result += emit(index++ ? "," : "") + visit(nested);
82
+ }
83
+ return result + emit("]");
84
+ }
85
+ let result = emit("{");
86
+ let index = 0;
87
+ for (const key in item) {
88
+ if (!remaining || work <= 0)
89
+ break;
90
+ if (!Object.prototype.hasOwnProperty.call(item, key))
91
+ continue;
92
+ const inspected = inspect(key, work);
93
+ consume(Math.min(key.length, work));
94
+ if (namingCredentialKey.test(inspected))
95
+ continue;
96
+ result += emit(index++ ? "," : "") + emit(JSON.stringify(redact(inspected)) + ":") + visit(item[key]);
97
+ }
98
+ return result + emit("}");
99
+ };
100
+ return visit(value);
101
+ };
102
+ }
@@ -15,13 +15,29 @@ export async function hostControlRoute(request, response, path, control, admissi
15
15
  send(response, 409, { error: 'Session Host instance changed' });
16
16
  return;
17
17
  }
18
+ if (body.resume === true) {
19
+ if (process.env.FLOW_SYSTEMD_HOST !== '1' || !admission.resume()) {
20
+ send(response, 409, { error: 'Only a quiesced systemd Session Host can resume admission' });
21
+ return;
22
+ }
23
+ send(response, 202, { stopping: false });
24
+ return;
25
+ }
18
26
  if (!admission.isStopping() && (admission.hasPending() || control.hasActiveWork()) && body.force !== true) {
19
27
  send(response, 409, { error: 'Session Host has active work; use --force to interrupt it' });
20
28
  return;
21
29
  }
22
- admission.stop();
30
+ if (body.quiesce === true && process.env.FLOW_SYSTEMD_HOST !== '1') {
31
+ send(response, 409, { error: 'Session Host is not configured for systemd updates' });
32
+ return;
33
+ }
34
+ if (body.quiesce === true)
35
+ admission.quiesce();
36
+ else
37
+ admission.stop();
23
38
  send(response, 202, { stopping: true });
24
- setImmediate(() => { void control.stop().catch(error => console.error(error)); });
39
+ if (body.quiesce !== true)
40
+ setImmediate(() => { void control.stop().catch(error => console.error(error)); });
25
41
  }
26
42
  catch (error) {
27
43
  send(response, 400, { error: String(error) });