@graview/tools 0.1.62 → 0.1.63

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 (87) hide show
  1. package/dist/agent/tools.d.ts +15 -0
  2. package/dist/agent/tools.d.ts.map +1 -1
  3. package/dist/agent/tools.js +46 -6
  4. package/dist/agent/tools.js.map +1 -1
  5. package/dist/agent/workflow-tools.d.ts +55 -0
  6. package/dist/agent/workflow-tools.d.ts.map +1 -0
  7. package/dist/agent/workflow-tools.js +82 -0
  8. package/dist/agent/workflow-tools.js.map +1 -0
  9. package/dist/cli.d.ts +2 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +11 -3
  12. package/dist/cli.js.map +1 -1
  13. package/dist/edit.d.ts +10 -2
  14. package/dist/edit.d.ts.map +1 -1
  15. package/dist/edit.js +4 -1
  16. package/dist/edit.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/starter.d.ts +17 -3
  21. package/dist/starter.d.ts.map +1 -1
  22. package/dist/starter.js +64 -7
  23. package/dist/starter.js.map +1 -1
  24. package/dist/tidy/away.d.ts +8 -1
  25. package/dist/tidy/away.d.ts.map +1 -1
  26. package/dist/tidy/away.js +3 -1
  27. package/dist/tidy/away.js.map +1 -1
  28. package/dist/tidy/dream.d.ts.map +1 -1
  29. package/dist/tidy/dream.js +7 -0
  30. package/dist/tidy/dream.js.map +1 -1
  31. package/dist/tidy/system-one.d.ts +6 -0
  32. package/dist/tidy/system-one.d.ts.map +1 -1
  33. package/dist/tidy/system-one.js +10 -1
  34. package/dist/tidy/system-one.js.map +1 -1
  35. package/dist/workflow-cli.d.ts +20 -0
  36. package/dist/workflow-cli.d.ts.map +1 -0
  37. package/dist/workflow-cli.js +187 -0
  38. package/dist/workflow-cli.js.map +1 -0
  39. package/dist/workflows/ask.d.ts +20 -0
  40. package/dist/workflows/ask.d.ts.map +1 -0
  41. package/dist/workflows/ask.js +42 -0
  42. package/dist/workflows/ask.js.map +1 -0
  43. package/dist/workflows/log.d.ts +4 -0
  44. package/dist/workflows/log.d.ts.map +1 -0
  45. package/dist/workflows/log.js +16 -0
  46. package/dist/workflows/log.js.map +1 -0
  47. package/dist/workflows/run-act.d.ts +4 -0
  48. package/dist/workflows/run-act.d.ts.map +1 -0
  49. package/dist/workflows/run-act.js +147 -0
  50. package/dist/workflows/run-act.js.map +1 -0
  51. package/dist/workflows/run-agent.d.ts +4 -0
  52. package/dist/workflows/run-agent.d.ts.map +1 -0
  53. package/dist/workflows/run-agent.js +87 -0
  54. package/dist/workflows/run-agent.js.map +1 -0
  55. package/dist/workflows/run-archive.d.ts +4 -0
  56. package/dist/workflows/run-archive.d.ts.map +1 -0
  57. package/dist/workflows/run-archive.js +121 -0
  58. package/dist/workflows/run-archive.js.map +1 -0
  59. package/dist/workflows/run-classify.d.ts +4 -0
  60. package/dist/workflows/run-classify.d.ts.map +1 -0
  61. package/dist/workflows/run-classify.js +144 -0
  62. package/dist/workflows/run-classify.js.map +1 -0
  63. package/dist/workflows/run-generate.d.ts +4 -0
  64. package/dist/workflows/run-generate.d.ts.map +1 -0
  65. package/dist/workflows/run-generate.js +126 -0
  66. package/dist/workflows/run-generate.js.map +1 -0
  67. package/dist/workflows/run.d.ts +5 -0
  68. package/dist/workflows/run.d.ts.map +1 -0
  69. package/dist/workflows/run.js +209 -0
  70. package/dist/workflows/run.js.map +1 -0
  71. package/dist/workflows/seat.d.ts +20 -0
  72. package/dist/workflows/seat.d.ts.map +1 -0
  73. package/dist/workflows/seat.js +27 -0
  74. package/dist/workflows/seat.js.map +1 -0
  75. package/dist/workflows/steps.d.ts +7 -0
  76. package/dist/workflows/steps.d.ts.map +1 -0
  77. package/dist/workflows/steps.js +21 -0
  78. package/dist/workflows/steps.js.map +1 -0
  79. package/dist/workflows/types.d.ts +164 -0
  80. package/dist/workflows/types.d.ts.map +1 -0
  81. package/dist/workflows/types.js +2 -0
  82. package/dist/workflows/types.js.map +1 -0
  83. package/dist/workflows.d.ts +13 -0
  84. package/dist/workflows.d.ts.map +1 -0
  85. package/dist/workflows.js +23 -0
  86. package/dist/workflows.js.map +1 -0
  87. package/package.json +7 -3
