@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.
- package/README.md +24 -99
- package/dist/extensions/goal/index.d.ts +2 -1
- package/dist/extensions/goal/index.d.ts.map +1 -1
- package/dist/extensions/goal/index.js +158 -1
- package/dist/extensions/goal/index.js.map +1 -1
- package/dist/extensions/process/index.d.ts +2 -1
- package/dist/extensions/process/index.d.ts.map +1 -1
- package/dist/extensions/process/index.js +78 -1
- package/dist/extensions/process/index.js.map +1 -1
- package/dist/extensions/process/manager.d.ts +2 -2
- package/dist/extensions/process/manager.d.ts.map +1 -1
- package/dist/extensions/safety/destructive-guard.d.ts +0 -7
- package/dist/extensions/safety/destructive-guard.d.ts.map +1 -1
- package/dist/extensions/safety/destructive-guard.js +63 -154
- package/dist/extensions/safety/destructive-guard.js.map +1 -1
- package/dist/extensions/safety/index.d.ts +4 -2
- package/dist/extensions/safety/index.d.ts.map +1 -1
- package/dist/extensions/safety/index.js +5 -2
- package/dist/extensions/safety/index.js.map +1 -1
- package/dist/extensions/safety/lifecycle.d.ts +1 -1
- package/dist/extensions/safety/lifecycle.d.ts.map +1 -1
- package/dist/extensions/tasks/index.d.ts +2 -1
- package/dist/extensions/tasks/index.d.ts.map +1 -1
- package/dist/extensions/tasks/index.js +164 -1
- package/dist/extensions/tasks/index.js.map +1 -1
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/managed-worker/main.js +230410 -233022
- package/dist/managed-worker/main.js.map +1 -1
- package/dist/managed-worker/main.meta.json +1 -1
- package/dist/managed-worker/protocol.d.ts +1 -2
- package/dist/managed-worker/protocol.d.ts.map +1 -1
- package/dist/managed-worker/protocol.js +2 -13
- package/dist/managed-worker/protocol.js.map +1 -1
- package/dist/managed-worker/worker.d.ts +4 -18
- package/dist/managed-worker/worker.d.ts.map +1 -1
- package/dist/managed-worker/worker.js +5 -139
- package/dist/managed-worker/worker.js.map +1 -1
- package/dist/{resources/resources.d.ts → resources.d.ts} +1 -2
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js.map +1 -0
- package/dist/{runner/runner.d.ts → runner.d.ts} +1 -3
- package/dist/runner.d.ts.map +1 -0
- package/dist/{runner/runner.js → runner.js} +18 -62
- package/dist/runner.js.map +1 -0
- package/dist/{runtime/runtime.d.ts → runtime.d.ts} +15 -11
- package/dist/runtime.d.ts.map +1 -0
- package/dist/{runtime/runtime.js → runtime.js} +33 -50
- package/dist/runtime.js.map +1 -0
- package/dist/startup-network-policy.d.ts +16 -0
- package/dist/startup-network-policy.d.ts.map +1 -0
- package/dist/{runtime/startup-network-policy.js → startup-network-policy.js} +2 -7
- package/dist/startup-network-policy.js.map +1 -0
- package/package.json +19 -57
- package/dist/auth/index.d.ts +0 -3
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -3
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/maia-auth.d.ts +0 -23
- package/dist/auth/maia-auth.d.ts.map +0 -1
- package/dist/auth/maia-auth.js +0 -97
- package/dist/auth/maia-auth.js.map +0 -1
- package/dist/auth/memory-credentials.d.ts +0 -9
- package/dist/auth/memory-credentials.d.ts.map +0 -1
- package/dist/auth/memory-credentials.js +0 -23
- package/dist/auth/memory-credentials.js.map +0 -1
- package/dist/extensions/goal/command.d.ts +0 -28
- package/dist/extensions/goal/command.d.ts.map +0 -1
- package/dist/extensions/goal/command.js +0 -80
- package/dist/extensions/goal/command.js.map +0 -1
- package/dist/extensions/goal/context.d.ts +0 -24
- package/dist/extensions/goal/context.d.ts.map +0 -1
- package/dist/extensions/goal/context.js +0 -35
- package/dist/extensions/goal/context.js.map +0 -1
- package/dist/extensions/goal/extension.d.ts +0 -7
- package/dist/extensions/goal/extension.d.ts.map +0 -1
- package/dist/extensions/goal/extension.js +0 -179
- package/dist/extensions/goal/extension.js.map +0 -1
- package/dist/extensions/goal/section.d.ts +0 -22
- package/dist/extensions/goal/section.d.ts.map +0 -1
- package/dist/extensions/goal/section.js +0 -49
- package/dist/extensions/goal/section.js.map +0 -1
- package/dist/extensions/process/extension.d.ts +0 -3
- package/dist/extensions/process/extension.d.ts.map +0 -1
- package/dist/extensions/process/extension.js +0 -79
- package/dist/extensions/process/extension.js.map +0 -1
- package/dist/extensions/prompt-section/index.d.ts +0 -2
- package/dist/extensions/prompt-section/index.d.ts.map +0 -1
- package/dist/extensions/prompt-section/index.js +0 -2
- package/dist/extensions/prompt-section/index.js.map +0 -1
- package/dist/extensions/prompt-section/prompt-section.d.ts +0 -26
- package/dist/extensions/prompt-section/prompt-section.d.ts.map +0 -1
- package/dist/extensions/prompt-section/prompt-section.js +0 -28
- package/dist/extensions/prompt-section/prompt-section.js.map +0 -1
- package/dist/extensions/safety/command-wrappers.d.ts +0 -31
- package/dist/extensions/safety/command-wrappers.d.ts.map +0 -1
- package/dist/extensions/safety/command-wrappers.js +0 -247
- package/dist/extensions/safety/command-wrappers.js.map +0 -1
- package/dist/extensions/safety/shell-tokens.d.ts +0 -13
- package/dist/extensions/safety/shell-tokens.d.ts.map +0 -1
- package/dist/extensions/safety/shell-tokens.js +0 -115
- package/dist/extensions/safety/shell-tokens.js.map +0 -1
- package/dist/extensions/search/bounds.d.ts +0 -22
- package/dist/extensions/search/bounds.d.ts.map +0 -1
- package/dist/extensions/search/bounds.js +0 -35
- package/dist/extensions/search/bounds.js.map +0 -1
- package/dist/extensions/search/extension.d.ts +0 -7
- package/dist/extensions/search/extension.d.ts.map +0 -1
- package/dist/extensions/search/extension.js +0 -18
- package/dist/extensions/search/extension.js.map +0 -1
- package/dist/extensions/search/index.d.ts +0 -2
- package/dist/extensions/search/index.d.ts.map +0 -1
- package/dist/extensions/search/index.js +0 -2
- package/dist/extensions/search/index.js.map +0 -1
- package/dist/extensions/tasks/context.d.ts +0 -20
- package/dist/extensions/tasks/context.d.ts.map +0 -1
- package/dist/extensions/tasks/context.js +0 -36
- package/dist/extensions/tasks/context.js.map +0 -1
- package/dist/extensions/tasks/extension.d.ts +0 -7
- package/dist/extensions/tasks/extension.d.ts.map +0 -1
- package/dist/extensions/tasks/extension.js +0 -178
- package/dist/extensions/tasks/extension.js.map +0 -1
- package/dist/extensions/tasks/summary.d.ts +0 -20
- package/dist/extensions/tasks/summary.d.ts.map +0 -1
- package/dist/extensions/tasks/summary.js +0 -50
- package/dist/extensions/tasks/summary.js.map +0 -1
- package/dist/extensions/title/extension.d.ts +0 -4
- package/dist/extensions/title/extension.d.ts.map +0 -1
- package/dist/extensions/title/extension.js +0 -37
- package/dist/extensions/title/extension.js.map +0 -1
- package/dist/extensions/title/index.d.ts +0 -2
- package/dist/extensions/title/index.d.ts.map +0 -1
- package/dist/extensions/title/index.js +0 -2
- package/dist/extensions/title/index.js.map +0 -1
- package/dist/extensions/title/title.d.ts +0 -9
- package/dist/extensions/title/title.d.ts.map +0 -1
- package/dist/extensions/title/title.js +0 -92
- package/dist/extensions/title/title.js.map +0 -1
- package/dist/home/index.d.ts +0 -2
- package/dist/home/index.d.ts.map +0 -1
- package/dist/home/index.js +0 -2
- package/dist/home/index.js.map +0 -1
- package/dist/home/maia-home.d.ts +0 -17
- package/dist/home/maia-home.d.ts.map +0 -1
- package/dist/home/maia-home.js +0 -84
- package/dist/home/maia-home.js.map +0 -1
- package/dist/login/index.d.ts +0 -2
- package/dist/login/index.d.ts.map +0 -1
- package/dist/login/index.js +0 -2
- package/dist/login/index.js.map +0 -1
- package/dist/login/provider-login.d.ts +0 -43
- package/dist/login/provider-login.d.ts.map +0 -1
- package/dist/login/provider-login.js +0 -153
- package/dist/login/provider-login.js.map +0 -1
- package/dist/managed-worker/index.d.ts +0 -2
- package/dist/managed-worker/index.d.ts.map +0 -1
- package/dist/managed-worker/index.js +0 -2
- package/dist/managed-worker/index.js.map +0 -1
- package/dist/managed-worker/operation-channel.d.ts +0 -24
- package/dist/managed-worker/operation-channel.d.ts.map +0 -1
- package/dist/managed-worker/operation-channel.js +0 -145
- package/dist/managed-worker/operation-channel.js.map +0 -1
- package/dist/resources/index.d.ts +0 -2
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js +0 -2
- package/dist/resources/index.js.map +0 -1
- package/dist/resources/resources.d.ts.map +0 -1
- package/dist/resources/resources.js.map +0 -1
- package/dist/runner/index.d.ts +0 -2
- package/dist/runner/index.d.ts.map +0 -1
- package/dist/runner/index.js +0 -2
- package/dist/runner/index.js.map +0 -1
- package/dist/runner/runner.d.ts.map +0 -1
- package/dist/runner/runner.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -3
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -3
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/kernel.d.ts +0 -18
- package/dist/runtime/kernel.d.ts.map +0 -1
- package/dist/runtime/kernel.js +0 -23
- package/dist/runtime/kernel.js.map +0 -1
- package/dist/runtime/runtime.d.ts.map +0 -1
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/runtime/startup-network-policy.d.ts +0 -9
- package/dist/runtime/startup-network-policy.d.ts.map +0 -1
- package/dist/runtime/startup-network-policy.js.map +0 -1
- /package/dist/{resources/resources.js → resources.js} +0 -0
package/README.md
CHANGED
|
@@ -1,115 +1,40 @@
|
|
|
1
1
|
# `@maiaos/agent`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The first-party Maia agent and managed worker, built on the official `@mariozechner/pi-coding-agent` SDK foundation.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
is published for installation testing:
|
|
13
|
+
Resource order follows the official Pi loader:
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
+
The lean built-in surface currently includes:
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
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
|
|
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
|
-
|
|
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
|
-
`
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
`
|
|
83
|
-
|
|
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
|
-
|
|
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":"
|
|
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
|
-
|
|
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,CAAC;IAC7B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;QACjB,IAAI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AW,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/process/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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
|
-
|
|
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":"
|
|
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,CAA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"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,
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/extensions/process/manager.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AACxE,MAAM,MAAM,eAAe,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":"
|
|
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,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;AAyHN,eAAO,MAAM,yBAAyB,GACpC,OAAO,uBAAuB,KAC7B,aAUF,CAAC"}
|