@maiaos/agent 0.1.0-canary.2 → 0.1.0-canary.a83f355.agent.186

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 (190) hide show
  1. package/README.md +24 -99
  2. package/dist/extensions/goal/index.d.ts +2 -1
  3. package/dist/extensions/goal/index.d.ts.map +1 -1
  4. package/dist/extensions/goal/index.js +158 -1
  5. package/dist/extensions/goal/index.js.map +1 -1
  6. package/dist/extensions/process/index.d.ts +2 -1
  7. package/dist/extensions/process/index.d.ts.map +1 -1
  8. package/dist/extensions/process/index.js +78 -1
  9. package/dist/extensions/process/index.js.map +1 -1
  10. package/dist/extensions/process/manager.d.ts +2 -2
  11. package/dist/extensions/process/manager.d.ts.map +1 -1
  12. package/dist/extensions/safety/destructive-guard.d.ts +0 -7
  13. package/dist/extensions/safety/destructive-guard.d.ts.map +1 -1
  14. package/dist/extensions/safety/destructive-guard.js +63 -154
  15. package/dist/extensions/safety/destructive-guard.js.map +1 -1
  16. package/dist/extensions/safety/index.d.ts +4 -2
  17. package/dist/extensions/safety/index.d.ts.map +1 -1
  18. package/dist/extensions/safety/index.js +5 -2
  19. package/dist/extensions/safety/index.js.map +1 -1
  20. package/dist/extensions/safety/lifecycle.d.ts +1 -1
  21. package/dist/extensions/safety/lifecycle.d.ts.map +1 -1
  22. package/dist/extensions/tasks/index.d.ts +2 -1
  23. package/dist/extensions/tasks/index.d.ts.map +1 -1
  24. package/dist/extensions/tasks/index.js +164 -1
  25. package/dist/extensions/tasks/index.js.map +1 -1
  26. package/dist/index.d.ts +4 -7
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -7
  29. package/dist/index.js.map +1 -1
  30. package/dist/managed-worker/main.js +230410 -233022
  31. package/dist/managed-worker/main.js.map +1 -1
  32. package/dist/managed-worker/main.meta.json +1 -1
  33. package/dist/managed-worker/protocol.d.ts +1 -2
  34. package/dist/managed-worker/protocol.d.ts.map +1 -1
  35. package/dist/managed-worker/protocol.js +2 -13
  36. package/dist/managed-worker/protocol.js.map +1 -1
  37. package/dist/managed-worker/worker.d.ts +4 -18
  38. package/dist/managed-worker/worker.d.ts.map +1 -1
  39. package/dist/managed-worker/worker.js +5 -139
  40. package/dist/managed-worker/worker.js.map +1 -1
  41. package/dist/{resources/resources.d.ts → resources.d.ts} +1 -2
  42. package/dist/resources.d.ts.map +1 -0
  43. package/dist/resources.js.map +1 -0
  44. package/dist/{runner/runner.d.ts → runner.d.ts} +1 -3
  45. package/dist/runner.d.ts.map +1 -0
  46. package/dist/{runner/runner.js → runner.js} +18 -62
  47. package/dist/runner.js.map +1 -0
  48. package/dist/{runtime/runtime.d.ts → runtime.d.ts} +15 -11
  49. package/dist/runtime.d.ts.map +1 -0
  50. package/dist/{runtime/runtime.js → runtime.js} +33 -50
  51. package/dist/runtime.js.map +1 -0
  52. package/dist/startup-network-policy.d.ts +16 -0
  53. package/dist/startup-network-policy.d.ts.map +1 -0
  54. package/dist/{runtime/startup-network-policy.js → startup-network-policy.js} +2 -7
  55. package/dist/startup-network-policy.js.map +1 -0
  56. package/package.json +19 -57
  57. package/dist/auth/index.d.ts +0 -3
  58. package/dist/auth/index.d.ts.map +0 -1
  59. package/dist/auth/index.js +0 -3
  60. package/dist/auth/index.js.map +0 -1
  61. package/dist/auth/maia-auth.d.ts +0 -23
  62. package/dist/auth/maia-auth.d.ts.map +0 -1
  63. package/dist/auth/maia-auth.js +0 -97
  64. package/dist/auth/maia-auth.js.map +0 -1
  65. package/dist/auth/memory-credentials.d.ts +0 -9
  66. package/dist/auth/memory-credentials.d.ts.map +0 -1
  67. package/dist/auth/memory-credentials.js +0 -23
  68. package/dist/auth/memory-credentials.js.map +0 -1
  69. package/dist/extensions/goal/command.d.ts +0 -28
  70. package/dist/extensions/goal/command.d.ts.map +0 -1
  71. package/dist/extensions/goal/command.js +0 -80
  72. package/dist/extensions/goal/command.js.map +0 -1
  73. package/dist/extensions/goal/context.d.ts +0 -24
  74. package/dist/extensions/goal/context.d.ts.map +0 -1
  75. package/dist/extensions/goal/context.js +0 -35
  76. package/dist/extensions/goal/context.js.map +0 -1
  77. package/dist/extensions/goal/extension.d.ts +0 -7
  78. package/dist/extensions/goal/extension.d.ts.map +0 -1
  79. package/dist/extensions/goal/extension.js +0 -179
  80. package/dist/extensions/goal/extension.js.map +0 -1
  81. package/dist/extensions/goal/section.d.ts +0 -22
  82. package/dist/extensions/goal/section.d.ts.map +0 -1
  83. package/dist/extensions/goal/section.js +0 -49
  84. package/dist/extensions/goal/section.js.map +0 -1
  85. package/dist/extensions/process/extension.d.ts +0 -3
  86. package/dist/extensions/process/extension.d.ts.map +0 -1
  87. package/dist/extensions/process/extension.js +0 -79
  88. package/dist/extensions/process/extension.js.map +0 -1
  89. package/dist/extensions/prompt-section/index.d.ts +0 -2
  90. package/dist/extensions/prompt-section/index.d.ts.map +0 -1
  91. package/dist/extensions/prompt-section/index.js +0 -2
  92. package/dist/extensions/prompt-section/index.js.map +0 -1
  93. package/dist/extensions/prompt-section/prompt-section.d.ts +0 -26
  94. package/dist/extensions/prompt-section/prompt-section.d.ts.map +0 -1
  95. package/dist/extensions/prompt-section/prompt-section.js +0 -28
  96. package/dist/extensions/prompt-section/prompt-section.js.map +0 -1
  97. package/dist/extensions/safety/command-wrappers.d.ts +0 -31
  98. package/dist/extensions/safety/command-wrappers.d.ts.map +0 -1
  99. package/dist/extensions/safety/command-wrappers.js +0 -247
  100. package/dist/extensions/safety/command-wrappers.js.map +0 -1
  101. package/dist/extensions/safety/shell-tokens.d.ts +0 -13
  102. package/dist/extensions/safety/shell-tokens.d.ts.map +0 -1
  103. package/dist/extensions/safety/shell-tokens.js +0 -115
  104. package/dist/extensions/safety/shell-tokens.js.map +0 -1
  105. package/dist/extensions/search/bounds.d.ts +0 -22
  106. package/dist/extensions/search/bounds.d.ts.map +0 -1
  107. package/dist/extensions/search/bounds.js +0 -35
  108. package/dist/extensions/search/bounds.js.map +0 -1
  109. package/dist/extensions/search/extension.d.ts +0 -7
  110. package/dist/extensions/search/extension.d.ts.map +0 -1
  111. package/dist/extensions/search/extension.js +0 -18
  112. package/dist/extensions/search/extension.js.map +0 -1
  113. package/dist/extensions/search/index.d.ts +0 -2
  114. package/dist/extensions/search/index.d.ts.map +0 -1
  115. package/dist/extensions/search/index.js +0 -2
  116. package/dist/extensions/search/index.js.map +0 -1
  117. package/dist/extensions/tasks/context.d.ts +0 -20
  118. package/dist/extensions/tasks/context.d.ts.map +0 -1
  119. package/dist/extensions/tasks/context.js +0 -36
  120. package/dist/extensions/tasks/context.js.map +0 -1
  121. package/dist/extensions/tasks/extension.d.ts +0 -7
  122. package/dist/extensions/tasks/extension.d.ts.map +0 -1
  123. package/dist/extensions/tasks/extension.js +0 -178
  124. package/dist/extensions/tasks/extension.js.map +0 -1
  125. package/dist/extensions/tasks/summary.d.ts +0 -20
  126. package/dist/extensions/tasks/summary.d.ts.map +0 -1
  127. package/dist/extensions/tasks/summary.js +0 -50
  128. package/dist/extensions/tasks/summary.js.map +0 -1
  129. package/dist/extensions/title/extension.d.ts +0 -4
  130. package/dist/extensions/title/extension.d.ts.map +0 -1
  131. package/dist/extensions/title/extension.js +0 -37
  132. package/dist/extensions/title/extension.js.map +0 -1
  133. package/dist/extensions/title/index.d.ts +0 -2
  134. package/dist/extensions/title/index.d.ts.map +0 -1
  135. package/dist/extensions/title/index.js +0 -2
  136. package/dist/extensions/title/index.js.map +0 -1
  137. package/dist/extensions/title/title.d.ts +0 -9
  138. package/dist/extensions/title/title.d.ts.map +0 -1
  139. package/dist/extensions/title/title.js +0 -92
  140. package/dist/extensions/title/title.js.map +0 -1
  141. package/dist/home/index.d.ts +0 -2
  142. package/dist/home/index.d.ts.map +0 -1
  143. package/dist/home/index.js +0 -2
  144. package/dist/home/index.js.map +0 -1
  145. package/dist/home/maia-home.d.ts +0 -17
  146. package/dist/home/maia-home.d.ts.map +0 -1
  147. package/dist/home/maia-home.js +0 -84
  148. package/dist/home/maia-home.js.map +0 -1
  149. package/dist/login/index.d.ts +0 -2
  150. package/dist/login/index.d.ts.map +0 -1
  151. package/dist/login/index.js +0 -2
  152. package/dist/login/index.js.map +0 -1
  153. package/dist/login/provider-login.d.ts +0 -43
  154. package/dist/login/provider-login.d.ts.map +0 -1
  155. package/dist/login/provider-login.js +0 -153
  156. package/dist/login/provider-login.js.map +0 -1
  157. package/dist/managed-worker/index.d.ts +0 -2
  158. package/dist/managed-worker/index.d.ts.map +0 -1
  159. package/dist/managed-worker/index.js +0 -2
  160. package/dist/managed-worker/index.js.map +0 -1
  161. package/dist/managed-worker/operation-channel.d.ts +0 -24
  162. package/dist/managed-worker/operation-channel.d.ts.map +0 -1
  163. package/dist/managed-worker/operation-channel.js +0 -145
  164. package/dist/managed-worker/operation-channel.js.map +0 -1
  165. package/dist/resources/index.d.ts +0 -2
  166. package/dist/resources/index.d.ts.map +0 -1
  167. package/dist/resources/index.js +0 -2
  168. package/dist/resources/index.js.map +0 -1
  169. package/dist/resources/resources.d.ts.map +0 -1
  170. package/dist/resources/resources.js.map +0 -1
  171. package/dist/runner/index.d.ts +0 -2
  172. package/dist/runner/index.d.ts.map +0 -1
  173. package/dist/runner/index.js +0 -2
  174. package/dist/runner/index.js.map +0 -1
  175. package/dist/runner/runner.d.ts.map +0 -1
  176. package/dist/runner/runner.js.map +0 -1
  177. package/dist/runtime/index.d.ts +0 -3
  178. package/dist/runtime/index.d.ts.map +0 -1
  179. package/dist/runtime/index.js +0 -3
  180. package/dist/runtime/index.js.map +0 -1
  181. package/dist/runtime/kernel.d.ts +0 -18
  182. package/dist/runtime/kernel.d.ts.map +0 -1
  183. package/dist/runtime/kernel.js +0 -23
  184. package/dist/runtime/kernel.js.map +0 -1
  185. package/dist/runtime/runtime.d.ts.map +0 -1
  186. package/dist/runtime/runtime.js.map +0 -1
  187. package/dist/runtime/startup-network-policy.d.ts +0 -9
  188. package/dist/runtime/startup-network-policy.d.ts.map +0 -1
  189. package/dist/runtime/startup-network-policy.js.map +0 -1
  190. /package/dist/{resources/resources.js → resources.js} +0 -0
