@akanjs/devkit 3.2.0-rc.30 → 3.2.0-rc.32
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/CHANGELOG.md +91 -4
- package/app/applicationBuildRunner.test.ts +58 -0
- package/app/applicationBuildRunner.ts +46 -7
- package/app/routeJsBudget.test.ts +16 -0
- package/app/routeJsBudget.ts +7 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +9 -2
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanToolPack.ts +1 -1
- package/commandDecorators/command.ts +30 -2
- package/commandDecorators/commandDecorators.test.ts +78 -1
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +69 -0
- package/commandDecorators/workspaceVersionCheck.ts +63 -13
- package/frontendBuild/precompressArtifacts.ts +18 -5
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +8 -5
- package/incrementalBuilder/ssrRegistry.ts +5 -1
- package/package.json +9 -9
- package/preview/previewView.test.ts +23 -1
- package/quality/qualityScanner.test.ts +40 -0
- package/quality/qualityScanner.ts +17 -83
- package/quality/workspaceSourceFiles.ts +82 -0
- package/typecheck/projectTypecheck.test.ts +22 -0
- package/typecheck/projectTypecheck.ts +9 -1
- package/typecheck/typeChecker.ts +4 -3
- package/typecheck/typecheck.proc.ts +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
Upgrade: a script that tested for exit 1 after a usage error, a failed check or a closed prompt tests for non-zero, or for 2, 3 and 130. A CI step that branches on exit 2 from the OTA commands needs no change. `@akanjs/devkit/commandDecorators` exports `CliError(code, message, { exitCode })`, `ExitCodeError` is now one coded from its exit status (2 as `refused`, 3 as `checkFailed`), and a target's `usageExitCode` now also sets the exit of a `usage` or `unknownTarget` failure thrown while it runs.
|
|
19
19
|
|
|
20
|
+
- 2fc03ed: A CLI whose major.minor differs from the workspace's `akanjs` now refuses every command that writes to the workspace (`akan sync`, the generators and scaffolds, `akan workflow apply`, `akan verify`, `akan lint` with fixes, `akan start`, `akan build` and the rest), naming both versions and `akan update`; commands that only read (`akan context`, `akan doctor`, `akan logs`, `akan lint --fix false`, `akan workflow plan` and the like) keep the warning, and a patch or prerelease difference within one major.minor still only warns. `akan update` also moves `react`, `react-dom` and `react-server-dom-webpack` to the peers of the `akanjs` release it installs, and a new workspace's devcontainer and README install the CLI at the workspace's `akanjs` version instead of `latest`.
|
|
21
|
+
|
|
22
|
+
A command marks itself as only reading with `readOnly` on its target (`target({ readOnly: true })`, or a function of its arguments and options); a command without it counts as writing.
|
|
23
|
+
|
|
24
|
+
**Upgrading.** A command that ran with a warning under a CLI of another major.minor now stops with exit code 2. Run `akan update` to move the workspace and the CLI to one release, install the CLI at the workspace's version, or set `AKAN_ALLOW_VERSION_MISMATCH=1` to run it anyway. A workspace created before this release still installs `@akanjs/cli@latest` in its devcontainer: change its `onCreateCommand` to the one a new workspace's `.devcontainer/devcontainer.json` holds, or to the install line of the CLI's README.
|
|
25
|
+
|
|
20
26
|
- d6b3619: Every `Err` is now one class, `Err` from `akanjs/common`. That covers the one an app's or lib's `lib/dict` builds, the one `useClient` returns, `akanjs/dictionary`'s own, and an error restored off the wire. Each is that class typed with its own dictionary's keys, so `Err.is` and the status classes behave the same in the browser and on the server. `instanceof Err` holds within one copy of the module. A page bundle and the framework each carry one, so check across them with `Err.is`.
|
|
21
27
|
|
|
22
28
|
- **`Err` is an `AkanError`.** `AkanError.is(err)` is true for every `Err`, and `err.forwarded` is true unless it was restored with a `code`, so the request path still sends its `toJSON()` as it is.
|
|
@@ -63,11 +69,43 @@
|
|
|
63
69
|
- The `akan-scaffold` skill builds the request without a supporting entity nobody asked for and says why one may be needed, instead of stopping to ask.
|
|
64
70
|
- `akan code` closes a turn that changed files with those files and what `akan_verify` said.
|
|
65
71
|
|
|
72
|
+
- 69a954c: `agentService.loop` takes the answer to a parked call as its own argument, `answer`, and accepts it only for the call the run parked on.
|
|
73
|
+
|
|
74
|
+
- `answer: { id, result }` or `{ id, error }` answers the call a run ended `awaiting` on with `client` or `question`: the first call of the last batch that nothing answered, and only when it is a client tool's or `askUser`'s. A page's `AgentClientTools.run(call)` result can be passed as it is.
|
|
75
|
+
- The run names the result after the call, whatever name was sent, hands it to `onMessage`, emits it as a `toolResult` event and runs the calls the batch has left.
|
|
76
|
+
- An endpoint tool's call is answered only by running it. An `answer` that names one, a call the run has not reached, or a call already answered ends the run with an `error` event whose `error` is `agent.error.answerRefused`, before anything runs. A resume without the `answer` carries on.
|
|
77
|
+
- Only `askUser`'s answer is exempt from the untrusted rule. A client tool's answer always taints the run.
|
|
78
|
+
- A run that ended `awaiting` with `connect`, on an `openToolkit` call for a remote the account has no connection to, is resumed in one of two ways. Once the user connected, resume with the stored messages and no `answer`: the run opens the remote itself. When the user declines, resume with `answer: { id, error }` for that call, which replaces appending `{ id, name: "openToolkit", error }` to the messages. The `error` only says that the user refused: the run stores a sentence of its own that names the remote, with the code `remoteDeclined`, as that call's result, and keeps none of the text sent. That sentence taints neither the run nor a later resume. A decline is accepted only for an `openToolkit` call that names a remote and is the first call of the last batch that nothing answered. The stored messages do not record why a run stopped there, so that holds whether the run parked on the connection, `approve` deferred the batch, or the run died before reaching the call. All a decline does is keep that open from running, with the run's own sentence as its result: it carries no text of the caller's, answers no other call and opens nothing, and the rest of the batch is judged as usual. An `answer` with a `result` for an `openToolkit` call is refused as `agent.error.answerRefused`: whether a connection exists is the server's to see.
|
|
79
|
+
- A stored result is read as the answer to the call its id names, under that call's name: a result stored under the name `askUser` no longer skips `untrusted` unless the call it answers is `askUser`'s.
|
|
80
|
+
- `messages` holds only the app's own user messages and what `onMessage` handed over. Never take `messages` from a request: store what `onMessage` hands out and pass from the client only `answer`, as a tool message a client wrote reads exactly like one the run stored.
|
|
81
|
+
- Pass `answer` only after an `awaiting` event with `client` or `question` named that call. `approve` is not asked about an answered call, as nothing runs on the server, so an answer given for a call `approve` deferred, or for one a run died before parking on, is stored as it stands.
|
|
82
|
+
|
|
83
|
+
**Upgrading.** An app built on a 3.2.0 release candidate that appends a tool message to `messages` before resuming must pass the answer instead:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// before
|
|
87
|
+
this.agentService.loop({
|
|
88
|
+
...request,
|
|
89
|
+
messages: [
|
|
90
|
+
...stored,
|
|
91
|
+
{ role: "tool", toolResults: [{ id, name, result }] },
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
// after
|
|
95
|
+
this.agentService.loop({
|
|
96
|
+
...request,
|
|
97
|
+
messages: stored,
|
|
98
|
+
answer: { id, result },
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The run stores the answer through `onMessage`, so do not store it yourself. An appended result is still read as a stored one, but nothing checks which call it answers: remove the append. Code that expects no `toolResult` event before the first model call of a resume now receives one for the answer.
|
|
103
|
+
|
|
66
104
|
- 4538737: `agentService.loop` can now ask the member a question and wait for the answer between runs, the way the in-page chat's `askUser` does.
|
|
67
105
|
|
|
68
106
|
- `ask: true` lists `askUser({ question, choices?, multiple? })`, with the in-page chat's own description and parameters.
|
|
69
107
|
- A call ends the run as `awaiting`, with `question: true` on the event. Calls written before it in the same batch have already run; calls written after it wait for the resume.
|
|
70
|
-
- Put the question to the member over your own transport
|
|
108
|
+
- Put the question to the member over your own transport and resume with `answer: { id, result }`, or `{ id, error }` when they dismiss it. A resume without the answer parks the call again. A resume without `ask` answers it as an unknown tool.
|
|
71
109
|
- `askUser` never reaches `approve` and counts as no tool call. `untrusted` never sees the answer, which is the member's own input.
|
|
72
110
|
- A call with no question is answered with an error and the run goes on.
|
|
73
111
|
- With `ask: true`, a `clientTools` entry named `askUser` is dropped, and an `allow` naming `askUser` is refused as an invalid argument.
|
|
@@ -77,16 +115,34 @@
|
|
|
77
115
|
- dcddea0: `agentService.loop` can now call the tools of a screen the member has open, without running them on the server. The run parks each such call, the way an approval parks one, until the page answers it.
|
|
78
116
|
|
|
79
117
|
- **Server.** `clientTools` takes the definitions the open page sent over the app's own transport. They are listed beside the endpoint tools.
|
|
80
|
-
- They are client input. Each definition is rebuilt from `name`, `description`, `parameters`, `readOnly`
|
|
81
|
-
- `approve` is still asked about each call. With no approver, a
|
|
118
|
+
- They are client input. Each definition is rebuilt from `name`, `description`, `parameters` and `needsConfirm`, and counts as a write whatever `readOnly` it carries. A name an endpoint tool holds is dropped, in a closed toolkit too, and so is `openToolkit`.
|
|
119
|
+
- `approve` is still asked about each call. With no approver, a client tool is refused once the run is tainted, and a `needsConfirm` one is always refused.
|
|
82
120
|
- An allowed call ends the run as `awaiting`, with `client: true` on the event. Calls written before it in the same batch have already run; calls written after it wait for the resume.
|
|
83
|
-
- The run never waits on a socket. The app delivers the call to the page
|
|
121
|
+
- The run never waits on a socket. The app delivers the call to the page and resumes with the page's result as `answer` (or `{ id, error }` when no page answers). A resume without it parks the call again. A resume without `clientTools` answers it as an unknown tool.
|
|
84
122
|
- **Browser.** `AgentClientTools` is new in `use-agentic` and re-exported from `akanjs/ui`, along with the `ToolRunnerHost` and `ToolApprovalRequest` types.
|
|
85
123
|
- `new AgentClientTools(surface?, host?).list()` gives the open screen's tools in the shape `clientTools` takes, each with `readOnly: false`.
|
|
86
124
|
- `run(call)` answers a parked call through the same `ToolRunner` as the in-page chat. A `confirm` still asks through `host.approve` and is refused without one, a card tool needs `host.card`, and the answer is clipped and fenced as the chat's would be.
|
|
87
125
|
|
|
88
126
|
Both are new and optional, so no upgrade step is needed.
|
|
89
127
|
|
|
128
|
+
- 69a954c: `agentService.loop` now counts what a run reads as untrusted unless the app says otherwise. With no `untrusted` option, every result of a call that ran taints the run: an endpoint tool's or a client tool's, an error included.
|
|
129
|
+
|
|
130
|
+
- A run with `approve` is asked with `tainted: true` for every call after the first result.
|
|
131
|
+
- A run with no `approve` writes only in the batch the model wrote before any result came back. A later write is not run: its result carries the code `writeAfterRead` and a sentence saying to pass `approve` or `untrusted`, and the server logs a warning naming the tool.
|
|
132
|
+
- `askUser`'s answer, `openToolkit`'s answer and a call the run refused without running taint nothing. A resume cannot tell a stored refusal from a stored result, so with no `untrusted` it counts every stored tool result.
|
|
133
|
+
- `untrusted` still decides for endpoint results when it is given: `() => false` trusts every one, and `(result) => !own.has(result.name)` trusts the endpoints the app names. No endpoint option says whose text a tool returns, so the predicate is where that is declared.
|
|
134
|
+
- A client tool's answer always taints the run and is never shown to `untrusted`: a page may lend a tool under the name of an endpoint the run does not list, which a predicate reading names would trust. `approve` receives `client: true` for a call to a page's tool, and only `approve` lets a write follow a page's answer. A resume reads this off the stored call, not off a stored mark: a stored result is judged by `untrusted` only when its call names an endpoint the resumed run lists, and any other, a page's tool or a tool the run no longer has, taints the run. The run's own answer to a tool name the model made up, `Unknown tool: <name>.` with nothing beside it, taints nothing. Keep `ask` and `toolkits` the same for the life of a transcript: a stored `askUser` or `openToolkit` answer whose name the page lends taints.
|
|
135
|
+
- With `remotes`, the open of a remote and any call into one taint the run whatever `untrusted` returns and with none given, a call the run refused included. A resume reads this off the stored call as well: a stored result whose call is `<remote>.<tool>`, or an `openToolkit` call that names a remote, taints the run unasked, with or without its mark. The one exception is the run's own sentence for a connection the user refused, stored with nothing beside it, which taints nothing; the error of an open that failed does. Keep `remotes` the same for the life of a transcript, like `ask` and `toolkits`.
|
|
136
|
+
- A compaction summary is now always written with its `tainted` field, and a stored summary without one counts as tainted in every run, where it used to count only in a run with `untrusted`.
|
|
137
|
+
|
|
138
|
+
**Upgrading.** This changes a default of the 3.2.0 release candidates. A `loop` call that passes neither `untrusted` nor `approve` and whose `allow` or `clientTools` hold a tool that changes data must now choose one of three:
|
|
139
|
+
|
|
140
|
+
- pass `approve`, and decide there what may run once `tainted` is `true`;
|
|
141
|
+
- pass `untrusted: (result) => …` returning `true` for the results that can carry text someone else wrote;
|
|
142
|
+
- pass `untrusted: () => false` to keep the release candidates' behaviour for endpoint tools, when nothing they return was written by anyone but the app and the member.
|
|
143
|
+
|
|
144
|
+
A run with `clientTools` and no `approve` refuses every write after a page's answer, whatever `untrusted` returns: pass `approve` and allow there what may follow. A resume whose `allow` no longer lists an endpoint that stored results came from starts tainted. A call that already passes `untrusted` otherwise changes nothing, with one exception for stored transcripts: a summary stored without a `tainted` field by a run that had no `untrusted` now taints the run that resumes from it. Set `tainted: false` on such a stored summary if what it replaced was the app's own data. A call that passes only `approve` now receives `tainted: true` after the first result, so an approver that denies or defers every tainted call does so from then on: pass `untrusted` as well to keep `tainted` for the results that warrant it.
|
|
145
|
+
|
|
90
146
|
- 2da2adc: `agentService.loop` takes `toolkits`, so a run over a large catalogue no longer sends every tool definition every round.
|
|
91
147
|
|
|
92
148
|
- **Shape.** `toolkits: { calendar: { description: "Read and edit the org calendar", tools: ["eventListInOrg", "updateEvent"] } }` groups names of `allow`. A tool in no toolkit is the core and is listed every round. `allow` still caps every toolkit.
|
|
@@ -368,6 +424,10 @@
|
|
|
368
424
|
- **The CSR build and its MCP App views** rewrite `akanjs/ui` imports to the components a file names, as the SSR route builds already did, so a page that imports `Link` no longer bundles every component.
|
|
369
425
|
- **Animations use `@react-spring/web`** instead of the `react-spring` umbrella package, which also installed the native, three.js, konva and zdog renderers.
|
|
370
426
|
|
|
427
|
+
- 842b9e4: The pi agent packages move from 1.3.0 to 1.5.2, so an install of the CLI no longer pulls undici 8.10.2 (four high advisories, among them a TLS certificate check dropped in `Agent`) and minimatch 10.2.6. They now resolve to undici 8.12.3 and minimatch 11.0.3.
|
|
428
|
+
|
|
429
|
+
`akan code` keeps the defaults it had on 1.3.0, so the bump changes nothing it bills: prompt caches are warmed only while a turn streams (pi 1.5 also warms them for up to 30 minutes between turns), and Anthropic requests carry the whole conversation instead of a server-side message thread. Setting `compat.supportsMessageThreads` in `models.json` still turns threads on.
|
|
430
|
+
|
|
371
431
|
- b516497: `akan create-package --name` takes `name` or `@scope/name`, each part lowercase letters, digits, `-`, `.` and `_` starting with a letter or digit, and refuses anything else before it touches a file: `"../x" is no package name; use name or @scope/name, each of lowercase letters, digits, -, . and _, starting with a letter or digit`. Before, `--name ../x` wrote `x/` beside `pkgs/` and added it to the root `tsconfig.json`. `akan create-ui`, `add-field` and `add-enum-field` refuse a `--module` that is not a module name with a `primitive-input-invalid` diagnostic in their report, as they already reported a missing one. Before, `create-ui --module ../x` wrote its component into the app root, and `add-field --module ../x` looked for the constant and dictionary outside the module folder. `plainNameProblem` returns the message `assertPlainName` throws, and `assertPackageName` sits beside it in `@akanjs/devkit/workflow/plainName`.
|
|
372
432
|
- 58b7329: `akan create-scalar`, `remove-scalar`, `create-module`, `create-service`, `create-application`, `create-library`, `install-library` and `create-workspace --app` refuse a name that is not one plain path segment before they touch a file, such as `"../.." is no scalar name; use letters, digits, - and _, starting with a letter`. Before, the name went into the path unchecked: `akan remove-scalar ../.. <app>` deleted `apps/<app>` and exited 0, and the create commands wrote their files outside `lib/`, `apps/` or `libs/`. A scalar, module or service name is checked as a workflow's `module` input already was, an app or lib name as its `app` input; both checks now live in `@akanjs/devkit/workflow/plainName`, with `assertPlainName`.
|
|
373
433
|
- 4e0a38e: A page preview starts a new browser when the one before it died. Bun refuses to start a new browser until a later event-loop turn has reaped the dead one. `akan preview` opens its pages back to back when the app's log socket does not answer. In that case, if Chrome died during one page, every page after it failed at once with `Failed to spawn Chrome (set BUN_CHROME_PATH, …)`. Now a preview whose browser fails to start for any reason other than running out of `startTimeoutMs` waits 100 ms and tries the start once more. A browser that cannot start at all still fails in about 100 ms, now with its own error, such as `Chrome process closed the pipe`.
|
|
@@ -580,6 +640,10 @@
|
|
|
580
640
|
- **`akan build` fails when the vendor scan cannot find a route's client entry**, and names the entry. Before, a build that wrote its route bundles somewhere the scan did not look narrowed every vendor entry to nothing. The build passed, and pages threw in the browser.
|
|
581
641
|
- **The vendor scan no longer overflows the stack on large minified chunks.** A function body of about 20,000 statements, which a minifier folds into one comma chain, used to fail `akan build` with `Maximum call stack size exceeded`.
|
|
582
642
|
|
|
643
|
+
- 595264b: `akan verify` now builds only each changed app's server and SSR routes, then checks the route JS budget, and skips the browser bundle, font pruning, compression and production metadata, so its build step finishes sooner. `ApplicationBuildRunner` takes a `verify` option for this.
|
|
644
|
+
|
|
645
|
+
**Upgrading.** After `akan verify`, `dist/apps/<app>` is not a deployable build: its `akan.build.json` says `"profile": "verify"`, and its `main.js` exits at once, telling you to run `akan build <app>`. Run `akan build` before you deploy or start it. A page that compiles for the server but not for the browser is no longer reported by `akan verify`, only by `akan build`.
|
|
646
|
+
|
|
583
647
|
- bd4d45a: `akan verify` now fixes or explains three lint failures that were costly to resolve by hand.
|
|
584
648
|
|
|
585
649
|
- **A daisyUI component class your own CSS defines is no longer refused.**
|
|
@@ -593,15 +657,22 @@
|
|
|
593
657
|
- The rule's own rewrite is removed. Under `--unsafe` it renamed a `#field` where it was called but not where it was declared.
|
|
594
658
|
- **A raw `Error` in an `srvkit/` adapter names its fix.** `akan verify` prints the `Err` import path from that file, and where the key goes: the app's or lib's own service dictionary, `lib/_<name>/<name>.dictionary.ts`, as `<name>.error.<key>`.
|
|
595
659
|
|
|
660
|
+
- 595264b: `akan verify` now typechecks a workspace package incrementally, keeping the cache under the workspace's git-ignored `.akan/typecheck/pkgs/<package>/`, so a second run over an unchanged package takes about as long as its lint instead of a full typecheck.
|
|
661
|
+
- 595264b: `akan verify`'s SSR check now reads only the apps and libs with a changed `.tsx` file, plus every lib's signals, instead of running the whole-workspace quality scan, so it takes a fraction of the time and reports the same warnings. `AkanQualityScanner` gains `scanSsr(workspaceRoot, dirs)` for this; `akan quality` still scans the whole workspace.
|
|
596
662
|
- d4d84c6: `akan workflow validate` exits 0 when the only failures left are known baseline blockers (`overallStatus` `passed-with-baseline-blockers`); any other failed validation still exits 1. Over MCP, a passing `apply_workflow` dry run names `apply_workflow` with the same `planPath` and no `dryRun` as `next`, where it named `run_validation`, which had nothing to validate. A failed `akan workflow apply` reports no generated files queued for sync, no recommended validation command and no `akan verify` next action, and a failed field, mutation or slice write (`akan add-field` and its siblings) lists no generated file, validation command or next action; both used to list them as if the write had passed. With `-o json`, `akan workflow plan`, `apply`, `validate` and `report` print only the JSON report on stdout and send their log lines (`File Create:`, sync's warnings) to stderr; `create-module` and `create-scalar` applies used to print them before the report, so stdout did not parse. The text output is unchanged. `add-field` (the workflow and `akan add-field`) imports the type it writes: a scalar of the target from `../__scalar/<scalar>/<scalar>.constant`, a model from `../<model>/<model>.constant`, and `ID`, `Any` and the other `akanjs/base` types from `akanjs/base`, where it imported only `Int` and `Float` and wrote `field(Address)` with no import. A type that is not built in, not imported by the constant and not a scalar or model of the target is refused with `primitive-field-type-unknown`, at plan time and again at apply, before anything is written.
|
|
597
663
|
- d2b2291: A failed workflow no longer reports success to its caller. `akan workflow plan` exits 1 when the plan has an error, `akan workflow apply` when the apply or its `--dry-run` fails, and `akan workflow validate` when its status is `failed` (which includes `passed-with-baseline-blockers`); all three exited 0 before. A dry run of a plan with an error, such as `add-field --type Number`, reports `failed` and lists no changed or generated files, where it used to list the plan's edits under "Automatically Modified". Over MCP, `plan_workflow` names `apply_workflow` in `next` and `approval.canApplyWith` only for a plan without an error, and `apply_workflow` names `run_validation` only when the apply did not fail; a refused plan also drops its "apply this plan" and "validate the apply report" recommendations. The workflows that write into an existing module (`add-field`, `add-enum-field`, `add-mutation`, `add-slice`, `create-ui`, `rename-key`) now refuse a service module, or any folder without its `<module>.constant.ts`, at plan time and again at apply. The `workflow-module-not-database` error lists the target's database modules and points at `create-module`, and for a field at `create-scalar`. Before, `add-field` on a service module passed its plan and dry run and failed only at apply, and `create-ui` wrote a misnamed `_<service>.View.tsx` into it. The `workflow-module-missing` error now lists only database modules too, says a name that matches a service module (with or without its `_`) is one instead of asking "Did you mean \_<service>?", and points at another app or library only when it holds a database module of that name.
|
|
598
664
|
- adcdf3b: `akan workflow plan` and the `plan_workflow` MCP tool refuse a module the target app or library lacks, for every workflow that writes into an existing module (`add-field`, `add-enum-field`, `add-mutation`, `add-slice`, `create-ui`, `rename-key`). The `workflow-module-missing` error names the module, lists the modules the target has, and points at the module whose name differs only in case or by a leading `_`, at a scalar of that name, or at the app or library that holds it; only when none exists does it point at `create-module`. Before, the plan passed and its dry run reported `passed`. `add-mutation` used to plan a missing module with a warning so that a `create-module` plan could precede it; it now refuses too, so plan it after applying `create-module`. Every workflow now refuses an unknown `app` at plan time, listing the workspace's apps and libraries. `apply` and `--dry-run` check the target again before anything else, so a plan written earlier for a module that is gone fails instead of passing. `plan_workflow` now inspects the MCP server's workspace rather than the process directory.
|
|
599
665
|
- Updated dependencies [bd198af]
|
|
600
666
|
- Updated dependencies [ba81635]
|
|
601
667
|
- Updated dependencies [bc792ab]
|
|
668
|
+
- Updated dependencies [69a954c]
|
|
602
669
|
- Updated dependencies [4538737]
|
|
670
|
+
- Updated dependencies [69a954c]
|
|
603
671
|
- Updated dependencies [dcddea0]
|
|
604
672
|
- Updated dependencies [3ebf990]
|
|
673
|
+
- Updated dependencies [69a954c]
|
|
674
|
+
- Updated dependencies [fd76e6f]
|
|
675
|
+
- Updated dependencies [876a2bd]
|
|
605
676
|
- Updated dependencies [2da2adc]
|
|
606
677
|
- Updated dependencies [e9a2c7f]
|
|
607
678
|
- Updated dependencies [6ffb8ef]
|
|
@@ -634,14 +705,18 @@
|
|
|
634
705
|
- Updated dependencies [7c85c42]
|
|
635
706
|
- Updated dependencies [ddd3d96]
|
|
636
707
|
- Updated dependencies [3f231a7]
|
|
708
|
+
- Updated dependencies [fd76e6f]
|
|
637
709
|
- Updated dependencies [96f9ff6]
|
|
710
|
+
- Updated dependencies [935bddf]
|
|
638
711
|
- Updated dependencies [0a81afa]
|
|
639
712
|
- Updated dependencies [d988c56]
|
|
713
|
+
- Updated dependencies [935bddf]
|
|
640
714
|
- Updated dependencies [af7c411]
|
|
641
715
|
- Updated dependencies [6d449b1]
|
|
642
716
|
- Updated dependencies [1ebc57a]
|
|
643
717
|
- Updated dependencies [c3b5b3c]
|
|
644
718
|
- Updated dependencies [dcb7e61]
|
|
719
|
+
- Updated dependencies [b236476]
|
|
645
720
|
- Updated dependencies [6d5b544]
|
|
646
721
|
- Updated dependencies [ca67c2c]
|
|
647
722
|
- Updated dependencies [73f8830]
|
|
@@ -649,14 +724,19 @@
|
|
|
649
724
|
- Updated dependencies [14134d3]
|
|
650
725
|
- Updated dependencies [958f175]
|
|
651
726
|
- Updated dependencies [9f30e93]
|
|
727
|
+
- Updated dependencies [b5989d1]
|
|
728
|
+
- Updated dependencies [a91a643]
|
|
652
729
|
- Updated dependencies [ad09fac]
|
|
653
730
|
- Updated dependencies [ae045d8]
|
|
731
|
+
- Updated dependencies [a91a643]
|
|
654
732
|
- Updated dependencies [d9eaacc]
|
|
655
733
|
- Updated dependencies [d79a206]
|
|
656
734
|
- Updated dependencies [d9eaacc]
|
|
657
735
|
- Updated dependencies [0e5db0a]
|
|
658
736
|
- Updated dependencies [c334caf]
|
|
659
737
|
- Updated dependencies [170be15]
|
|
738
|
+
- Updated dependencies [3a54335]
|
|
739
|
+
- Updated dependencies [374abac]
|
|
660
740
|
- Updated dependencies [d9f5ad5]
|
|
661
741
|
- Updated dependencies [f314eba]
|
|
662
742
|
- Updated dependencies [e143263]
|
|
@@ -668,11 +748,16 @@
|
|
|
668
748
|
- Updated dependencies [256b6e3]
|
|
669
749
|
- Updated dependencies [c48d780]
|
|
670
750
|
- Updated dependencies [3537448]
|
|
751
|
+
- Updated dependencies [e3a1d31]
|
|
671
752
|
- Updated dependencies [c882491]
|
|
672
753
|
- Updated dependencies [f3def22]
|
|
754
|
+
- Updated dependencies [876a2bd]
|
|
755
|
+
- Updated dependencies [9928a8f]
|
|
756
|
+
- Updated dependencies [9928a8f]
|
|
673
757
|
- Updated dependencies [8424863]
|
|
674
758
|
- Updated dependencies [bf28968]
|
|
675
759
|
- Updated dependencies [dfc3564]
|
|
760
|
+
- Updated dependencies [a91a643]
|
|
676
761
|
- Updated dependencies [24dcb1e]
|
|
677
762
|
- Updated dependencies [d12f556]
|
|
678
763
|
- Updated dependencies [9b5bcee]
|
|
@@ -740,10 +825,12 @@
|
|
|
740
825
|
- Updated dependencies [91ccf38]
|
|
741
826
|
- Updated dependencies [c2af76a]
|
|
742
827
|
- Updated dependencies [df32c46]
|
|
828
|
+
- Updated dependencies [9928a8f]
|
|
743
829
|
- Updated dependencies [5f809e8]
|
|
744
830
|
- Updated dependencies [fd125b0]
|
|
745
831
|
- Updated dependencies [a5c476a]
|
|
746
832
|
- Updated dependencies [76705dd]
|
|
833
|
+
- Updated dependencies [9292352]
|
|
747
834
|
- Updated dependencies [206bb69]
|
|
748
835
|
- Updated dependencies [170be15]
|
|
749
836
|
- Updated dependencies [cfe50cb]
|
|
@@ -389,4 +389,62 @@ console.info(new SampleService().name);
|
|
|
389
389
|
await rm(root, { recursive: true, force: true });
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
|
+
|
|
393
|
+
test("a verify build stops after the backend and SSR route compile but still measures the route JS budget", async () => {
|
|
394
|
+
const { root, workspace } = await createTempApp("portal");
|
|
395
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
396
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
397
|
+
await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(root, "apps", "portal", file), "")));
|
|
398
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
399
|
+
app.prepareCommand = async () => ({ env: {} });
|
|
400
|
+
const bundle = spyOn(Bun, "build").mockImplementation(
|
|
401
|
+
async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
|
|
402
|
+
);
|
|
403
|
+
try {
|
|
404
|
+
const { phases } = await new ApplicationBuildRunner(app, { verify: true }).build();
|
|
405
|
+
expect(phases.map((phase) => phase.id)).toEqual(["prepare", "backend", "ssr", "budget"]);
|
|
406
|
+
expect(await Bun.file(path.join(app.dist.cwdPath, "package.json")).exists()).toBe(false);
|
|
407
|
+
} finally {
|
|
408
|
+
bundle.mockRestore();
|
|
409
|
+
for (const key of keys) {
|
|
410
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
411
|
+
else process.env[key] = shellEnv[key];
|
|
412
|
+
}
|
|
413
|
+
await rm(root, { recursive: true, force: true });
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test("marks a verify build's output and makes its main.js refuse to boot", async () => {
|
|
418
|
+
const { root, workspace } = await createTempApp("portal");
|
|
419
|
+
const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
|
|
420
|
+
const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
|
|
421
|
+
await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(root, "apps", "portal", file), "")));
|
|
422
|
+
const app = AppExecutor.from(workspace, "portal");
|
|
423
|
+
app.prepareCommand = async () => ({ env: {} });
|
|
424
|
+
const bundle = spyOn(Bun, "build").mockImplementation(
|
|
425
|
+
async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
|
|
426
|
+
);
|
|
427
|
+
try {
|
|
428
|
+
await new ApplicationBuildRunner(app, { verify: true }).build();
|
|
429
|
+
const main = bundle.mock.calls.find(([config]) => config.entrypoints.some((entry) => entry.endsWith("main.ts")));
|
|
430
|
+
const banner = main?.[0].banner ?? "";
|
|
431
|
+
const mainPath = path.join(root, "main.js");
|
|
432
|
+
await writeFile(mainPath, `${banner}\nconsole.log("booted");\n`);
|
|
433
|
+
const proc = Bun.spawnSync([process.execPath, mainPath], { stdout: "pipe", stderr: "pipe" });
|
|
434
|
+
|
|
435
|
+
expect(proc.exitCode).toBe(1);
|
|
436
|
+
expect(proc.stdout.toString()).toBe("");
|
|
437
|
+
expect(proc.stderr.toString()).toContain("Run `akan build portal` first.");
|
|
438
|
+
expect(await Bun.file(path.join(app.dist.cwdPath, "akan.build.json")).json()).toMatchObject({
|
|
439
|
+
profile: "verify",
|
|
440
|
+
});
|
|
441
|
+
} finally {
|
|
442
|
+
bundle.mockRestore();
|
|
443
|
+
for (const key of keys) {
|
|
444
|
+
if (shellEnv[key] === undefined) delete process.env[key];
|
|
445
|
+
else process.env[key] = shellEnv[key];
|
|
446
|
+
}
|
|
447
|
+
await rm(root, { recursive: true, force: true });
|
|
448
|
+
}
|
|
449
|
+
});
|
|
392
450
|
});
|
|
@@ -45,11 +45,15 @@ export type BuildPhaseId =
|
|
|
45
45
|
| "budget"
|
|
46
46
|
| "metadata";
|
|
47
47
|
|
|
48
|
+
type RouteJsMeasure = RouteJsBudgetStatus & { sizes: RouteJsSize[] };
|
|
49
|
+
|
|
48
50
|
export type BuildPhaseResult = ApplicationBuildPhaseResult & { id: BuildPhaseId };
|
|
49
51
|
export type BuildResult = ApplicationBuildResult;
|
|
50
52
|
export type BuildProgressReporter = ApplicationBuildProgressReporter;
|
|
51
53
|
export interface ApplicationBuildRunnerOptions {
|
|
52
54
|
fast?: boolean;
|
|
55
|
+
/** `akan verify`'s build stops after the SSR route compile and the route JS budget, so its `dist/` is not deployable. */
|
|
56
|
+
verify?: boolean;
|
|
53
57
|
reporter?: BuildProgressReporter;
|
|
54
58
|
/** The backend env the build is for, when it is not the workspace's own (a mobile or desktop build's `--env`). */
|
|
55
59
|
environment?: string;
|
|
@@ -101,6 +105,7 @@ export const AKAN_OPTIONAL_BACKEND_EXTERNALS = ["bullmq", "ioredis", "postgres",
|
|
|
101
105
|
export class ApplicationBuildRunner {
|
|
102
106
|
#app: App;
|
|
103
107
|
#fast: boolean;
|
|
108
|
+
#verify: boolean;
|
|
104
109
|
#reporter?: BuildProgressReporter;
|
|
105
110
|
#environment?: string;
|
|
106
111
|
#profile?: string;
|
|
@@ -112,10 +117,18 @@ export class ApplicationBuildRunner {
|
|
|
112
117
|
|
|
113
118
|
constructor(
|
|
114
119
|
app: App,
|
|
115
|
-
{
|
|
120
|
+
{
|
|
121
|
+
fast = false,
|
|
122
|
+
verify = false,
|
|
123
|
+
reporter,
|
|
124
|
+
environment,
|
|
125
|
+
profile,
|
|
126
|
+
budget = "report",
|
|
127
|
+
}: ApplicationBuildRunnerOptions = {},
|
|
116
128
|
) {
|
|
117
129
|
this.#app = app;
|
|
118
|
-
this.#fast = fast;
|
|
130
|
+
this.#fast = fast || verify;
|
|
131
|
+
this.#verify = verify;
|
|
119
132
|
this.#reporter = reporter;
|
|
120
133
|
this.#environment = environment;
|
|
121
134
|
this.#profile = profile;
|
|
@@ -177,6 +190,11 @@ export class ApplicationBuildRunner {
|
|
|
177
190
|
? "skipped"
|
|
178
191
|
: "disabled by akan.config.ts web.ssr",
|
|
179
192
|
);
|
|
193
|
+
if (this.#verify) {
|
|
194
|
+
const routeJs = await this.#runBudgetPhase(environment);
|
|
195
|
+
await this.#app.dist.writeJson("akan.build.json", { profile: "verify", builtAt: new Date().toISOString() });
|
|
196
|
+
return this.#resultOf(environment, routeJs);
|
|
197
|
+
}
|
|
180
198
|
await this.#runPhase(
|
|
181
199
|
"csr",
|
|
182
200
|
"Building CSR assets",
|
|
@@ -201,13 +219,21 @@ export class ApplicationBuildRunner {
|
|
|
201
219
|
? `${result.files} files, ${ApplicationBuildRunner.formatBytes(result.inputBytes)} -> gzip ${ApplicationBuildRunner.formatBytes(result.outputBytes)} / br ${ApplicationBuildRunner.formatBytes(result.brotliBytes)}`
|
|
202
220
|
: "no files",
|
|
203
221
|
);
|
|
204
|
-
const routeJs = await this.#
|
|
222
|
+
const routeJs = await this.#runBudgetPhase(environment);
|
|
223
|
+
await this.#runPhase("metadata", "Writing production metadata", () => this.buildAppMeta());
|
|
224
|
+
return this.#resultOf(environment, routeJs);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#runBudgetPhase(environment: string) {
|
|
228
|
+
return this.#runPhase(
|
|
205
229
|
"budget",
|
|
206
230
|
"Measuring route JS",
|
|
207
231
|
() => this.#measureRouteJs(environment),
|
|
208
232
|
(result) => result?.summary ?? (this.#budget === "off" ? "off for this build" : "no server pages"),
|
|
209
233
|
);
|
|
210
|
-
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#resultOf(environment: string, routeJs: RouteJsMeasure | null): BuildResult {
|
|
211
237
|
return {
|
|
212
238
|
phases: this.#phases,
|
|
213
239
|
...(routeJs ? { routeJs: routeJs.sizes } : {}),
|
|
@@ -341,6 +367,13 @@ export class ApplicationBuildRunner {
|
|
|
341
367
|
return this.#serverEnv;
|
|
342
368
|
}
|
|
343
369
|
|
|
370
|
+
//? `bun main.js` in dist/apps/<app> is a documented way to run a build, and a verify output has no CSR bundle or
|
|
371
|
+
//? production env file, so its main.js refuses to boot before any app module runs.
|
|
372
|
+
#verifyBanner() {
|
|
373
|
+
const message = `dist/apps/${this.#app.name} holds the partial output of akan verify, not a build. Run \`akan build ${this.#app.name}\` first.`;
|
|
374
|
+
return `console.error(${JSON.stringify(message)});process.exit(1);`;
|
|
375
|
+
}
|
|
376
|
+
|
|
344
377
|
async #buildBackend() {
|
|
345
378
|
const { externalLibs, web, baseDevEnv, branches } = await this.#app.getConfig();
|
|
346
379
|
const backendEntryPoints = [`${this.#app.cwdPath}/main.ts`, `${this.#app.cwdPath}/server.ts`];
|
|
@@ -362,7 +395,11 @@ export class ApplicationBuildRunner {
|
|
|
362
395
|
};
|
|
363
396
|
//* Built apart so main.js keeps its own module copies; splitting moves lazy vendor `import()`s out of the boot parse.
|
|
364
397
|
const [mainResult, serverResult] = [
|
|
365
|
-
await this.#buildOrThrow("backend", {
|
|
398
|
+
await this.#buildOrThrow("backend", {
|
|
399
|
+
...backendConfig,
|
|
400
|
+
entrypoints: [backendEntryPoints[0]],
|
|
401
|
+
...(this.#verify ? { banner: this.#verifyBanner() } : {}),
|
|
402
|
+
}),
|
|
366
403
|
await this.#buildOrThrow("backend", { ...backendConfig, entrypoints: [backendEntryPoints[1]], splitting: true }),
|
|
367
404
|
];
|
|
368
405
|
// Nothing spawns the RSC worker without SSR, so an api-only image does not carry it.
|
|
@@ -450,12 +487,14 @@ void run().catch((error) => {
|
|
|
450
487
|
return { base, allRoutes };
|
|
451
488
|
}
|
|
452
489
|
|
|
453
|
-
//? After `compress`: a route is measured by the brotli bytes it is served as, read from the `.br` sidecars
|
|
454
|
-
|
|
490
|
+
//? After `compress`: a route is measured by the brotli bytes it is served as, read from the `.br` sidecars, which a
|
|
491
|
+
//? verify build skips writing and measures in memory instead.
|
|
492
|
+
async #measureRouteJs(environment: string): Promise<RouteJsMeasure | null> {
|
|
455
493
|
if (this.#budget === "off" || !this.#modulesByRoute) return null;
|
|
456
494
|
const sizes = await RouteJsBudget.measure(
|
|
457
495
|
path.join(this.#app.dist.cwdPath, ".akan/artifact"),
|
|
458
496
|
this.#modulesByRoute,
|
|
497
|
+
{ precompressed: !this.#verify },
|
|
459
498
|
);
|
|
460
499
|
const budgetPath = path.join(this.#app.cwdPath, RouteJsBudget.fileName);
|
|
461
500
|
const { summary: status, warnings } = await RouteJsBudget.check(sizes, {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import type { App } from "../commandDecorators";
|
|
4
|
+
import { precompressArtifacts } from "../frontendBuild/precompressArtifacts";
|
|
3
5
|
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
4
6
|
import { RouteJsBudget, type RouteJsSize } from "./routeJsBudget";
|
|
5
7
|
|
|
@@ -31,6 +33,20 @@ describe("RouteJsBudget", () => {
|
|
|
31
33
|
]);
|
|
32
34
|
});
|
|
33
35
|
|
|
36
|
+
test("sizes a file without its sidecar as precompressArtifacts compresses it, for a build that skips that step", async () => {
|
|
37
|
+
const distPath = await makeTempRoot();
|
|
38
|
+
const artifactDir = path.join(distPath, ".akan/artifact");
|
|
39
|
+
await write(path.join(artifactDir, "client/page.js"), `export const x = ${JSON.stringify("page ".repeat(900))};`);
|
|
40
|
+
await write(path.join(artifactDir, "client/tiny.js"), "t".repeat(200));
|
|
41
|
+
const modulesByRoute = { "/:lang": ["/_akan/client/page.js", "/_akan/client/tiny.js"] };
|
|
42
|
+
|
|
43
|
+
const inMemory = await RouteJsBudget.measure(artifactDir, modulesByRoute, { precompressed: false });
|
|
44
|
+
await precompressArtifacts({ dist: { cwdPath: distPath }, verbose: () => undefined } as unknown as App);
|
|
45
|
+
|
|
46
|
+
expect(inMemory).toEqual(await RouteJsBudget.measure(artifactDir, modulesByRoute));
|
|
47
|
+
expect(inMemory[0]?.brotliBytes).toBeLessThan(inMemory[0]?.rawBytes ?? 0);
|
|
48
|
+
});
|
|
49
|
+
|
|
34
50
|
test("fails only a route past its entry plus the larger of 1% and 4KB, and leaves a route without one to the report", () => {
|
|
35
51
|
const budget = RouteJsBudget.parse(
|
|
36
52
|
JSON.stringify({ routeJsBrotliKB: { "/:lang": 100, "/:lang/memo": 120, "/:lang/feed": 500 } }),
|
package/app/routeJsBudget.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { toError } from "akanjs/common";
|
|
3
3
|
import { FontPruner } from "../frontendBuild/fontPruner";
|
|
4
|
+
import { servedBrotliBytesOf } from "../frontendBuild/precompressArtifacts";
|
|
4
5
|
import { JsonFormatter } from "../util/jsonFormatter";
|
|
5
6
|
|
|
6
7
|
export interface RouteJsSize {
|
|
@@ -58,11 +59,16 @@ export class RouteJsBudget {
|
|
|
58
59
|
static readonly #absoluteSlack = 4096;
|
|
59
60
|
|
|
60
61
|
//? A file under 1 KB has no `.br` sidecar (precompressArtifacts skips it), so it is served, and counted, raw.
|
|
61
|
-
static async measure(
|
|
62
|
+
static async measure(
|
|
63
|
+
artifactDir: string,
|
|
64
|
+
modulesByRoute: Record<string, string[]>,
|
|
65
|
+
{ precompressed = true }: { precompressed?: boolean } = {},
|
|
66
|
+
): Promise<RouteJsSize[]> {
|
|
62
67
|
const sizeByUrl = new Map<string, { raw: number; brotli: number }>();
|
|
63
68
|
const sizeOf = async (url: string) => {
|
|
64
69
|
const file = path.join(artifactDir, url.replace(/^\/_akan\//, ""));
|
|
65
70
|
const raw = Bun.file(file).size;
|
|
71
|
+
if (!precompressed) return { raw, brotli: await servedBrotliBytesOf(artifactDir, file) };
|
|
66
72
|
const sidecar = Bun.file(`${file}.br`);
|
|
67
73
|
return { raw, brotli: (await sidecar.exists()) ? sidecar.size : raw };
|
|
68
74
|
};
|
|
@@ -12,6 +12,11 @@ import type { CodeAgentProxy } from "./CodeAgentProxy";
|
|
|
12
12
|
import { CodeSessionIndex } from "./CodeSessionIndex";
|
|
13
13
|
import { WorkspaceTrust } from "./WorkspaceTrust";
|
|
14
14
|
|
|
15
|
+
type PrepareRequest = (
|
|
16
|
+
model: unknown,
|
|
17
|
+
options?: Record<string, unknown>,
|
|
18
|
+
) => Promise<{ model: { compat?: Record<string, unknown> } }>;
|
|
19
|
+
|
|
15
20
|
export interface AkanCodeServicesOptions {
|
|
16
21
|
workspaceRoot: string;
|
|
17
22
|
cwd: string;
|
|
@@ -30,6 +35,8 @@ export class AkanCodeServices {
|
|
|
30
35
|
enableAnalytics: false,
|
|
31
36
|
quietStartup: true,
|
|
32
37
|
compaction: { reserveTokens: AkanCodeCompaction.reserveFloor },
|
|
38
|
+
// pi 1.5 defaults to "idle", which sends billed cache refreshes for up to 30 minutes between turns.
|
|
39
|
+
cacheWarming: "streaming",
|
|
33
40
|
});
|
|
34
41
|
}
|
|
35
42
|
|
|
@@ -43,11 +50,27 @@ export class AkanCodeServices {
|
|
|
43
50
|
: akanCodePaths.authFile(),
|
|
44
51
|
modelsPath: akanCodePaths.modelsFile(),
|
|
45
52
|
});
|
|
53
|
+
AkanCodeServices.#holdMessageThreadsOff(runtime);
|
|
46
54
|
if (proxy) await proxy.apply(runtime);
|
|
47
55
|
else await AkanEnvKeys.apply(runtime, workspaceRoot);
|
|
48
56
|
return runtime;
|
|
49
57
|
}
|
|
50
58
|
|
|
59
|
+
// pi 1.5 turned Anthropic message threads on for api.anthropic.com; a models.json `compat` that names it still wins.
|
|
60
|
+
static #holdMessageThreadsOff(runtime: ModelRuntime) {
|
|
61
|
+
const target = runtime as unknown as { prepareRequest?: PrepareRequest };
|
|
62
|
+
const original = target.prepareRequest?.bind(runtime);
|
|
63
|
+
if (!original) throw new Error("The model runtime no longer exposes prepareRequest; update AkanCodeServices");
|
|
64
|
+
target.prepareRequest = async (model, options) => {
|
|
65
|
+
const prepared = await original(model, options);
|
|
66
|
+
if (prepared.model.compat?.supportsMessageThreads !== undefined) return prepared;
|
|
67
|
+
return {
|
|
68
|
+
...prepared,
|
|
69
|
+
model: { ...prepared.model, compat: { ...prepared.model.compat, supportsMessageThreads: false } },
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
51
74
|
static sessions(workspaceRoot: string, cwd: string, profile: CodeAgentProfile, resume?: string) {
|
|
52
75
|
//* `remote` has no store of its own yet, so it keeps a file session: a pod worker's suspended asks need it.
|
|
53
76
|
if (profile.session.store === "memory") return SessionManager.inMemory(cwd);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import type { ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { AkanCodeServices } from "./AkanCodeServices";
|
|
7
|
+
import { akanCodePaths } from "./akanCodePaths";
|
|
8
|
+
|
|
9
|
+
const saved: Record<string, string | undefined> = {};
|
|
10
|
+
let home = "";
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
home = mkdtempSync(path.join(tmpdir(), "akan-code-services-test-"));
|
|
14
|
+
for (const key of ["AKAN_CODE_HOME", "ANTHROPIC_API_KEY"]) saved[key] = process.env[key];
|
|
15
|
+
process.env.AKAN_CODE_HOME = home;
|
|
16
|
+
process.env.ANTHROPIC_API_KEY = "test-key-never-sent";
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
rmSync(home, { recursive: true, force: true });
|
|
21
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
22
|
+
if (value === undefined) delete process.env[key];
|
|
23
|
+
else process.env[key] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const threadsOf = async (runtime: ModelRuntime) => {
|
|
28
|
+
const model = runtime.getModels("anthropic")[0];
|
|
29
|
+
if (!model) throw new Error("pi lists no anthropic model");
|
|
30
|
+
expect(model.baseUrl).toContain("api.anthropic.com");
|
|
31
|
+
const prepare = (runtime as unknown as { prepareRequest: (model: unknown, options: object) => Promise<unknown> })
|
|
32
|
+
.prepareRequest;
|
|
33
|
+
const prepared = (await prepare.call(runtime, model, {})) as { model: { compat?: Record<string, unknown> } };
|
|
34
|
+
return prepared.model.compat?.supportsMessageThreads;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("AkanCodeServices holds the defaults akan code had on pi 1.3.0", () => {
|
|
38
|
+
test("prompt caches are warmed only while a turn streams, never in the idle time between turns", () => {
|
|
39
|
+
expect(AkanCodeServices.settings().getCacheWarmingMode()).toBe("streaming");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("an Anthropic request carries the whole conversation instead of continuing a server-side thread", async () => {
|
|
43
|
+
expect(await threadsOf(await AkanCodeServices.runtime(home))).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("models.json can still turn Anthropic message threads on", async () => {
|
|
47
|
+
mkdirSync(path.dirname(akanCodePaths.modelsFile()), { recursive: true });
|
|
48
|
+
writeFileSync(
|
|
49
|
+
akanCodePaths.modelsFile(),
|
|
50
|
+
JSON.stringify({ providers: { anthropic: { compat: { supportsMessageThreads: true } } } }),
|
|
51
|
+
);
|
|
52
|
+
expect(await threadsOf(await AkanCodeServices.runtime(home))).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -38,10 +38,17 @@ an endpoint with a real guard is published, one with none is refused, and so is
|
|
|
38
38
|
and refusals in-process plus the `mcp: "agent"` entries, batch servers included. Pass only an account the server resolved, never client input.
|
|
39
39
|
- `this.agentService.loop({ account | principal, allow, messages, approve, untrusted, onMessage, meta, budget })`
|
|
40
40
|
runs a model over those tools until it answers; `option.setAgentAccountResolver` resolves a stored `principal`
|
|
41
|
-
before every round. Each round is metered as its own turn with `turn.loop` and `turn.meta`.
|
|
41
|
+
before every round. Each round is metered as its own turn with `turn.loop` and `turn.meta`. With no `untrusted`,
|
|
42
|
+
everything a tool returns counts as untrusted: a run with no `approve` then writes only before its first result,
|
|
43
|
+
so pass `approve`, or `untrusted` to name the results that carry another party's text. `toolkits` holds named
|
|
42
44
|
groups of `allow` back until the model calls `openToolkit`; `clientTools` (from `AgentClientTools` on an open page)
|
|
43
45
|
parks a call as `awaiting { client: true }` for the page to run; `ask: true` lists `askUser`, which parks as
|
|
44
|
-
`awaiting { question: true }`
|
|
46
|
+
`awaiting { question: true }`. Resume either with `answer: { id, result | error }`, never by appending a
|
|
47
|
+
client's result to `messages`, and never take `messages` from a request: store what `onMessage` hands out.
|
|
48
|
+
- `remotes: this.remoteService.sources(account, [{ name, url, description }])` (`libs/shared`, `remote.enabled`) lets
|
|
49
|
+
the loop call another server's `/mcp` as the user: each is a toolkit, tools read `<name>.<tool>`, a missing
|
|
50
|
+
connection parks as `awaiting { connect: name }` for `<Remote.Util.Connect>`, and every remote result taints the run.
|
|
51
|
+
Once connected, resume with the stored messages; when the user declines, resume with `answer: { id, error }`.
|
|
45
52
|
|
|
46
53
|
## Verify
|
|
47
54
|
|
|
@@ -7,9 +7,9 @@ description: "Run the akan check loop after editing and fix each failure class t
|
|
|
7
7
|
|
|
8
8
|
## One call does the whole chain
|
|
9
9
|
|
|
10
|
-
`akan verify` (the `akan_verify` tool in akan code) syncs, lints with fixes, typechecks,
|
|
11
|
-
changed app, and runs the SSR check for a `.tsx` change — over everything the working tree has changed, in one
|
|
12
|
-
process. It prints one line when it passes and one line per problem when it fails. **Run it after editing,
|
|
10
|
+
`akan verify` (the `akan_verify` tool in akan code) syncs, lints with fixes, typechecks, builds each
|
|
11
|
+
changed app's server and SSR routes, and runs the SSR check for a `.tsx` change — over everything the working tree has changed, in one
|
|
12
|
+
process. A changed lib also typechecks every app and lib that uses it, so an error can name a file you did not edit. It prints one line when it passes and one line per problem when it fails. **Run it after editing,
|
|
13
13
|
before you say you are done.** In akan code it also runs itself at the end of a turn that changed source.
|
|
14
14
|
|
|
15
15
|
Never run `akan lint`, `akan typecheck` and `akan build` in turn: that is the same work three times over, at
|
|
@@ -65,7 +65,7 @@ export class AkanToolPack {
|
|
|
65
65
|
name: AkanToolPack.verifyToolName,
|
|
66
66
|
label: "akan verify",
|
|
67
67
|
description:
|
|
68
|
-
"Run `akan verify` over everything the working tree has changed: sync, lint (with fixes), typecheck, a
|
|
68
|
+
"Run `akan verify` over everything the working tree has changed: sync, lint (with fixes), typecheck, a build of each changed app's server and SSR routes, and the SSR check for .tsx changes, in one call. It prints one line when it passes and one line per problem when it fails. Call this after editing, before you finish; never run lint, typecheck or build separately.",
|
|
69
69
|
promptSnippet: "akan_verify: sync, lint, typecheck and build what the working tree changed, in one call",
|
|
70
70
|
parameters: Type.Object({}),
|
|
71
71
|
execute: async () => {
|