@akanjs/cli 3.0.0-alpha.46 → 3.0.0-alpha.48
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/.build-stamp +1 -1
- package/{application.command-cfx525a9.js → application.command-5w691e89.js} +1 -1
- package/{applicationBuildRunner-7gnfz7ww.js → applicationBuildRunner-0xjav921.js} +1 -1
- package/buildBatch.proc.js +1 -1
- package/{cloud.command-4mkbvey2.js → cloud.command-dq0mvj11.js} +3 -3
- package/guidelines/agentRule/agentRule.generate.json +31 -0
- package/guidelines/agentRule/agentRule.instruction.md +400 -0
- package/guidelines/conventions/conventions.instruction.md +163 -665
- package/guidelines/mcpRule/mcpRule.generate.json +25 -0
- package/guidelines/mcpRule/mcpRule.instruction.md +164 -0
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +41 -375
- package/{index-3h0d06v8.js → index-2kjyh1jb.js} +1 -1
- package/{index-xc6bbz6e.js → index-awt2gttt.js} +2 -2
- package/{index-yay1fd05.js → index-hnysajy8.js} +1 -1
- package/{index-hg0qvhmx.js → index-wr999y03.js} +2 -0
- package/index.js +4 -4
- package/{localRegistry.command-tet9rxqb.js → localRegistry.command-mp3yc9gg.js} +2 -2
- package/package.json +2 -2
- package/templates/workspaceRoot/docs/AI-DEVELOPMENT.md.template +10 -14
- package/templates/workspaceRoot/docs/GENERATED.md.template +12 -10
- package/{workspace.command-f2966kvr.js → workspace.command-zkhcjsj2.js} +3 -3
package/.build-stamp
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
c66fbb78023410bf160409f3c2822f00af904208ed2a82d0f83975a3432cbbe1
|
package/buildBatch.proc.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
CloudScript
|
|
4
|
-
} from "./index-
|
|
5
|
-
import"./index-
|
|
4
|
+
} from "./index-awt2gttt.js";
|
|
5
|
+
import"./index-2kjyh1jb.js";
|
|
6
6
|
import"./index-7zd96bng.js";
|
|
7
7
|
import {
|
|
8
8
|
GlobalConfig
|
|
9
9
|
} from "./index-sh01r3pm.js";
|
|
10
|
-
import"./index-
|
|
10
|
+
import"./index-hnysajy8.js";
|
|
11
11
|
import"./index-6bs24rb4.js";
|
|
12
12
|
import"./index-76rn3g2c.js";
|
|
13
13
|
import {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "In-Page Agent Rule",
|
|
3
|
+
"description": "How an akan screen exposes itself to an in-page agent — st.tool, subscribed keys, built-ins, and the chat",
|
|
4
|
+
"group": "core",
|
|
5
|
+
"codegenPriority": 4,
|
|
6
|
+
"deprecated": false,
|
|
7
|
+
"scans": [
|
|
8
|
+
{
|
|
9
|
+
"type": "example",
|
|
10
|
+
"description": "Components publishing an agent tool beside the control that already performs the action",
|
|
11
|
+
"path": "{apps,libs}/*/**/*.tsx",
|
|
12
|
+
"sample": 4
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"update": {
|
|
16
|
+
"filePath": "./agentRule.instruction.md",
|
|
17
|
+
"contents": [
|
|
18
|
+
"what a declaration publishes",
|
|
19
|
+
"mounting the chat",
|
|
20
|
+
"publishing a tool",
|
|
21
|
+
"forms and reading state",
|
|
22
|
+
"built-in tools"
|
|
23
|
+
],
|
|
24
|
+
"rules": [
|
|
25
|
+
"Use current Akan APIs only",
|
|
26
|
+
"State the rule before the reason, and keep the reason to one clause",
|
|
27
|
+
"Never describe a store class as an exposure surface — only st.tool and subscribed keys publish",
|
|
28
|
+
"Keep it workspace-neutral — no app or repo names"
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# Akan In-Page Agent Guideline
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Use this when mounting `<Agent.Chat />`, publishing an `st.tool`, or deciding what an in-page agent may read and
|
|
5
|
+
drive. The always-loaded convention set carries the short version; this is the full contract.
|
|
6
|
+
|
|
7
|
+
## The Surface Is The Declaration
|
|
8
|
+
|
|
9
|
+
Every akan app can host a component-level agent that reads the rendered screen and drives it. **A component
|
|
10
|
+
declaration is the surface, exactly**: `st.tool` publishes one action, and `st.use` / `st.sel` / `st.ref` make one
|
|
11
|
+
store key readable while the reading component is mounted. Nothing is derived from a store class — declaring a
|
|
12
|
+
method on a `store(...)` gives an agent nothing at all, because a lever the screen does not offer the user is not
|
|
13
|
+
one an agent may pull in their place, and a module's whole vocabulary published at once was noise the model paid
|
|
14
|
+
for. `Load` scopes, the route, and the live keys complete the context. The React core is the `use-agentic` package;
|
|
15
|
+
apps and libs never import it directly (`no-import-external-library`) — everything reaches them through `st.*` and
|
|
16
|
+
`akanjs/ui`.
|
|
17
|
+
|
|
18
|
+
## Mounting The Chat
|
|
19
|
+
- **Mount `<Agent.Chat />` once in a layout.** That is the floating chat, the approval card, and the client-side
|
|
20
|
+
loop. The default runner drives `runAgentTurn`, which the **framework serves on every app** — no lib to mount,
|
|
21
|
+
`AKAN_AGENT=false` takes it off — and negotiates streaming via `accept`, so assistant text arrives as it is
|
|
22
|
+
generated with zero app code. The endpoint is a stateless relay and **never executes tools**: every tool runs in
|
|
23
|
+
the caller's own browser session, gated by guards and the approval card. Its guard is `AgentRelayAccess`, which
|
|
24
|
+
**refuses every call until the app names a guard of its own** — the same answer `None` gives, with no boot
|
|
25
|
+
warning. A product with accounts names it in its `option.ts`, `option.setAgentAccess(SignedIn)`, taking the same
|
|
26
|
+
guard classes every endpoint takes (an array is ANDed, `null` clears what a library set); without one the chat
|
|
27
|
+
cannot spend the LLM key.
|
|
28
|
+
`persist` keeps the transcript across reloads (sessionStorage; `{ storage: "local" }` to outlive the tab),
|
|
29
|
+
default off, and `shortcut={false}` gives the browser back the Cmd/Ctrl+L the launcher otherwise captures.
|
|
30
|
+
**A session the chat made ends when the chat unmounts** — nothing renders its approvals once it is gone, so a
|
|
31
|
+
turn left running would drive a screen the user has navigated away from; a session handed down by an
|
|
32
|
+
`AgentProvider` or an `Agent.Zone` belongs to whoever provided it. Re-skin through the `AgentChat` slot in
|
|
33
|
+
`_overrides.tsx`.
|
|
34
|
+
- **The LLM is configured in `option.ts`, never through the environment.** `option.setLlm({ apiKey, model, host })`
|
|
35
|
+
— or `setLlm((options) => …)` to read the key out of the app's own env object, which is where a secret belongs —
|
|
36
|
+
fills whichever adaptor holds `LlmAdaptorRole`, reaching it as the `llmOption` use. The settings are the role's
|
|
37
|
+
rather than one provider's, so they survive a swap. **DeepSeek is the built-in default** (`deepseek-v4-flash` at
|
|
38
|
+
`https://api.deepseek.com`); with no `apiKey` the app still boots and the chat answers `llmUnavailable`. Swap
|
|
39
|
+
providers the way middleware is applied: `option.applyAdaptor(LlmAdaptorRole, ClaudeLlm)`, where the
|
|
40
|
+
implementation is an `adapt()` class in a `srvkit/` implementing `LlmAdaptor.chat(request, onDelta?)` — ignore
|
|
41
|
+
`onDelta` and the chat still answers whole.
|
|
42
|
+
- **An adaptor answers `null` for "not configured" and *throws* for a refusal it can explain.** The two are
|
|
43
|
+
different things to be told: collapsing both into `null`, the way the adapter convention otherwise reads, left a
|
|
44
|
+
user reading `llmUnavailable` — "no model is configured" — about a conversation that had merely outgrown the
|
|
45
|
+
context window. A thrown `Err` reaches the chat as its own text, so the reason the provider gave is what the
|
|
46
|
+
user sees. It travels as the dictionary key plus the values that key interpolates, on both the JSON and the SSE
|
|
47
|
+
path, and **`fetchRunner` resolves it against the dictionary one step before the transcript** — the endpoint has
|
|
48
|
+
no language to resolve it in and the browser does, which is why the key was reaching the screen raw.
|
|
49
|
+
|
|
50
|
+
## Attachments And Speech
|
|
51
|
+
- **A file the user attaches rides the message, and nothing is stored.** The composer takes a paperclip, a drop and
|
|
52
|
+
a paste; an image rides as bytes and a text file as text, which is all a browser reads with no dependency.
|
|
53
|
+
Everything else is the app's own reader — `<Agent.Chat attach={…} />`, one `File` in, a `MessageAttachment` or
|
|
54
|
+
`null` out — because extracting a PDF needs a parser and the framework carries attachments without depending on
|
|
55
|
+
one. It runs ahead of the built-in, so it is also where an image is downscaled before it costs a megabyte of
|
|
56
|
+
prompt. **What the provider cannot read is replaced by a note naming the file**, never dropped: an attachment the
|
|
57
|
+
model never saw is one it answers about from the filename. An adaptor declares `accepts: { image, document }` and
|
|
58
|
+
`AgentService.readable` degrades the rest, so a text-only provider needs no attachment code at all — DeepSeek
|
|
59
|
+
declares none, which is why an image against the default provider is refused out loud while an extracted PDF
|
|
60
|
+
works, `text` being readable by every model there is. **A `prompt()`'s `Msg.image` is the same wire shape** and
|
|
61
|
+
reaches the chat as an attachment rather than the literal `[image]` it used to become. Persisting keeps each
|
|
62
|
+
attachment's name and drops its content: web storage is a few megabytes, one screenshot fills a chunk of it, and
|
|
63
|
+
a save that fails is silent — so keeping the bytes would quietly stop keeping the transcript.
|
|
64
|
+
**The ceilings are the message's, not the file's**: 4 MB per file, 8 MB and five files per message, and the same
|
|
65
|
+
file twice is refused by name. The bytes ride inside one turn's JSON, so what a provider refuses is the sum —
|
|
66
|
+
and a request that cannot be sent is one the user has to empty the composer to escape, which is why the refusal
|
|
67
|
+
happens at the paperclip and names the file it dropped.
|
|
68
|
+
- **Speech is one engine contract and the framework's own policy.** `<Agent.Chat voice={engine} />` takes a
|
|
69
|
+
`VoiceEngine` — `listen(handlers)` and `speak(sentence)`, both cancellable — and the chat decides everything
|
|
70
|
+
else: a press-to-talk microphone whose transcript lands in the composer to be corrected, one utterance per
|
|
71
|
+
press, sentence-at-a-time reading, barge-in on the next press or on Stop, and markdown stripped so `**bold**`
|
|
72
|
+
is not pronounced. **A reply is read aloud only when the ask arrived by voice**, so a typed question never turns
|
|
73
|
+
on the speakers — and it needs no wire field, because how a message was sent is the composer's own business.
|
|
74
|
+
A question or an approval the loop parked on is read aloud under that same condition, because the loop stops
|
|
75
|
+
there: a voice user who is never told about the card is a conversation that simply ends.
|
|
76
|
+
The contract is a subscription rather than `listen(): Promise<string>` on purpose: a promise fits push-to-talk
|
|
77
|
+
and nothing else, so hands-free could then only arrive as a breaking change. `useSpeech` in a util lib's
|
|
78
|
+
`webkit/` is the engine — the browser's own recognition and synthesis on the web, the Capacitor plugins in a
|
|
79
|
+
WebView, **which has neither on Android or iOS**, so a `speech.plugin.ts` declares the permission and
|
|
80
|
+
the packages the native build needs. An engine answering `available()` false renders no microphone at all,
|
|
81
|
+
the same rule as publishing no tool for a control the screen does not draw.
|
|
82
|
+
- **`attach` and `voice` both carry functions, so a server layout cannot pass either.** A closure does not cross
|
|
83
|
+
the RSC boundary — `non-scalar-props-restricted` says so on `page/**` — so an app that wants either mounts the
|
|
84
|
+
chat from a small client component in the app's own `ui/` that calls the hook.
|
|
85
|
+
- **A dialog's close is the dialog's own dismissal, not a state flip.** `closeDialogIn<Ns>` (and `Dialog.Close`)
|
|
86
|
+
run through whatever `Dialog.Modal` registered, so the agent takes the exact path the X button takes —
|
|
87
|
+
`confirmClose` still prompts and `onCancel` still fires. A close that only set `open` to false would skip both,
|
|
88
|
+
which is a different action wearing the same name.
|
|
89
|
+
|
|
90
|
+
## Zones And Route Guidance
|
|
91
|
+
- **`<Agent.Zone id="comments">` runs a second agent over one section, in parallel with the root.** Everything
|
|
92
|
+
mounted inside — `st.use` subscriptions, hook tools, Guides — belongs to that zone's own conversation *and*
|
|
93
|
+
stays visible to the root agent: **zones are views, never walls**, so wrapping a section costs the root nothing.
|
|
94
|
+
An `Agent.Chat` inside binds to the zone session automatically; a zone's `readScreen` reads only its own
|
|
95
|
+
`data-agent-zone` container; guides follow the layout cascade (ancestors and own, never a sibling's). Zone
|
|
96
|
+
membership is positional — there is no per-declaration zone key, so a lib component joins whatever zone the app
|
|
97
|
+
mounts it in.
|
|
98
|
+
- **Route guidance is `<Agent.Guide instructions="..." />`** rendered from a `_layout.tsx` or a page — the render
|
|
99
|
+
tree is the cascade: nested Guides concatenate outer-to-inner and navigating away withdraws them. It is a
|
|
100
|
+
component, not a pageConfig field. Module `*.abstract.md` files are developer docs and are never served to the
|
|
101
|
+
agent.
|
|
102
|
+
|
|
103
|
+
## Publishing A Tool
|
|
104
|
+
- **Declare the tool beside the control that already does it.**
|
|
105
|
+
`st.tool("x", { desc }).arg("id", ID).exec(fn)` publishes one action and returns the callable to hand to
|
|
106
|
+
`onClick` — one handler for the person and the agent, which is the point: a button wired to an inline arrow can
|
|
107
|
+
be clicked by a person and by nobody else. `.exec()` is the only hook, so the chain completes in one
|
|
108
|
+
unconditional statement, and the callable carries `data-akan-action` like a store setter does. A `remove*` name
|
|
109
|
+
defaults to a confirm gate. Reach a store action from the body — `.exec((id) => st.do.removeX(id))` — which is
|
|
110
|
+
how an agent gets CRUD; `st.do` on its own reaches nobody.
|
|
111
|
+
- **A falsy name declares the tool without publishing it** — the callable still drives the click a person makes,
|
|
112
|
+
and the agent never learns the tool exists. That is the only way a conditional surface stays legal, because
|
|
113
|
+
`.exec()` is a hook and the declaration can never be skipped: withhold the name, not the call. `st.useState`
|
|
114
|
+
and `st.expose` take a falsy name the same way, and an unpublished callable carries no `data-akan-action` —
|
|
115
|
+
that attribute names a tool an agent can reach. **Publish a tool only where the screen already renders the
|
|
116
|
+
control**: a lever no one can pull by hand is not one to hand an agent, and every published tool is paid for in
|
|
117
|
+
every turn's prompt. The mirror of the same rule is why the control gets a tool at all.
|
|
118
|
+
- **An `enumOf` class is a complete argument type on its own**: `.arg("mode", TaskStatus)` publishes the values as
|
|
119
|
+
the argument's `enum`, refuses anything off them by name at call time, and narrows the `.exec` parameter to the
|
|
120
|
+
value union — nothing else to write, and the scalar (`string` / `integer` / `number`) comes from the values.
|
|
121
|
+
**A value set the *render* decides takes `.arg(name, type, { oneOf })`** instead, because `enumOf` registers
|
|
122
|
+
globally and a component cannot build one per render: pass the list it has — a slice's sort keys, the options a
|
|
123
|
+
prop carried — and it is published and enforced the same way. Neither reaches a set that fills in *after* the
|
|
124
|
+
first render, since a declaration is mount-static; put that in the tool's `guard`, which is re-read per call and
|
|
125
|
+
can name the current values in its refusal. **An argument type nothing can describe — a model class, `Any`, a
|
|
126
|
+
`Map` — withdraws the whole tool and says so on the console**, naming the tool, the argument and the type; the
|
|
127
|
+
callable still drives the click a person makes. It does not throw: a tool schema is built during render, and an
|
|
128
|
+
agent-tooling mistake that aborted the render would cost the route its server rendering. `st.useState`'s `set`
|
|
129
|
+
degrades the same way, to read-only.
|
|
130
|
+
- **A component that renders once per row never closes over its row's id — it takes the id as an argument.** A
|
|
131
|
+
tool that captured its own row would be fifty registrations of one name, forty-nine of them shadowed, and the
|
|
132
|
+
survivor would remove whichever row happened to mount last. Take the id instead — `removeTask(taskId)`, never
|
|
133
|
+
fifty `removeTask` — and every row's registration is then interchangeable, so a row component may publish after
|
|
134
|
+
all: say so with `shared: true` and the repeats are one declaration rather than a warned-about clash. The ids
|
|
135
|
+
come from the `<slice>.items` resource `Load.Units` and `Data.ListContainer` already expose. `shared` is a claim
|
|
136
|
+
about the *tool*, not a way to quiet a console: two rows whose tools would do different things (a different
|
|
137
|
+
`modal`, a different redirect) are not interchangeable, and that one wants a `namespace` or nothing at all.
|
|
138
|
+
|
|
139
|
+
## What `akanjs/ui` Publishes For You
|
|
140
|
+
- **`akanjs/ui` publishes its own controls, so an app writes nothing for them.** `Data.ListContainer` (and every
|
|
141
|
+
`Model.AdminPanel`) publishes its toolbar and its row verbs; `Model.NewWrapper` (so `Model.New` too) publishes
|
|
142
|
+
`new<Model>`; `Load.Units`, `Load.Pagination` and `Data.Pagination` publish `setPageOf<Model>`; `Layout.Sider`,
|
|
143
|
+
`System.SelectLanguage`, `Link.Back` and `System.ThemeToggle` publish the shell. **A component that can render
|
|
144
|
+
twice on one screen takes a `namespace` prop and publishes nothing without it** — `Tab`, `Dialog`,
|
|
145
|
+
`ScreenNavigator`, `Dropdown`. Pass one (`<Tab namespace="detail">`) and the tool becomes `switchTabInDetail`;
|
|
146
|
+
leave it off and that tab is invisible to the agent, because two tabs answering to `switchTab` would mean the
|
|
147
|
+
first to mount loses. A named `Dropdown` publishes `openDropdownIn<Ns>` / `closeDropdownIn<Ns>` and the state
|
|
148
|
+
`dropdownIn<Ns>`, and its trigger annotates whichever of the two its next click performs. `Model.NewWrapper`
|
|
149
|
+
takes the same prop but publishes without one, because its slice already names it — a second create trigger for
|
|
150
|
+
the same slice, opening a form seeded differently, is what needs the suffix.
|
|
151
|
+
- **The `Model.*` row wrappers publish their verb, taking the id.** `Model.EditWrapper`, `Model.ViewWrapper`,
|
|
152
|
+
`Model.RemoveWrapper` and `Model.Remove` publish `edit<Model>` / `view<Model>` / `remove<Model>` with a
|
|
153
|
+
`modelId` argument, so a list built from `Load.Units` and an app's own `Unit` reaches the same verbs an
|
|
154
|
+
`AdminPanel` does. `Model.SureToRemove` publishes the same — except under `typeNameToRemove`, where it
|
|
155
|
+
publishes nothing: that gate makes a person retype the model's name, an approval card is one click, and
|
|
156
|
+
offering the lever at a friction the screen does not have is not the same control.
|
|
157
|
+
- **A dropdown's menu is mounted from the first render and hidden while closed** — the deliberate opposite of the
|
|
158
|
+
modal rule below, because a menu is one click away rather than a surface of its own. A tool is declared by a
|
|
159
|
+
mount effect, so an unmounted menu is one whose row verbs and field setters do not exist yet: an agent asked for
|
|
160
|
+
one finds nothing, and no catalogue entry hints that opening the menu would help. `readScreen` still skips
|
|
161
|
+
hidden content, so the items themselves are read only after `openDropdownIn<Ns>` — what a closed menu publishes
|
|
162
|
+
is its tools, not its text. The cost is that `content` renders on page load, so a heavy panel belongs behind a
|
|
163
|
+
`Dialog` instead.
|
|
164
|
+
- **A modal publishes its verbs while it is open, and only then.** `Model.EditModal` publishes `submit<Model>`
|
|
165
|
+
and `cancelEditOf<Model>`, `Model.ViewModal` publishes `closeViewOf<Model>`, and `Model.ViewEditModal`
|
|
166
|
+
publishes `edit<Model>` / `submit<Model>` / `closeViewOf<Model>` — each from a subtree that mounts with the
|
|
167
|
+
open modal, never from the component that merely holds it. That is what makes a list legal: `Data.CardList`
|
|
168
|
+
renders one editor per row, and at most one of them is ever open, so one name is registered rather than fifty.
|
|
169
|
+
It also means the verb is absent from the catalogue while nothing is open, which is honest — and costs the
|
|
170
|
+
agent nothing, because the catalogue is re-read on the turn that follows the tool call that opened the form.
|
|
171
|
+
|
|
172
|
+
## Forms
|
|
173
|
+
- **A form control publishes its own setter, and reading a form publishes one tool that fills several at once.**
|
|
174
|
+
Both are free: an app writes no `st.tool` for a form. A `Field.*` / `Input.*` / `Select` / `Switch` handed
|
|
175
|
+
`onChange={st.do.setTitleOnTask}` **by reference** publishes `setTitleOnTask` while it is on screen — the same
|
|
176
|
+
reference that earns `data-akan-action`, so the tool and the person press one function and an inline arrow
|
|
177
|
+
still publishes nothing. `st.use.taskForm()` adds `fillTaskForm(patch)`, which takes several fields in one call
|
|
178
|
+
and is the only way to reach a list, a map, or an embedded object, whose rows are written through
|
|
179
|
+
`writeOnTask(path, value)` and can carry no annotation. It is a patch: a field left out keeps its value.
|
|
180
|
+
`fillTaskForm` refuses a plain field whose control is not on screen and names the ones that are; a composite it
|
|
181
|
+
cannot see is let through, which is the one place an agent reaches a field the screen may not draw. Never a
|
|
182
|
+
relation (picked or uploaded, not typed), a base document field, or a `hidden`/`secret` one at any depth —
|
|
183
|
+
their reads are masked and a writer would be the door around that. `st.use.taskForm({ agent: false })`
|
|
184
|
+
withholds the patch tool; an inline arrow withholds a control's own.
|
|
185
|
+
**The patch writes each plain field through that control's own published tool, not the setter underneath it** —
|
|
186
|
+
which is what carries the control's `transform`, so a field cannot normalize one way for `setPhoneOnBizAccount`
|
|
187
|
+
and another way for `fillBizAccountForm`. Only a composite, having no control, dispatches its setter directly.
|
|
188
|
+
The patch tool is registered `shared`, because the entry is a pure function of the model: a form put on screen by
|
|
189
|
+
a shell that subscribes it (`Model.EditModal`) *and* by the `Template` inside it is one declaration twice over,
|
|
190
|
+
not a clash — so neither has to suppress the other, and neither is asked to.
|
|
191
|
+
- **A `disabled` control publishes nothing, so the agent never gets a lever the person cannot pull.** Every value
|
|
192
|
+
control reads it — `Field.*`, `Input.*`, `Select`, `Switch`, and the four relation pickers — and disabling a
|
|
193
|
+
mounted control withdraws its tool for as long as it stays disabled. One gate covers both writers: with no
|
|
194
|
+
control published, `fill<Model>Form`'s guard refuses that field too. `readScreen` says `(disabled)` beside the
|
|
195
|
+
control, from the native attribute or `aria-disabled`, so a refusal is something the agent could have read first
|
|
196
|
+
rather than a surprise. This is the same rule as publishing only where the screen renders the control, applied to
|
|
197
|
+
a control the screen renders but withholds.
|
|
198
|
+
- **Whatever the wrapper was for, there is a place to put it that is not the wrapper.** An inline arrow is the one
|
|
199
|
+
shape that publishes nothing, so each reason for writing one has its own home, and reaching for that home is what
|
|
200
|
+
keeps the field reachable:
|
|
201
|
+
- *normalize* — `(v) => set(formatPhone(v))` becomes the control's own `transform` prop, which every text and
|
|
202
|
+
number `Field.*` already takes (`Field.Phone` defaults it to `formatPhone`). `onChange` stays a reference, and
|
|
203
|
+
**`transform` runs on the agent's write too**, by both paths — the field's own tool and `fill<Model>Form`,
|
|
204
|
+
which goes through the control to get it — otherwise a person would store `010-1234-5678` and an agent the raw
|
|
205
|
+
digits. It normalizes one scalar, so an array control applies it per element and a cleared nullable field stays
|
|
206
|
+
null. It is the *control's* rule, though: a rule that must hold however the field is written — including a
|
|
207
|
+
composite path or a base-document write — belongs in `_postSet<Field>` below.
|
|
208
|
+
- *multi-write* — `(v) => { set(v); other(v); }` becomes a **`_postSet<Field>` method on the store**, and the
|
|
209
|
+
control keeps handing over the generated setter by reference. It runs right after the field is written, so it
|
|
210
|
+
reads the new value, and it reaches every other generated action with `this.` —
|
|
211
|
+
`_postSetToBiz(toBiz) { if (toBiz) this.addSendEmailsOnEstSheet(toBiz.sendEmails ?? []); }`. Nothing about the
|
|
212
|
+
control changes, so `data-akan-action` **and** `data-akan-state` both survive, and the rule now fires for every
|
|
213
|
+
writer — the person, the agent, `fill<Model>Form` — which is what a rule about a field should do.
|
|
214
|
+
**A generated action cannot be overridden, so do not try.** They all come from mapped types, and a mapped type
|
|
215
|
+
produces *properties*: a subclass method of the same name is `TS2425`, optional or not, and the two shapes
|
|
216
|
+
TypeScript does allow — a class field and a getter — are both skipped by `StoreRegistry.register`, which only
|
|
217
|
+
collects prototype descriptors holding a function. There is no legal middle, which is exactly why the hook
|
|
218
|
+
carries a leading `_` and no model suffix: a name no mapped type can produce is the only name a subclass may
|
|
219
|
+
declare. It cannot be typed either, for the same reason, so a misspelled field is named on the console at
|
|
220
|
+
registration instead. Calling a generated action *from* a custom one is fine and always was — `this.setXOnY(v)`
|
|
221
|
+
typechecks anywhere.
|
|
222
|
+
- *nested path* — `(v) => writeOnTask("payments.3.name", v)` has no home and needs none: an embedded row is
|
|
223
|
+
unannotatable by design, and an agent reaches it through `fillTaskForm`, which waves composites through.
|
|
224
|
+
|
|
225
|
+
`no-unpublished-form-setter.grit` errors on the pure-forwarding shape only, because every other one has a
|
|
226
|
+
legitimate reading. **`akan quality scan` counts them all** (`akan.agent.unpublished-form-setter`, one warning per
|
|
227
|
+
file): the lint rule is the per-line enforcement, the scan is the inventory of fields this screen writes but
|
|
228
|
+
cannot be asked to write.
|
|
229
|
+
- **A relation reaches an agent from its picker, not from the form patch.** `fillTaskForm` publishes no schema for
|
|
230
|
+
one and is right not to: the form holds the whole related document, so an id would need a lookup the store does
|
|
231
|
+
not do. The picker is where that lookup lives, so `Field.Parent` / `Field.Children` publish the pair themselves —
|
|
232
|
+
`load<Field>OptionsOn<Model>`, which loads the slice and returns `[{ id, label }]`, and the field's own
|
|
233
|
+
`set<Field>On<Model>` taking `<field>Id` / `<field>Ids`. Listing is its own tool because loading is its own step
|
|
234
|
+
for a person too: the options arrive when the dropdown opens, and an agent never opens it. `Field.ParentId` /
|
|
235
|
+
`Field.ChildrenId` need none of that — the id *is* the value, so the ordinary setter describes it. All four still
|
|
236
|
+
require the setter **by reference**, and a `disabled` picker publishes nothing.
|
|
237
|
+
- **An array of embedded rows also publishes `add<Field>On<Model>` and `sub<Field>On<Model>`** — append, and
|
|
238
|
+
remove-by-position — beside the whole-array setter. Not new authority: the setter can already produce any array
|
|
239
|
+
those two can, so they are strictly weaker. What they add is that neither can touch a row it was not given, and
|
|
240
|
+
that is the point: writing the whole array means echoing every row the agent is *not* changing, `checked`
|
|
241
|
+
validates types and not values, so one mistyped row nobody asked about is written silently. Both take a list and
|
|
242
|
+
act atomically, because removing positions one call at a time would shift the ones not yet removed. **Only an
|
|
243
|
+
embedded-row array gets them** — an array of primitives or of relation ids has nothing to retype wrong, its
|
|
244
|
+
values *are* the payload, so it keeps one setter and pays for no extra tools. `add` appends and publishes no
|
|
245
|
+
insert position, matching the `+` a person presses; `addOrSub` is never published, since it matches by `indexOf`
|
|
246
|
+
and would compare rows by reference. Editing a row in place stays `fill<Model>Form`'s job.
|
|
247
|
+
- **A list the person can drag also publishes `move<Field>On<Model>(from, to)`**, and `DraggableList` is a form
|
|
248
|
+
control like any other: handed the generated setter by reference it publishes that field, so an app that renders
|
|
249
|
+
its own rows with `DraggableList` writes no `st.tool`. The reorder tool exists for the same reason `add`/`sub` do
|
|
250
|
+
— the drag is the lever the screen offers and it changes no entry's content, so moving one row should not mean
|
|
251
|
+
retyping the nine beside it. No store action answers to it: reordering *is* a whole-array write, so the tool
|
|
252
|
+
splices the live entries and hands them to the setter the drag hands them to, `transform` deliberately not
|
|
253
|
+
applied, since the values are stored already and dragging normalizes nothing. It comes from the control saying
|
|
254
|
+
it sorts, not from the field, so a plain `Field.List` publishes no reorder and a scalar field never gets one.
|
|
255
|
+
**A component that composes `DraggableList` and already published the field hands the inner list a wrapper** —
|
|
256
|
+
the two would otherwise register one name twice, and the outer one is the one holding `transform`. That is what
|
|
257
|
+
`Field.TextList` does, and the only place an inline arrow is the right answer rather than a bug.
|
|
258
|
+
|
|
259
|
+
## Reading State
|
|
260
|
+
- **Reading is per key, not per store.** `st.useState(name, initial, meta)` publishes local state (read-only
|
|
261
|
+
unless `set:` names a type) and `st.expose(name, value)` a derived value. A subscribed store key is listed in
|
|
262
|
+
the state context block by name and pulled with `readState(key)`, masked by the model that key declares — while
|
|
263
|
+
a key the screen does not read stays unreadable even when a sibling key of the same store is live. **There is no
|
|
264
|
+
store-level exposure declaration**: a store class says nothing about agents, and `st.use.x({ agent: false })` is
|
|
265
|
+
how the component that subscribes a value keeps it off the surface. Base-store plumbing does the same at the
|
|
266
|
+
call site — `st.use.path({ agent: false })`, `st.use.tryJwt({ agent: false })` — so routing and the caller's
|
|
267
|
+
credential stay off the surface unless a component opts a key in, as ThemeToggle does for `theme`.
|
|
268
|
+
- **Model-facing text is English, always** — tool `desc`, `instructions`, Guide text. The `l()` rule covers
|
|
269
|
+
strings a *user* reads: Chat's own buttons go through `l("base.*")`, the model's text never does.
|
|
270
|
+
- A masked model never crosses the boundary: a value whose `hidden`/`secret` fields are populated is refused at
|
|
271
|
+
read unless a `mask:` model is named — the same rule and wording as `AgentBridge.read`.
|
|
272
|
+
|
|
273
|
+
## Slash Commands And The Transcript
|
|
274
|
+
- **`prompt()` endpoints double as the chat's slash commands.** There is no listing endpoint — the client reads
|
|
275
|
+
its own serialized signals — so a prompt's dictionary `.desc()` is what the menu shows, and its guards are
|
|
276
|
+
enforced by the prompt's own GET at call time. Arguments are positional and whitespace-separated, and quoting
|
|
277
|
+
is how a sentence stays one of them (`/reviewTask t1 "look at the totals"`) — a prompt taking a single `String`
|
|
278
|
+
is the common case, and an unquoted sentence would fill its second parameter with the second word.
|
|
279
|
+
- **The chat answers six slash commands of its own**, listed in the same `/` menu ahead of the prompts:
|
|
280
|
+
`/new` (`/clear`), `/retry`, `/compact`, `/copy`, `/help` and `/tools`. An app writes none of them and cannot add
|
|
281
|
+
one — the extension point for a product's own command is a `prompt()` endpoint, which is guarded and server-side.
|
|
282
|
+
**A built-in wins a name collision with a prompt of the same name**, the mirror image of the tool rule: a
|
|
283
|
+
component's `st.tool` shadows a built-in it means to replace, but no library's prompt may take `/new` away from
|
|
284
|
+
the user who typed it — so a shadowed prompt is dropped from the menu rather than listed twice. `/new` and
|
|
285
|
+
`/copy` are also dispatched *before* the is-a-turn-running check **and before the question card takes the
|
|
286
|
+
composer**, because mid-turn is exactly when they are reached for and a question the agent asked is the middle
|
|
287
|
+
of a turn like any other — answered as text, `/new` would have reached the model as the user's decision.
|
|
288
|
+
`/new` therefore aborts the turn it is clearing and waits for it to wind down, since the loop clears its own
|
|
289
|
+
running flag a microtask later and a transcript emptied before that lands is one the dying turn appends onto.
|
|
290
|
+
- **A command's output is a `local` message: rendered in the transcript, withheld from the wire.** The transcript
|
|
291
|
+
*is* the model's history, so `/help` text appended plainly would come back next turn as something the assistant
|
|
292
|
+
believes it said. `session.note(text)` is the only way to write one, `session.report(error)` stays what a
|
|
293
|
+
host-side *failure* lands in, and `local` messages are left out of a `/copy` export too — they are the chat
|
|
294
|
+
talking to itself. Their text is user-facing, so it goes through `l("base.*")` like every other chat string.
|
|
295
|
+
- **`/copy` exists because nothing else keeps the transcript.** The relay is stateless and the conversation lives
|
|
296
|
+
only in that browser, so an export is the one path a wrong answer has to whoever could fix it — which is why it
|
|
297
|
+
carries the route and the timestamp. `/retry` replays only the trailing user message, leaving anything before it
|
|
298
|
+
in place, so a prompt's own preamble is not sent twice.
|
|
299
|
+
- **A long conversation summarizes itself, because nothing else is keeping it inside the model's window.** The
|
|
300
|
+
loop runs in the browser and the relay holds no session, so an uncompacted chat grows until the provider
|
|
301
|
+
refuses the whole request — a refusal, never a shorter answer, which is why compaction runs *before* the turn
|
|
302
|
+
that would have overflowed rather than as a recovery after it. Past `compact.at` estimated tokens (four
|
|
303
|
+
characters to a token, over the JSON the turn posts; 24k by default, well under the smallest window a provider
|
|
304
|
+
is likely to have, since the tools and the screen context ride on top of it and neither compacts) the history above the last `keep` messages
|
|
305
|
+
becomes one message standing in for it, flagged `summary` on the wire — `<Agent.Chat compact={{ at, keep }} />`
|
|
306
|
+
tunes it per provider and `{ at: 0 }` turns it off, and `/compact` does the same on demand keeping nothing.
|
|
307
|
+
**The cut only ever lands on a user message**: everything above one is settled, so the kept half can never open
|
|
308
|
+
with a `tool` result whose call was summarized away, a shape every provider dialect rejects. The summarizing
|
|
309
|
+
turn carries no tools and no screen context — it summarizes the conversation, it does not act on it — and it is
|
|
310
|
+
fed a *bounded* digest rather than the transcript itself, since the transcript being summarized is the one that
|
|
311
|
+
no longer fits. A summary that cannot be produced leaves the transcript alone and the turn goes out as it would
|
|
312
|
+
have; one that fails to shrink anything is not retried until another threshold's worth has been added. On the
|
|
313
|
+
wire a summary wears the user's role because the wire has no other, so a provider mapping frames it as a system
|
|
314
|
+
message and `/retry` steps over it — replaying it would send the notes back as a question.
|
|
315
|
+
- **A stopped turn answers the calls it never ran, because an unanswered call ends the conversation.** Every
|
|
316
|
+
provider dialect refuses an assistant message whose `tool_calls` have no results — on that turn and on every
|
|
317
|
+
later one — so Stop landing between a call and its result would leave a transcript nothing can be sent from,
|
|
318
|
+
with no way out but `/new`. `Transcript.sanitize` holds the invariant in one place and runs where a transcript
|
|
319
|
+
is assembled rather than where each hole is made: the turn's own request, a transcript restored from storage,
|
|
320
|
+
and a stored transcript capped to its newest messages, whose window can start mid-pair. A call the loop never
|
|
321
|
+
reached is *answered* rather than erased — a model told the call was stopped asks again, where one shown no
|
|
322
|
+
call at all answers as if it had the result.
|
|
323
|
+
- **A turn that failed says so on the wire.** `error` is a field only this wire has, so a provider mapping reads
|
|
324
|
+
`text` and drops it; `AgentService.explained` folds it into the text before any adaptor sees it, because an
|
|
325
|
+
assistant turn that says nothing is one the model repeats.
|
|
326
|
+
- **↑ and ↓ in the composer walk what was sent**, seeded from the transcript so a persisted chat does not lose
|
|
327
|
+
only what was just typed. A single-line input has nothing of its own on the vertical arrows, and the
|
|
328
|
+
half-written draft they were walked away from comes back at the bottom of the walk. **The `/` menu takes those
|
|
329
|
+
keys while it is open** — it is the thing on screen the arrows point at — with Enter picking the highlighted
|
|
330
|
+
row, Tab completing its name, and Escape closing the menu and then, pressed again, the panel.
|
|
331
|
+
|
|
332
|
+
## Built-In Tools
|
|
333
|
+
- The framework publishes five built-ins on every store surface: `navigate` (internal paths only, the same
|
|
334
|
+
router `Link` rides), `goBack` (this session's history — global, because history is not a control a page owns and
|
|
335
|
+
a page that draws no back link is not one you may not leave), `readScreen` (the rendered DOM as compact text —
|
|
336
|
+
headings, links, control values, and `(disabled)` on a control or button that has it; the chat's own UI is
|
|
337
|
+
skipped via `data-agent-ui`, and a password value is never read), `readState(key)` (one masked store key), and
|
|
338
|
+
`highlight(target)`. Declaring a hook tool under one of those names shadows the built-in, so reuse them only to
|
|
339
|
+
mean that. **There is no general-purpose wait**: a built-in one was reachable on every screen and a model spent
|
|
340
|
+
it on whatever key it liked, parking turns nobody asked to park. Waiting belongs to the screen that knows what
|
|
341
|
+
is worth waiting for — publish an `st.tool` beside the control that starts the work, and let it await the work.
|
|
342
|
+
- **A tool that changes the screen waits for the screen before it answers.** `router.push` returns while the RSC
|
|
343
|
+
payload is still in flight and a store action that fires `void fetch.*` commits a tick later, so `navigate`
|
|
344
|
+
awaits `ScreenSettle.wait()` — DOM quiescence, bounded, because the client router hands its promise to nobody —
|
|
345
|
+
and the session awaits it after every non-`query` tool before taking the change report. Without it the report
|
|
346
|
+
describes the moment before the change landed and the `readScreen` that follows reads the page the user left.
|
|
347
|
+
New tools and state from a fresh route are still only listed from the next turn: the catalogue is snapshotted
|
|
348
|
+
when the turn starts.
|
|
349
|
+
- **A tool that waits for its own work costs no model turns; one that returns early costs one round trip per
|
|
350
|
+
look.** The session awaits `run`, so a `.exec` that awaits the store action finishing the job simply makes the
|
|
351
|
+
turn take that long — and the change report that follows carries whatever landed, so the model needs no second
|
|
352
|
+
call to read the result. A fire-and-forget tool leaves the agent to poll instead, which burns the whole
|
|
353
|
+
`maxTurns` budget in seconds on a job measured in minutes. Say so in the `desc` ("takes about two minutes; do
|
|
354
|
+
not poll while it runs") and, for a route full of slow work, in an `Agent.Guide`.
|
|
355
|
+
- **A wait is a screen's own tool, declared where the slow work is.** For the job a tool cannot await — one
|
|
356
|
+
started in an earlier turn, or by a person clicking the button — publish an `st.tool` that parks on the thing
|
|
357
|
+
*that* screen knows about, and say in its `desc` what it waits for and roughly how long. A general built-in was
|
|
358
|
+
tried and removed: reachable on every screen with no idea what any key means, a model spent it on whatever key
|
|
359
|
+
looked promising and parked turns nobody asked to park. The screen that starts the work is the only place that
|
|
360
|
+
knows what finishing looks like, and a tool declared there is also one the agent cannot reach on a screen where
|
|
361
|
+
waiting makes no sense. Honour `AgentAbort.current` in the body and report with `AgentProgress.report`, so Stop
|
|
362
|
+
ends the wait and the row says how it is going.
|
|
363
|
+
- **Stop reaches a tool that is still running.** The session races every call against its abort signal, so a
|
|
364
|
+
two-minute tool does not hold the loop for two minutes after the user presses Stop. The signal itself arrives
|
|
365
|
+
through `AgentAbort.current` — the same module slot `AgentProgress` is — and honouring it is optional, since the
|
|
366
|
+
race lands whatever the tool does; what it buys is the tool's own cleanup, a timer or a poll loop that would
|
|
367
|
+
otherwise run out with nobody left to answer. A tool that ignores it is left running rather than cancelled: the
|
|
368
|
+
work is usually a job a server is already doing.
|
|
369
|
+
- **`readScreen` takes a `section`, and `highlight` a `target`.** Both resolve a name the agent has already seen —
|
|
370
|
+
a `data-akan-action` / `data-akan-state` annotation, an `Agent.Zone` or `useScreenScope` container
|
|
371
|
+
(`data-agent-scope`, which `Load.Units` / `Load.View` / `Data.ListContainer` put on the container they render),
|
|
372
|
+
an element id, or **a heading by its own text**, matched on letters and digits so the slug an agent writes for a
|
|
373
|
+
heading it read resolves. That tolerance stops at headings: a heading is a landmark and scrolling to the wrong
|
|
374
|
+
one costs nothing, while two buttons reading "Save" are not the same control. **Nothing hidden ever resolves** —
|
|
375
|
+
a ring nobody can see reads as a broken tool, not as a miss. A section named by a heading is read to the next
|
|
376
|
+
heading of its level or higher.
|
|
377
|
+
- **A screen is only aimable if its names are printed.** `readScreen` writes `(#anchor)` beside a heading that
|
|
378
|
+
opens an id'd or scoped container, and a truncated read ends with the headings below the cut — otherwise
|
|
379
|
+
everything past the 8000-character limit is unreachable, because nothing names it, and an agent asked to point
|
|
380
|
+
at a section it cannot name guesses a slug and is refused. A refusal lists the sections actually on screen.
|
|
381
|
+
`highlight` scrolls its target into view and flashes it **once the scroll lands**, since a smooth scroll across a
|
|
382
|
+
long page outlasts the flash; it is the one built-in that exists for the *user's* benefit, because showing where
|
|
383
|
+
a control is beats writing directions to it.
|
|
384
|
+
- **A slow tool reports its own progress with `AgentProgress.report(message, { done, total })`** from wherever the
|
|
385
|
+
work is — a store action, an upload loop, an adapter — reached through a module slot rather than a parameter, and
|
|
386
|
+
a no-op when nobody is rendering it. The chat shows it on that call's row until the row resolves. It is the
|
|
387
|
+
browser twin of `McpProgress.report`. Import it and `AgentAbort` from `akanjs/store`: an app may not reach
|
|
388
|
+
`use-agentic` directly (`no-import-external-library`), and those two are the channels a long tool body needs.
|
|
389
|
+
- **The turn cap is a question, not a dead end.** At `maxTurns` the session asks whether to keep going through the
|
|
390
|
+
same card `askUser` uses, and the answer rides as the user's own turn — so a steer typed instead of the
|
|
391
|
+
keep-going choice reaches the model as guidance. A host that renders no `pendingQuestion` passes no
|
|
392
|
+
`continueAsk` and keeps the old failure, because asking with nobody listening would hang.
|
|
393
|
+
- **`askUser` is a fourth built-in the *session* owns, not the surface.** The answer comes from the conversation
|
|
394
|
+
rather than the screen, so it rides on every turn whatever the page declares, and a zone agent asks inside its
|
|
395
|
+
own transcript. `choices` offers a pick (`multiple` for several) and omitting them asks for free text; the card
|
|
396
|
+
keeps a free-text row either way, because the model wrote the options and only the user knows whether the answer
|
|
397
|
+
is among them. The loop parks on the question exactly as it parks on an approval, a dismissal is the tool's
|
|
398
|
+
error result rather than a silent empty answer, and the settled exchange renders as question-and-answer instead
|
|
399
|
+
of a tool row. **Never re-implement it per screen** — a `st.tool("askAboutX")` that opens a modal is the same
|
|
400
|
+
thing with a worse transcript — and a hook tool named `askUser` shadows it like any other built-in.
|