@parcha/agentrun-pi 0.1.0-beta.20 → 0.1.0-beta.21

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 CHANGED
@@ -17,9 +17,11 @@ pi install npm:@parcha/agentrun-pi@beta -l
17
17
  pi --offline
18
18
  ```
19
19
 
20
- `-l` writes project settings in `.pi/settings.json`. Omit it to install for all your Pi sessions. `--offline` skips startup downloads; it does not disable model calls. No AgentRun checkout or build is needed.
20
+ `pi --offline` opens Pi's terminal interface, so run it in an interactive terminal; with no terminal attached it prints nothing and exits. `-l` writes project settings in `.pi/settings.json`. Omit it to install for all your Pi sessions. `--offline` skips startup downloads; it does not disable model calls. No AgentRun checkout or build is needed.
21
21
 
22
- On first launch, Pi asks whether you trust the project before loading its extension. If Pi is already open, use `/reload`. The current draft is restored from a persisted Pi session branch when available; named definition saves are stored separately.
22
+ On first launch, Pi asks "Trust project folder?" before loading the extension, with five choices: Trust, Trust parent folder, Trust (this session only), Do not trust, and Do not trust (this session only). Choose Trust, or Trust (this session only), to load it. If Pi is already open, use `/reload`. The current draft is restored from a persisted Pi session branch when available; named definition saves are stored separately.
23
+
24
+ With no model configured, `pi --offline` prints two warnings at startup: `Warning: fd not found. Offline mode enabled, skipping download.` (the optional `fd` tool is not installed and `--offline` skips fetching it) and `Warning: No models available. Use /login to log into a provider via OAuth or API key.` Both are expected here and the scripted demo needs neither. The `[Skills]` list shows `agentrun-author` and the `[Extensions]` list shows `@parcha/agentrun-pi` when the extension loaded.
23
25
 
24
26
  For live tasks, configure model access in Pi first. AgentRun uses Pi's current model and authentication; it needs no separate model configuration. The scripted demo below works without provider access.
25
27
 
@@ -43,6 +45,8 @@ For an offline Pi startup, use `pi --offline`. Without that flag, Pi may downloa
43
45
 
44
46
  ## Preview, run, save, reuse
45
47
 
48
+ **This section needs a configured model.** Authoring a workflow from a task is a model call, so the preview below, and the `input`, `run`, `save` and `load` steps after it, are for a Pi with a model selected. With no model, `/agentrun <task>` answers `AgentRun requires an active Pi model. Use /login to connect a provider, then /model to select it. Try /agentrun demo without model access.` and `/agentrun demo` (above) is the one workflow you have: `/agentrun input`, `run` and `save` act on that scripted demo, not on a release review.
49
+
46
50
  ```text
47
51
  /agentrun Preview a reusable workflow that identifies breaking changes and migration actions in supplied release notes. Do not run it yet.
