@ftrdotdev/pi-delegates 0.0.0-stage → 0.1.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/OPERATIONS.md +57 -0
  4. package/README.md +448 -2
  5. package/ROADMAP.md +158 -0
  6. package/TESTING.md +1061 -0
  7. package/agents.ts +8 -0
  8. package/examples/README.md +114 -0
  9. package/examples/gated.ts +28 -0
  10. package/index.ts +9 -0
  11. package/package.json +93 -4
  12. package/skills/pi-delegates/SKILL.md +147 -0
  13. package/skills/pi-delegates/references/control.md +159 -0
  14. package/skills/pi-delegates/references/definitions.md +163 -0
  15. package/skills/pi-delegates/references/gates.md +175 -0
  16. package/skills/pi-delegates/references/launch.md +156 -0
  17. package/src/domain/definitions.test.ts +41 -0
  18. package/src/domain/definitions.ts +161 -0
  19. package/src/domain/ids.ts +13 -0
  20. package/src/domain/names.ts +35 -0
  21. package/src/domain/orchestration/admission.ts +78 -0
  22. package/src/domain/orchestration/control.test.ts +1298 -0
  23. package/src/domain/orchestration/control.ts +436 -0
  24. package/src/domain/orchestration/fanout.test.ts +419 -0
  25. package/src/domain/orchestration/fanout.ts +334 -0
  26. package/src/domain/orchestration/gates.test.ts +686 -0
  27. package/src/domain/orchestration/gates.ts +360 -0
  28. package/src/domain/orchestration/launch.test.ts +173 -0
  29. package/src/domain/orchestration/launch.ts +581 -0
  30. package/src/domain/orchestration/requests.test.ts +700 -0
  31. package/src/domain/orchestration/requests.ts +769 -0
  32. package/src/domain/orchestration/review.test.ts +214 -0
  33. package/src/domain/orchestration/review.ts +168 -0
  34. package/src/domain/orchestration/run-wait.test.ts +262 -0
  35. package/src/domain/orchestration/run-wait.ts +256 -0
  36. package/src/domain/orchestration/workflow-section.test.ts +62 -0
  37. package/src/domain/orchestration/workflow-section.ts +99 -0
  38. package/src/domain/orchestration/workflow.test.ts +1425 -0
  39. package/src/domain/orchestration/workflow.ts +705 -0
  40. package/src/domain/run-records.test.ts +27 -0
  41. package/src/domain/run-records.ts +527 -0
  42. package/src/domain/shapes.test.ts +165 -0
  43. package/src/domain/skills.test.ts +466 -0
  44. package/src/domain/skills.ts +97 -0
  45. package/src/domain/tool-schema.test.ts +46 -0
  46. package/src/domain/tool-schema.ts +20 -0
  47. package/src/domain/toolkit.test.ts +201 -0
  48. package/src/domain/toolkit.ts +379 -0
  49. package/src/domain/view.test.ts +739 -0
  50. package/src/domain/view.ts +459 -0
  51. package/src/example.test.ts +15 -0
  52. package/src/extension/commands.test.ts +481 -0
  53. package/src/extension/commands.ts +227 -0
  54. package/src/extension/entry.test.ts +1118 -0
  55. package/src/extension/entry.ts +342 -0
  56. package/src/extension/gate-alerts.test.ts +235 -0
  57. package/src/extension/gate-alerts.ts +143 -0
  58. package/src/extension/guard.test.ts +48 -0
  59. package/src/extension/guard.ts +31 -0
  60. package/src/extension/host-signals.test.ts +20 -0
  61. package/src/extension/host-signals.ts +13 -0
  62. package/src/extension/inspector-command.test.ts +1191 -0
  63. package/src/extension/inspector-command.ts +638 -0
  64. package/src/extension/prompt.test.ts +110 -0
  65. package/src/extension/prompt.ts +50 -0
  66. package/src/extension/request-alerts.test.ts +183 -0
  67. package/src/extension/request-alerts.ts +181 -0
  68. package/src/extension/revocation.test.ts +81 -0
  69. package/src/extension/revocation.ts +84 -0
  70. package/src/extension/shortcut.test.ts +64 -0
  71. package/src/extension/shortcut.ts +105 -0
  72. package/src/extension/tools.test.ts +993 -0
  73. package/src/extension/tools.ts +505 -0
  74. package/src/extension/version.test.ts +123 -0
  75. package/src/extension/version.ts +97 -0
  76. package/src/harness-policy.test.ts +74 -0
  77. package/src/package-manifest.test.ts +157 -0
  78. package/src/presentation/actions.test.ts +221 -0
  79. package/src/presentation/actions.ts +85 -0
  80. package/src/presentation/activity.test.ts +387 -0
  81. package/src/presentation/activity.ts +66 -0
  82. package/src/presentation/close.test.ts +361 -0
  83. package/src/presentation/inspector.test.ts +679 -0
  84. package/src/presentation/inspector.ts +440 -0
  85. package/src/presentation/overlay.test.ts +555 -0
  86. package/src/presentation/overlay.ts +229 -0
  87. package/src/presentation/repaint.test.ts +329 -0
  88. package/src/presentation/shortcut.ts +2 -0
  89. package/src/presentation/snapshot.test.ts +530 -0
  90. package/src/presentation/snapshot.ts +306 -0
  91. package/src/presentation/strip.test.ts +196 -0
  92. package/src/presentation/strip.ts +74 -0
  93. package/src/presentation/wording.test.ts +238 -0
  94. package/src/presentation/wording.ts +222 -0
  95. package/src/runtime/bridge.test.ts +131 -0
  96. package/src/runtime/bridge.ts +134 -0
  97. package/src/runtime/config.test.ts +44 -0
  98. package/src/runtime/config.ts +87 -0
  99. package/src/runtime/context.test.ts +19 -0
  100. package/src/runtime/context.ts +9 -0
  101. package/src/runtime/execution-env.test.ts +35 -0
  102. package/src/runtime/execution-env.ts +15 -0
  103. package/src/runtime/extensions.test.ts +86 -0
  104. package/src/runtime/extensions.ts +140 -0
  105. package/src/runtime/log.test.ts +128 -0
  106. package/src/runtime/log.ts +68 -0
  107. package/src/runtime/mcp.test.ts +1453 -0
  108. package/src/runtime/mcp.ts +938 -0
  109. package/src/runtime/models.test.ts +145 -0
  110. package/src/runtime/models.ts +259 -0
  111. package/src/runtime/observe.test.ts +50 -0
  112. package/src/runtime/observe.ts +150 -0
  113. package/src/runtime/session.test.ts +359 -0
  114. package/src/runtime/session.ts +425 -0
  115. package/src/runtime/timers.test.ts +31 -0
  116. package/src/runtime/timers.ts +10 -0
