@krapht/ork 1.0.0-alpha.1 → 1.0.0-alpha.11

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 (43) hide show
  1. package/README.md +3 -4
  2. package/dist/{__build_info__-D9lSlMFy.mjs → __build_info__-CIchF6nr.mjs} +2 -2
  3. package/dist/bin.mjs +1479 -600
  4. package/dist/chips-BA7SrrH5.mjs +43 -0
  5. package/dist/{clean-CA_Oi2Wl.mjs → clean-Di-KT7Mf.mjs} +5 -2
  6. package/dist/{completion-DBGfL-gN.mjs → completion-C5D0sEs5.mjs} +23 -16
  7. package/dist/context-BaNshWr9.mjs +695 -0
  8. package/dist/{decide-CoIJh34e.mjs → decide-B6PnKeqo.mjs} +3 -3
  9. package/dist/{find-rBBk7Jui.mjs → find-BicBbGMg.mjs} +1 -1
  10. package/dist/format-lWhN-jYR.mjs +286 -0
  11. package/dist/{in-a-run-DdAakpRR.mjs → in-a-run-CgkVouyG.mjs} +1 -1
  12. package/dist/{limits-BPM9wUlV.mjs → limits-jZQp9ZJC.mjs} +1 -1
  13. package/dist/{list-Bv5Lxu7z.mjs → list-CEaJ07jd.mjs} +11 -4
  14. package/dist/{mcp-DM30MFBw.mjs → mcp-DYgVA9f5.mjs} +6 -6
  15. package/dist/output-CM95njYt.mjs +421 -0
  16. package/dist/{pause-C7lJkSma.mjs → pause-D6PuSlNl.mjs} +4 -4
  17. package/dist/{relay-BipJYszF.mjs → relay-DNx7be9k.mjs} +2 -2
  18. package/dist/{remove-BDs9isB6.mjs → remove-CpMb4NDl.mjs} +14 -7
  19. package/dist/{report-DK4LGqwF.mjs → report-CEN8VoUb.mjs} +31 -20
  20. package/dist/{send-nbkjf3sc.mjs → send-CLs_fyg7.mjs} +3 -3
  21. package/dist/{src-BxUJPGa5.mjs → src-9iGkjnsy.mjs} +487 -341
  22. package/dist/{src-B0TT7DBi.mjs → src-B6KvTm7B.mjs} +106 -90
  23. package/dist/src-BnZgZGrf.mjs +2697 -0
  24. package/dist/{src-hrj2h0IZ.mjs → src-D6_xjm-x.mjs} +6719 -3389
  25. package/dist/ui/THIRD_PARTY_LICENSES.txt +594 -0
  26. package/dist/ui/assets/app-CxURph7a.js +75 -0
  27. package/dist/ui/assets/app-QoHVi-mb.css +1 -0
  28. package/dist/ui/assets/{index-CPx74lFf.js → index-By_8KKG6.js} +3 -3
  29. package/dist/ui/assets/theme-CdXvqTQ6.js +1 -0
  30. package/dist/ui/index.html +2 -2
  31. package/dist/{ui-B98FSboa.mjs → ui-CIci4UBW.mjs} +4 -4
  32. package/dist/{usage-EW7DI6Z7.mjs → usage-GceBGMjU.mjs} +43 -32
  33. package/dist/{watch-BAkSGaOp.mjs → watch-BmoybMQg.mjs} +28 -16
  34. package/dist/{workflows-vsEohqa7.mjs → workflows-DZvW3i1e.mjs} +4 -3
  35. package/dist/{worktrees-Ahj9rdWK.mjs → worktrees-Be51E2rB.mjs} +84 -24
  36. package/package.json +2 -4
  37. package/dist/context-6x3kXREO.mjs +0 -274
  38. package/dist/format-zMmhqyLE.mjs +0 -427
  39. package/dist/output-TV_j7Ni0.mjs +0 -950
  40. package/dist/src-B9v0lDc6.mjs +0 -1204
  41. package/dist/ui/assets/app-BNT0SuIz.css +0 -1
  42. package/dist/ui/assets/app-CmkynZyW.js +0 -67
  43. package/dist/ui/assets/theme-3xH5jxKs.js +0 -1
