@aisac/cli 0.4.0-beta.2 → 0.4.0-beta.22
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 +146 -10
- package/dist/assets/claude/hooks/context-compaction.ts +17 -5
- package/dist/assets/claude/hooks/native-host-contract-runtime.ts +1 -1
- package/dist/assets/claude/hooks/native-host-contract.test.ts +8 -4
- package/dist/assets/claude/hooks/provider-window.d.ts +83 -0
- package/dist/assets/codex-context-compaction.mjs +846 -14
- package/dist/assets/jev-paid-pilot-terminal.mjs +12 -1
- package/dist/claude-compatibility.mjs +26 -25
- package/dist/claude-observation.mjs +2 -1
- package/dist/cli.mjs +641 -35
- package/dist/codex-compatibility.mjs +48 -2
- package/dist/codex-engineering.mjs +165 -0
- package/dist/codex-hooks.mjs +411 -0
- package/dist/codex-permissions.mjs +67 -34
- package/dist/codex-protocol-fingerprint.json +11 -11
- package/dist/engineering-init.mjs +615 -0
- package/dist/engineering-pack.mjs +276 -23
- package/dist/engineering-scan-pins.json +42 -0
- package/dist/engineering-scan-report.mjs +1274 -0
- package/dist/engineering-scan-tools.mjs +1418 -0
- package/dist/engineering-scan.mjs +1265 -0
- package/dist/extensions-catalog.mjs +390 -0
- package/dist/extensions-cli.mjs +492 -0
- package/dist/extensions-preferences.mjs +151 -0
- package/dist/guardrails/continuity.mjs +239 -0
- package/dist/guardrails/format.mjs +111 -0
- package/dist/guardrails/guards.mjs +1557 -0
- package/dist/guardrails/patch.mjs +33 -0
- package/dist/guardrails/run.mjs +286 -0
- package/dist/guardrails/shell-words.mjs +206 -0
- package/dist/guardrails-plugin.mjs +207 -0
- package/dist/launch.mjs +403 -47
- package/dist/managed-host.mjs +977 -0
- package/dist/manager/bus.mjs +1921 -0
- package/dist/manager/delegation.mjs +354 -0
- package/dist/manager/hooks.mjs +918 -0
- package/dist/manager/launch-role.mjs +476 -0
- package/dist/manager/mcp-stdio.mjs +463 -0
- package/dist/manager/messages.mjs +791 -0
- package/dist/manager/reserve.mjs +2166 -0
- package/dist/manager/room.mjs +106 -0
- package/dist/manager/server.mjs +1792 -0
- package/dist/manager/status.mjs +118 -0
- package/dist/manager/watch.mjs +87 -0
- package/dist/manager/worker.mjs +2793 -0
- package/dist/manager/workers-cli.mjs +1403 -0
- package/dist/mcp-servers.mjs +192 -0
- package/dist/mcp.mjs +10 -2
- package/dist/monitor.mjs +76 -1
- package/dist/package.json +1 -1
- package/dist/platform.mjs +78 -29
- package/dist/release-manifest-public-keys.json +10 -0
- package/dist/release-manifest.json +328 -0
- package/dist/release-manifest.mjs +817 -0
- package/dist/release-settings.mjs +210 -0
- package/dist/self-update.mjs +1036 -0
- package/dist/state.mjs +25 -1
- package/dist/token-guide.mjs +132 -0
- package/dist/update-actions.mjs +442 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# aisac
|
|
2
2
|
|
|
3
|
-
The AISAC client for Claude Code and Codex on Linux
|
|
3
|
+
The AISAC client for Claude Code and Codex on Linux, WSL and macOS, with
|
|
4
|
+
Node.js 22 or newer:
|
|
4
5
|
AI Brain memory, context management and, for AISAC Founding Cohort members,
|
|
5
6
|
AISAC Engineering.
|
|
6
7
|
|
|
@@ -18,19 +19,129 @@ For licensed accounts, `aisac claude` downloads the AISAC Engineering pack for
|
|
|
18
19
|
the session, verifies its Ed25519 signature against the key pinned in this
|
|
19
20
|
release, and loads it as the `aisac-engineering` plugin from the session's
|
|
20
21
|
private folder, which is deleted on exit. Any failure starts Claude without the
|
|
21
|
-
pack. `aisac setup --lang pt-BR|en` picks the pack language without a
|
|
22
|
-
call
|
|
22
|
+
pack. Once set up, `aisac setup --lang pt-BR|en` picks the pack language without a
|
|
23
|
+
network call; on a machine that was never set up it runs the full setup in that
|
|
24
|
+
language. The pack is never part of this npm package.
|
|
23
25
|
|
|
24
|
-
Codex
|
|
25
|
-
|
|
26
|
+
`aisac codex` (Codex 0.164.0 or later) loads the same verified pack for that
|
|
27
|
+
session only: its skills are added to the Codex app-server the launch owns
|
|
28
|
+
(call one with `$`, for example `$spec`) and its agents become session agent
|
|
29
|
+
roles. Nothing is written to `~/.codex`, `~/.agents` or the project, and the
|
|
30
|
+
session's folder is deleted on exit. An older Codex starts without the pack and
|
|
31
|
+
says `codex_outdated`.
|
|
32
|
+
|
|
33
|
+
`aisac init [dir]` (licensed accounts, client `0.4.0-beta.14` or later) writes the
|
|
34
|
+
AISAC skeleton into a new or existing project: `CLAUDE.md`, `AGENTS.md`,
|
|
35
|
+
`NOTES.example.md`, the `docs/` tree with its templates, a Claude Code rules file,
|
|
36
|
+
a CI workflow with pinned actions, Dependabot, `.gitignore` and the workloop
|
|
37
|
+
template. The templates travel inside the licensed pack, fetched and verified like
|
|
38
|
+
a launch; the command writes only files that are missing, never follows a symbolic
|
|
39
|
+
link, never touches `.git/` and prints every file it wrote or skipped. Options:
|
|
40
|
+
`--stack node|python|none` (otherwise detected from `package.json`, `pyproject.toml`
|
|
41
|
+
or `requirements.txt`), `--lang pt-BR|en`, `--dry-run`, `--json`. Exit codes: `0`
|
|
42
|
+
when every file exists or was written, `1` for a license, pack or write failure
|
|
43
|
+
(nothing is written before the pack is verified), `2` for a usage error. Until the
|
|
44
|
+
pack carries the templates, the command says so and writes nothing.
|
|
45
|
+
|
|
46
|
+
`aisac scan [dir]` (licensed accounts, client `0.4.0-beta.17` or later) runs four
|
|
47
|
+
pinned security scanners over your own project and writes one report under
|
|
48
|
+
`.security-reports/aisac-scan/<UTC>/`: gitleaks (secrets), Semgrep CE (static
|
|
49
|
+
analysis), osv-scanner (dependency advisories) and Trivy (infrastructure as code). It
|
|
50
|
+
calls no model and sends no finding anywhere. Each tool runs from its official image,
|
|
51
|
+
pinned by digest, read-only and without network where the tool allows. Without Docker
|
|
52
|
+
it runs a gitleaks, Semgrep or osv-scanner binary from an absolute `PATH` directory
|
|
53
|
+
only when its version is the pinned one, and otherwise skips the tool with a reason.
|
|
54
|
+
Trivy runs only from its image, so without Docker `iac` is skipped
|
|
55
|
+
(`tool_needs_container`). The report has `summary.md` in your language,
|
|
56
|
+
`summary.json` and a sanitized copy of each tool's output, with secret values
|
|
57
|
+
redacted and every finding mapped to OWASP ids. Scanner config files in your project
|
|
58
|
+
(`.gitleaks.toml`, `osv-scanner.toml`, `.semgrepignore` and the like) are ignored and
|
|
59
|
+
listed as `repo_scanner_config:<path>` warnings. osv-scanner sends package names and
|
|
60
|
+
versions to OSV.dev and contacts nothing else, and the client fetches the Semgrep
|
|
61
|
+
registry rules before the scan; `--skip sca` avoids the first. Options, each at most
|
|
62
|
+
once with its value as the next argument:
|
|
63
|
+
`--fail-on critical|high|medium|low|none`, `--only <kinds>` or `--skip <kinds>` (not
|
|
64
|
+
both; a comma list of `secrets`, `sast`, `sca`, `iac`, `container`), `--history`
|
|
65
|
+
(adds a git-history pass; `dir` must hold `.git`), `--no-docker`, `--lang pt-BR|en`,
|
|
66
|
+
`--json`, `--check-tools`, `--timeout <seconds>` (1 to 3600, default 600).
|
|
67
|
+
`--check-tools` shows what would run without a license, a pack or a network call, and
|
|
68
|
+
`aisac doctor` reports the same on its `scan` line. Exit codes: `0` below `--fail-on`
|
|
69
|
+
(default `high`), `1` at or above it, `2` for a usage error, `3` when the scan could
|
|
70
|
+
not run as asked: no scanner ran, a tool failed, `--history` found no repository, the
|
|
71
|
+
license is inactive, the pack could not be loaded, or another error stopped it.
|
|
72
|
+
Guide: [`aisac scan`](../../docs/how-to/aisac-scan.md).
|
|
73
|
+
|
|
74
|
+
Licensed `aisac claude` sessions also load guardrail hooks as the session plugin
|
|
75
|
+
`aisac-guardrails`.
|
|
76
|
+
- **Default on:** `secrets-guard` refuses secret files by name, and `bus-guard`
|
|
77
|
+
keeps the agent's tools out of the manager bus directory. Four more hooks
|
|
78
|
+
keep continuity: a repository snapshot at start and after a compaction, a
|
|
79
|
+
docs reminder, and the NOTES/spec/CHANGELOG pass.
|
|
80
|
+
- **Default off:** `git-guard`, `destructive-guard` and `format-on-edit`.
|
|
81
|
+
- **Changing them:** `aisac hooks` lists them, and `aisac hooks enable|disable
|
|
82
|
+
<id>` or `aisac hooks reset` changes the next session. The agent cannot change
|
|
83
|
+
them from inside a session.
|
|
84
|
+
- **Code:** it ships in this package and runs locally. Nothing comes from the
|
|
85
|
+
server.
|
|
86
|
+
- **Codex (0.166.0 or later):** licensed `aisac codex` sessions get the same hooks
|
|
87
|
+
from session flags. Codex runs them only after you approve the AISAC hooks once
|
|
88
|
+
in `/hooks`, and you can switch each one off there too. The launch line says how
|
|
89
|
+
many are on and how many wait for that review; `aisac doctor` reports the same
|
|
90
|
+
under `extensions.codexHooks`. A new Node path (for example after an nvm or
|
|
91
|
+
Homebrew upgrade) changes the hook commands, so Codex asks for the review again.
|
|
92
|
+
|
|
93
|
+
Licensed sessions of `aisac claude` and `aisac codex` can also load reviewed MCP
|
|
94
|
+
servers: `github` (read-only, token in `GITHUB_PERSONAL_ACCESS_TOKEN`), `supabase`
|
|
95
|
+
(read-only), `vercel`, `playwright` (pinned, isolated), `context7` and `creatives` (the
|
|
96
|
+
AISAC Creatives Studio, from client `0.4.0-beta.15`).
|
|
97
|
+
- **Default:** every server is off. `aisac mcp` lists them, `aisac mcp enable|disable
|
|
98
|
+
<id>` or `aisac mcp reset` changes the next session, and `aisac mcp info <id>` says
|
|
99
|
+
what a server reaches and how to log in.
|
|
100
|
+
- **Login:** the host does it (`/mcp` in Claude Code, `aisac mcp login <id>` for Codex)
|
|
101
|
+
and keeps it in its own store. No token reaches `~/.aibrain` or AISAC.
|
|
102
|
+
|
|
103
|
+
Manager and workers (licensed accounts, from client `0.4.0-beta.22`): `aisac claude --manager` and
|
|
104
|
+
`aisac codex --worker <name>`, opened in the same repository (or with the same
|
|
105
|
+
`--room <name>`), let one Claude Code session coordinate up to 16 Codex sessions on this
|
|
106
|
+
machine. You talk only to the manager; it sends each worker a task and reads the reply
|
|
107
|
+
through its `manager_*` tools. `aisac workers` lists the room.
|
|
108
|
+
- **Workers stay terminals:** you watch them, type in them and answer their approval
|
|
109
|
+
prompts there. A manager message is labelled as not typed by you, carries no approval
|
|
110
|
+
and never changes a worker's sandbox or approval policy. What you type into a turn the
|
|
111
|
+
manager started goes back to it with the answer; turns you start yourself do not.
|
|
112
|
+
- **Hosts:** the worker role is offered only on the Codex versions the client was measured
|
|
113
|
+
with; `aisac doctor` shows it on its `manager` line. Otherwise, or without an active
|
|
114
|
+
license, the host starts without the role and says why in one line.
|
|
115
|
+
- **Sends ask you:** Claude Code asks before the first `manager_send`; allow it for the
|
|
116
|
+
session or the project from that prompt.
|
|
117
|
+
- **Overnight:** `aisac workers delegate --for 8h`, typed in your own terminal with a
|
|
118
|
+
confirmation, lets the manager answer approval prompts one request at a time until the
|
|
119
|
+
grant ends (`--off` ends it early). Secrets, pushes to `main` or `master`, force pushes
|
|
120
|
+
and pushes that do not name their destination, destructive commands, publishing,
|
|
121
|
+
deploying, infrastructure, remote databases, merges, releases, `sudo`, commands the
|
|
122
|
+
client cannot fully read, wider permissions and writes outside the repository always
|
|
123
|
+
wait for you. The reserve reads the command line, not what a script does.
|
|
124
|
+
`aisac workers decisions` shows every delegated decision.
|
|
125
|
+
- **Privacy:** messages are private files under `~/.aibrain/bus/`, deleted once taken and
|
|
126
|
+
swept after 24 hours; no telemetry carries them and nothing is written to the AI Brain.
|
|
127
|
+
The text does cross providers: a manager message enters the worker's Codex context and
|
|
128
|
+
its reply enters the manager's Claude Code context. The decision record keeps the text
|
|
129
|
+
of each delegated request for 30 days.
|
|
130
|
+
|
|
131
|
+
Guide: [manager and workers](../../docs/how-to/aisac-manager.md).
|
|
132
|
+
|
|
133
|
+
On Linux/WSL, Codex capture also requires the `flock` utility from `util-linux`,
|
|
134
|
+
normally included. On macOS it uses `/usr/bin/perl`, `/usr/sbin/sysctl` and
|
|
135
|
+
`/bin/ps` instead. The launcher and doctor check availability before a
|
|
26
136
|
monitored Codex session starts. Capture coordination is released by the kernel
|
|
27
137
|
after a process exits unexpectedly. An unidentifiable empty lock left by an
|
|
28
138
|
older client requires a verified support migration; do not delete checkpoints,
|
|
29
139
|
notes or lock files to work around a reported storage error.
|
|
30
140
|
|
|
31
141
|
The reviewed native compatibility set is Claude Code 2.1.294, 2.1.295, 2.1.296,
|
|
32
|
-
2.1.299, 2.1.300, 2.1.301, 2.1.302 or 2.1.
|
|
33
|
-
0.162.0, 0.162.1, 0.163.0
|
|
142
|
+
2.1.299, 2.1.300, 2.1.301, 2.1.302, 2.1.303, 2.1.311, 2.1.322 or 2.1.323, and Codex CLI 0.161.0,
|
|
143
|
+
0.162.0, 0.162.1, 0.163.0, 0.164.0, 0.166.0 or 0.167.1 (0.165.0 and 0.167.0 were never
|
|
144
|
+
qualified; 0.167.0 shares the 0.167.1 contract, so the structural probe admits it). A newer stable Codex 0.x release may continue only
|
|
34
145
|
after its locally generated experimental protocol schemas and transport flags
|
|
35
146
|
match the bundled adapter contract; prereleases, older releases and new majors
|
|
36
147
|
remain rejected. Starting with beta14, newer stable Claude 2.1 patches can
|
|
@@ -46,6 +157,29 @@ record formats. Native launch/resume qualification is separate from a new
|
|
|
46
157
|
model/JEV compaction qualification. A later native release that changes the
|
|
47
158
|
consumed contract can still require an AI Brain compatibility update.
|
|
48
159
|
|
|
160
|
+
`0.4.0-beta.9` refreshes the bundled contract to Codex 0.166.0. Its delta is
|
|
161
|
+
additive: optional item timing, an image generation id, an attach-to-source fork
|
|
162
|
+
flag and two error codes. See the
|
|
163
|
+
[Codex 0.166 qualification record](../../docs/reference/codex-166-compatibility-2026-11-04.md).
|
|
164
|
+
|
|
165
|
+
`0.4.0-beta.16` refreshes the bundled contract to Codex 0.167.1 and qualifies Claude Code
|
|
166
|
+
2.1.311 and 2.1.322. The Codex delta is additive: audio inputs may reference an uploaded
|
|
167
|
+
file (`fileId` / `file_id`) instead of a URL, `initialize` gains the optional
|
|
168
|
+
`requiredHumanApproval` capability and `humanCommand` becomes an approval kind only
|
|
169
|
+
clients that declare it receive. See the
|
|
170
|
+
[Codex 0.167 qualification record](../../docs/reference/codex-167-compatibility-2026-11-11.md)
|
|
171
|
+
and the [Claude 2.1.322 record](../../docs/reference/claude-322-compatibility-2026-11-11.md).
|
|
172
|
+
|
|
173
|
+
`0.4.0-beta.17` adds `aisac scan`, keeps the pack's `scan/` rules out of every session
|
|
174
|
+
(like `init/`), and lets a command exit with `3`. The qualified Claude Code and Codex
|
|
175
|
+
versions are those of `0.4.0-beta.16`.
|
|
176
|
+
|
|
177
|
+
`0.4.0-beta.18` qualifies Claude Code 2.1.323. Its `claude plugin validate` type-checks the
|
|
178
|
+
hook modules, so the bundled plugin now type-checks under the host's tsconfig (typing only,
|
|
179
|
+
no behaviour change) and ships `provider-window.d.ts`; the host probe also reads an
|
|
180
|
+
inventory that the validator wraps across several notes. See the
|
|
181
|
+
[Claude 2.1.323 record](../../docs/reference/claude-323-compatibility-2026-11-12.md).
|
|
182
|
+
|
|
49
183
|
The Codex terminal bridge permits the native session picker's separate read-only
|
|
50
184
|
connection while keeping the primary conversation and monitor intact. A picker
|
|
51
185
|
cannot compact, start a turn, inject history or take ownership of the primary
|
|
@@ -54,7 +188,7 @@ connection. Its failure or timeout closes only that auxiliary connection.
|
|
|
54
188
|
```sh
|
|
55
189
|
# Install the published beta:
|
|
56
190
|
npm install -g @aisac/cli@beta
|
|
57
|
-
aisac setup --client both
|
|
191
|
+
aisac setup # configures the clients on PATH; --client claude|codex|both to choose
|
|
58
192
|
aisac doctor --json
|
|
59
193
|
aisac claude
|
|
60
194
|
aisac codex
|
|
@@ -68,8 +202,10 @@ Installation does not contact AI Brain, change native client configuration, or
|
|
|
68
202
|
enable all paid accounts. Setup requires an existing AI Brain PAT, explicit
|
|
69
203
|
versioned disclosure, and successful provider-free pilot access. Claude and
|
|
70
204
|
Codex continue to own their own authentication. Windows native is unsupported;
|
|
71
|
-
run the beta inside WSL.
|
|
72
|
-
|
|
205
|
+
run the beta inside WSL. On macOS, Codex capture locks with the system
|
|
206
|
+
`/usr/bin/perl` (`flock(2)`) and identifies the lock owner with `sysctl` and
|
|
207
|
+
`ps`, so nothing extra needs installing. Pricing and general customer
|
|
208
|
+
activation are outside this beta.
|
|
73
209
|
|
|
74
210
|
For reviewed noninteractive automation only, use a private token file and
|
|
75
211
|
explicitly acknowledge the displayed disclosure with
|
|
@@ -151,7 +151,7 @@ type Register = (
|
|
|
151
151
|
) => void;
|
|
152
152
|
|
|
153
153
|
const MAX_RESULT_BYTES = 256 * 1024;
|
|
154
|
-
const CLAUDE_HOOK_VERSION = '0.4.0-beta.
|
|
154
|
+
const CLAUDE_HOOK_VERSION = '0.4.0-beta.7';
|
|
155
155
|
const MAX_DIAGNOSTIC_BYTE_COUNT = 128 * 1024 * 1024;
|
|
156
156
|
const COOLDOWN_MS = 60_000;
|
|
157
157
|
const MAX_TRUNCATED_CODE_POINTS = 300;
|
|
@@ -463,6 +463,10 @@ function v2WireOptions(options: V2Options): Record<string, unknown> {
|
|
|
463
463
|
|
|
464
464
|
function safeErrorCategory(error: unknown): string {
|
|
465
465
|
const record = isRecord(error) ? error : {};
|
|
466
|
+
// A coded error names its own reason; the keyword guess below would read
|
|
467
|
+
// "AI Brain plan does not meet the minimum estimated reduction" as invalid_plan.
|
|
468
|
+
if (COMPACT_ERROR_CODES.includes(record.compactErrorCode as CompactErrorCode))
|
|
469
|
+
return record.compactErrorCode as CompactErrorCode;
|
|
466
470
|
const code = typeof record.code === 'string' ? record.code.toLowerCase() : '';
|
|
467
471
|
const name = typeof record.name === 'string' ? record.name.toLowerCase() : '';
|
|
468
472
|
const message = typeof record.message === 'string' ? record.message.toLowerCase() : '';
|
|
@@ -4504,11 +4508,19 @@ type ClaudeTelemetry = {
|
|
|
4504
4508
|
disconnected(): boolean;
|
|
4505
4509
|
flush(timeoutMs?: number): Promise<void>;
|
|
4506
4510
|
};
|
|
4511
|
+
// The host tsconfig (lib es2023 only) declares no timers; the hook runtime provides them
|
|
4512
|
+
// on globalThis, so the handle stays opaque and the defaults are read from there.
|
|
4513
|
+
type ClaudeTimerHandle = unknown;
|
|
4507
4514
|
type ClaudeTelemetryTimers = {
|
|
4508
|
-
setTimeout(callback: () => void, delay: number):
|
|
4509
|
-
clearTimeout(timer:
|
|
4515
|
+
setTimeout(callback: () => void, delay: number): ClaudeTimerHandle;
|
|
4516
|
+
clearTimeout(timer: ClaudeTimerHandle): void;
|
|
4510
4517
|
};
|
|
4511
4518
|
|
|
4519
|
+
function hostTelemetryTimers(): ClaudeTelemetryTimers {
|
|
4520
|
+
const host = globalThis as unknown as ClaudeTelemetryTimers;
|
|
4521
|
+
return { setTimeout: host.setTimeout, clearTimeout: host.clearTimeout };
|
|
4522
|
+
}
|
|
4523
|
+
|
|
4512
4524
|
const TELEMETRY_HELPER_MAX_STDOUT_BYTES = 8 * 1024;
|
|
4513
4525
|
|
|
4514
4526
|
type TelemetryHelperConfiguration = 'none' | 'valid' | 'invalid';
|
|
@@ -4673,7 +4685,7 @@ export function createClaudeTelemetryReporter(
|
|
|
4673
4685
|
getSessionId: () => PromiseLike<string> | string,
|
|
4674
4686
|
sendReport: (payload: Record<string, unknown>) => PromiseLike<unknown> | unknown,
|
|
4675
4687
|
now: () => number = () => Date.now(),
|
|
4676
|
-
timers: ClaudeTelemetryTimers =
|
|
4688
|
+
timers: ClaudeTelemetryTimers = hostTelemetryTimers(),
|
|
4677
4689
|
): ClaudeTelemetry {
|
|
4678
4690
|
const active =
|
|
4679
4691
|
enabled === true &&
|
|
@@ -4748,7 +4760,7 @@ export function createClaudeTelemetryReporter(
|
|
|
4748
4760
|
if (attempt.expired) return;
|
|
4749
4761
|
if (!telemetryAckAccepted(response)) throw new Error('telemetry_report_rejected');
|
|
4750
4762
|
})();
|
|
4751
|
-
let timer:
|
|
4763
|
+
let timer: ClaudeTimerHandle | undefined;
|
|
4752
4764
|
void (async () => {
|
|
4753
4765
|
try {
|
|
4754
4766
|
await Promise.race([
|
|
@@ -10,7 +10,7 @@ const contractTest: Parameters<typeof test>[2] = async ($, on) => {
|
|
|
10
10
|
on('session.usage', () => ({
|
|
11
11
|
value: (() => {
|
|
12
12
|
usageCalls += 1;
|
|
13
|
-
return { context: { percent: 90, tokens: 900, window: 1_000 } };
|
|
13
|
+
return { startedAt: 0, context: { percent: 90, tokens: 900, window: 1_000 }, rateLimits: [] };
|
|
14
14
|
})(),
|
|
15
15
|
}));
|
|
16
16
|
on('ui.log', () => ({ value: undefined }));
|
|
@@ -23,17 +23,21 @@ const contractTest: Parameters<typeof test>[2] = async ($, on) => {
|
|
|
23
23
|
};
|
|
24
24
|
});
|
|
25
25
|
on('turn.complete', () => ({ text: '' }));
|
|
26
|
-
const prompt = await $.prompt.submit({
|
|
26
|
+
const prompt = await $.prompt.submit({
|
|
27
|
+
text: 'native-host-contract-input',
|
|
28
|
+
wait: false,
|
|
29
|
+
origin: { kind: 'composer' },
|
|
30
|
+
});
|
|
27
31
|
const tool = await $.tool.call({ tool: 'Read', file_path: 'native-host-contract.txt' });
|
|
28
32
|
await $.turn.complete({
|
|
29
33
|
turnId: 'native-contract-turn',
|
|
30
34
|
answer: 'native-turn-contract-ok',
|
|
31
35
|
durationMs: 1,
|
|
32
36
|
isAborted: false,
|
|
33
|
-
|
|
37
|
+
reason: 'answer',
|
|
34
38
|
});
|
|
35
39
|
expect(prompt.text).toBe('native-host-contract-ok');
|
|
36
|
-
expect(tool.result.content).toBe('native-host-tool-ok');
|
|
40
|
+
expect((tool.result as { readonly content: unknown }).content).toBe('native-host-tool-ok');
|
|
37
41
|
expect(usageCalls).toBe(1);
|
|
38
42
|
expect(compactCalls).toBe(1);
|
|
39
43
|
const monotonicEnd = globalThis.performance?.now?.();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { ProviderFitOptions, ProviderFitPreflight, ProviderFitProjection, ProviderFitProjectionMessage, ProviderFitProjectionPair } from './state-fitting.mjs';
|
|
2
|
+
export declare const PROVIDER_WINDOW_MAX_PAIRS = 200;
|
|
3
|
+
export declare const PROVIDER_WINDOW_MAX_MESSAGES = 1000;
|
|
4
|
+
export declare const PROVIDER_WINDOW_MAX_REFERENCES = 200;
|
|
5
|
+
export declare const PROVIDER_WINDOW_MAX_REQUEST_BYTES: number;
|
|
6
|
+
export declare const PROVIDER_WINDOW_REQUEST_HEADROOM_BYTES: number;
|
|
7
|
+
export declare const PROVIDER_WINDOW_MAX_SEARCH_ATTEMPTS = 12;
|
|
8
|
+
export declare const PROVIDER_WINDOW_MAX_STATE_TOKENS = 25000;
|
|
9
|
+
export declare const PROVIDER_WINDOW_MAX_REQUEST_TOKENS = 30000;
|
|
10
|
+
export declare const PROVIDER_WINDOW_MAX_RESERVED_TOKENS = 120000;
|
|
11
|
+
export declare const PROVIDER_WINDOW_OUTPUT_TOKEN_ALLOWANCE = 4000;
|
|
12
|
+
export type ProviderWindowMessage = ProviderFitProjectionMessage;
|
|
13
|
+
export interface ProviderWindowPair extends ProviderFitProjectionPair {
|
|
14
|
+
readonly callId: string;
|
|
15
|
+
readonly resultId: string;
|
|
16
|
+
readonly callMessage: number;
|
|
17
|
+
readonly resultMessage: number;
|
|
18
|
+
readonly resultText: string;
|
|
19
|
+
readonly protectedPair: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ProviderWindowProjection {
|
|
22
|
+
readonly goal: string;
|
|
23
|
+
readonly messages: readonly ProviderWindowMessage[];
|
|
24
|
+
readonly pairs: readonly ProviderWindowPair[];
|
|
25
|
+
readonly protectedItemCount: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ProviderWindowWireProjection {
|
|
28
|
+
readonly goal: string;
|
|
29
|
+
readonly messages: readonly {
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly role: 'user' | 'assistant';
|
|
32
|
+
readonly text: string;
|
|
33
|
+
readonly call_ids: readonly string[];
|
|
34
|
+
readonly result_ids: readonly string[];
|
|
35
|
+
}[];
|
|
36
|
+
readonly pairs: readonly {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly tool: string;
|
|
39
|
+
readonly input_text: string;
|
|
40
|
+
readonly result_chars: number;
|
|
41
|
+
readonly result_is_error: boolean;
|
|
42
|
+
readonly eligibility: 'reproducible_read' | 'compatible_tool' | 'protected';
|
|
43
|
+
readonly pin_reasons: readonly string[];
|
|
44
|
+
}[];
|
|
45
|
+
readonly protected_item_count: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ProviderWindowOptions extends ProviderFitOptions {
|
|
48
|
+
readonly preserveRecentMessages: number;
|
|
49
|
+
readonly maxPairs?: number;
|
|
50
|
+
readonly maxMessages?: number;
|
|
51
|
+
readonly maxReferencesPerMessage?: number;
|
|
52
|
+
readonly maxRequestBytes?: number;
|
|
53
|
+
readonly requestHeadroomBytes?: number;
|
|
54
|
+
readonly maxReservedTokens?: number;
|
|
55
|
+
/** Shared capacity snapshot limits. These are advisory; backend admission remains authoritative. */
|
|
56
|
+
readonly maxBatchesPerOperation?: number;
|
|
57
|
+
readonly outputTokenAllowance?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface ProviderWindowPreflight extends ProviderFitPreflight {
|
|
60
|
+
readonly requestBytes: number;
|
|
61
|
+
readonly estimatedReservationTokens: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ProviderWindowSuccess {
|
|
64
|
+
readonly ok: true;
|
|
65
|
+
readonly projection: ProviderWindowWireProjection;
|
|
66
|
+
readonly pairs: readonly ProviderWindowPair[];
|
|
67
|
+
readonly deferredPairs: readonly ProviderWindowPair[];
|
|
68
|
+
readonly preflight: ProviderWindowPreflight;
|
|
69
|
+
readonly attempts: number;
|
|
70
|
+
readonly anchorPairCount: number;
|
|
71
|
+
readonly selectedEligibleCount: number;
|
|
72
|
+
}
|
|
73
|
+
export type ProviderWindowFailureReason = 'anchor_overflow' | 'message_limit_exceeded' | 'no_feasible_window';
|
|
74
|
+
export interface ProviderWindowFailure {
|
|
75
|
+
readonly ok: false;
|
|
76
|
+
readonly reason: ProviderWindowFailureReason;
|
|
77
|
+
readonly attempts: number;
|
|
78
|
+
readonly anchorPairCount: number;
|
|
79
|
+
}
|
|
80
|
+
export type ProviderWindowResult = ProviderWindowSuccess | ProviderWindowFailure;
|
|
81
|
+
type ProviderFit = (projection: ProviderFitProjection, eligible: readonly ProviderFitProjectionPair[], options: ProviderFitOptions) => ProviderFitPreflight;
|
|
82
|
+
export declare function prepareProviderWindow(input: ProviderWindowProjection, options: ProviderWindowOptions, fit?: ProviderFit): ProviderWindowResult;
|
|
83
|
+
export {};
|