package/ROADMAP.md ADDED
@@ -0,0 +1,158 @@
1
+ # pi-delegates roadmap
2
+
3
+ The first release ships durable delegation: three in-session tools, one prompt
4
+ section, `/delegates`, single launch, fanout, review, control, gates, skills,
5
+ scripted workflows, MCP servers and the inspector. Each section below names
6
+ deferred work and why it waits. The last section names what the design rejects;
7
+ that work is not deferred.
8
+
9
+ ## Shipped
10
+
11
+ - **MCP servers.** The package reads `mcp.json` and, when the project is
12
+ trusted, `.pi/mcp.json`, with the host's override rules. Only servers a
13
+ registered definition references connect; an inline definition can use them
14
+ but cannot bring one in. Each connection registers one extension
15
+ `mcp:<server>` with the namespace `mcp__<server>` and one durable tool per
16
+ visible server tool. A definition selects them by exact name or by a
17
+ `mcp__<server>__<prefix>*` pattern; an unknown namespace fails the launch.
18
+ `exposure` and `toolExposure` map to `callers` and `deferred`, and a selected
19
+ tool auto-selects `codemode` or `tool-search`. A server that cannot connect
20
+ degrades with one diagnostic and one aggregated warning; connects race a 10 s
21
+ deadline and calls race the server's `timeout` and the run's cancellation.
22
+ Bounded results are saved under the session directory. Remaining gaps: OAuth
23
+ sign-in, resource tools, a per-run reconnect, config writes, and servers that
24
+ other extensions register with `pi.registerMcpServer()`. Also open: an inline
25
+ definition cannot reference a server that no registered definition does,
26
+ because the referenced set is read at session start. Re-read
27
+ `pi-coding-agent/dist/extensions/mcp/config.js` before trusting the merge.
28
+ - **Delegated-agent skills.** A definition declares `skills` by name; the binder
29
+ adds the `skills` extension, the toolkit document records the names (version
30
+ 2), and the prompt section lists only the declared skills. A name that does
31
+ not resolve fails the launch, and a stored name that stops resolving is
32
+ refused with the missing list.
33
+ - **Questions from a delegate.** A child whose definition selects `questions`
34
+ and `ask` can put one question to the user and park on the answer. The record
35
+ is a session document keyed by conversation and call, with one index row
36
+ written in the same commit. A wait attaches to both indexes and resolves on
37
+ the commit, so the parent turn ends at the question. `delegate_control`
38
+ `answer` and `decline`, and `/delegates:answer`, are the writes. A request
39
+ expires after 24 hours, and a decided record is pruned 7 days after it was
40
+ requested. What remains: a web control plane, `tools.ask` for workflow
41
+ scripts, multi-question calls and multi-select answers. `gatedTool` still has
42
+ the commit/park window that `ask` closes: a decision that lands between the
43
+ gate's read and `requestGate`'s commit is lost for that call. The fanout
44
+ admission loop still polls at 1000 ms; `docs/issues/fanout-latency.md`
45
+ records it and it is unrelated to the wait.
46
+
47
+ ## Durability and hosts
48
+
49
+ - **Store retention and cleanup.** Stores live beside the session file and are
50
+ never pruned. A later changeset adds a retention command.
51
+ - **Store migration between package versions.** Durable task and document
52
+ migrations are supported today. A store migration between
53
+ `@ftrdotdev/pi-delegates` versions is not.
54
+ - **A second writer.** One Pi process owns a store. Read-only open is
55
+ supported. Multi-process writing, leases and store takeover wait for a
56
+ durable coordination primitive.
57
+ - **Progress without an open Pi process.** Closing Pi pauses delegated work.
58
+ A daemon needs the cooperation of the session file, which Pi owns.
59
+ - **Scheduled launches (cron and one-shot).** Nothing starts a run without a
60
+ tool call. A timer surface needs a process that runs while Pi is closed, so
61
+ it depends on the daemon item above.
62
+
63
+ ## Work items and authorization
64
+
65
+ - **Gate revocation after launch.** A committed toolkit cannot change. Removing
66
+ a gate later is not supported, because the child's conversation already runs
67
+ with the old rules.
68
+ - **Spend enforcement.** The package reports no spend. Budgets and goal limits
69
+ are not enforced.
70
+ - **A live approval dialog.** Gates are committed records and parked calls.
71
+ They are not interactive prompts inside a running delegate.
72
+
73
+ ## Surfaces and observability
74
+
75
+ - **A wider failure log.** Version 1 writes one JSONL file per session, with a
76
+ stable `code` and a 200-character `detail`. It adds no telemetry context, no
77
+ trace links and no counters, because one sink has one reader. Log rotation
78
+ waits until a session log reaches 5 MB.
79
+ - **Telemetry, metrics and trace links.** Version 1 writes the JSONL file and
80
+ nothing else: no Effect logger, no `pi-telemetry` context, no counters and no
81
+ span links. A second reader or a trace view is the trigger; until then it
82
+ adds a failure mode without an audience.
83
+ - **A bounded status read.** A session status returns the newest 50 runs and
84
+ prints how many it left out. A paging cursor, a wider bound and concurrent
85
+ reads wait until sessions routinely exceed 50 runs.
86
+ - **Progress inside the parent conversation.** A delegate reports a final
87
+ answer or a status row, and the parent polls. Streaming partial text into the
88
+ parent turn needs an event path from a child conversation to the host, which
89
+ the durable task model does not carry today.
90
+ - **A setup check.** `/delegates` lists runs and nothing else. No command
91
+ reports the resolved registry, the config diagnostics, the store path and the
92
+ version verdict together, though the runtime records each part.
93
+ - **The CLI.** `pi delegates runs|lanes|gates|reviews|spend|diagnostics` would
94
+ open a store read-only, aggregate sessions and reject writes.
95
+ - **Cross-session aggregation.** Every view reads one session's store. A merge
96
+ across stores must decide its order, its bound, and where it finds the stores;
97
+ run ids already carry the session id, so they do not collide.
98
+ - **The panel.** A read-only local page over the same view model, refreshed on
99
+ an interval.
100
+ - **A live inspector.** Transcript paging and per-turn evidence are not in the
101
+ first release.
102
+
103
+ ## Agent definitions and toolkits
104
+
105
+ - **Scripted workflows inside a delegate.** A registered definition with
106
+ `codemode: "runs"` runs a workflow launch: the child's model passes the
107
+ script to durable's `codemode` tool, and a script gate parks the workflow on
108
+ `script:<name>`. The lane cap binds `launch_many` groups only; `tools.launch`
109
+ claims its child without admission. The script the model passes is trusted:
110
+ the toolkit does not compare it with the launch script. What remains: a
111
+ workflow language of the package's own, nested workflows (code mode is
112
+ model-only), retry policies for a failed script, and a UI for script progress
113
+ beyond `pi.live.nestedTools`.
114
+ - **Declarative definition files.** Definitions are exported objects passed to
115
+ the factory. Version 1 has no definition file format and no reload command.
116
+ - **Loading Pi extension files per agent.** Agents select installed durable
117
+ extensions by name. The package does not use jiti or package-manifest
118
+ discovery.
119
+
120
+ ## Isolation and execution
121
+
122
+ - **One session runtime with logger, tracer, metrics and clock layers.** No
123
+ domain code consumes Effect services, so a session `ManagedRuntime` would
124
+ add a layer without a consumer. Cancellation needs a signal, not a runtime.
125
+ - **A live task-graph watch.** The wait attaches to the gate index and the
126
+ request index and resolves on a commit; a 5 s backstop re-checks after a
127
+ missed push. A stream lifecycle replaces it only when a measured need
128
+ appears.
129
+ - **`Effect.Semaphore` admission.** The durable task count is the correct
130
+ source across restarts; a semaphore is process-local. Do not add it.
131
+ - **A cumulative spawn budget.** The admission caps bound live runs per lane
132
+ and per session, not the total. A resumed run creates a new task each time,
133
+ so one run can spawn without a counter. A per-run-tree cap needs a durable
134
+ count beside the launch index.
135
+ - **Per-part health entries.** One `RuntimeState` covers the whole runtime. The
136
+ log carries config diagnostics; a per-part health surface needs its own
137
+ reader.
138
+ - **Worktrees per child.** Every child in a run shares one working directory.
139
+ The package records no lane merge evidence.
140
+ - **Multi-repo runs.** A run uses one repository. Runs across several
141
+ repositories are not supported.
142
+ - **Nested delegation.** `delegates-control` is not installed in the first
143
+ release, so a definition that names it fails as an unresolved name.
144
+ - **A non-blocking launch.** `delegate_launch` waits up to `launchWaitMs` and
145
+ returns a run id at the deadline. Returning at once and reading the run with
146
+ `delegate_status` is a UX change that needs evidence; the inline wait exists
147
+ because a person asked for the result.
148
+
149
+ ## Rejected by design
150
+
151
+ The design concept rejects this work, so it is not deferred and needs a new
152
+ design concept before it becomes a ticket.
153
+
154
+ - **Mandate, Policy and an authorization layer.** Authority is the agent
155
+ definition plus its gate rules. There is no admission table, no mandate
156
+ revalidation, and no policy version separate from the committed toolkit.
157
+ - **Source intake and work-item Tickets.** A run starts from a tool call, not
158
+ from a Source admitted through a Trigger.