@clemrig/factory 0.1.0 → 0.2.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.
Files changed (107) hide show
  1. package/README.md +6 -17
  2. package/dist/app/doctor.d.ts +2 -4
  3. package/dist/app/doctor.js +6 -4
  4. package/dist/app/doctor.js.map +1 -1
  5. package/dist/app/factory.d.ts +2 -0
  6. package/dist/app/factory.js +13 -2
  7. package/dist/app/factory.js.map +1 -1
  8. package/dist/app/init.d.ts +1 -5
  9. package/dist/app/init.js +1 -13
  10. package/dist/app/init.js.map +1 -1
  11. package/dist/app/options.d.ts +17 -0
  12. package/dist/app/options.js +78 -0
  13. package/dist/app/options.js.map +1 -0
  14. package/dist/app/run.d.ts +4 -20
  15. package/dist/app/run.js +22 -93
  16. package/dist/app/run.js.map +1 -1
  17. package/dist/app/runs.d.ts +4 -32
  18. package/dist/app/runs.js +9 -61
  19. package/dist/app/runs.js.map +1 -1
  20. package/dist/cli/application.d.ts +1 -1
  21. package/dist/cli/application.js +1 -1
  22. package/dist/cli/args.js +2 -2
  23. package/dist/cli/args.js.map +1 -1
  24. package/dist/cli/doctor.d.ts +1 -1
  25. package/dist/cli/doctor.js +1 -1
  26. package/dist/cli/doctor.js.map +1 -1
  27. package/dist/cli/help.d.ts +1 -1
  28. package/dist/cli/help.js +1 -1
  29. package/dist/cli/init.d.ts +1 -1
  30. package/dist/cli/init.js +1 -1
  31. package/dist/cli/launcher.d.ts +1 -1
  32. package/dist/cli/launcher.js +4 -4
  33. package/dist/cli/launcher.js.map +1 -1
  34. package/dist/cli/reporter.d.ts +1 -1
  35. package/dist/cli/reporter.js +1 -2
  36. package/dist/cli/reporter.js.map +1 -1
  37. package/dist/cli/run.d.ts +1 -5
  38. package/dist/cli/run.js +24 -11
  39. package/dist/cli/run.js.map +1 -1
  40. package/dist/cli/ui.d.ts +1 -1
  41. package/dist/cli/ui.js +10 -3
  42. package/dist/cli/ui.js.map +1 -1
  43. package/dist/index.d.ts +3 -7
  44. package/dist/index.js +3 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/system/factory.d.ts +1 -1
  47. package/dist/system/factory.js +1 -1
  48. package/dist/system/factory.js.map +1 -1
  49. package/dist/system/npm.d.ts +5 -0
  50. package/dist/system/npm.js +14 -0
  51. package/dist/system/npm.js.map +1 -0
  52. package/dist/system/templates.d.ts +1 -1
  53. package/dist/system/templates.js +1 -1
  54. package/package.json +7 -17
  55. package/dist/engine/metrics.d.ts +0 -45
  56. package/dist/engine/metrics.js +0 -60
  57. package/dist/engine/metrics.js.map +0 -1
  58. package/dist/engine/primitives.d.ts +0 -34
  59. package/dist/engine/primitives.js +0 -81
  60. package/dist/engine/primitives.js.map +0 -1
  61. package/dist/engine/profiles.d.ts +0 -53
  62. package/dist/engine/profiles.js +0 -117
  63. package/dist/engine/profiles.js.map +0 -1
  64. package/dist/engine/runner.d.ts +0 -13
  65. package/dist/engine/runner.js +0 -157
  66. package/dist/engine/runner.js.map +0 -1
  67. package/dist/engine/types.d.ts +0 -194
  68. package/dist/engine/types.js +0 -2
  69. package/dist/engine/types.js.map +0 -1
  70. package/dist/engine/workflow.d.ts +0 -18
  71. package/dist/engine/workflow.js +0 -196
  72. package/dist/engine/workflow.js.map +0 -1
  73. package/dist/system/process.d.ts +0 -21
  74. package/dist/system/process.js +0 -238
  75. package/dist/system/process.js.map +0 -1
  76. package/dist/system/runtimes/adapter.d.ts +0 -90
  77. package/dist/system/runtimes/adapter.js +0 -20
  78. package/dist/system/runtimes/adapter.js.map +0 -1
  79. package/dist/system/runtimes/agent-runtime.d.ts +0 -45
  80. package/dist/system/runtimes/agent-runtime.js +0 -184
  81. package/dist/system/runtimes/agent-runtime.js.map +0 -1
  82. package/dist/system/runtimes/claude-code.d.ts +0 -10
  83. package/dist/system/runtimes/claude-code.js +0 -383
  84. package/dist/system/runtimes/claude-code.js.map +0 -1
  85. package/dist/system/runtimes/inspect.d.ts +0 -25
  86. package/dist/system/runtimes/inspect.js +0 -129
  87. package/dist/system/runtimes/inspect.js.map +0 -1
  88. package/dist/system/runtimes/pi.d.ts +0 -7
  89. package/dist/system/runtimes/pi.js +0 -235
  90. package/dist/system/runtimes/pi.js.map +0 -1
  91. package/dist/system/runtimes/protocol.d.ts +0 -9
  92. package/dist/system/runtimes/protocol.js +0 -38
  93. package/dist/system/runtimes/protocol.js.map +0 -1
  94. package/dist/system/runtimes/registry.d.ts +0 -5
  95. package/dist/system/runtimes/registry.js +0 -5
  96. package/dist/system/runtimes/registry.js.map +0 -1
  97. package/dist/system/store.d.ts +0 -20
  98. package/dist/system/store.js +0 -126
  99. package/dist/system/store.js.map +0 -1
  100. package/dist/ui/server.d.ts +0 -8
  101. package/dist/ui/server.js +0 -111
  102. package/dist/ui/server.js.map +0 -1
  103. package/dist/ui/static/dashboard.js +0 -266
  104. package/dist/ui/static/follow.js +0 -67
  105. package/dist/ui/static/index.html +0 -20
  106. package/dist/ui/static/style.css +0 -166
  107. package/dist/ui/static/timeline.js +0 -180
