@llblab/pi-actors 0.49.2 → 0.50.0

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.
@@ -27,14 +27,14 @@ const asRecord = ToolsResponse.asRecord;
27
27
  const maybeJsonText = ToolsResponse.maybeJsonText;
28
28
  function runtimeStatus() {
29
29
  return {
30
- automatic_review: process.env.PI_ACTORS_AUTOMATIC_REVIEW !== "off",
30
+ automatic_review: Paths.isAutomaticRecipeReviewEnabled(),
31
31
  run_root: Paths.getRunStateRoot(),
32
32
  state_schema: RuntimeIdentity.RUN_STATE_SCHEMA,
33
33
  version: RuntimeIdentity.getPackageVersion(),
34
34
  };
35
35
  }
36
36
  function runtimeRuns(ctx, deps, status) {
37
- const session = ToolsAccess.getContextSessionId(ctx);
37
+ const session = ToolsAccess.requireContextSessionId(ctx, "runtime Run inventory");
38
38
  const listed = deps.listRuns
39
39
  ? deps.listRuns()
40
40
  : AsyncRuns.listRuns(undefined, status);
@@ -49,8 +49,8 @@ function runtimeRuns(ctx, deps, status) {
49
49
  return run;
50
50
  }
51
51
  })
52
- .filter((run) => !session || !run.ownerId || run.ownerId === session);
53
- return { ...(session ? { owner_session: session } : {}), runs };
52
+ .filter((run) => run.ownerId === session);
53
+ return { owner_session: session, runs };
54
54
  }