48
52
  ```
@@ -84,7 +88,7 @@ Loading starts with empty input and does not execute. A save retains the definit
84
88
 
85
89
  A progress widget shows active steps and the number finished. Results distinguish completion, escalation, failure, and interruption. Decision records show supplied evidence, criteria, answer, and route, not hidden reasoning or proof of correctness.
86
90
 
87
- Pi 1.1.0 cannot export a fresh session containing only slash-command results. To save an offline research receipt from the checkout, run `node examples/research-live.mjs --out research-result.json`. This runs the scripted example again and writes its result; it does not export the Pi session.
91
+ Pi 1.1.0 cannot export a fresh session containing only slash-command results. To save an offline research receipt, run [`examples/research-live.mjs`](https://github.com/Parcha-ai/agentrun/blob/main/examples/research-live.mjs) from a checkout of the repository (the `examples/` directory is in the repository, not in the npm package): `node examples/research-live.mjs --out research-result.json`. This runs the scripted example again and writes its result; it does not export the Pi session.
88
92
 
89
93
  A live run is durable. Its journal is kept in `.pi/agentrun/runs/<run id>/journal.json`, and `/agentrun run` after an interruption (`/agentrun stop`, a closed session, a killed process) or a failure continues the same run: committed steps are answered from the journal, a tool call that completed is answered from its receipt and is not made again, and the next step runs. The run is bound to its workflow, input, SOP text and tool names; a change to any of them starts a new run. A tool call that was in flight when the run stopped has an unknown outcome and is never made again: the resumed run fails naming it, and the person who knows whether it happened reconciles it before a new run. An agent step that was interrupted starts over from its first turn. A run that completed or escalated is not resumed; `/agentrun run` starts a new one. Scripted demos keep no journal.
90
94
 
@@ -103,13 +107,14 @@ const revisions = await store.list(); // every revision,
103
107
 
104
108
  The argument is a project directory, not the workflows directory: the extension keeps its records for `ctx.cwd` in the same place, so a host that passes that directory and the extension read each other's records. Storage needs real directories and regular files (a symbolic link in the path or among the records fails with `WorkflowStoreError` code `unsafe_path`), and every load checks the record's metadata and the SHA-256 of its workflow. A `<name>/` directory copied into the workflows directory loads. A saved workflow is a procedure, not authority: the host still checks it against its current capabilities before it runs.
105
109
 
106
- ### Three demo modes
110
+ ### Demo modes
107
111
 
108
112
  | Command | What it demonstrates |
109
113
  | --- | --- |
110
114
  | `/agentrun demo` | Scripted successful execution over the bundled fictional sources, without model calls. |
111
115
  | `/agentrun demo empty` | Scripted insufficient-evidence path, without model calls. |
112
116
  | `/agentrun demo live` | Real Pi agent steps and Jev system one decisions over the same fictional sources. |
117
+ | `/agentrun triage` | A second scripted workflow, support-ticket triage over a fictional ticket, without model calls. |
113
118
 
114
119
  Live mode uses your active Pi model and requires configured TypeSafe access for Jev. It still does not search the web or prove accuracy on real research. See the [Jev adapter configuration](https://github.com/Parcha-ai/agentrun/tree/main/packages/jev#readme). Live calls can incur usage charges; scripted mode needs no provider access.
115
120
 
@@ -160,7 +165,7 @@ The native model-facing interface starts with `agentrun` and `action: "describe"
160
165
 
161
166
  ### Configure the native extension from a host
162
167
 
163
- Hosts that own a restricted corpus, an approved Jev transport, or shared accounting can configure the same native extension:
168
+ Hosts that own a restricted corpus, an approved Jev transport, or shared accounting can configure the same native extension. This is a sketch, not a runnable sample: `approvedToolsFor`, `makeHostJudge` and `sharedBudget` stand for your own host's code. See [Integrate with your application](../../docs/host-integration.md) for what a host supplies.
164
169
 
165
170
  ```js
166
171
  import { createAgentRunExtension } from '@parcha/agentrun-pi/extension';
@@ -201,7 +206,7 @@ An operator may select a different active Pi model between inspection and execut
201
206
 
202
207
  ## SDK: embed the runner
203
208
 
204
- The native extension handles configuration above. For another Pi extension that already has a context:
209
+ The native extension handles configuration above. For another Pi extension that already has a context, this sketch shows the call (not runnable as it stands: `ctx` is the context Pi hands your extension, and `workflow`, `input` and `allowedTools` are yours; see [Integrate with your application](../../docs/host-integration.md)):
205
210
 
206
211
  ```js
207
212
  import { runWorkflow } from '@parcha/agentrun-dsl';
@@ -223,7 +228,7 @@ The child model delivers `{value: result}` through its `submit` tool. Schema and
223
228
 
224
229
  ## SDK: retain candidates and check fixed fixtures
225
230
 
226
- `authorWorkflow` lives in `@parcha/agentrun-dsl` beside the language it teaches. It saves candidate files separately from the native extension's current draft and named procedure revisions. Give it a Pi runner with no host tools, and bound its submissions by the candidate limit:
231
+ `authorWorkflow` lives in `@parcha/agentrun-dsl` beside the language it teaches. It saves candidate files separately from the native extension's current draft and named procedure revisions. Give it a Pi runner with no host tools, and bound its submissions by the candidate limit. This is a sketch, not runnable as it stands: `options` is your configured `PiRunnerOptions` and `checkAgainstYourFixtures` is your own function (see [Integrate with your application](../../docs/host-integration.md)):
227
232
 