@@ -0,0 +1,126 @@
1
+ import { counted, labelOf } from "@graview/core";
2
+ import { generateWants } from "@graview/core/workflows";
3
+ /*
4
+ * MAKE DATED RECORDS FROM A PATTERN, RUN (Roadmap f-job-generate-from-pattern).
5
+ * Core says what the step wants (`generateWants`): each record by its key
6
+ * and the id the key gives it. Here each is made when it is not there yet,
7
+ * through the act that makes the kind, under that id — so the store itself
8
+ * refuses a second — and linked to its source; and changed where the
9
+ * source changed. What a person did to a made record stands: a field they
10
+ * changed is not set back (unless the step says `overwrite`), one they set
11
+ * aside stays aside, and one they removed — or a run they undid — is not
12
+ * made again. A day the source skips is not among the days it wants.
13
+ */
14
+ /** A relation's name as an act's name spells it: `takenOn` → `taken-on`. */
15
+ const inActName = (relation) => relation.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
16
+ const same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
17
+ /** What the log says of the records a step makes: those taken away, and the fields somebody other than the run's author changed. */
18
+ function historyOf(ops, ids, author) {
19
+ const removed = new Set();
20
+ const touched = new Map();
21
+ const touch = (id, field) => {
22
+ let fields = touched.get(id);
23
+ if (!fields)
24
+ touched.set(id, (fields = new Set()));
25
+ fields.add(field);
26
+ };
27
+ for (const op of ops) {
28
+ for (const primitive of op.primitives) {
29
+ if (primitive.op === "remove-node" && ids.has(primitive.node.id))
30
+ removed.add(primitive.node.id);
31
+ if (primitive.op === "add-node" && ids.has(primitive.node.id))
32
+ removed.delete(primitive.node.id);
33
+ if (op.author.id === author)
34
+ continue;
35
+ if (primitive.op === "patch-node" && ids.has(primitive.id))
36
+ for (const field of Object.keys(primitive.after))
37
+ touch(primitive.id, field);
38
+ if (primitive.op === "splice-text" && ids.has(primitive.id))
39
+ touch(primitive.id, primitive.field);
40
+ }
41
+ }
42
+ return { removed, touched };
43
+ }
44
+ export const runGenerateStep = {
45
+ key: "generate",
46
+ async run(step, context) {
47
+ const store = context.store;
48
+ const schema = store.schema;
49
+ const graph = context.seen.graph;
50
+ const brand = context.app.brand;
51
+ const wants = generateWants(step, { graph, schema, workflow: context.workflow.name, now: context.now, today: context.today, timeZone: brand?.timeZone ?? store.timeZone, locale: brand?.locale });
52
+ for (const problem of wants.problems)
53
+ context.holdBack(problem.source ? `${problem.source}: ${problem.why}.` : `${problem.why.replace(/^./, (first) => first.toUpperCase())}.`);
54
+ const makers = store.allMutations().filter((mutation) => mutation.creates?.includes(step.generate));
55
+ const maker = step.using ? makers.find((mutation) => mutation.name === step.using) : makers.length === 1 ? makers[0] : undefined;
56
+ if (!maker) {
57
+ context.skipped(step.using ? `"${step.using}" does not make one of “${step.generate}”.` : makers.length === 0 ? `No act makes one of “${step.generate}”.` : `Several acts make one of “${step.generate}”; the step says none of them.`);
58
+ return;
59
+ }
60
+ const madeDefinition = schema.tryDefinition(step.generate);
61
+ const acts = new Set(store.allMutations().map((mutation) => mutation.name));
62
+ /** The call that links a made record to its source, and whether they are linked already. */
63
+ const linkOf = (wanted) => {
64
+ if (step.link === undefined)
65
+ return { linked: true };
66
+ const onMade = !!madeDefinition?.edges?.[step.link];
67
+ const [from, to, kind] = onMade ? [wanted.id, wanted.source, step.generate] : [wanted.source, wanted.id, wanted.sourceKind];
68
+ const linked = graph.has(from) && graph.out(from, step.link).some((node) => node.id === to);
69
+ const name = `connect-${kind}-${inActName(step.link)}`;
70
+ return acts.has(name) ? { call: { name, args: { id: from, to } }, linked } : { linked };
71
+ };
72
+ const { removed, touched } = historyOf(store.log.all(), new Set(wants.wanted.map((wanted) => wanted.id)), context.principal.id);
73
+ let notMadeAgain = 0;
74
+ let keptAside = 0;
75
+ let keptChanges = 0;
76
+ let unlinkedSaid = false;
77
+ for (const wanted of wants.wanted) {
78
+ const source = graph.getNode(wanted.source);
79
+ const sourceDefinition = schema.tryDefinition(wanted.sourceKind);
80
+ const label = source && sourceDefinition ? labelOf(sourceDefinition, source) : wanted.source;
81
+ const basis = `From “${label}” on ${wanted.day}`;
82
+ const existing = store.graph.getNode(wanted.id);
83
+ if (!existing) {
84
+ if (removed.has(wanted.id)) {
85
+ notMadeAgain++;
86
+ continue;
87
+ }
88
+ const link = linkOf(wanted);
89
+ if (step.link !== undefined && !link.call && !unlinkedSaid) {
90
+ unlinkedSaid = true;
91
+ context.holdBack(`No act links through "${step.link}", so what it makes is not linked to its source.`);
92
+ }
93
+ context.change({ calls: [{ name: maker.name, args: { ...wanted.values, id: wanted.id } }, ...(link.call ? [link.call] : [])], basis, confidence: 1, key: wanted.key });
94
+ continue;
95
+ }
96
+ if (store.graph.isArchived(wanted.id)) {
97
+ keptAside++;
98
+ continue;
99
+ }
100
+ const theirs = touched.get(wanted.id);
101
+ const changes = {};
102
+ for (const [field, value] of Object.entries(wanted.values)) {
103
+ if (same(existing[field], value))
104
+ continue;
105
+ if (theirs?.has(field) && !step.overwrite) {
106
+ keptChanges++;
107
+ continue;
108
+ }
109
+ changes[field] = value;
110
+ }
111
+ const link = linkOf(wanted);
112
+ const calls = [...(Object.keys(changes).length > 0 ? [{ name: `edit-${step.generate}`, args: { id: wanted.id, ...changes } }] : []), ...(!link.linked && link.call ? [link.call] : [])];
113
+ if (calls.length > 0)
114
+ context.change({ calls, basis, confidence: 1, key: wanted.key });
115
+ }
116
+ const days = wants.from === wants.to ? wants.from : `${wants.from} to ${wants.to}`;
117
+ context.note(`${wants.wanted.length === 0 ? "Nothing" : counted(schema, step.generate, wants.wanted.length)} wanted for ${days}.`);
118
+ if (keptChanges > 0)
119
+ context.note(`Kept ${keptChanges} change${keptChanges === 1 ? "" : "s"} a person made to what it made before.`);
120
+ if (keptAside > 0)
121
+ context.note(`Left ${keptAside} record${keptAside === 1 ? "" : "s"} a person set aside where ${keptAside === 1 ? "it is" : "they are"}.`);
122
+ if (notMadeAgain > 0)
123
+ context.note(`Did not make ${notMadeAgain} record${notMadeAgain === 1 ? "" : "s"} again that ${notMadeAgain === 1 ? "was" : "were"} taken away.`);
124
+ },
125
+ };
126
+ //# sourceMappingURL=run-generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-generate.js","sourceRoot":"","sources":["../../src/workflows/run-generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAwD,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,aAAa,EAAwC,MAAM,yBAAyB,CAAC;AAG9F;;;;;;;;;;GAUG;AAEH,4EAA4E;AAC5E,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAEnH,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,CAAU,EAAW,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;AAE1G,oIAAoI;AACpI,SAAS,SAAS,CAAC,GAAyB,EAAE,GAAwB,EAAE,MAA0B;IAChG,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC/C,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,KAAa,EAAE,EAAE;QAC1C,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM;YAAE,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC,CAAC;IACF,K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O,KAAK,CAAC,EAAE,EAAE,CAAC;QACnF,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,IAAI,GAAG,CAAC,CAAC;QACnI,IAAI,WAAW,GAAG,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,WAAW,UAAU,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,wCAAwC,CAAC,CAAC;QACrI,IAAI,SAAS,GAAG,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,QAAQ,SAAS,UAAU,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,6BAA6B,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC;QAC7J,IAAI,YAAY,GAAG,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,gBAAgB,YAAY,UAAU,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,eAAe,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,cAAc,CAAC,CAAC;IAC1K,CAAC;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type AnySchema } from "@graview/core";
2
+ import type { RunWorkflowOptions, WorkflowRun } from "./types.js";
3
+ /** RUN ONE WORKFLOW ONCE, and keep the run in the host's log. */
4
+ export declare function runWorkflow<S extends AnySchema>(options: RunWorkflowOptions<S>): Promise<WorkflowRun>;
5
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/workflows/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,SAAS,EAA+E,MAAM,eAAe,CAAC;AAMnJ,OAAO,KAAK,EAAiB,kBAAkB,EAA4C,WAAW,EAAE,MAAM,YAAY,CAAC;AA6C3H,iEAAiE;AACjE,wBAAsB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAwJ3G"}
@@ -0,0 +1,209 @@
1
+ import { ARCHIVED, isAutomated } from "@graview/core";
2
+ import { suggest } from "@graview/core/tidying";
3
+ import { declaredWorkflows, policiesOf, resolveWorkflow, workflowAuthor, workflowSpecHash, workflowWorldOfApp } from "@graview/core/workflows";
4
+ import { routeOf } from "../tidy/policy.js";
5
+ import { askedOf } from "./ask.js";
6
+ import { stepRunnerOf } from "./steps.js";
7
+ /*
8
+ * RUNNING ONE WORKFLOW (Roadmap f-jobs-declared, f-job-idempotency,
9
+ * f-job-pause-dry-run).
10
+ *
11
+ * A run is the app's own actor under the workflow's name: an automated
12
+ * system author, `workflow:<name>` named by its title, every op it makes
13
+ * carrying `lineage.run` so Activity folds the run into one row said by
14
+ * the title. Each step goes to its runner, and every change any runner
15
+ * would make goes through one door (`StepContext.change`):
16
+ *
17
+ * - in a DRY run it is previewed (`previewAll`) and nothing is kept: the
18
+ * run says what it would make, change, set aside or suggest. A run by
19
+ * hand of a paused workflow is dry, and so is the FIRST run after the
20
+ * workflow is added or its declaration changes (its `specHash` differs
21
+ * from the last run's): "First run after a change: nothing was kept".
22
+ * The next is real;
23
+ * - otherwise by `approve`: "apply" makes it; "suggest" makes what it is
24
+ * sure enough of for how much it would undo (dreaming's bands), suggests
25
+ * what it is less sure of and lets go of the rest; "ask" gathers it for
26
+ * a person to approve (`askedOf`).
27
+ *
28
+ * A paused workflow's scheduled or triggered run does nothing and says so
29
+ * (`held`). A step that throws stops the run (`failed`); what it kept
30
+ * before stands, and the next run's cursor (`through`) is the last good
31
+ * run's, so a retry reads the same ops and — an act step's `key` making
32
+ * every record under one id — makes nothing twice. The host keeps the run
33
+ * (`WorkflowLog`); the framework never writes it into the graph.
34
+ */
35
+ const said = (error) => (error instanceof Error ? error.message : String(error));
36
+ /** The seq the log's next op takes: a run reads every op before it. */
37
+ const headOf = (store) => (store.log.all().at(-1)?.seq ?? -1) + 1;
38
+ /** The day a moment falls on in a zone: what `$today` reads. */
39
+ const dayIn = (at, zone) => {
40
+ try {
41
+ return new Intl.DateTimeFormat("en-CA", { year: "numeric", month: "2-digit", day: "2-digit", ...(zone ? { timeZone: zone } : {}) }).format(at);
42
+ }
43
+ catch {
44
+ return new Date(at).toISOString().slice(0, 10);
45
+ }
46
+ };
47
+ /** RUN ONE WORKFLOW ONCE, and keep the run in the host's log. */
48
+ export async function runWorkflow(options) {
49
+ const store = options.store;
50
+ const workflows = declaredWorkflows(options.app) ?? {};
51
+ const declared = workflows[options.workflow];
52
+ if (!declared)
53
+ throw new Error(`The app has no workflow "${options.workflow}"${Object.keys(workflows).length > 0 ? `; it has ${Object.keys(workflows).map((name) => `"${name}"`).join(", ")}` : ""}.`);
54
+ const world = workflowWorldOfApp(options.app);
55
+ const workflow = resolveWorkflow(options.workflow, declared, world);
56
+ const principal = options.principal ?? workflowAuthor(workflow);
57
+ if (!isAutomated(principal))
58
+ throw new Error("A workflow runs as the app's own actor: an author that says automated: true (a system or agent seat, never a person).");
59
+ const via = options.via ?? `workflow:${workflow.name}`;
60
+ const now = options.now === undefined ? Date.now() : new Date(options.now).getTime();
61
+ const started = new Date(now).toISOString();
62
+ const id = `workflow:${workflow.name}:${started}`.slice(0, 120);
63
+ const trigger = options.trigger ?? { kind: "byHand" };
64
+ const specHash = workflowSpecHash(declared);
65
+ const previous = options.log.runs(workflow.name).filter((run) => run.outcome !== "held");
66
+ const lastGood = previous.find((run) => !run.dry && run.outcome !== "failed");
67
+ const cursor = lastGood?.through ?? 0;
68
+ const made = new Set();
69
+ const changed = new Set();
70
+ const archived = new Set();
71
+ const suggested = [];
72
+ const heldBack = [];
73
+ const notes = [];
74
+ let skipped = false;
75
+ let refused = false;
76
+ const finish = (outcome, dry, through) => {
77
+ const run = { id, workflow: workflow.name, trigger, started, finished: new Date(Math.max(now, Date.now())).toISOString(), outcome, dry, made: [...made], changed: [...changed], archived: [...archived], suggested, heldBack, through, specHash, notes };
78
+ options.log.add(run);
79
+ return run;
80
+ };
81
+ // Paused: a clock or a change starts nothing; a person's Run now is a dry run.
82
+ if (workflow.status === "paused" && trigger.kind !== "byHand") {
83
+ notes.push(`“${workflow.title}” is paused: it did not run.`);
84
+ return finish("held", true, cursor);
85
+ }
86
+ let dry = options.dryRun === true;
87
+ if (workflow.status === "paused") {
88
+ dry = true;
89
+ notes.push(`“${workflow.title}” is paused: run by hand, it is a dry run and nothing was kept.`);
90
+ }
91
+ else if (!dry && previous[0]?.specHash !== specHash) {
92
+ dry = true;
93
+ notes.push("First run after a change: nothing was kept. The next run keeps what it does.");
94
+ }
95
+ else if (dry)
96
+ notes.push("A dry run: nothing was kept.");
97
+ const asked = dry ? undefined : askedOf({ store, principal, run: id, workflow: { name: workflow.name, title: workflow.title }, via });
98
+ const follows = policiesOf(store.graph, store.schema, declared.follows);
99
+ const since = store.log.all().filter((op) => op.seq >= cursor);
100
+ const through = headOf(store);
101
+ const seen = store.seenBy(principal);
102
+ /** What a change's primitives made, changed and set aside, counted on the run. */
103
+ const count = (primitives) => {
104
+ for (const primitive of primitives) {
105
+ if (primitive.op === "add-node")
106
+ made.add(primitive.node.id);
107
+ else if (primitive.op === "patch-node" || primitive.op === "splice-text") {
108
+ if (primitive.op === "patch-node" && primitive.after[ARCHIVED] === true)
109
+ archived.add(primitive.id);
110
+ else if (!made.has(primitive.id))
111
+ changed.add(primitive.id);
112
+ }
113
+ }
114
+ };
115
+ let outcome;
116
+ try {
117
+ for (const [index, step] of workflow.steps.entries()) {
118
+ const runner = stepRunnerOf(step);
119
+ const approve = step.approve ?? workflow.approve;
120
+ const at = `Step ${index + 1}`;
121
+ if (!runner) {
122
+ skipped = true;
123
+ heldBack.push({ step: index, why: `${at} is no kind of step this build runs.` });
124
+ continue;
125
+ }
126
+ const context = {
127
+ app: options.app,
128
+ store,
129
+ seen,
130
+ workflow: { name: workflow.name, title: workflow.title },
131
+ index,
132
+ run: id,
133
+ principal,
134
+ now,
135
+ today: dayIn(now, options.app.brand?.timeZone ?? store.timeZone),
136
+ dry,
137
+ approve,
138
+ trigger,
139
+ ...(options.ai ? { ai: options.ai } : {}),
140
+ follows,
141
+ since,
142
+ change(change) {
143
+ const lineage = {
144
+ basis: change.basis.slice(0, 500),
145
+ run: id,
146
+ actor: `workflow:${workflow.name}`.slice(0, 120),
147
+ ...(change.confidence !== undefined ? { confidence: change.confidence } : {}),
148
+ ...(change.model ? { model: change.model.slice(0, 120) } : {}),
149
+ ...(change.key ? { key: change.key } : {}),
150
+ };
151
+ const calls = [...change.calls];
152
+ try {
153
+ if (dry) {
154
+ const preview = store.previewAll(calls, { author: principal, lineage, via });
155
+ count(preview.primitives);
156
+ return { as: "previewed", ops: preview.ops };
157
+ }
158
+ const route = change.ask ? "ask" : approve === "apply" ? "act" : approve === "ask" ? "ask" : routeOf(change.confidence ?? 1, change.severity ?? "categorize");
159
+ if (route === "drop")
160
+ return { as: "dropped" };
161
+ if (route === "ask") {
162
+ if ((approve === "ask" || change.ask) && asked) {
163
+ const held = asked.add(change);
164
+ if (held.as === "suggested" && held.op)
165
+ suggested.push(held.op);
166
+ return held;
167
+ }
168
+ const op = suggest(store, calls, { author: principal, lineage, via });
169
+ if (op)
170
+ suggested.push(op.id);
171
+ return { as: "suggested", ...(op ? { op: op.id } : {}) };
172
+ }
173
+ const result = store.applyAll(calls, { author: principal, lineage, via });
174
+ count(result.primitives);
175
+ return { as: "applied", ops: result.ops };
176
+ }
177
+ catch (error) {
178
+ refused = true;
179
+ heldBack.push({ step: index, why: `${at}: ${said(error)}` });
180
+ return { as: "refused", error: said(error) };
181
+ }
182
+ },
183
+ holdBack: (why) => void heldBack.push({ step: index, why: `${at}: ${why}` }),
184
+ note: (words) => void notes.push(words),
185
+ skipped(why) {
186
+ skipped = true;
187
+ heldBack.push({ step: index, why: `${at}: ${why}` });
188
+ },
189
+ };
190
+ await runner.run(step, context);
191
+ }
192
+ }
193
+ catch (error) {
194
+ notes.push(`It stopped on a failure: ${said(error)}. What it kept before stands, and running it again is safe.`);
195
+ outcome = "failed";
196
+ }
197
+ const closed = asked?.close();
198
+ if (closed)
199
+ suggested.push(closed);
200
+ if (!outcome) {
201
+ const didSomething = made.size + changed.size + archived.size + suggested.length > 0;
202
+ outcome = skipped || refused ? "partial" : didSomething ? "ok" : "nothing-new";
203
+ if (outcome === "nothing-new")
204
+ notes.push("Nothing new: everything it would do was done already.");
205
+ }
206
+ // A dry run reads nothing for good; a failed one is retried from the same place.
207
+ return finish(outcome, dry, dry || outcome === "failed" ? cursor : through);
208
+ }
209
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/workflows/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAA+F,MAAM,eAAe,CAAC;AACnJ,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC/I,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,C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"}
@@ -0,0 +1,20 @@
1
+ import type { AnySchema, GraviewApp, Store } from "@graview/core";
2
+ import type { HostAi } from "../ai.js";
3
+ import type { WorkflowTools } from "../agent/workflow-tools.js";
4
+ import type { WorkflowLog } from "./types.js";
5
+ /**
6
+ * WHAT A HOST HANDS AN OWNER'S SEAT (Roadmap f-jobs-declared): a way to run
7
+ * the app's workflows over its store, kept in its log, an agent step asking
8
+ * its model — `createToolRuntime(store, { workflows: seatWorkflows(…) })`
9
+ * then lists `run_workflow`, and with `edit` (the host's write of the
10
+ * declaration) `pause_workflow` and `resume_workflow`. A run is the app's
11
+ * own actor's, `workflow:<name>`, whoever pressed it.
12
+ */
13
+ export declare function seatWorkflows<S extends AnySchema>(options: {
14
+ readonly app: GraviewApp<S>;
15
+ readonly store: Store<S>;
16
+ readonly log: WorkflowLog;
17
+ readonly ai?: HostAi;
18
+ readonly edit?: WorkflowTools["edit"];
19
+ }): WorkflowTools;
20
+ //# sourceMappingURL=seat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seat.d.ts","sourceRoot":"","sources":["../../src/workflows/seat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,EAAE,OAAO,EAAE;IAC1D,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACvC,GAAG,aAAa,CAgBhB"}
@@ -0,0 +1,27 @@
1
+ import { declaredWorkflows } from "@graview/core/workflows";
2
+ import { runWorkflow } from "./run.js";
3
+ /**
4
+ * WHAT A HOST HANDS AN OWNER'S SEAT (Roadmap f-jobs-declared): a way to run
5
+ * the app's workflows over its store, kept in its log, an agent step asking
6
+ * its model — `createToolRuntime(store, { workflows: seatWorkflows(…) })`
7
+ * then lists `run_workflow`, and with `edit` (the host's write of the
8
+ * declaration) `pause_workflow` and `resume_workflow`. A run is the app's
9
+ * own actor's, `workflow:<name>`, whoever pressed it.
10
+ */
11
+ export function seatWorkflows(options) {
12
+ return {
13
+ // Read at each call: a pause the host wrote is what the next call sees.
14
+ declared: () => Object.entries(declaredWorkflows(options.app) ?? {}).map(([name, one]) => ({ name, title: one.title, status: one.status === "paused" ? "paused" : "active" })),
15
+ run: (name, { dryRun, who }) => runWorkflow({
16
+ app: options.app,
17
+ store: options.store,
18
+ workflow: name,
19
+ log: options.log,
20
+ trigger: { kind: "byHand", ...(who !== undefined ? { who } : {}) },
21
+ ...(dryRun ? { dryRun: true } : {}),
22
+ ...(options.ai ? { ai: options.ai } : {}),
23
+ }),
24
+ ...(options.edit ? { edit: options.edit } : {}),
25
+ };
26
+ }
27
+ //# sourceMappingURL=seat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seat.js","sourceRoot":"","sources":["../../src/workflows/seat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAsB,OAMlD;IACC,OAAO;QACL,wEAAwE;QACxE,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9K,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,CAC7B,WAAW,CAAC;YACV,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,IAAI;YACd,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;YAClE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1C,CAAC;QACJ,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { WorkflowStep } from "@graview/core/workflows";
2
+ import type { StepRunner } from "./types.js";
3
+ /** Every kind of step, run, by the key `STEP_KINDS` tells it apart by. A new kind: its file, and one line here. */
4
+ export declare const STEP_RUNNERS: Readonly<Record<string, StepRunner<never>>>;
5
+ /** The runner for a step, by the one key of `STEP_RUNNERS` it holds. */
6
+ export declare function stepRunnerOf(step: WorkflowStep): StepRunner<WorkflowStep> | undefined;
7
+ //# sourceMappingURL=steps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/workflows/steps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAM5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,mHAAmH;AACnH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAMpE,CAAC;AAEF,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,GAAG,SAAS,CAGrF"}
@@ -0,0 +1,21 @@
1
+ import { runActStep } from "./run-act.js";
2
+ import { runAgentStep } from "./run-agent.js";
3
+ import { runGenerateStep } from "./run-generate.js";
4
+ import { runArchiveStep } from "./run-archive.js";
5
+ import { runClassifyStep } from "./run-classify.js";
6
+ /** Every kind of step, run, by the key `STEP_KINDS` tells it apart by. A new kind: its file, and one line here. */
7
+ export const STEP_RUNNERS = {
8
+ act: runActStep,
9
+ agent: runAgentStep,
10
+ generate: runGenerateStep,
11
+ archive: runArchiveStep,
12
+ classify: runClassifyStep,
13
+ };
14
+ /** The runner for a step, by the one key of `STEP_RUNNERS` it holds. */
15
+ export function stepRunnerOf(step) {
16
+ for (const key of Object.keys(STEP_RUNNERS))
17
+ if (key in step)
18
+ return STEP_RUNNERS[key];
19
+ return undefined;
20
+ }
21
+ //# sourceMappingURL=steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"steps.js","sourceRoot":"","sources":["../../src/workflows/steps.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,mHAAmH;AACnH,MAAM,CAAC,MAAM,YAAY,GAAgD;IACvE,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,YAAY;IACnB,QAAQ,EAAE,eAAe;IACzB,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,eAAe;CAC1B,CAAC;AAEF,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,IAAkB;IAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,IAAI,GAAG,IAAI,IAAI;YAAE,OAAO,YAAY,CAAC,GAAG,CAAwC,CAAC;IAC9H,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,164 @@
1
+ import type { AnySchema, Author, GraviewApp, MutationCall, Operation, Store, Via } from "@graview/core";
2
+ import type { WorkflowApproval, WorkflowPolicy, WorkflowStep } from "@graview/core/workflows";
3
+ import type { HostAi } from "../ai.js";
4
+ import type { Severity } from "../tidy/policy.js";
5
+ /** What became of a run as a whole. */
6
+ export type WorkflowOutcome =
7
+ /** It did what it was declared to. */
8
+ "ok"
9
+ /** It ran and there was nothing new to do. */
10
+ | "nothing-new"
11
+ /** Some of it did not run — a step skipped (no model lent), or refused — and the rest did. */
12
+ | "partial"
13
+ /** It did not run: paused, or held back as a whole. */
14
+ | "held"
15
+ /** It stopped on a failure; what it kept before the failure stands, and a rerun is safe. */
16
+ | "failed";
17
+ /** What started a run. */
18
+ export type WorkflowRunTrigger = {
19
+ readonly kind: "schedule";
20
+ readonly at: string;
21
+ } | {
22
+ readonly kind: "made" | "changed";
23
+ readonly records: readonly string[];
24
+ } | {
25
+ readonly kind: "synced";
26
+ readonly connection: string;
27
+ } | {
28
+ readonly kind: "byHand";
29
+ readonly who?: string;
30
+ };
31
+ /** One run, as a host keeps it. */
32
+ export interface WorkflowRun {
33
+ /** `workflow:<name>:<started>`: on every op the run made, as `lineage.run`. */
34
+ readonly id: string;
35
+ readonly workflow: string;
36
+ readonly trigger: WorkflowRunTrigger;
37
+ readonly started: string;
38
+ readonly finished: string;
39
+ readonly outcome: WorkflowOutcome;
40
+ /** Nothing was kept: a dry run says what it would have done. */
41
+ readonly dry: boolean;
42
+ readonly made: readonly string[];
43
+ readonly changed: readonly string[];
44
+ readonly archived: readonly string[];
45
+ /** The ops that hold what it suggested. */
46
+ readonly suggested: readonly string[];
47
+ /** What it held back, by step (its index), and why, in words. */
48
+ readonly heldBack: readonly {
49
+ readonly step: number;
50
+ readonly why: string;
51
+ }[];
52
+ /** How far it read the log: every op before this seq. The next run reads from here (`StepContext.since`); a dry or failed run leaves it where the last good run had it. */
53
+ readonly through: number;
54
+ /** A hash of the workflow as declared when it ran: the first run after a change is a dry run. */
55
+ readonly specHash: string;
56
+ /** What it says, in sentences, in order. */
57
+ readonly notes: readonly string[];
58
+ }
59
+ /** The host's log of runs: the last of a workflow's, all of them newest first, and keeping one. */
60
+ export interface WorkflowLog {
61
+ last(name: string): WorkflowRun | undefined;
62
+ add(run: WorkflowRun): void;
63
+ runs(name: string, limit?: number): readonly WorkflowRun[];
64
+ }
65
+ export interface RunWorkflowOptions<S extends AnySchema = AnySchema> {
66
+ /** The app: its declaration says the workflow; its brand the clock. */
67
+ readonly app: GraviewApp<S>;
68
+ /** The store that keeps the log — a server's, for a hosted app. */
69
+ readonly store: Store<S>;
70
+ /** Which workflow, by name. */
71
+ readonly workflow: string;
72
+ /** The run's moment. Now when unsaid. */
73
+ readonly now?: Date | string | number;
74
+ /** What started it. By hand when unsaid. */
75
+ readonly trigger?: WorkflowRunTrigger;
76
+ /** Keep nothing; say what it would do. A run by hand of a paused workflow, and the first run after a change, are dry whatever this says. */
77
+ readonly dryRun?: boolean;
78
+ /** Where the runs are kept. */
79
+ readonly log: WorkflowLog;
80
+ /** The host's AI, for an agent step: its `complete` proposes. Without one an agent step is skipped. */
81
+ readonly ai?: HostAi;
82
+ /** Who runs: an automated system author, `workflow:<name>` named by its title, when unsaid. */
83
+ readonly principal?: Author;
84
+ /** What its changes come through, as the log records it. `workflow:<name>` when unsaid. */
85
+ readonly via?: Via;
86
+ }
87
+ /** One change a step would make, before what `approve` makes of it. */
88
+ export interface StepChange {
89
+ readonly calls: readonly MutationCall[];
90
+ /** Why, in words: on the lineage. */
91
+ readonly basis: string;
92
+ /** How sure: 1 for a deterministic step. */
93
+ readonly confidence?: number;
94
+ /** How much it would undo, for `suggest`'s routing. "categorize" when unsaid. */
95
+ readonly severity?: Severity;
96
+ /** The model that proposed it. */
97
+ readonly model?: string;
98
+ /** The stable key of what it makes (an act step's `key`), kept on the lineage. */
99
+ readonly key?: string;
100
+ /** It waits for a person whatever `approve` says: a label a host shows the public (a classify step's `confirm`). */
101
+ readonly ask?: boolean;
102
+ }
103
+ /** What `StepContext.change` did with one change. */
104
+ export type ChangeOutcome = {
105
+ readonly as: "applied";
106
+ readonly ops: readonly Operation[];
107
+ } | {
108
+ readonly as: "previewed";
109
+ readonly ops: readonly Operation[];
110
+ } | {
111
+ readonly as: "suggested";
112
+ readonly op?: string;
113
+ } | {
114
+ readonly as: "dropped" | "unchanged";
115
+ } | {
116
+ readonly as: "refused";
117
+ readonly error: string;
118
+ };
119
+ /** What a step runner is handed: the store, the run, and the one door every change goes through. */
120
+ export interface StepContext<S extends AnySchema = AnySchema> {
121
+ readonly app: GraviewApp<S>;
122
+ /** The store, whole; read it as the run's principal sees it with `seen`. */
123
+ readonly store: Store<AnySchema>;
124
+ /** The store as the run's principal sees it. */
125
+ readonly seen: Store<AnySchema>;
126
+ readonly workflow: {
127
+ readonly name: string;
128
+ readonly title: string;
129
+ };
130
+ /** The step's place in the workflow. */
131
+ readonly index: number;
132
+ readonly run: string;
133
+ readonly principal: Author;
134
+ readonly now: number;
135
+ /** The run's day on the app's clock: what `$today` reads. */
136
+ readonly today: string;
137
+ readonly dry: boolean;
138
+ /** What this step's changes become: its own word, else the workflow's, else the default. */
139
+ readonly approve: WorkflowApproval;
140
+ readonly trigger: WorkflowRunTrigger;
141
+ readonly ai?: HostAi;
142
+ /** The policy records the workflow follows (`follows`), read once for the run; none when it follows none. */
143
+ readonly follows: readonly WorkflowPolicy[];
144
+ /** The ops from the last good run's `through` on: what was made and changed since it. */
145
+ readonly since: readonly Operation[];
146
+ /**
147
+ * THE ONE DOOR: a change made, previewed (a dry run), suggested or let
148
+ * go by `approve` and its confidence, with the run's lineage, and what it
149
+ * made, changed and set aside counted on the run.
150
+ */
151
+ change(change: StepChange): ChangeOutcome;
152
+ /** Hold something back, said in words. */
153
+ holdBack(why: string): void;
154
+ /** Say something on the run. */
155
+ note(said: string): void;
156
+ /** The step did not run, and the run is `partial` for it. */
157
+ skipped(why: string): void;
158
+ }
159
+ /** One kind of step, run: keyed as `STEP_KINDS` is. */
160
+ export interface StepRunner<Step extends WorkflowStep = WorkflowStep> {
161
+ readonly key: string;
162
+ run(step: Step, context: StepContext): Promise<void>;
163
+ }
164
+ //# sourceMappingURL=types.d.ts.map