@@ -1,86 +1,16 @@
1
- import { B as linkNodes, Cn as runDirOf, Ct as walkChecks, En as inside, Fn as applyEdits, G as requestContinue, Gn as expandEdge, Hn as EdgeInputSchema, Ht as planPost, In as newWorkflowText, J as tellLiveRun, K as requestPause, Ln as readDocument, Nn as skillsIn, Nt as nodeSays, On as LESSON_CAP_TOKENS, Pn as WorkflowEditSchema, Rn as renderJsonSchema, St as checkWorkflowText, Tn as workflowDirOf, U as unlinkNodes, Ut as runGh, Vt as DISCUSSIONS, Wt as sendPost, _t as runStatus, bn as placeFiles, bt as processAlive, ct as explainWorkflowText, d as runningRunIds, f as runningScript, gt as pausedOf, hn as loadAgents, ht as liveStatus, l as planUpgrade, nt as resumable, o as limitsReport, ot as detachRun, p as detectInstaller, q as requestStop, qn as NodeSchema, r as capsHere, st as followEvents, tn as readCondition, tt as detachResume, u as releaseNotes, v as triggersReport, vt as runTree, wt as walkSummary, xn as placeFor, zn as parseWorkflow } from "./src-hrj2h0IZ.mjs";
2
- import { C as feedbackActions, S as placeOf$1, _ as previewPost, a as registryShown, b as acceptItem, c as checkDue, f as readUpdateCache, g as nodeSession, h as writeUpdateCache, i as registryOf, l as fetchLatest, m as updateCachePath, o as updateSwitchOff, p as refreshUpdateCache, s as runInstall, u as newerVersion, w as openFixRun, x as lessonPlaceOf, y as recordNote } from "./__build_info__-D9lSlMFy.mjs";
3
- import { n as pendingDecisions, r as builtinProblem, t as answerDecision } from "./decide-CoIJh34e.mjs";
4
- import { n as newRunId, t as findRun } from "./find-rBBk7Jui.mjs";
5
- import { c as openStore, l as storePath, s as nodeOf } from "./output-TV_j7Ni0.mjs";
6
- import { n as usageReport } from "./report-DK4LGqwF.mjs";
7
- import { a as planClean, i as keyOf, o as stepActs, r as cleanStep, s as stepPrunes, t as applyClean } from "./clean-CA_Oi2Wl.mjs";
8
- import { a as readWorktrees, c as planLine, i as projectHead, l as removeRefusal, n as lostWork, o as labelOf, r as planRemove, s as mergeStateOf, t as applyRemove, u as stateParts } from "./remove-BDs9isB6.mjs";
1
+ import { $n as skillsIn, $t as endOf, At as nestItems, B as linkNodes, Bn as placeFiles, C as openStore, Ct as runStatus, Dt as processAlive, G as requestContinue, Gn as workflowDirOf, In as loadAgents, J as tellLiveRun, Jn as LESSON_CAP_TOKENS, K as requestPause, Kn as inside, S as isNodeEvent, St as pausedOf, U as unlinkNodes, Un as runDirOf, Ut as nodeSays, Vn as placeFor, X as detachResume, Z as resumable, a as releaseNotes, c as detectInstaller, cn as planPost, er as WorkflowEditSchema, et as detachRun, gt as walkSummary, hr as NodeSchema, ht as walkChecks, i as planUpgrade, it as limitsReport, ln as runGh, mt as checkWorkflowText, nn as END_KINDS, nr as newWorkflowText, o as runningRunIds, or as renderJsonSchema, p as triggersReport, pr as expandEdge, q as requestStop, r as capsHere, rr as readDocument, s as runningScript, sn as DISCUSSIONS, sr as parseWorkflow, st as explainWorkflowText, tr as applyEdits, tt as followEvents, un as sendPost, ur as EdgeInputSchema, w as storePath, x as activeTree, xt as liveStatus, yn as readCondition } from "./src-D6_xjm-x.mjs";
2
+ import { C as feedbackActions, S as placeOf$1, _ as previewPost, a as registryShown, b as acceptItem, c as checkDue, f as readUpdateCache, g as nodeSession, h as writeUpdateCache, i as registryOf, l as fetchLatest, m as updateCachePath, o as updateSwitchOff, p as refreshUpdateCache, s as runInstall, u as newerVersion, w as openFixRun, x as lessonPlaceOf, y as recordNote } from "./__build_info__-CIchF6nr.mjs";
3
+ import { n as pendingDecisions, r as builtinProblem, t as answerDecision } from "./decide-B6PnKeqo.mjs";
4
+ import { n as newRunId, t as findRun } from "./find-BicBbGMg.mjs";
5
+ import { n as usageReport } from "./report-CEN8VoUb.mjs";
6
+ import { a as planClean, i as keyOf, o as stepActs, r as cleanStep, s as stepPrunes, t as applyClean } from "./clean-Di-KT7Mf.mjs";
7
+ import { a as readWorktrees, c as mergeStateOf, d as stateParts, i as projectHead, l as planLine, n as lostWork, r as planRemove, s as labelOf, t as applyRemove, u as removeRefusal } from "./remove-CpMb4NDl.mjs";
9
8
  import path from "node:path";