228
233
  ```js
229
234
  import { authorWorkflow } from '@parcha/agentrun-dsl';
@@ -244,11 +249,20 @@ The host owns `checkAgainstYourFixtures`: return diagnostics, or `[]` to accept.
244
249
 
245
250
  With `rubricSections`, every supplied section must appear on every generated LLM node, including child workflows. The author conservatively rejects Jev nodes, semantic `ask` predicates, and `verify` clauses under that policy; those need a separately reviewed question contract. Schema properties named `node`, `verify`, or `predicate` remain ordinary data. Supply the authoritative rubric as `deps.sop` when executing the candidate.
246
251
 
247
- The standalone CLI remains available as `node packages/pi/dist/cli.js --help` from source. It imports a trusted caller-owned `--config` module for `author` and `run`; importing that module executes its code. `validate` can evaluate code probes. Review executable workflows before using it.
252
+ The package also installs a command line, `agentrun-pi`. Try it from an empty directory after `npm install @parcha/agentrun-pi@beta`:
253
+
254
+ ```sh
255
+ npx agentrun-pi --help
256
+ npx agentrun-pi demo
257
+ cp node_modules/@parcha/agentrun-dsl/skills/author/examples/review-release-notes.json workflow.json
258
+ npx agentrun-pi validate workflow.json --inputs notes
259
+ ```
260
+
261
+ `--inputs` names the keys of the workflow's input object; `review-release-notes.json` takes one, `notes`. `demo` needs no key and no peers. `author` and `run` import a trusted caller-owned `--config` module (its code runs when imported) that exports your runner options, and need the peers listed under Dependencies. `validate` can evaluate code probes. Review executable workflows before using it.
248
262
 
249
263
  ## Sign in, pick a model, check keys
250
264
 
251
- `@parcha/agentrun-pi/signin` is what a demo, or your own app, runs before its first model call. It is the only entry of this package that loads `@earendil-works/pi-ai`, an optional peer: install it beside the package (`npm install @earendil-works/pi-ai`) to use this entry. No other entry imports it.
265
+ `@parcha/agentrun-pi/signin` is what a demo, or your own app, runs before its first model call. The sample below is a sketch, not runnable as written: `spec` is a demo's spec (the `demo.json` of an example in the repository's `examples/` directory), and `provider`, `modelId` and `context` are your app's. It is the only entry of this package that loads `@earendil-works/pi-ai`, an optional peer: install it beside the package (`npm install @earendil-works/pi-ai`) to use this entry. No other entry imports it.
252
266
 
253
267
  ```js
254
268
  import { builtinModels } from '@earendil-works/pi-ai/providers/all';
@@ -47,6 +47,10 @@ function json(value) {
47
47
  return item;
48
48
  }));
49
49
  }
50
+ /** A journal effect from its stored document. */
51
+ function storedEffect(id, e) {
52
+ return { id, name: e.name, argsHash: e.argsHash, status: e.status, session: e.session, result: json(e.result), ...(e.intent ? { intent: json(e.intent) } : {}), ...(e.args !== undefined ? { args: json(e.args) } : {}), ...(Array.isArray(e.calls) ? { calls: json(e.calls) } : {}) };
53
+ }
50
54
  /** The journals open in this process. The run's lock keeps every other process off the run, and the journal's generation
51
55
  * fences a stale writer; this keeps a second open of one key off it here. Without an owner a host's own keys are
52
56
  * tracked; with one, the keys by owner. */
@@ -100,8 +104,7 @@ async function openDocumentJournal(host, key, bound, options) {
100
104
  doc.generation += 1;
101
105
  const effects = [];
102
106
  for (const id of doc.effects) {
103
- const e = await tx.doc(EffectDoc, effectKey(key, id), null);
104
- effects.push({ id, name: e.name, argsHash: e.argsHash, status: e.status, session: e.session, result: json(e.result), ...(e.intent ? { intent: json(e.intent) } : {}), ...(e.args !== undefined ? { args: json(e.args) } : {}), ...(Array.isArray(e.calls) ? { calls: json(e.calls) } : {}) });
107
+ effects.push(storedEffect(id, await tx.doc(EffectDoc, effectKey(key, id), null)));
105
108
  }
106
109
  return { existing, generation: doc.generation, revision: doc.revision, state: json(doc.state), notes: json(doc.notes), effects };
107
110
  }, context).catch((error) => { held.undo(); throw storeFailure(error); });
@@ -142,7 +145,6 @@ async function openDocumentJournal(host, key, bound, options) {
142
145
  }, context).then((done) => { revision = done.revision; return done; });
143
146
  /** A read in a commit of its own: it writes nothing the caller did not ask for. */
144
147
  const read = (body) => inOrder(() => host.commit(body, context));