55
55
  function runtimeTriage(ctx, deps) {
56
56
  const inventory = runtimeRuns(ctx, deps, undefined);
@@ -354,7 +354,7 @@ function inspectRun(run, view, input, ctx, deps) {
354
354
  throw new Error("inspect run:<id> supports view=recipe, view=trace, or view=control.");
355
355
  }
356
356
  const status = deps.getRunStatus
357
- ? deps.getRunStatus(run)
357
+ ? ToolsAccess.assertRunStatusAccessibleToContext(run, deps.getRunStatus(run), ctx)
358
358
  : ToolsAccess.assertRunAccessibleToContext(run, ctx);
359
359
  const stateDir = String(status.state_dir);
360
360
  if (view === "recipe") {
@@ -4,6 +4,7 @@
4
4
  * Owns public Control execution; journaling, delivery, and lifecycle mutation stay in Run domains.
5
5
  */
6
6
  export interface ControlToolDeps {
7
+ getRunStatus?: (run: string) => Record<string, unknown>;
7
8
  handleRuntimeControl?: (action: string, input: unknown) => Record<string, unknown>;
8
9
  }
9
10
  export declare function createControlToolDefinition<TContext = unknown>(deps?: ControlToolDeps): any;
@@ -67,7 +67,9 @@ export function createControlToolDefinition(deps = {}) {
67
67
  }
68
68
  else {
69
69
  const run = request.target.slice(4);
70
- const status = ToolsAccess.assertRunAccessibleToContext(run, ctx);
70
+ const status = deps.getRunStatus
71
+ ? ToolsAccess.assertRunStatusAccessibleToContext(run, deps.getRunStatus(run), ctx)
72
+ : ToolsAccess.assertRunAccessibleToContext(run, ctx);
71
73
  const runInstanceId = typeof status.run_instance_id === "string"
72
74
  ? status.run_instance_id
73
75
  : undefined;
package/docs/README.md CHANGED
@@ -8,6 +8,7 @@ Living index of all documentation in the `/docs` directory.
8
8
  - [template-recipes.md](./template-recipes.md) — Saved JSON/Markdown recipe standard, imports, and reusable command-template graph composition
9
9
  - [async-runs.md](./async-runs.md) — Run lifecycle, state, Control, Trace, cancellation, and terminal reconciliation
10
10
  - [actor-inspector.md](./actor-inspector.md) — Owner-filtered actor-instance navigation through Recipe, Trace, and Control
11
+ - [inspection.md](./inspection.md) — Complete `inspect` target/view matrix, authorization boundaries, and diagnostic routes
11
12
  - [tool-registry.md](./tool-registry.md) — Local `pi-actors` registry storage and `register_tool` adaptation
12
13
  - [recipe-library.md](./recipe-library.md) — Packaged standard recipe library such as async subagents, coordinator pipelines, utilities, and music playback
13
14
  - [releasing.md](./releasing.md) — Guarded tag validation, npm Trusted Publisher setup, registry verification, and GitHub Release convergence
@@ -19,13 +19,13 @@ Shows captured execution provenance:
19
19
  - declared artifacts and actor-local actions;
20
20
  - model/thinking policy and launch source.
21
21
 
22
- Captured Recipe evidence belongs to the Run generation and does not change when an active Recipe file later changes. Skill components display logical identities such as `artifacts/report`; private physical `source_file`, `skill_dir`, and `recipe_dir` stay out of Inspector and model-facing views. Non-empty object values render as indented brace-delimited property lists rather than flattened inline strings.
22
+ Captured Recipe evidence belongs to the Run generation and does not change when an active Recipe file later changes. Skill components display logical identities such as `artifacts/report`; private physical `source_file`, `skill_dir`, and `recipe_dir` stay out of Inspector and model-facing views. Non-empty objects render as indented brace-delimited property lists. Complex arrays use compact zero-based entries such as `#0: {` rather than Markdown list markers.
23
23
 
24
24
  ## Trace
25
25
 
26
- Shows the unified bounded Trace projection. Sources include lifecycle/runtime observations, Controls, owned Pi turns, command-log tails, results, artifacts, and diagnostics. Filter by source and open a row for structured detail.
26
+ Shows the unified bounded Trace projection. Sources include lifecycle/runtime observations, Controls, owned Pi turns, command-log tails, results, artifacts, and diagnostics. The source selector displays only `all` plus sources present in the current projection from `lifecycle`, `control`, `process`, `agent`, `artifact`, and `runtime`. Select a row to open structured detail.
27
27
 
28
- Trace ordering stays deterministic and newest-first: timestamp descending, same-source physical ordinal descending, fixed internal source rank, then stable id. Internal ordinals are never displayed or interpreted as cross-source causality. Row numbers still read chronologically from bottom to top: the oldest visible event is `#1` and the newest carries the highest number. The summary states whether retained history is complete; `runtime.trace_compacted` means older history was discarded and shows bounded cumulative drop evidence. Terminal/result/execution/artifact evidence keeps its own authority. The projection applies path containment and redaction before rendering.
28
+ Trace ordering stays deterministic and newest-first: timestamp descending, same-source physical ordinal descending, fixed internal source rank, then stable id. Internal ordinals are never displayed or interpreted as cross-source causality. Row numbers are zero-based chronological identities even though display is newest-first: the oldest visible event is `#0` and the newest carries the highest number. The summary states whether retained history is complete; `runtime.trace_compacted` means older history was discarded and shows bounded cumulative drop evidence. Terminal/result/execution/artifact evidence keeps its own authority. The projection applies path containment and redaction before rendering.
29
29
 
30
30
  ## Control
31
31
 
@@ -39,12 +39,28 @@ Shows:
39
39
 
40
40
  A service endpoint counts as ready only when `control-endpoint.json` matches the Run's immutable `run_instance_id`. Capacity reaches zero at 64 pending Controls; further requests are rejected before admission, while admitted nonterminal Controls never expire automatically. Runtime-owned kill remains available for a stuck saturated Run. Recent Control input and errors use the same bounded structured redaction as tool inspection. The durable `controls.jsonl` journal remains raw and local; rendering never mutates it or attaches an unredacted copy.
41
41
 
42
+ ## Focus and Selectors
43
+
44
+ `selectedBg` marks the current focus or selection; `customMessageBg` remains reserved for alternating content stripes. Opening the Run or Trace-source selector preserves `selectedBg` on its parent control, so focus reads as parent → child menu → selected option. Menus are composited over only their bounded rectangle; base content before, beside, and below that rectangle remains rendered.
45
+
46
+ The Run selector uses aligned zero-based sequence, Run name, and semantic status columns. The Trace selector uses `Trace: <source>`; when a non-`all` source is active, the tab projects the same colon grammar and value color.
47
+
42
48
  ## Keys
43
49
 
44
- The footer displays current bindings. Use tab navigation to switch Recipe/Trace/Control, movement keys to select rows, detail navigation to inspect evidence, refresh to reconcile disk state, and the documented kill key for lifecycle termination.
50
+ The footer is authoritative for the current focus. The stable navigation contract is:
51
+
52
+ | Focus | Keys |
53
+ | --- | --- |
54
+ | Run control | `←`/`→` change Run, `↓` enters tabs, `Enter` opens the Run selector, `k` requests kill when available |
55
+ | Tabs | `←`/`→` or `Tab` changes tab, `↑` returns to Run, `↓` enters content, `Enter` opens content or the Trace-source selector |
56
+ | Trace tab | `f` cycles present sources without opening the selector |
57
+ | List/document/detail | `↑`/`↓` and `PgUp`/`PgDn` navigate; `→`/`Enter` opens a Trace row; `←` or `Esc` moves back |
58
+ | Selector | `↑`/`↓` chooses, `Enter`/`→` applies, `←`/`Esc` cancels |
59
+ | Kill confirmation | `←`/`→` or `Tab` chooses, `Enter`/`y` confirms, `Esc`/`n` cancels |
60
+ | Overlay | `Esc` closes from the top level; `Ctrl-C` closes immediately |
45
61
 
46
62
  Run kill revalidates owner and generation through the canonical lifecycle path. After success, the Run status header is the sole confirmation; the content area does not duplicate it. The Inspector never edits state directly and never derives authority from displayed data.
47
63
 
48
64
  ## Scope
49
65
 
50
- The Actor Inspector treats each Run as a concrete actor instance. It does not expose group conversations, peer addresses, routing, or communication topology. Use `inspect target=runtime view=status`, `inspect target=recipes view=status`, and `inspect target=tool:<name> view=status` for non-Run management targets.
66
+ The Actor Inspector treats each Run as a concrete actor instance. It does not expose group conversations, peer addresses, routing, or communication topology. Use `inspect target=runtime view=status|runs|triage`, `inspect target=recipes view=status|summary|doctor|imports|reviews`, and `inspect target=tool:<name> view=status|schema` for non-Run management targets. See [Management Inspection](./inspection.md) for exact applicability and authorization boundaries.
@@ -25,7 +25,7 @@ Each Run persists:
25
25
  - captured Recipe/template/values;
26
26
  - model and thinking policy provenance.
27
27
 
28
- Inspection, Control, cancellation, kill, retirement, and teardown filter by owner. Lifecycle mutations revalidate generation, state, and process identity under the canonical lock.
28
+ Inspection, Control, cancellation, kill, retirement, and teardown filter by owner. Public Run-specific `inspect` and `message` also require a current coordinator session whose id exactly matches the persisted non-empty owner; possession of `run:<id>` alone grants no access. Missing coordinator identity, ownerless state, and cross-owner state fail closed. `inspect target=runtime view=runs` returns only the current session's exact-owner inventory and is the supported diagnostic when a remembered Run is inaccessible. Lifecycle mutations additionally revalidate generation, state, and process identity under the canonical lock.
29
29
 
30
30
  ## State Files
31
31
 
@@ -86,11 +86,19 @@ Unix services may publish a FIFO; native Windows services publish a Windows name
86
86
 
87
87
  A service exact-id claims queued or transport-delivered Controls and records handled/failed outcomes through the canonical Control journal authority. Admission performs one locked read, integrity/generation check, terminal-tail compaction, capacity decision, and atomic write. The 65th pending Control and a rewrite exceeding 1 MiB fail as bounded `control_backpressure` before admission; malformed, unreadable, oversized, or stale-generation journals fail with an integrity reason and no rejected record. `inspect view=control` reports pending capacity, saturation, stale work, journal bytes, and diagnostics. Every transition uses the same lock, expected-state fence, 128-terminal compaction, and atomic bounded rewrite; persisted errors truncate inside the string at 4 KiB. Admitted nonterminal Controls never expire automatically. Delivery failure evidence cannot regress a Control already claimed or completed by a fast consumer. Services capture their startup generation, so stale-generation Controls never execute.
88
88
 
89
- Runtime lifecycle `kill`, retention actions, and review retry/reset remain runtime-owned rather than Recipe-declared. Kill is the recovery path for a stuck saturated Run: it bypasses actor-local Control capacity and creates no synthetic Control. Same-directory restart clears all generation-local evidence before the new `run_instance_id`; archive moves the exact bounded terminal tree, while prune removes kernel state and preserves only explicitly requested artifacts.
89
+ Runtime lifecycle `kill`, retention actions, and review retry/reset remain runtime-owned rather than Recipe-declared. Invoke Run actions through the public tool exactly as follows:
90
+
91
+ ```text
92
+ message target=run:<id> action=kill
93
+ message target=run:<id> action=archive
94
+ message target=run:<id> action=prune input={"preserve_artifacts":true}
95
+ ```
96
+
97
+ Kill accepts only a running owned generation and is the recovery path for a stuck saturated Run: it bypasses actor-local Control capacity and creates no synthetic Control. Archive and prune accept only terminal owned Runs. Archive moves the entire Run state directory and leaves a tombstone at the original path. Prune removes kernel state and preserves declared existing artifacts only when `preserve_artifacts` is explicitly true, copying them to retained artifact storage first. Same-directory restart clears all generation-local evidence before the new `run_instance_id`.
90
98
 
91
99
  ## Execution Evidence
92
100
 
93
- `execution.json` stores general command/session provenance. The async runner keeps bounded stdout/stderr logs plus complete capture artifacts when semantic validation requires untruncated evidence. Pi command execution also records owned session provenance for later Trace projection and review checks. Trace and Control quotas do not constrain declared user artifacts, repositories or media sources, complete execution captures, or actor-owned queue/workload state; each remains governed by its own lifecycle and policy.
101
+ `execution.json` stores general command/session provenance. The async runner keeps bounded stdout/stderr logs plus complete capture artifacts when semantic validation requires untruncated evidence. Pi command execution also records owned session provenance for later Trace projection and review checks. Session evidence files larger than 4 MiB are rejected before JSONL materialization and surface explicit truncation diagnostics instead of being loaded unboundedly. Artifact manifests compute size and SHA-256 incrementally in 64 KiB chunks. Trace and Control quotas do not constrain declared user artifacts, repositories or media sources, complete execution captures, or actor-owned queue/workload state; each remains governed by its own lifecycle and policy.
94
102
 
95
103
  Review acceptance remains a command-stage concern. General execution evidence does not imply review approval.
96
104
 
@@ -126,7 +134,7 @@ Packaged controlled services demonstrate the endpoint protocol:
126
134
  - `music-player/playback` consumes playback Controls and emits playback Trace;
127
135
  - `actors/resource-locker` consumes queue/lease actions, emits lock Trace, and atomically retains at most 512 valid journal records within 1 MiB.
128
136
 
129
- Shared archive/prune evidence similarly retains at most 256 valid records within 1 MiB under its canonical lock. The obsolete advisory `wake.jsonl` notifier was removed; filesystem watchers and bounded reconciliation observe authoritative state directly.
137
+ Shared archive/prune evidence similarly retains at most 256 valid records within 1 MiB under its canonical lock. Filesystem watchers and bounded reconciliation observe authoritative state directly.
130
138
 
131
139
  One-shot pipelines omit Control and terminate through their command graph.
132
140
 
@@ -136,6 +144,10 @@ One-shot pipelines omit Control and terminate through their command graph.
136
144
  inspect target=run:<id> view=recipe
137
145
  inspect target=run:<id> view=trace source=lifecycle lines=40
138
146
  inspect target=run:<id> view=control
147
+ inspect target=runtime view=runs
148
+ inspect target=runtime view=triage
139
149
  ```
140
150
 
151
+ Runtime `runs` is the exact-owner inventory; `triage` aggregates failed Runs, Control pressure, incomplete Trace evidence, and attention for that inventory. See [Management Inspection](./inspection.md) for every target/view combination and applicable inputs.
152
+
141
153
  Use `/actor-inspector` to inspect Runs as concrete actor instances in the live TUI. Runtime, Recipe registry, and tool definitions remain separate management targets. No public noun, tool, target, or view is added by bounded retention.
@@ -30,7 +30,7 @@ Command-template standard does not own:
30
30
 
31
31
  ## Shape
32
32
 
33
- A command template is either a command-line string or an ordered array of command-template leaves:
33
+ A command template is a command-line string, an ordered array of command-template nodes, or an object that applies execution fields to a nested `template`:
34
34
 
35
35
  ```json
36
36
  {
@@ -62,7 +62,8 @@ Common object fields:
62
62
  - `retry`: Optional max attempts including the first. Default is `1`.
63
63
  - `failure`: Optional failure propagation scope: `continue`, `branch`, or `root`. Default is `continue`.
64
64
  - `recover`: Optional command template run between failed retry attempts. Recovery output is ignored; recovery failure stops retries.
65
- - `template`: Required command string or ordered composition array.
65
+ - `repeat`: Optional non-negative expansion count or supported length expression. Repeated nodes receive generated zero-based index placeholders.
66
+ - `template`: Required nested command string, ordered composition array, or command-template object.
66
67
 
67
68
  For object form, write `template` last. Read the node flags first, then the executable content. Storage paths, labels, selectors, descriptions, and registry-specific metadata belong to each extension's local schema.
68
69
 
@@ -83,7 +84,7 @@ Implementations may expand `~` in command position and may resolve relative comm
83
84
  Supported forms:
84
85
 
85
86
  | Form | Meaning |
86
- | ------------------ | ------------------------------------------------ |
87
+ | --- | --- |
87
88
  | `{name}` | Required value from runtime values or `defaults` |
88
89
  | `{name=default}` | Inline default when no value is provided |
89
90
  | `{name??fallback}` | Fallback when value is missing, null, or empty |
@@ -206,7 +207,7 @@ Repeat expressions support only integers, `index`, `prev`, `next`, `repeat`, par
206
207
 
207
208
  Repeat placeholders are local generated values. Call-time args should not use these reserved names to override the repeat index.
208
209
 
209
- Parallel children use the same object shape: flags come first and `template` stays last. A join remains usable when at least one branch succeeds and reports each branch label/status. Some local schemas may accept `pipe`, but the portable standard is `template: [...]`.
210
+ Parallel children use the same object shape: flags come first and `template` stays last. A join remains usable when at least one branch succeeds and reports each branch label/status. The portable composition field is always `template`.
210
211
 
211
212
  ## Failure Propagation
212
213
 
@@ -0,0 +1,83 @@
1
+ # Management Inspection
2
+
3
+ The public `inspect` tool exposes four exact target families. Targets are management projections, not interchangeable aliases.
4
+
5
+ ## Target and View Matrix
6
+
7
+ | Target | Views | Purpose |
8
+ | --- | --- | --- |
9
+ | `run:<id>` | `recipe`, `trace`, `control` | Inspect one accessible Run generation |
10
+ | `runtime` | `status`, `runs`, `triage` | Inspect package policy, owned Run inventory, or aggregate operational pressure |
11
+ | `recipes` | `status`, `summary`, `doctor`, `imports`, `reviews` | Inspect user Recipe discovery, active Skill components, exact resolution, imports, and automatic-review recovery |
12
+ | `tool:<name>` | `status`, `schema` | Inspect persistent-tool activation/usage or its current callable schema |
13
+
14
+ `verbose=false` normally returns compact text and `verbose=true` returns structured details. `tool:<name> view=schema` is always structured because its callable parameter schema has no useful compact equivalent.
15
+
16
+ ## Run Targets
17
+
18
+ ```text
19
+ inspect target=run:demo view=recipe
20
+ inspect target=run:demo view=trace source=lifecycle lines=40
21
+ inspect target=run:demo view=control lines=20
22
+ ```
23
+
24
+ Run views require a current coordinator session and an exact, non-empty match between that session id and the Run's persisted owner. Possessing a `run:<id>` is not authorization. Missing coordinator identity, ownerless state, and cross-owner state fail closed.
25
+
26
+ - `recipe` returns captured generation-local Recipe, launch, policy, and artifact declarations.
27
+ - `trace` returns the bounded unified projection plus retained-history completeness. `source` accepts `all`, `lifecycle`, `control`, `process`, `agent`, `artifact`, or `runtime`; `lines` bounds returned rows.
28
+ - `control` returns endpoint readiness, declared and runtime-owned actions, pending capacity, saturation, stale work, diagnostics, and recent redacted records; `lines` bounds recent records.
29
+
30
+ Use the runtime inventory when a remembered Run id is inaccessible from the current session:
31
+
32
+ ```text
33
+ inspect target=runtime view=runs
34
+ ```
35
+
36
+ ## Runtime Targets
37
+
38
+ ```text
39
+ inspect target=runtime view=status
40
+ inspect target=runtime view=runs
41
+ inspect target=runtime view=runs status=failed
42
+ inspect target=runtime view=triage
43
+ ```
44
+
45
+ - `status` reports immutable package/runtime identity, state schema, and current automatic-review policy.
46
+ - `runs` returns the complete inventory owned by the current coordinator session; it is not paginated or capped by `lines`. Optional `status` filters that exact-owner inventory.
47
+ - `triage` aggregates the same exact-owner inventory into failed Runs, pending/stale Controls, backpressure, incomplete Trace diagnostics, and retained attention evidence.
48
+
49
+ Runtime inventory never broadens authorization and never returns ownerless or foreign Run state.
50
+
51
+ ## Recipe Targets
52
+
53
+ ```text
54
+ inspect target=recipes view=status
55
+ inspect target=recipes view=summary
56
+ inspect target=recipes view=doctor identity=music-player/playback
57
+ inspect target=recipes view=imports verbose=true
58
+ inspect target=recipes view=reviews verbose=true
59
+ ```
60
+
61
+ - `status` reports registry/watch state, active/shadowed/invalid/disabled user Recipes, active Skill components, drafts, usage, and diagnostics.
62
+ - `summary` returns the compact discovery-oriented projection of the same current context.
63
+ - `doctor` diagnoses one canonical `<skill>/<recipe>` identity when `identity` is provided; without an identity it reports registry remediation evidence.
64
+ - `imports` exposes active Skill namespaces and component import inventory for resolution diagnosis.
65
+ - `reviews` exposes bounded automatic draft/tool review state and recovery guidance.
66
+
67
+ `identity` is accepted only with `view=doctor`. Skill inventory is fail-soft diagnostic evidence; exact launch and registration still resolve against the immutable active-session context.
68
+
69
+ ## Tool Targets
70
+
71
+ ```text
72
+ inspect target=tool:music_player view=status
73
+ inspect target=tool:music_player view=schema
74
+ ```
75
+
76
+ - `status` separates persistence, registry admission, host registration, `callable_now`, activation boundary, source identity, and `tool_calls` versus `spawn_calls`.
77
+ - `schema` returns the currently callable description, parameter schema, and prompt snippet. It fails clearly when a definition is persisted but its live callable schema is unavailable.
78
+
79
+ A registered tool is a capability definition, not a Run. Tool status cannot substitute for Run inspection, and Recipe spawning cannot prove registered-tool invocation.
80
+
81
+ ## Boundaries
82
+
83
+ Inspection is read-only, owner-filtered where Run state is involved, and redacted. Evidence-heavy Run, review, diagnostic, and text projections apply their documented bounds; `runtime view=runs` deliberately returns the complete matching exact-owner inventory. Inspection does not mutate journals, infer authority from displayed data, expose private active-Skill installation paths, or turn retained Trace into an audit archive. Use `message` for admitted runtime or actor-local actions.
@@ -80,7 +80,7 @@ Do not bulk-copy bundled Recipes into the user Recipe root. Internal `recipe-mem
80
80
  npm run recipes:qa
81
81
  ```
82
82
 
83
- Recipe QA recursively inventories direct Skill components and validates filesystem identity, syntax, imports, Control declarations, origin ownership, portable artifact paths, and `{skill_dir}` helper references. Nested files and JSON/Markdown stem collisions fail precisely. Recipe descriptions remain optional; QA requires zero capability diagnostics and zero warnings without enforcing style, documentation quotas, or architecture policy. Removed mailbox declarations fail with the migration diagnostic rather than receiving automatic conversion.
83
+ Recipe QA recursively inventories direct Skill components and validates filesystem identity, syntax, imports, Control declarations, origin ownership, portable artifact paths, and `{skill_dir}` helper references. Nested files and JSON/Markdown stem collisions fail precisely. Recipe descriptions remain optional; QA requires zero capability diagnostics and zero warnings without enforcing style, documentation quotas, or architecture policy. `mailbox` is not part of the current Recipe contract and fails validation.
84
84
 
85
85
  ## Related
86
86