10
9
  import { z } from "zod";
11
10
  import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
12
11
  import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
13
12
  import { homedir } from "node:os";
14
13
  import { createServer } from "node:http";
15
- // ../core/src/store/activity.ts
16
- const LONGEST_LINE = 120;
17
- /**
18
- * The fields of a tool's input that say what it's working on, best first. Only
19
- * these are shown, so what else a tool was given stays in the logs.
20
- */
21
- const TARGETS = [
22
- "file_path",
23
- "notebook_path",
24
- "path",
25
- "url",
26
- "pattern",
27
- "query",
28
- "command"
29
- ];
30
- const oneLine = (text) => {
31
- const line = text.replaceAll(/\s+/gu, " ").trim();
32
- return line.length > LONGEST_LINE ? `${line.slice(0, 119)}…` : line;
33
- };
34
- const toolLine = ({ name, input }) => {
35
- const target = TARGETS.map((field) => input[field]).find((value) => typeof value === "string" && value.trim() !== "");
36
- if (typeof target !== "string") return name;
37
- return oneLine(target.startsWith(`${name} `) ? target : `${name} ${target}`);
38
- };
39
- /** What a finished node said, or why it failed. */
40
- const finishedNow = (ok, error, summary) => {
41
- if (!ok) return error === void 0 ? void 0 : oneLine(error);
42
- return typeof summary === "string" && summary.trim() !== "" ? oneLine(summary) : void 0;
43
- };
44
- /** Each node's activity, by id; a node that never started has none. */
45
- const runActivity = (stored) => {
46
- const nodes = /* @__PURE__ */ new Map();
47
- const of = (id) => {
48
- const found = nodes.get(id);
49
- if (found !== void 0) return found;
50
- const fresh = {};
51
- nodes.set(id, fresh);
52
- return fresh;
53
- };
54
- for (const { at, event } of stored) if (event.type === "node.started") {
55
- const node = of(event.id);
56
- node.startedAt ??= at;
57
- delete node.finishedAt;
58
- delete node.now;
59
- } else if (event.type === "node.event") {
60
- if (event.event.type === "tool.called") of(event.id).now = toolLine(event.event);
61
- } else if (event.type === "decision.opened") of(event.node).now = oneLine(`Asked: ${event.question}`);
62
- else if (event.type === "decision.answered") of(event.node).now = oneLine(`Answered: ${event.answer}`);
63
- else if (event.type === "decision.withdrawn") delete of(event.node).now;
64
- else if (event.type === "node.finished") {
65
- const node = of(event.id);
66
- node.finishedAt = at;
67
- const now = finishedNow(event.ok, event.error, event.output["summary"]);
68
- if (now === void 0) delete node.now;
69
- else node.now = now;
70
- }
71
- return nodes;
72
- };
73
- /** The ownership tree, with what each node is doing and when it ran. */
74
- const activeTree = (stored) => {
75
- const activity = runActivity(stored);
76
- const dress = (node) => {
77
- Object.assign(node, activity.get(node.id));
78
- for (const child of node.children) dress(child);
79
- };
80
- const roots = runTree(stored.map(({ event }) => event));
81
- for (const root of roots) dress(root);
82
- return roots;
83
- };
84
14
  // ../server/src/contract-builder.ts