145
- const storedEffect = (id, e) => ({ id, name: e.name, argsHash: e.argsHash, status: e.status, session: e.session, result: json(e.result), ...(e.intent ? { intent: json(e.intent) } : {}), ...(e.args !== undefined ? { args: json(e.args) } : {}), ...(Array.isArray(e.calls) ? { calls: json(e.calls) } : {}) });
146
148
  return {
147
149
  existing: opened.existing, generation: opened.generation, state: opened.state,
148
150
  get revision() { return revision; },
package/dist/extension.js CHANGED
@@ -40,6 +40,8 @@ function singleTextInput(workflow) {
40
40
  }
41
41
  const nativeLimits = Object.freeze({ deadlineMs: 600_000, modelRequests: 50, judgeCalls: 100, toolAttempts: 100,
42
42
  nodeMaxTurns: 8, nodeMaxSubmissions: 3, nodeTimeoutMs: 120_000 });
43
+ /** Forgets a session's last run (its observation, report and run id), so the next run starts fresh. */
44
+ const clearRun = (s) => { s.observation = undefined; s.report = undefined; s.runId = undefined; };
43
45
  /** Configure the native extension without granting configuration to workflow authors. */
44
46
  export function createAgentRunExtension(options = {}) {
45
47
  if (options.hostTools !== undefined && typeof options.hostTools !== 'function')
@@ -188,15 +190,10 @@ function registerExtension(pi, configuration) {
188
190
  if (changed) {
189
191
  s.demo = undefined;
190
192
  s.savedName = undefined;
191
- s.observation = undefined;
192
- s.report = undefined;
193
- s.runId = undefined;
194
- }
195
- if (input !== undefined) {
196
- s.observation = undefined;
197
- s.report = undefined;
198
- s.runId = undefined;
193
+ clearRun(s);
199
194
  }
195
+ if (input !== undefined)
196
+ clearRun(s);
200
197
  s.input = nextInput;
201
198
  if (workflow !== undefined || input !== undefined)
202
199
  persist(s);
@@ -382,8 +379,9 @@ function registerExtension(pi, configuration) {
382
379
  persist(s, true);
383
380
  const ordinal = ++runOrdinal;
384
381
  let sequence = 0;
382
+ const runDeps = sop ? { ...deps, sop: sop.text } : deps;
385
383
  const report = await s.service.run(s.input, {
386
- deps: observation.observe(driver ? withRecovery(driver, sop ? { ...deps, sop: sop.text } : deps) : sop ? { ...deps, sop: sop.text } : deps),
384
+ deps: observation.observe(driver ? withRecovery(driver, runDeps) : runDeps),
387
385
  signal: driver ? AbortSignal.any([signal, driver.signal]) : signal,
388
386
  ...(configuration.onWorkflowEvent ? { onTraceEvent: (event) => configuration.onWorkflowEvent({ workflowDigest: prepared.digest, runOrdinal: ordinal, sequence: ++sequence, event }) } : {}),
389
387
  onEvent: event => {
@@ -515,9 +513,7 @@ function registerExtension(pi, configuration) {
515
513
  s.input = structuredClone(args.input ?? {});
516
514
  s.savedName = saved.name;
517
515
  s.demo = undefined;
518
- s.report = undefined;
519
- s.observation = undefined;
520
- s.runId = undefined;
516
+ clearRun(s);
521
517
  persist(s);
522
518
  const preview = view(ctx, s);
523
519
  return textResult(modelJson({ preview: formatWorkflowView(preview), workflow: s.draft, input: s.input }), { ...result, saved, view: preview });
@@ -610,9 +606,7 @@ function registerExtension(pi, configuration) {
610
606
  s.savedName = saved.name;
611
607
  s.input = {};
612
608
  s.demo = undefined;
613
- s.report = undefined;
614
- s.observation = undefined;
615
- s.runId = undefined;
609
+ clearRun(s);
616
610
  persist(s);
617
611
  show(s, `Loaded procedure. Supply new input with /agentrun input. Loading never executes it.\n\n${formatWorkflowView(view(ctx, s))}`);
618
612
  }
@@ -124,7 +124,7 @@ function snapshotEntry(entry) {
124
124
  return undefined;
125
125
  }
126
126
  }
127
- function interrupted(s) {
127
+ function markInterrupted(s) {
128
128
  if (!s.running)
129
129
  return s;
130
130
  s.running = false;
@@ -145,7 +145,7 @@ export function restoreWorkflowSession(branch) {
145
145
  for (let i = branch.length - 1; i >= 0; i--) {
146
146
  const snapshot = snapshotEntry(Object.getOwnPropertyDescriptor(branch, String(i))?.value);
147
147
  if (snapshot)
148
- return interrupted(snapshot);
148
+ return markInterrupted(snapshot);
149
149
  }
150
150
  return undefined;
151
151
  }
@@ -162,7 +162,7 @@ export function workflowRunHistory(branch) {
162
162
  if (seen.has(key))
163
163
  continue;
164
164
  seen.add(key);
165
- results.push(interrupted(snapshot));
165
+ results.push(markInterrupted(snapshot));
166
166
  }
167
167
  return results;
168
168
  }
@@ -11,11 +11,11 @@ export class WorkflowStoreError extends Error {
11
11
  this.name = 'WorkflowStoreError';
12
12
  }
13
13
  }
14
- const validName = (name) => {
14
+ const assertValidName = (name) => {
15
15
  if (typeof name !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(name))
16
16
  throw new WorkflowStoreError('invalid_name', 'Use a workflow name of 1–64 lowercase letters, digits, hyphens or underscores, starting with a letter or digit.');
17
17
  };
18
- const validDigest = (digest) => {
18
+ const assertValidDigest = (digest) => {
19
19
  if (typeof digest !== 'string' || !/^[a-f0-9]{64}$/.test(digest))
20
20
  throw new WorkflowStoreError('invalid_revision', 'A workflow revision must be its complete SHA-256 digest.');
21
21
  };
@@ -50,7 +50,7 @@ export class WorkflowStore {
50
50
  constructor(projectDirectory) { this.projectDirectory = resolve(projectDirectory); }
51
51
  async directory(name, create = false) {
52
52
  if (name !== undefined)
53
- validName(name);
53
+ assertValidName(name);
54
54
  let directory = await realpath(this.projectDirectory);
55
55
  for (const component of ['.pi', 'agentrun', 'workflows', ...(name === undefined ? [] : [name])]) {
56
56
  directory = join(directory, component);
@@ -78,8 +78,8 @@ export class WorkflowStore {
78
78
  return directory;
79
79
  }
80
80
  async read(name, digest) {
81
- validName(name);
82
- validDigest(digest);
81
+ assertValidName(name);
82
+ assertValidDigest(digest);
83
83
  const directory = await this.directory(name);
84
84
  if (!directory)
85
85
  throw new WorkflowStoreError('not_found', 'Saved workflow revision not found.');
@@ -159,7 +159,7 @@ export class WorkflowStore {
159
159
  const revisions = [];
160
160
  const latest = new Map();
161
161
  for (const name of await readdir(directory)) {
162
- validName(name);
162
+ assertValidName(name);
163
163
  const child = await this.directory(name);
164
164
  if (!child)
165
165
  continue;
@@ -180,7 +180,7 @@ export class WorkflowStore {
180
180
  || Number(b.digest === latest.get(b.name)) - Number(a.digest === latest.get(a.name)) || a.digest.localeCompare(b.digest));
181
181
  }
182
182
  async load(name, digest) {
183
- validName(name);
183
+ assertValidName(name);
184
184
  if (digest !== undefined)
185
185
  return this.read(name, digest);
186
186
  const latest = await this.latest(name);
@@ -197,7 +197,7 @@ export class WorkflowStore {
197
197
  }
198
198
  /** Publish a complete immutable revision atomically; identical saves are idempotent. */
199
199
  async save(name, value) {
200
- validName(name);
200
+ assertValidName(name);
201
201
  const { workflow, digest } = checkedWorkflow(value);
202
202
  const directory = (await this.directory(name, true));
203
203
  const temporary = join(directory, `.pending-${randomUUID()}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-pi",
3
- "version": "0.1.0-beta.20",
3
+ "version": "0.1.0-beta.21",
4
4
  "description": "Pi extension for building, running and evaluating AgentRun workflows",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -50,12 +50,12 @@
50
50
  "@earendil-works/pi-coding-agent": "1.1.0",
51
51
  "@earendil-works/pi-durable": "1.1.0",
52
52
  "@earendil-works/pi-tui": "1.1.0",
53
- "@parcha/pi-durable-disk": "0.1.0-beta.20",
53
+ "@parcha/pi-durable-disk": "0.1.0-beta.21",
54
54
  "typebox": "1.3.7"
55
55
  },
56
56
  "dependencies": {
57
- "@parcha/agentrun-dsl": "0.1.0-beta.20",
58
- "@parcha/agentrun-jev": "0.1.0-beta.20"
57
+ "@parcha/agentrun-dsl": "0.1.0-beta.21",
58
+ "@parcha/agentrun-jev": "0.1.0-beta.21"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@earendil-works/pi-agent-core": "*",