package/README.md CHANGED
@@ -1,115 +1,40 @@
1
1
  # `@maiaos/agent`
2
2
 
3
- [![npm canary](https://img.shields.io/npm/v/@maiaos/agent/canary?label=npm%20canary)](https://www.npmjs.com/package/@maiaos/agent)
3
+ The first-party Maia agent and managed worker, built on the official `@mariozechner/pi-coding-agent` SDK foundation.
4
4
 
5
- Maia's own AI coding agent, `maia agent`, and the managed Pi worker that Maia
6
- Node runs, both built on the official
7
- [`@earendil-works/pi-coding-agent`](https://www.npmjs.com/package/@earendil-works/pi-coding-agent)
8
- SDK.
5
+ This README describes the current package boundary. The normative target for
6
+ activation, resources, extension behavior, Session attachment, and the Pi SDK
7
+ TUI is [`docs/maia-agent/architecture.md`](../../docs/maia-agent/architecture.md).
9
8
 
10
- `maia agent` is Pi rebranded for Maia, not a different agent interface: Pi
11
- supplies the agent loop, models, providers, compaction, steering, TUI, sessions
12
- and extensions. Maia adds Maia-owned paths and credentials, digest-pinned
13
- project resources, a few reviewed built-ins, and the boundary to Maia Node. Use
14
- it as an interactive coding agent, or embed the package when you build on the
15
- same harness. It never invokes an installed `pi` executable or reads `~/.pi`.
9
+ `maia agent` is Pi rebranded for Maia, not a different agent interface. Pi SDK supplies the agent loop, model, provider, compaction, steering, TUI, session, and extension primitives. Extensions use the upstream Pi API and can register tools, slash commands, CLI flags, shortcuts, renderers, providers, and lifecycle hooks just as they can in standalone Pi. Maia adds its durable harness contract: exact Maia identities, Maia-owned resource paths, task and goal state, process boundaries, authorization, receipts, recovery, telemetry, and control-plane integration. It does not invoke an installed Pi CLI, use `~/.pi`, or introduce a parallel plugin API.
16
10
 
17
- ## Install
11
+ Every public Maia Agent entry establishes `PI_OFFLINE=1` and `PI_SKIP_VERSION_CHECK=1` as permanent process invariants before constructing or running official Pi. With the pinned official Pi 0.73.1 SDK, these supported flags suppress automatic version, package-update, telemetry, and managed-tool download traffic at startup without disabling an explicitly selected model/provider transport. Inherited false-like values are overwritten rather than interpreted by Pi's inconsistent flag readers. Callers embedding `@maiaos/agent` should therefore dedicate that process to the Agent boundary.
18
12
 
19
- `maia agent` ships with the [`maia` CLI](../../apps/cli/README.md). The library
20
- is published for installation testing:
13
+ Resource order follows the official Pi loader:
21
14
 
22
- ```sh
23
- pnpm add @maiaos/agent@canary
24
- ```
15
+ 1. digest-pinned project extensions explicitly listed in `.maia/maia.json`;
16
+ 2. reviewed Maia built-ins, which remain available even when discovered extensions are disabled.
25
17
 
26
- Canary builds are not release-qualified and can lag the source; npm's
27
- automatic `latest` tag also points at a canary build.
18
+ `maia agent -ne` and `maia agent --no-extensions` preserve standalone Pi semantics: they skip discovered extensions without resolving or digesting configured Project extension paths, while an explicit `-e`/`--extension` path may still load. Reviewed Maia kernel extensions remain available because they are part of the harness contract rather than discovery. The switch intentionally leaves Skills and `AGENTS.md` unchanged.
28
19
 
29
- ## Example
20
+ The lean built-in surface currently includes:
30
21
 
31
- ```sh
32
- maia agent # interactive session; type /login to sign in
33
- maia agent --print --no-session -- "Explain this repository"
34
- maia agent --json-events --no-session -- "Review the current diff"
35
- maia agent -e <path-to-extension.ts> # load one extension explicitly
36
- maia agent extension digest <extension-path> # digest to pin in .maia/maia.json
37
- ```
22
+ - destructive-command safety;
23
+ - task and goal state keyed by the durable Maia session under the explicit private `.maia` state root;
24
+ - bounded, session-owned background processes that are stopped on session shutdown.
38
25
 
39
- ## Key concepts
26
+ Managed workers bind state to the Maia session ID rather than the disposable in-memory Pi session ID. Durable history is rehydrated from Maia on activation. Session processes remain intentionally ephemeral; fire-and-forget jobs and reboot-durable services require Maia-owned job/daemon operations, idempotency, receipts, and recovery.
40
27
 
41
- - **Pi extensions, unchanged.** Extensions use the upstream Pi API to register
42
- tools, slash commands, CLI flags, shortcuts, renderers, providers and
43
- lifecycle hooks. There is no Maia-specific plugin API.
44
- - **Resources.** The agent loads project extensions only when they are listed
45
- and digest-pinned in `.maia/maia.json`, then reviewed Maia built-ins. `-ne`
46
- (`--no-extensions`) keeps Pi's meaning: skip discovered extensions, while an
47
- explicit `-e` path still loads. Skills and `AGENTS.md` stay available.
48
- - **Built-ins.** A destructive-command guard, bounds on Pi's `find` and
49
- `grep`, task and goal state keyed by the durable Maia Session, and
50
- Session-owned background processes stopped at shutdown. Pi's `find` and
51
- `grep` stay inactive. The standalone `maia agent` adds `/goal` and `/tasks`,
52
- a bounded goal and open-task section in the system prompt, and a name for an
53
- unnamed session taken from its first request.
54
- - **Credentials.** Provider credentials live in Maia's `auth.json` under
55
- `MAIA_HOME` (default `~/.maia`), one per provider; `maia login <provider>`
56
- uses Pi's own sign-in. `MAIA_AGENT_HOME` moves only the agent directory.
57
- - **Offline by default.** Every entry sets `PI_OFFLINE=1` and
58
- `PI_SKIP_VERSION_CHECK=1`, which stop Pi's update, telemetry and tool
59
- download traffic but not the model provider you select. Embed the package in
60
- a process dedicated to the agent.
61
- - **Managed worker.** The `maia-agent-worker` binary speaks a versioned,
62
- bounded NDJSON protocol to Maia Node. It keeps Pi state in memory, receives
63
- durable history from the Node, and holds a leased provider credential only in
64
- memory.
28
+ Direct parent/child messaging will be a narrow adapter to Maia-owned lineage, mailbox, idempotency, and delivery services. Durable daemon mutations likewise require Maia operation authorization. Factory scheduling, child creation, Codex account pools, provider-capacity allocation, and recursive orchestration belong to the separate `maia swarm` layer, not this package.
65
29
 
66
- Project extension code runs with the agent process's operating-system
67
- permissions; review it before pinning its digest. Extensions cannot bypass the
68
- Node's authorization, confirmation, compare-and-set, idempotency or receipts.
30
+ Project extension code executes with the agent process's operating-system permissions. Review it before pinning its digest. Pi extensions cannot bypass Maia's server-side operation authorization, confirmation, compare-and-set, idempotency, or receipt requirements.
69
31
 
70
- ## Status
32
+ The package also builds `maia-agent-worker`, a versioned NDJSON boundary for an out-of-process official-Pi session. It uses an in-memory Pi `SessionManager`; Maia durable history is supplied explicitly and Pi session files are not authoritative. A bounded, model-matched OAuth credential may be supplied during initialization and is installed in Pi's in-memory `AuthStorage`; the worker neither creates `auth.json` nor emits the credential. Request fingerprints retain only SHA-256 digests. Inputs, outputs, credentials, prompts, responses, history, and request identities are bounded. Duplicate request IDs replay a terminal result or fail on conflicting input.
71
33
 
72
- `maia agent` and its built-ins are implemented source candidates. Running Maia
73
- Agent as a general Node worker for swarms (bound Agent definitions with granted
74
- tools) is planned; bound activation is denied today. `maia session attach`
75
- (S12b) renders Codex Sessions; Pi Sessions join with S12c. Replacing
76
- a full daily Pi harness is tracked as
77
- [R11](../../docs/maia-agent/pi-harness-migration.md).
34
+ The built-in destructive-command guard is a reviewed port from `vllnt/pi-config`'s `pi-safety` extension, adapted from the forked package namespace to the official Pi extension API. The task, goal, and process tools are reduced Maia implementations informed by the reviewed `pi-tasks`, `pi-goal`, and `pi-daemon` contracts; they intentionally exclude Factory, fleet, hub, subagent, cron, terminal, and shared-account behavior.
78
35
 
79
- ## How it fits in Maia
80
-
81
- The CLI runs `maia agent` locally without a Node. Maia Node launches
82
- `maia-agent-worker` out of process for managed Pi Sessions and stays the
83
- authority for Sessions, credential leases and receipts. Swarm scheduling,
84
- account pools and recursive orchestration belong to Maia Node and Skills, not
85
- to this package. See the [Agent architecture](../../docs/maia-agent/architecture.md).
86
-
87
- ## Provenance
88
-
89
- The destructive-command guard, the `find` and `grep` bounds, `/goal`, `/tasks`,
90
- the goal and task prompt sections, session naming and the tool-metadata
91
- contract test are reviewed ports from `vllnt/pi-config` at commit `b90808fb`
92
- ([D-069](../../docs/decisions.md#d-069)); each file names its source in a
93
- header comment, and the [port record](../../docs/maia-agent/pi-harness-port.md)
94
- lists every source extension and where it belongs in Maia. The task, goal and
95
- process tools are reduced Maia implementations informed by the reviewed
96
- `pi-tasks`, `pi-goal` and `pi-daemon` contracts.
97
-
98
- ## Development
99
-
100
- ```sh
101
- pnpm --filter @maiaos/agent build
102
- pnpm --filter @maiaos/agent lint
103
- pnpm --filter @maiaos/agent typecheck
104
- pnpm --filter @maiaos/agent test
105
- ```
106
-
107
- ## Documentation
108
-
109
- - [Maia Agent architecture](../../docs/maia-agent/architecture.md)
110
- - [Pi harness migration (R11)](../../docs/maia-agent/pi-harness-migration.md)
111
- - [Providers and login](../../docs/providers/architecture.md)
112
-
113
- ## License
114
-
115
- No license has been published yet. All rights reserved.
36
+ The target terminal surface does not move durable state into this package.
37
+ Local `maia agent` may use Pi SDK `InteractiveMode`; managed
38
+ `maia session attach` renders the Node-owned Session timeline through a narrow
39
+ `PiTuiRenderer` client adapter in `apps/cli`. Renderer failure detaches only the
40
+ client and cannot terminate or mutate the Session.
@@ -1,2 +1,3 @@
1
- export { makeGoalExtension } from "./extension.js";
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ export declare const makeGoalExtension: (stateRoot: string, durableSessionId?: string) => (pi: ExtensionAPI) => void;
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/goal/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,+BAA+B,CAAC;AA0MvC,eAAO,MAAM,iBAAiB,GAC3B,WAAW,MAAM,EAAE,mBAAmB,MAAM,MAC5C,IAAI,YAAY,KAAG,IAenB,CAAC"}
@@ -1,2 +1,159 @@
1
- export { makeGoalExtension } from "./extension.js";
1
+ import { lstat, mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { Type } from "typebox";
4
+ const MAX_GOAL_BYTES = 16 * 1024;
5
+ const parameters = Type.Object({
6
+ action: Type.Union([
7
+ Type.Literal("rewrite"),
8
+ Type.Literal("update"),
9
+ Type.Literal("status"),
10
+ Type.Literal("show"),
11
+ Type.Literal("verify"),
12
+ Type.Literal("pause"),
13
+ Type.Literal("resume"),
14
+ Type.Literal("done"),
15
+ Type.Literal("abandon"),
16
+ ]),
17
+ constraints: Type.Optional(Type.Array(Type.String({ maxLength: 512 }), { maxItems: 16 })),
18
+ evidence: Type.Optional(Type.String({ maxLength: 4096 })),
19
+ next: Type.Optional(Type.String({ maxLength: 1024 })),
20
+ objective: Type.Optional(Type.String({ maxLength: 2048 })),
21
+ success: Type.Optional(Type.Array(Type.String({ maxLength: 512 }), { maxItems: 16 })),
22
+ });
23
+ const isGoalState = (value) => typeof value === "object" &&
24
+ value !== null &&
25
+ typeof Reflect.get(value, "objective") === "string" &&
26
+ typeof Reflect.get(value, "next") === "string" &&
27
+ typeof Reflect.get(value, "revision") === "number" &&
28
+ Array.isArray(Reflect.get(value, "constraints")) &&
29
+ Array.isArray(Reflect.get(value, "success"));
30
+ const goalPath = (stateRoot, sessionId) => join(stateRoot, "sessions", sessionId, "goal.json");
31
+ const readDurableGoal = async (path) => {
32
+ try {
33
+ const stats = await lstat(path);
34
+ if (!stats.isFile() ||
35
+ stats.isSymbolicLink() ||
36
+ stats.size > MAX_GOAL_BYTES) {
37
+ throw new Error("The session goal state is unsafe or too large.");
38
+ }
39
+ const value = JSON.parse(await readFile(path, "utf8"));
40
+ if (!isGoalState(value))
41
+ throw new Error("The session goal state is invalid.");
42
+ return value;
43
+ }
44
+ catch (error) {
45
+ if (error.code === "ENOENT")
46
+ return undefined;
47
+ throw error;
48
+ }
49
+ };
50
+ const writeDurableGoal = async (path, goal) => {
51
+ await mkdir(dirname(path), { mode: 0o700, recursive: true });
52
+ const text = `${JSON.stringify(goal, undefined, 2)}\n`;
53
+ if (Buffer.byteLength(text, "utf8") > MAX_GOAL_BYTES) {
54
+ throw new Error("The session goal state exceeds its byte limit.");
55
+ }
56
+ const temporary = `${path}.${String(process.pid)}.${String(goal.revision)}.tmp`;
57
+ await writeFile(temporary, text, { flag: "wx", mode: 0o600 });
58
+ await rename(temporary, path);
59
+ };
60
+ const textResult = (value) => ({
61
+ content: [{ text: JSON.stringify(value), type: "text" }],
62
+ details: value,
63
+ });
64
+ const requireActiveGoal = (goal) => {
65
+ if (goal === undefined)
66
+ throw new Error("No session goal exists.");
67
+ if (goal.status === "completed" || goal.status === "abandoned") {
68
+ throw new Error("The session goal is terminal.");
69
+ }
70
+ return goal;
71
+ };
72
+ const rewriteGoal = (input) => {
73
+ if (input.objective === undefined || input.objective.trim().length === 0) {
74
+ throw new Error("Goal rewrite requires an objective.");
75
+ }
76
+ return {
77
+ constraints: input.constraints ?? [],
78
+ next: input.next?.trim() || "Choose the next smallest verifiable action.",
79
+ objective: input.objective.trim(),
80
+ revision: 1,
81
+ status: "active",
82
+ success: input.success ?? [],
83
+ updatedAt: Date.now(),
84
+ verification: "not_run",
85
+ };
86
+ };
87
+ const updateGoal = (goal, input) => ({
88
+ ...goal,
89
+ ...(input.constraints === undefined
90
+ ? {}
91
+ : { constraints: input.constraints }),
92
+ ...(input.next === undefined ? {} : { next: input.next }),
93
+ ...(input.objective === undefined ? {} : { objective: input.objective }),
94
+ revision: goal.revision + 1,
95
+ ...(input.success === undefined ? {} : { success: input.success }),
96
+ updatedAt: Date.now(),
97
+ verification: "not_run",
98
+ });
99
+ const statusGoal = (goal, status) => ({
100
+ ...goal,
101
+ revision: goal.revision + 1,
102
+ status,
103
+ updatedAt: Date.now(),
104
+ });
105
+ const actionStatus = {
106
+ abandon: "abandoned",
107
+ done: "completed",
108
+ pause: "paused",
109
+ resume: "active",
110
+ };
111
+ const verifiedGoal = (goal, evidence) => ({
112
+ ...goal,
113
+ ...(evidence === undefined ? {} : { evidence }),
114
+ revision: goal.revision + 1,
115
+ updatedAt: Date.now(),
116
+ verification: "unknown",
117
+ });
118
+ const mutateGoal = (current, input) => {
119
+ if (input.action === "rewrite")
120
+ return rewriteGoal(input);
121
+ const active = requireActiveGoal(current);
122
+ if (input.action === "update")
123
+ return updateGoal(active, input);
124
+ if (input.action === "verify")
125
+ return verifiedGoal(active, input.evidence);
126
+ if (input.action === "status" || input.action === "show") {
127
+ throw new Error("Goal status is read-only.");
128
+ }
129
+ return statusGoal(active, actionStatus[input.action]);
130
+ };
131
+ const createExecuteGoal = (stateRoot, durableSessionId) => async (...arguments_) => {
132
+ const input = arguments_[1];
133
+ const context = arguments_[4];
134
+ const sessionId = durableSessionId ?? context.sessionManager.getSessionId();
135
+ const path = goalPath(stateRoot, sessionId);
136
+ const current = await readDurableGoal(path);
137
+ if (input.action === "status" || input.action === "show") {
138
+ return textResult(current ?? { status: "none" });
139
+ }
140
+ const next = mutateGoal(current, input);
141
+ await writeDurableGoal(path, next);
142
+ return textResult(next);
143
+ };
144
+ export const makeGoalExtension = (stateRoot, durableSessionId) => (pi) => {
145
+ pi.registerTool({
146
+ description: "Own one durable objective for this agent session; update status and record bounded verification evidence.",
147
+ execute: createExecuteGoal(stateRoot, durableSessionId),
148
+ executionMode: "sequential",
149
+ label: "Goal",
150
+ name: "goal",
151
+ parameters,
152
+ promptGuidelines: [
153
+ "Keep the session objective in goal and work progress in task.",
154
+ "Verification evidence is recorded as unknown until independently checked; it never grants authority.",
155
+ ],
156
+ promptSnippet: "Own one durable objective for this agent session",
157
+ });
158
+ };
2
159
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/goal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAM1C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC;AACjC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,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C,EAAgB,EAAQ,EAAE;IACzB,EAAE,CAAC,YAAY,CAAC;QACd,WAAW,EACT,2GAA2G;QAC7G,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,CAAC;QACvD,aAAa,EAAE,YAAY;QAC3B,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,MAAM;QACZ,UAAU;QACV,gBAAgB,EAAE;YAChB,+DAA+D;YAC/D,sGAAsG;SACvG;QACD,aAAa,EAAE,kDAAkD;KAClE,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,2 +1,3 @@
1
- export { processExtension } from "./extension.js";
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ export default function processExtension(pi: ExtensionAPI): void;
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,+BAA+B,CAAC;AA2EvC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAmB/D"}
@@ -1,2 +1,79 @@
1
- export { processExtension } from "./extension.js";
1
+ import { Type } from "typebox";
2
+ import { SessionProcessManager } from "./manager.js";
3
+ const MAX_COMMAND_LENGTH = 32 * 1024;
4
+ const MAX_INPUT_LENGTH = 64 * 1024;
5
+ const MAX_TIMEOUT_MS = 24 * 60 * 60 * 1000;
6
+ const parameters = Type.Object({
7
+ action: Type.Union([
8
+ Type.Literal("start"),
9
+ Type.Literal("list"),
10
+ Type.Literal("output"),
11
+ Type.Literal("logs"),
12
+ Type.Literal("stop"),
13
+ Type.Literal("write"),
14
+ Type.Literal("clear"),
15
+ ]),
16
+ command: Type.Optional(Type.String({ maxLength: MAX_COMMAND_LENGTH })),
17
+ cwd: Type.Optional(Type.String({ maxLength: 4096 })),
18
+ end: Type.Optional(Type.Boolean()),
19
+ id: Type.Optional(Type.String({ maxLength: 80 })),
20
+ input: Type.Optional(Type.String({ maxLength: MAX_INPUT_LENGTH })),
21
+ name: Type.Optional(Type.String({ maxLength: 120 })),
22
+ timeoutMs: Type.Optional(Type.Integer({ maximum: MAX_TIMEOUT_MS, minimum: 1 })),
23
+ });
24
+ const textResult = (value) => ({
25
+ content: [{ text: JSON.stringify(value), type: "text" }],
26
+ details: value,
27
+ });
28
+ const requireId = (input) => {
29
+ if (input.id === undefined)
30
+ throw new Error(`Process ${input.action} requires id.`);
31
+ return input.id;
32
+ };
33
+ const runAction = async (manager, input, sessionCwd) => {
34
+ if (input.action === "list")
35
+ return manager.list();
36
+ if (input.action === "start") {
37
+ if (input.command === undefined || input.command.trim().length === 0) {
38
+ throw new Error("Process start requires command.");
39
+ }
40
+ return manager.start({
41
+ command: input.command,
42
+ cwd: input.cwd ?? sessionCwd,
43
+ ...(input.name === undefined ? {} : { name: input.name }),
44
+ ...(input.timeoutMs === undefined ? {} : { timeoutMs: input.timeoutMs }),
45
+ });
46
+ }
47
+ const id = requireId(input);
48
+ if (input.action === "output" || input.action === "logs") {
49
+ return manager.get(id);
50
+ }
51
+ if (input.action === "stop")
52
+ return manager.stop(id);
53
+ if (input.action === "clear") {
54
+ manager.clear(id);
55
+ return { cleared: id };
56
+ }
57
+ return manager.write(id, input.input ?? "", input.end === true);
58
+ };
59
+ const createExecute = (manager) => async (...arguments_) => textResult(await runAction(manager, arguments_[1], arguments_[4].cwd));
60
+ export default function processExtension(pi) {
61
+ const manager = new SessionProcessManager();
62
+ pi.registerTool({
63
+ description: "Start and supervise bounded session processes. Processes are session-owned, not durable services or swarm workers.",
64
+ execute: createExecute(manager),
65
+ executionMode: "sequential",
66
+ label: "Process",
67
+ name: "process",
68
+ parameters,
69
+ promptGuidelines: [
70
+ "Use process only for background work owned by this agent session.",
71
+ "Stop or clear session processes when work completes; use daemon only for explicitly durable services.",
72
+ ],
73
+ promptSnippet: "Supervise session-owned background processes",
74
+ });
75
+ pi.on("session_shutdown", async () => {
76
+ await manager.shutdown();
77
+ });
78
+ }
2
79
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/process/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;QACjB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;KACtB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;IACtE,GAAG,EAAE,IAAI,CAAC,QAAQ,CA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,IAAI,CAAC,CAAC;AAClE,CAAC,CAAC;AAGF,MAAM,aAAa,GACjB,CAAC,OAA8B,EAAkB,EAAE,CACnD,KAAK,EAAE,GAAG,UAAsC,EAAE,EAAE,CAClD,UAAU,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE3E,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAgB;IACvD,MAAM,OAAO,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAC5C,EAAE,CAAC,YAAY,CAAC;QACd,WAAW,EACT,oHAAoH;QACtH,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC;QAC/B,aAAa,EAAE,YAAY;QAC3B,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,SAAS;QACf,UAAU;QACV,gBAAgB,EAAE;YAChB,mEAAmE;YACnE,uGAAuG;SACxG;QACD,aAAa,EAAE,8CAA8C;KAC9D,CAAC,CAAC;IACH,EAAE,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;QACnC,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,5 @@
1
- type ProcessStatus = "exited" | "failed" | "running" | "stopped";
2
- type ProcessSnapshot = {
1
+ export type ProcessStatus = "exited" | "failed" | "running" | "stopped";
2
+ export type ProcessSnapshot = {
3
3
  readonly command: string;
4
4
  readonly cwd: string;
5
5
  readonly exitCode?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/extensions/process/manager.ts"],"names":[],"mappings":"AAOA,KAAK,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACjE,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,C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,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;CAChC,CAAC;AAuEF,KAAK,UAAU,GAAG;IAChB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AA+BF,qBAAa,qBAAqB;;IAGhC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe;IAYzC,IAAI,IAAI,SAAS,eAAe,EAAE;IAIlC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe;IAIhC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,eAAe;IAOzD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAmBhD,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAQjB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAsBhC"}
@@ -13,12 +13,5 @@ export type GuardDecision = {
13
13
  readonly operation: DestructiveOperation;
14
14
  readonly reasonCode: GuardReasonCode;
15
15
  };
16
- /**
17
- * Blocks recursive `rm` and `find -delete` against `/`, `/root`, the home
18
- * directory or one of its ancestors. It follows straight-line `cd`, the
19
- * `sudo`, `env`, `command` and `exec` wrappers and nested `sh -c` or
20
- * `bash -c` commands up to four levels, and blocks deeper nesting. This
21
- * tripwire guards against accidental loss; it gives no sandbox.
22
- */
23
16
  export declare const inspectDestructiveCommand: (input: DestructiveCommandInput) => GuardDecision;
24
17
  //# sourceMappingURL=destructive-guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"destructive-guard.d.ts","sourceRoot":"","sources":["../../../src/extensions/safety/destructive-guard.ts"],"names":[],"mappings":"AAuBA,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,IAAI,CAAC;AACjD,MAAM,MAAM,eAAe,GACzB,uBAAuB,GAAG,wBAAwB,CAAC;AAErD,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC9B;IACE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;CACtC,CAAC;AAkNN;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,UAC7B,uBAAuB,KAC7B,aAIU,CAAC"}
1
+ {"version":3,"file":"destructive-guard.d.ts","sourceRoot":"","sources":["../../../src/extensions/safety/destructive-guard.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,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