85
15
  /** A new workflow's name, as its file and its `name:` take it. */
86
16
  const NewWorkflowSchema = z.strictObject({ name: z.string().min(1) });
@@ -167,7 +97,13 @@ const AcceptSchema = z.strictObject({
167
97
  /** Which workflow's lessons, when it was seen in more than one. */
168
98
  workflow: z.string().min(1).optional()
169
99
  });
170
- const ApplySchema = z.strictObject({ driver: z.enum(["sdk", "cli"]).optional() });
100
+ const DriverIdSchema = z.enum({
101
+ "claude-code": "claude-code",
102
+ "open-code": "open-code",
103
+ "command-code": "command-code"
104
+ });
105
+ DriverIdSchema.options;
106
+ const ApplySchema = z.strictObject({ driver: DriverIdSchema.optional() });
171
107
  const PublishPreviewSchema = z.strictObject({
172
108
  /** Also hide the repositories' and workflows' names. */
173
109
  hideNames: z.boolean() });
@@ -327,7 +263,6 @@ const WORKTREES_API = {
327
263
  // ../server/src/contract.ts
328
264
  const Count = z.coerce.number().int().positive();
329
265
  const Seq = z.coerce.number().int().nonnegative();
330
- const Driver = z.enum(["sdk", "cli"]);
331
266
  const RunsQuerySchema = z.strictObject({
332
267
  project: z.string().min(1).optional(),
333
268
  limit: Count.optional()
@@ -349,7 +284,9 @@ const EventsQuerySchema = z.strictObject({
349
284
  });
350
285
  const DecisionsQuerySchema = z.strictObject({
351
286
  run: z.string().min(1).optional(),
352
- project: z.string().min(1).optional()
287
+ project: z.string().min(1).optional(),
288
+ /** Only runs of this workflow, by name; ANDed with `run` or `project`. */
289
+ workflow: z.string().min(1).optional()
353
290
  });
354
291
  /** An answer: the option, and what the person said with it, if anything. */
355
292
  const AnswerSchema = z.strictObject({
@@ -358,7 +295,7 @@ const AnswerSchema = z.strictObject({
358
295
  });
359
296
  const RunFlags = {
360
297
  inputs: z.record(z.string(), z.string()).optional(),
361
- driver: Driver.optional(),
298
+ driver: DriverIdSchema.optional(),
362
299
  inPlace: z.boolean().optional(),
363
300
  allowDirty: z.boolean().optional()
364
301
  };
@@ -483,7 +420,8 @@ const STREAMS = {
483
420
  run: "/api/runs/:id/stream",
484
421
  /**
485
422
  * `runs`, `decisions`, `version`, each when it changes; `?project=` keeps
486
- * one. `upgrade`: the upgrade's output, then `end` (contract-update.ts).
423
+ * one, `?workflow=` narrows `decisions` to that workflow's. `upgrade`: the
424
+ * upgrade's output, then `end` (contract-update.ts).
487
425
  */
488
426
  overview: "/api/stream",
489
427
  upgrade: "/api/upgrade/stream"
@@ -841,7 +779,7 @@ const runOf = (context, id) => {
841
779
  const projectOf = (context, key) => context.store.projects().find((p) => p.id === key || p.root === key);
842
780
  /** A run as the API shows it: with its live status and what is paused. */
843
781
  const viewOf$2 = (context, run) => {
844
- const events = run.status === "running" ? context.store.events(run.id).map((stored) => stored.event) : [];
782
+ const events = run.status === "running" ? context.store.controlEvents(run.id).map((stored) => stored.event) : [];
845
783
  return {
846
784
  ...run,
847
785
  live: runStatus(run, events),
@@ -1512,6 +1450,72 @@ const builderRoutes = (context) => {
1512
1450
  builderSave: ({ params, body }) => inProject(params.id, (project) => saveDraft(context, project, params.name, body.force === true))
1513
1451
  };
1514
1452
  };
1453
+ // ../server/src/end-view.ts
1454
+ /**
1455
+ * @file Resolves how nodes ended for the API: each `node.finished` event (read
1456
+ * through core's `endOf`, so a run stored before ends existed gets a kind
1457
+ * too) and each tree node get an `EndView` (contract-ends.ts).
1458
+ */
1459
+ /** Core's hints send the reader to Details; with no detail there is none. */
1460
+ const HINT_TO_DETAILS = /\bIts (?:last )?(?:output|detail) is under Details(?:; |\.\s*)/u;
1461
+ const hintFor = (hint, hasDetail) => {
1462
+ if (hasDetail) return hint;
1463
+ const rest = hint.replace(HINT_TO_DETAILS, "");
1464
+ return rest === "" ? rest : rest[0]?.toUpperCase() + rest.slice(1);
1465
+ };
1466
+ const endViewOf = (end) => {
1467
+ const info = END_KINDS[end.kind];
1468
+ return {
1469
+ kind: end.kind,
1470
+ message: end.message,
1471
+ ...end.detail === void 0 ? {} : { detail: end.detail },
1472
+ label: info.label,
1473
+ actor: info.actor,
1474
+ transient: info.transient,
1475
+ hint: hintFor(info.hint, end.detail !== void 0),
1476
+ docsAnchor: info.docsAnchor
1477
+ };
1478
+ };
1479
+ /** The event as served: a `node.finished` gets its `end`, old ones too. */
1480
+ const servedEvent = (stored) => {
1481
+ const { event } = stored;
1482
+ return event.type === "node.finished" ? {
1483
+ ...stored,
1484
+ event: {
1485
+ ...event,
1486
+ end: endViewOf(endOf(event))
1487
+ }
1488
+ } : {
1489
+ ...stored,
1490
+ event
1491
+ };
1492
+ };
1493
+ /**
1494
+ * The tree with each node's latest end, from the events it was folded from. A
1495
+ * node that started again has none until it finishes; a failed node's `now` is
1496
+ * the end's message, not the raw error.
1497
+ */
1498
+ const treeWithEnds = (roots, stored) => {
1499
+ const ends = /* @__PURE__ */ new Map();
1500
+ for (const { event } of stored) if (event.type === "node.started") ends.delete(event.id);
1501
+ else if (event.type === "node.finished") ends.set(event.id, endViewOf(endOf(event)));
1502
+ const dress = (node) => {
1503
+ const end = ends.get(node.id);
1504
+ const children = node.children.map(dress);
1505
+ if (end === void 0) return {
1506
+ ...node,
1507
+ children
1508
+ };
1509
+ const failed = node.state === "failed" && end.actor !== null;
1510
+ return {
1511
+ ...node,
1512
+ ...failed ? { now: end.message } : {},
1513
+ end,
1514
+ children
1515
+ };
1516
+ };
1517
+ return roots.map((node) => dress(node));
1518
+ };
1515
1519
  // ../server/src/workflows.ts
1516
1520
  /**
1517
1521
  * @file A project's workflows, for the UI's Run workflow dialog: each
@@ -1610,7 +1614,8 @@ const readRoutes = (context) => ({
1610
1614
  tree: ({ params }) => {
1611
1615
  const found = runOf(context, params.id);
1612
1616
  if (!found.ok) return found.refusal;
1613
- return ok(activeTree(context.store.events(found.run.id)));
1617
+ const stored = context.store.events(found.run.id);
1618
+ return ok(treeWithEnds(nestItems(activeTree(stored)), stored));
1614
1619
  },
1615
1620
  graph: ({ params }) => {
1616
1621
  const found = runOf(context, params.id);
@@ -1620,15 +1625,22 @@ const readRoutes = (context) => ({
1620
1625
  events: ({ params, query }) => {
1621
1626
  const found = runOf(context, params.id);
1622
1627
  if (!found.ok) return found.refusal;
1623
- const events = context.store.events(found.run.id, query.after ?? 0).filter((s) => query.node === void 0 || nodeOf(s.event) === query.node);
1628
+ const events = context.store.events(found.run.id, query.after ?? 0).filter((s) => query.node === void 0 || isNodeEvent(s.event, query.node));
1624
1629
  const newest = query.last === void 0 ? events : events.slice(-query.last);
1625
- return ok(query.limit === void 0 ? newest : newest.slice(0, query.limit));
1630
+ return ok((query.limit === void 0 ? newest : newest.slice(0, query.limit)).map((stored) => servedEvent(stored)));
1626
1631
  },
1627
1632
  decisions: ({ query }) => {
1628
- if (query.run === void 0) return ok(pendingDecisions(context.store, query.project === void 0 ? {} : { project: projectRoot(context, query.project) }));
1633
+ const workflow = query.workflow === void 0 ? {} : { workflow: query.workflow };
1634
+ if (query.run === void 0) return ok(pendingDecisions(context.store, {
1635
+ ...workflow,
1636
+ ...query.project === void 0 ? {} : { project: projectRoot(context, query.project) }
1637
+ }));
1629
1638
  const found = runOf(context, query.run);
1630
1639
  if (!found.ok) return found.refusal;
1631
- return ok(pendingDecisions(context.store, { runId: found.run.id }));
1640
+ return ok(pendingDecisions(context.store, {
1641
+ ...workflow,
1642
+ runId: found.run.id
1643
+ }));
1632
1644
  },
1633
1645
  decision: ({ params }) => {
1634
1646
  const found = context.store.decision(params.id);
@@ -2856,7 +2868,7 @@ const runStream = async (context, req, res, url, id, shutdown) => {
2856
2868
  }
2857
2869
  const stream = openEventStream(res);
2858
2870
  const end = await followEvents(context.store, found.run.id, (stored) => {
2859
- stream.send("run-event", stored, stored.seq);
2871
+ stream.send("run-event", servedEvent(stored), stored.seq);
2860
2872
  }, {
2861
2873
  follow: true,
2862
2874
  after,
@@ -2869,6 +2881,7 @@ const runStream = async (context, req, res, url, id, shutdown) => {
2869
2881
  const overviewStream = (context, res, url, shutdown) => {
2870
2882
  const key = url.searchParams.get("project");
2871
2883
  const root = key === null ? void 0 : projectOf(context, key)?.root ?? key;
2884
+ const workflow = url.searchParams.get("workflow");
2872
2885
  const stream = openEventStream(res);
2873
2886
  const last = {
2874
2887
  runs: "",
@@ -2881,7 +2894,10 @@ const overviewStream = (context, res, url, shutdown) => {
2881
2894
  ...filter,
2882
2895
  limit: OVERVIEW_RUNS
2883
2896
  }).map((run) => viewOf$2(context, run));
2884
- const decisions = pendingDecisions(context.store, filter);
2897
+ const decisions = pendingDecisions(context.store, {
2898
+ ...filter,
2899
+ ...workflow === null ? {} : { workflow }
2900
+ });
2885
2901
  for (const [name, value] of [
2886
2902
  ["runs", runs],
2887
2903
  ["decisions", decisions],