@@ -1,180 +0,0 @@
1
- // @ts-check
2
- /**
3
- * The dashboard's pure logic: a run's events grouped into one block per stage
4
- * execution, and the formats of durations and costs. Served as is to the browser.
5
- */
6
-
7
- /** @typedef {import("../../engine/types.js").RunEvent} RunEvent */
8
- /** @typedef {import("../../engine/types.js").AgentActivity} AgentActivity */
9
- /** @typedef {import("../../engine/metrics.js").TokenCounts} TokenCounts */
10
- /** @typedef {import("../../engine/metrics.js").AgentUsage} AgentUsage */
11
-
12
- /**
13
- * @typedef {object} Call
14
- * @property {string} [runtime]
15
- * @property {string} [model]
16
- * @property {string} [session]
17
- * @property {"running" | "completed" | "failed"} status
18
- * @property {AgentUsage} [usage] As the runtime announced it at the end of the call.
19
- * @property {"call" | "session"} [scope] Whether `usage` is the call's own or its session's total.
20
- */
21
-
22
- /**
23
- * @typedef {object} Tool
24
- * @property {string} id
25
- * @property {string} name
26
- * @property {"running" | "completed" | "failed"} status
27
- * @property {number} [durationMs]
28
- */
29
-
30
- /**
31
- * @typedef {object} Block
32
- * @property {string} stage
33
- * @property {string} kind
34
- * @property {"running" | "passed" | "failed" | "completed"} status
35
- * @property {string} startedAt
36
- * @property {number | null} durationMs
37
- * @property {{ verdict: string; reason: string; destination: string | null }} [decision]
38
- * @property {{ key: string; count: number; max: number }} [retry]
39
- * @property {string} [detail]
40
- * @property {Call} [call]
41
- * @property {Tool[]} tools
42
- * @property {TokenCounts | null} tokens The call's responses so far.
43
- * @property {boolean} provisional Whether `tokens` includes figures replaced at the end of the call.
44
- * @property {string[]} warnings
45
- * @property {{ at: string; message: string }[]} journal
46
- */
47
-
48
- /**
49
- * @param {string} stage
50
- * @param {string} kind
51
- * @param {string} at
52
- * @returns {Block}
53
- */
54
- const block = (stage, kind, at) => ({
55
- stage,
56
- kind,
57
- status: "running",
58
- startedAt: at,
59
- durationMs: null,
60
- tools: [],
61
- tokens: null,
62
- provisional: false,
63
- warnings: [],
64
- journal: [],
65
- });
66
-
67
- /**
68
- * @param {Block} target
69
- * @param {AgentActivity} activity
70
- */
71
- function apply(target, activity) {
72
- switch (activity.kind) {
73
- case "call":
74
- if (activity.status === "started") {
75
- const { runtime, model, session } = activity;
76
- target.call = { runtime, model, session, status: "running" };
77
- } else
78
- target.call = {
79
- ...target.call,
80
- runtime: activity.runtime,
81
- status: activity.status,
82
- usage: activity.usage,
83
- scope: activity.scope,
84
- };
85
- break;
86
- case "tool": {
87
- const tool = target.tools.find(({ id }) => id === activity.id);
88
- const update =
89
- activity.status === "started"
90
- ? { id: activity.id, name: activity.name, status: "running" }
91
- : {
92
- id: activity.id,
93
- name: activity.name,
94
- status: activity.status,
95
- durationMs: activity.durationMs,
96
- };
97
- if (tool) Object.assign(tool, update);
98
- else target.tools.push(/** @type {Tool} */ (update));
99
- break;
100
- }
101
- case "response": {
102
- const sum = target.tokens ?? {
103
- input: 0,
104
- output: 0,
105
- cacheRead: 0,
106
- cacheWrite: 0,
107
- };
108
- for (const field of /** @type {const} */ ([
109
- "input",
110
- "output",
111
- "cacheRead",
112
- "cacheWrite",
113
- ]))
114
- sum[field] += activity.tokens[field];
115
- target.tokens = sum;
116
- target.provisional ||= activity.provisional;
117
- break;
118
- }
119
- case "warning":
120
- target.warnings.push(activity.message);
121
- }
122
- }
123
-
124
- /**
125
- * One block per stage execution, in order: a stage's journal, agent activity
126
- * and decision go to its latest block.
127
- * @param {RunEvent[]} events
128
- * @returns {Block[]}
129
- */
130
- export function timeline(events) {
131
- /** @type {Block[]} */
132
- const blocks = [];
133
- const latest = (/** @type {string} */ stage) =>
134
- blocks.findLast((candidate) => candidate.stage === stage);
135
- for (const event of events) {
136
- if (event.type === "stage" && event.status === "started") {
137
- blocks.push(block(event.stage, event.kind, event.at));
138
- continue;
139
- }
140
- let target = latest(event.stage);
141
- if (!target || (event.type === "stage" && target.status !== "running")) {
142
- // A stage reported without a start, such as one failed by an interruption.
143
- target = block(event.stage, event.kind, event.at);
144
- blocks.push(target);
145
- }
146
- if (event.type === "stage") {
147
- target.status = event.status === "started" ? "running" : event.status;
148
- target.durationMs = Date.parse(event.at) - Date.parse(target.startedAt);
149
- if (event.decision) target.decision = event.decision;
150
- if (event.retry) target.retry = event.retry;
151
- if (event.detail) target.detail = event.detail;
152
- } else if (event.type === "log")
153
- target.journal.push({ at: event.at, message: event.message });
154
- else apply(target, event.activity);
155
- }
156
- return blocks;
157
- }
158
-
159
- /**
160
- * @param {number | null} ms
161
- * @returns {string}
162
- */
163
- export function duration(ms) {
164
- if (ms === null) return "—";
165
- const seconds = Math.floor(ms / 1000);
166
- const hours = Math.floor(seconds / 3600);
167
- const minutes = Math.floor((seconds % 3600) / 60);
168
- return `${hours ? `${hours} h ` : ""}${minutes} min ${seconds % 60} s`;
169
- }
170
-
171
- /**
172
- * An estimated cost as the runtimes announced it; unknown without any measure.
173
- * @param {number | null} usd
174
- * @param {boolean} partial Some agent call announced no usage.
175
- * @returns {string}
176
- */
177
- export function cost(usd, partial) {
178
- const value = usd === null ? "—" : `${usd.toFixed(4)} USD`;
179
- return partial ? `${value} (partial)` : value;
180
- }