@ai-ecoverse/slicc-agent 7.20.3 → 7.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/dist/approvals/sudo.js +1 -1
- package/dist/approvals/sudo.js.map +2 -2
- package/dist/owner.js +1 -0
- package/dist/owner.js.map +2 -2
- package/dist/secrets/extension.js +4 -2
- package/dist/secrets/extension.js.map +2 -2
- package/dist/types/secrets/extension.d.ts +1 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -748,17 +748,18 @@ Every approval, of a guest's prompt, of a tool call in a run a guest started, or
|
|
|
748
748
|
- **In the worker,** `AgentHost.approvals` has `request(draft, ctx)`, `decide(id, answer, reason, by, ctx)` (`by` is a `DecidedBy`, or `{ by, device }` to record the deciding device), `settled(id, ctx)` (resolves when the item leaves `pending`), `withdraw(id, reason, ctx)` and `withdrawSeat(seat, ctx)`, which withdraws a revoked seat's pending items.
|
|
749
749
|
- **Over the link,** `AgentTranscript.approvals` replicates the items, and `AgentControl.decide(id, decision, reason, ctx)` answers one, for every owner device: the owner's pages and followers with or without Control, all with the same powers. `decidedBy` comes from the link's seat (`owner` for the owner's pages, `follower` for the others), and is only a record of who answered. A guest never gets `decide`.
|
|
750
750
|
- **In spectrum** (1.112 on, which shows approvals in `<slicc-approvals>` with Always allow when `always` is true, as notices without `decide`, and the verdict's level), `createAgentModel` returns `approvals`, an `ApprovalsAdapter` for `SliccModel.approvals`. `list()` has the pending `user` items, oldest first, as spectrum's `Approval`s, with the cone's name as `agentName` and the item's own `always`, so a guest approval offers Always allow only when the policy did when it was asked. Every approval carries the judge's `verdict` once it lands, as `{ level?, aligned?, reason }` (spectrum 1.112 on shows the level; `aligned` is `true` at P ≥ 0.8, or the chat model's yes or no), `judging: true` while the check runs and `verdictError` when there is none. Its `always` is the item's, so Always allow shows up only when a level 1 verdict offers it. `decide(id, decision, reason?)` rejects with the agent's message, and `ended` reports `answered`, `expired` or `withdrawn` for an item that left without this tab's decision. Every owner device's adapter has `decide`; a guest connection's doesn't. So a notice instead of a dialog shows only where nothing can answer. A `guest-tool` approval also carries `args`, the call's arguments pretty-printed as JSON (two-space indent), so spectrum can show them uncut when `summary` is empty. The worker runs every string in the arguments through the secrets scrub before it files the item, so `summary`, `detail.arguments` and `args` show a secret as its placeholder; the seat's Always rules still match the call's own arguments. `args` is capped at 64 KiB (65,536 UTF-16 code units, `ARGS_LENGTH`, never splitting a surrogate pair): longer arguments are sent as that prefix with `argsTruncated: true`, and spectrum must then offer only Deny and Always deny, never Allow, because the end wasn't seen.
|
|
751
|
-
- **Kernel sudo:** `AgentOwner.approve(req, { signal, where? })` from `startAgent` takes slicc-kernel's sudo request as it comes to the kernel's `approve` hook and resolves `once`, `always` or `deny`. bios hands its hook to it while the agent runs, and to its own dialog otherwise. It rejects with `code: 'EAGAIN'` before anything is recorded when the agent can't take the request (released, restarting, or an older worker)
|
|
751
|
+
- **Kernel sudo:** `AgentOwner.approve(req, { signal, where? })` from `startAgent` takes slicc-kernel's sudo request as it comes to the kernel's `approve` hook and resolves `once`, `always` or `deny`. bios hands its hook to it while the agent runs, and to its own dialog otherwise. It rejects with `code: 'EAGAIN'` before anything is recorded when the agent can't take the request (released, restarting, or an older worker) or when the request's `kind` isn't `sudo`, such as a program's secret `ask`, so that's when to fall back; any other rejection is a deny. The request goes through `slicc.agent.sudo`, a service only the owner's pages get, and becomes a `sudo` item on the `user` tier with the kernel's `expiresAt`:
|
|
752
752
|
- **Requester** comes from the kernel's process tag: `{ kind: 'agent', agentId }` is the cone or scoop by its name, `{ kind: 'user', where }` is the kernel user with `where` (`terminal:…` reads "a terminal", `follower:<device>` the `where` the page passes, such as "on Pat's phone", or "a linked device", with the device id kept as `requester.device`), and anything else is the kernel user alone.
|
|
753
753
|
- **Detail:** the command as the kernel resolved it (`path` and the arguments, shell-quoted), `target`, `cwd`, `alwaysScope: 'cwd'` when `req.always === true`, since the kernel's Always writes a rule for that directory, and the kernel's facts for the judge: `stdin` (`tty`, `none`, `pipe` or `file`), `rootOnly` (for each path on the line, whether only root can change it) and `writable` (`req.always`, whether the kernel can record the line). Requests without them still work; `req.always: false` or `writable: false` means no Always.
|
|
754
754
|
- **Answers:** `approved` resolves its answer, a judge's rejection resolves a `SudoDenial`, `{ answer: 'deny', message: 'sudo: denied by the approval judge: <reason>' }` (the prefix is `JUDGE_DENIED`), so the shell can say who refused, and anything else `deny`. A kernel that doesn't know the object denies it as it denies any answer but `once` and `always`. Every device of the owner answers with the same powers: a follower, with or without Control, sees the same item, Always included when the verdict offers it, and its `always` counts as the owner tab's would. `device` on the item names the device that answered, from `owner.port({ device })`.
|
|
755
755
|
- **Ends:** when the kernel aborts `signal` (`withdrawn`) the item is withdrawn, and on `expired` the page keeps its link until the record's own timeout settles it (`unanswered`), so it never reads as withdrawn. When the page's link closes the worker withdraws its open sudo items (`disconnected`). A restart or release of the owner first ends the old worker, then denies the requests still waiting, so the old worker never sees their links close, and the next worker withdraws their items (`restart`). The kernel already allows one pending request per user.
|
|
756
756
|
- **Scoops:** a scoop's request sends its cone a `sudo-request` lick without actions once a person has to answer it (at once on the `user` tier, after the judge hands it on with the `agent` policy, never when the judge decides), so the cone knows the scoop waits and can't approve it itself. A cone that asks gets none: it waits in its own command.
|
|
757
757
|
- **With the host's own approvals:** bios has its own `approvals` port for sudo, and a page that spreads `{ ...bios, ...createAgentModel(connection) }` would lose it. Pass that port in instead, as `createAgentModel(connection, { approvals: biosPort })`. The returned port then lists both sets, oldest first, sends `decide` to whichever port listed the id, and passes on both ports' `approvals` and `ended` events. It has `decide` when either side can answer; asked for an item its owner can't answer, it rejects with "This request can't be answered in this tab." Without the option, it lists only the agent's items.
|
|
758
|
+
- **Secret requests** (a program's `ask` on `/dev/sealed`, such as `fnox set NAME --ask` or `sealed ask NAME`) are bios's approvals of kind `secret`, and only a person answers them. They come in through `approvals: biosPort` and go out unchanged: the adapter lists them with the rest, oldest first, sends their `decide` (Deny, which cancels the vault's request) to bios, and passes on bios's `ended`. The value is typed, and a reveal allowed, only in the vault's own frame inside the dialog, so neither the agent nor the page sees it. They are never items in `slicc.approvals`, so the judge never gives them a verdict or an answer, whatever `sudo.approver` says, and `AgentOwner.approve` refuses them with `EAGAIN`.
|
|
758
759
|
|
|
759
760
|
#### The automatic judge
|
|
760
761
|
|
|
761
|
-
The judge ([`src/approvals/judge.ts`](src/approvals/judge.ts)) gives a request a verdict by the owner's intent, never the requester's. `request()` starts it at once for every `sudo` item, whatever its tier, and for every `agent` or `user` item, so a person is asked with the verdict shown. Who answers is the gate: a `sudo` item's tier is the owner's approval policy (`sudo.approver`), not the request's, `user` (a person) by default and for anything but `agent`; a guest item's tier is the seat's gate. On a `user` item the verdict is advice for the person and decides nothing; on an `agent` item the routing table below decides. The dialog never waits: Allow once and Deny work while `judging` is `true`.
|
|
762
|
+
The judge ([`src/approvals/judge.ts`](src/approvals/judge.ts)) gives a request a verdict by the owner's intent, never the requester's. It judges only items in `slicc.approvals`, never a `secret` approval, which always goes to a person. `request()` starts it at once for every `sudo` item, whatever its tier, and for every `agent` or `user` item, so a person is asked with the verdict shown. Who answers is the gate: a `sudo` item's tier is the owner's approval policy (`sudo.approver`), not the request's, `user` (a person) by default and for anything but `agent`; a guest item's tier is the seat's gate. On a `user` item the verdict is advice for the person and decides nothing; on an `agent` item the routing table below decides. The dialog never waits: Allow once and Deny work while `judging` is `true`.
|
|
762
763
|
|
|
763
764
|
- **Levels:** the verdict is `level` 1 Routine (a sysadmin would approve it as normal work: it reads, builds, installs, or changes files and services in the course of the work, including reaching outside the session, and doesn't change who may do what; whether the owner wanted that is the aligned question), 2 Permissions (it changes who may do what: sudoers, users and groups, ownership or modes of system files, secret rules, the approvals policy, guest seats, credentials and tokens) or 3 Harm (it would damage the system or the work in a way that is hard to undo: delete or overwrite system files or others' work, lock the owner out, or expose secrets or private work to anyone but the owner); `aligned`, whether it serves what the owner asked for; and for sudo `always`, whether a later run of exactly this line can do no more than this one. No command lists anywhere: the level is the model's call, from the kernel's facts: `request.sudo: { stdin, writable, rootOnly }` holds only what the requester can't choose (`rootOnly` is whether every path on the line and the directory can be changed only by root), while the command, the target user, the directory and each path's root-only fact (`path "/etc/x": root-only` or `changeable`, one JSON-quoted path per line) are inside the fenced `request.untrusted`, because the requester chose them.
|
|
764
765
|
- **The calls:** two in parallel, with one 15 s timeout (`JUDGE_TIMEOUT`) for both. One `models.classify` call on `approvals.judgeModel` (in the agent's `settings.json`, `/etc/slicc/agent/settings.json` with kernel users, `adobe/clef` by default), on the harness's own `Models`, with one retry, asks `level` (`routine`, `permissions`, `harm`), `aligned`, and for sudo `always` ("Could a later run of exactly this command line do more than this one, because of input, files or code the person can't see in the dialog?"). The level reads the three probabilities as an ordered scale: 3 when P(harm) ≥ 0.4 (`JUDGE_HARM`), else 2 when P(permissions) + P(harm) ≥ 0.5 (`JUDGE_CUT`), else 1. Both cuts allow 1e-9 (`JUDGE_EPSILON`) of floating-point error, so a share that is exactly at a cut counts as reaching it. So moving probability to a higher level never lowers the level, and being unsure between routine and permissions never gives harm: `ls -la /root/v6` at P(routine) 0.598 is level 1, where the old rule (the higher of the top two when the top was under 0.6) made it 3. Harm's cut is lower because harm is the costly miss: on `adobe/clef`, P(harm) stayed under 0.35 for all 70 reads of a real cleanup session and reached 0.46 to 0.97 for every request the eval set expects denied. The verdict also keeps P(routine) as `routine`; `aligned` counts at P ≥ 0.8 (`JUDGE_ALLOW`); Always is safe at P(more) ≤ 0.2 (`JUDGE_ALWAYS`). The other is a short text call on the conversation's own chat model (the item's cone, or the active cone for a terminal), through the same `completeText` thread titles use, with the same instructions and fenced input, scrubbed as titles are, for the reason: one or two sentences on what granting the request would do to the system, control characters stripped, at most 300 characters (code points): a longer one is cut at the last word that fits and ends with `…`, never silently at a sentence, so a later sentence is never hidden, and never inside a surrogate pair. The reason never says whether the owner wants it: that is `aligned`, which spectrum shows next to it as its own sentence, so a chat model that reads the owner's words differently from the classifier can't contradict the verdict in the same dialog. The verdict lands when the classifier answers, and the reason is patched in when it comes; a deny waits for it, so its message carries it. Without it the reason is a plain one per level (`VERDICT_REASONS`): level 1 "It looks like routine work.", level 3 "It could harm the system or the work in a way that is hard to undo.", and level 2 "The check leaned toward a change in who may do what.", which claims nothing about the request itself. No decision ever reads the reason. Both calls' spend goes into the conversation's `pi.usage`.
|
|
@@ -839,7 +840,7 @@ A guest seat (plan D13, PR 19) is a revocable seat on one cone: the guest sees t
|
|
|
839
840
|
|
|
840
841
|
### Credentials
|
|
841
842
|
|
|
842
|
-
The agent never holds a secret's value. Values live in the vault (`vault.sliccy.ai`); the agent sees names and placeholders (`fnox_proxy_…`),
|
|
843
|
+
The agent worker never holds a secret's value. Values live in the vault (`vault.sliccy.ai`); the agent sees names and placeholders (`fnox_proxy_…`). A program the agent runs gets a value only from the vault: through `fnox exec` or a shell grant the user enabled for that secret, or by a revealed `ask` (`sealed ask NAME --reveal`) the owner allowed with a click in the vault's own frame, asked each time. Every text that could reach the model, that program's output included, is still scrubbed through the vault first, so the model sees the placeholder. The design is secrets rev 4 (§3.12, §3.15–§3.18); scrubbing is AGENT-S1 and the model and MCP transport VAULT-2 (slicc-agent 4.0.0). Without a vault port there are no model credentials.
|
|
843
844
|
|
|
844
845
|
- **The port.** bios posts `{ kernel, admin, vault, scrub }` to the worker, where `vault` is a `MessagePort` to the vault frame (role `agent`) and `scrub` the last-known `{ needed, version }`, or `null` when no vault ever connected. On a vault reload it posts `{ vault, scrub }` again, and the worker resends its unanswered ops. The agent port gets no events, so bios also posts `{ locked }` (a boolean, from the page port's `status`) whenever the lock changes; the worker reads the initial state from the vault's `welcome`. Without a port, or with `needed: false`, nothing is sent and every scrub is the identity. A `version` newer than the last pair read counts as `needed` until the new pair arrives.
|
|
845
846
|
- **The wire** is slicc-vault's `AgentOp`/`AgentReply` (`@ai-ecoverse/slicc-vault`, types only). Requests are `{ v: 1, id, op, ... }` and answers `{ v: 1, id, op, ... }` or `{ v: 1, id, error: { code, message } }`, in request order: `redact { texts }` (strings and `Uint8Array`s, answered in the same order and types, with `version`), the stream ops `redactStream`, `push { chunk }`, `end` and `drop` with the worker's string `stream` id, and `model`, `mcp`, `records`, `grant`, `refresh` and `endpoints`. The vault's first message, `welcome`, carries `status.scrub` and `status.locked`; version bumps come only from bios's `{ scrub }` posts and the `version` in answers.
|
|
@@ -854,13 +855,13 @@ The agent never holds a secret's value. Values live in the vault (`vault.sliccy.
|
|
|
854
855
|
- **Shown as:** `- NAME = <placeholder>: <rules>; in every bash` for a sealed secret; a fnox key the vault doesn't hold reads `- NAME = $NAME: not sealed` (a plain fnox secret), and a sealed secret the config lacks says `not in the fnox config`.
|
|
855
856
|
- **Failures are loud.** When fnox is missing (exit 127), a command exits non-zero, `/dev/sealed` fails or a reply doesn't parse, the `secrets` section is "Secrets are unavailable: <reason>.", `/secrets` says the same, and the worker logs one `slicc-secrets: secrets are unavailable: <reason>` line until the reason changes. The reason is a fixed sentence: fnox's error `kind` (`config` reads "the fnox config has an error; check /etc/fnox/config.toml") or the vault's error `code`, never their message, since fnox quotes the offending config line and a plain secret's value can sit on it, which the vault's scrub doesn't know. The message goes only to that log line, redacted by the vault and cut to 200 characters. stderr is never read. Only a config with no keys and a vault with no sealed secrets shows "No secrets are configured".
|
|
856
857
|
- **Shell grants stay off while fnox would hand out unsealed values.** `fnox exec` also sets every config secret it may inject (`injectable.exec`, which is `env = true` and `env = "exec"`), and a plain or age secret's value isn't one the vault scrubs. So while any such key isn't in the vault's list, the wrapper isn't used, the section and `/secrets` say "Shell grants are off: fnox exec would also give every command the unsealed fnox secrets <names>; seal them or set env = false for them.", and one line is logged.
|
|
857
|
-
- **The hooks:** an `afterTool` hook scrubbing every result's text, diagnostics and string `details` (pi-fnox's `tool_result`); the `secrets` system section with the names, placeholders, where each works and how to use them (`before_agent_start`); and `/secrets`, answered locally as a `slicc.secrets` entry (`/fnox-list`; reloading is automatic). When the listing succeeded, no unsealed key would be injected and the vault grants at least one listed secret `{ shell = true }`, every conversation command runs as `fnox exec --shell-grants -- <argv>` (pi-fnox's `spawnHook`). slicc-agent doesn't depend on `@kickythrust/pi-fnox`. Every conversation keeps the extension: new ones are pinned at creation, and conversations stored with an extension list that lacks it get it back at start.
|
|
858
|
+
- **The hooks:** an `afterTool` hook scrubbing every result's text, diagnostics and string `details` (pi-fnox's `tool_result`); the `secrets` system section with the names, placeholders, where each works and how to use them (`before_agent_start`), and, also when nothing is configured, how to ask for a missing one (`ASK_LINE`): `fnox set NAME --ask` or `sealed ask NAME`, the user types it in a dialog and the command prints only the placeholder; `fnox set` only for a missing secret, since it always replaces (`replace: true`); `--reveal` on `sealed ask` only when a tool needs the plaintext, piped straight into it; and a non-zero exit (declined, expired or refused) isn't asked again unless the user wants it; and `/secrets`, answered locally as a `slicc.secrets` entry (`/fnox-list`; reloading is automatic). When the listing succeeded, no unsealed key would be injected and the vault grants at least one listed secret `{ shell = true }`, every conversation command runs as `fnox exec --shell-grants -- <argv>` (pi-fnox's `spawnHook`). slicc-agent doesn't depend on `@kickythrust/pi-fnox`. Every conversation keeps the extension: new ones are pinned at creation, and conversations stored with an extension list that lacks it get it back at start.
|
|
858
859
|
- **Where text is scrubbed before anything keeps or cuts it:** command output, per stream, before the bash tool's tail window, the spill file and the live slot; `read`'s bytes (images aren't, and files over 8 MiB stream in 1 MiB chunks); MCP results before their middle cut and progress text; codemode output before its cut; user and remote sends after skill expansion; every lick (sprinkle sends and scoop results included) before triage and the outbox; and memory writes, before the pattern redaction. Remote-control summaries are built from stored entries only.
|
|
859
860
|
- **The hold.** A vault that doesn't answer within 2 s reads as `waiting`. Nothing unscrubbed is appended: tool results, sends and licks wait in memory, model requests wait before they start, and command output held past 32 MiB kills the command with "output held: waiting for the vault". The state is the transcript's `vault` field (`{ port, needed, version, locked, held }`), and remote `watch` streams get a `notice` "waiting for the vault" and one when it answers again.
|
|
860
861
|
- **In spectrum.** The agent port's `hold()` is `{ reason: 'locked', held }` while the vault needs a passkey, `{ reason: 'waiting', held }` while scrubbing is needed and the port isn't `ready`, and `null` otherwise, with a `hold` event on each change (and `null` when it clears); spectrum (≥ 1.62.0) shows it above the composer, and older spectrum ignores it. While a hold is up, the worker's active cone is busy (`working` when it isn't running), so the composer steers and queues; a send made during the hold waits in the tab, shown in that cone's queue, and goes to the worker once the hold clears; removing it before then means it's never sent. `/secrets` entries (`slicc.secrets`) show as a "Secrets listed" notice, or "Secrets unavailable" with the reason.
|
|
861
862
|
- **The 3.x store is wiped.** 3.x kept model and MCP keys in the IndexedDB database `slicc-agent-credentials`; 4.x doesn't migrate them. At start, before any model call, the worker reads only that database's record keys (never decrypting), deletes it, and keeps the accounts it found (`adobe` as Adobe, `amazon-bedrock` as Bedrock, `mcp:<server>|…` as the server, anything else by its providerId) in the session document `slicc.keys-moved`. A missing database, or no `indexedDB`, does nothing. The worker waits up to 3 s for the delete and claims the keys moved only once it succeeds. A delete blocked by an open 3.x tab shows no notice yet: if it succeeds later in the session (the tab closes) its accounts are added then, and otherwise the next start tries again. A delete that fails reports nothing. Once the vault's records are read, the accounts still without a record are the settings state's `moved`, and the spectrum adapter's `notices` port shows one notice, with model accounts first and MCP servers grouped after them: "Your keys moved to seven's vault. Add them again in Settings › Accounts: Adobe, Bedrock; MCP servers: github, jira." (or "…, and the MCP server github" for one). Dismissing it calls `AgentSettings.dismissMoved`, which marks the document, so it stays dismissed across reloads. An account without a record reads not connected. A model call that finds no credential ("Provider is not configured", "No API key") leads with "Adobe isn't connected." or "Bedrock isn't connected.", with "Connect it in Settings › Accounts." underneath instead of the raw error, and opens settings, and a send whose run finds no model because its account isn't connected (Adobe lists models only once signed in) shows the same error. "Your Adobe session has expired." is kept for a 401 from a token that exists. The settings state's `labels` names every model of a provider without a record from the agent's catalogue ("Claude Haiku 4.5 (US) on Bedrock"), and the adapter puts that name in the header of a reply whose model isn't in the picker, instead of the raw id.
|
|
862
863
|
- **For bios:** the agent's `notices` (keys moved) would replace bios's own port in `{ ...bios, ...createAgentModel(connection) }`, so pass that port in instead, as `createAgentModel(connection, { notices: biosPort })`. The returned port lists bios's notices and then the agent's, sends `act` and `dismiss` to whichever port listed the id (never dismissing one with `dismissible: false`), and passes on both ports' `notices` events. Without the option, it lists only the agent's.
|
|
863
|
-
- **Tests.** The worker never compiles values: `src/` takes only `import type { Hit }` from [`@ai-ecoverse/slicc-scrub`](https://www.npmjs.com/package/@ai-ecoverse/slicc-scrub), the vault's scrubber, and the package is a devDependency. The fake vault the tests use scrubs with that package, and its `vectors.json` (every form, line-wrapped base64 and hex included) runs through each scrub point and each cut. A suite-wide check asserts that no captured model request, entry, slot or memory file holds any form of a seeded value. `test/integration/secrets-fnox.test.mjs` runs the listing on the page kernel with `@ai-ecoverse/wasi-fnox` (a devDependency) and the fake vault's `/dev/sealed` side (`fakeSealed`: `list`, `placeholder`, `materialize`, `materializeConsume`): a sealed secret in the section and `/secrets`, a shell grant reaching a command through `fnox exec --shell-grants`, shell grants kept off by an unsealed `env = true` secret, fnox missing, fnox exiting non-zero on a config error that quotes a plain value (which never reaches the prompt, `/secrets` or the transcript),
|
|
864
|
+
- **Tests.** The worker never compiles values: `src/` takes only `import type { Hit }` from [`@ai-ecoverse/slicc-scrub`](https://www.npmjs.com/package/@ai-ecoverse/slicc-scrub), the vault's scrubber, and the package is a devDependency. The fake vault the tests use scrubs with that package, and its `vectors.json` (every form, line-wrapped base64 and hex included) runs through each scrub point and each cut. A suite-wide check asserts that no captured model request, entry, slot or memory file holds any form of a seeded value. `test/integration/secrets-fnox.test.mjs` runs the listing on the page kernel with `@ai-ecoverse/wasi-fnox` (a devDependency) and the fake vault's `/dev/sealed` side (`fakeSealed`: `list`, `placeholder`, `materialize`, `materializeConsume` and `ask`): a sealed secret in the section and `/secrets`, a shell grant reaching a command through `fnox exec --shell-grants`, shell grants kept off by an unsealed `env = true` secret, fnox missing, fnox exiting non-zero on a config error that quotes a plain value (which never reaches the prompt, `/secrets` or the transcript), an empty config, and the kernel's `sealed ask` (slicc-kernel 1.175 on): a revealed value reaches the command while the transcript and every model request hold only its placeholder, and a cancelled ask exits 1; and `fnox set NAME --ask` (wasi-fnox 1.45.0-2 on), which seals what the user typed and prints only its placeholder.
|
|
864
865
|
|
|
865
866
|
## The kernel
|
|
866
867
|
|
package/dist/approvals/sudo.js
CHANGED
|
@@ -9,7 +9,7 @@ const shellWord = (word) => SAFE.test(word) ? word : `'${word.replaceAll("'", `'
|
|
|
9
9
|
const text = (value) => typeof value === "string";
|
|
10
10
|
function sudoRequest(value) {
|
|
11
11
|
const request = value;
|
|
12
|
-
if (typeof request !== "object" || request === null) return null;
|
|
12
|
+
if (typeof request !== "object" || request === null || request.kind !== "sudo") return null;
|
|
13
13
|
const { argv, user, expiresAt } = request;
|
|
14
14
|
if (!Array.isArray(argv) || !argv.length || !argv.every(text)) return null;
|
|
15
15
|
if (!text(user) || typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/approvals/sudo.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Context, ReplicatedState } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { AgentsState } from '../agents.ts';\nimport type { Licks } from '../licks/licks.ts';\nimport { sprinklesOf } from '../sprinkles/cgi.ts';\nimport type { Approvals } from './index.ts';\nimport {\n type Approval,\n type ApprovalRequester,\n cleanReason,\n REASONS,\n type SudoDetail,\n type SudoStdin,\n} from './record.ts';\n\nexport type SudoAnswer = 'once' | 'always' | 'deny';\n\nexport type SudoDenial = { answer: 'deny'; message: string };\n\nexport type SudoReply = SudoAnswer | SudoDenial;\n\nexport interface SudoRequest {\n id: string;\n kind: 'sudo';\n user: string;\n uid?: number;\n target?: string;\n argv: string[];\n path?: string;\n cwd?: string;\n pid?: number;\n tag?: string;\n tags?: string[];\n tty?: string;\n createdAt?: number;\n expiresAt: number;\n always?: boolean;\n stdin?: SudoStdin;\n rootOnly?: Record<string, boolean>;\n}\n\nexport type SudoAsked = { id: string; error: null } | { id: null; error: string };\n\nexport interface AgentSudo {\n readonly approvals: ReplicatedState<Approval[]>;\n request(request: SudoRequest, where: string | null, context: Context): Promise<SudoAsked>;\n withdraw(id: string, reason: string | null, context: Context): Promise<void>;\n}\n\nconst SAFE = /^[\\w@%+=:,./-]+$/;\n\nexport const shellWord = (word: string): string =>\n SAFE.test(word) ? word : `'${word.replaceAll(\"'\", `'\\\\''`)}'`;\n\nconst text = (value: unknown): value is string => typeof value === 'string';\n\nexport function sudoRequest(value: unknown): SudoRequest | null {\n const request = value as Partial<SudoRequest> | null;\n if (typeof request !== 'object' || request === null) return null;\n const { argv, user, expiresAt } = request;\n if (!Array.isArray(argv) || !argv.length || !argv.every(text)) return null;\n if (!text(user) || typeof expiresAt !== 'number' || !Number.isFinite(expiresAt)) return null;\n return request as SudoRequest;\n}\n\nfunction tagOf(tag: unknown): { kind?: unknown; agentId?: unknown; where?: unknown } | null {\n if (!text(tag)) return null;\n try {\n const parsed = JSON.parse(tag);\n return typeof parsed === 'object' && parsed !== null ? parsed : null;\n } catch {\n return null;\n }\n}\n\nconst TERMINAL = 'terminal:';\nconst FOLLOWER = 'follower:';\n\nfunction shownWhere(where: string, given: string | undefined): string {\n if (given) return given;\n if (where.startsWith(TERMINAL)) return 'a terminal';\n if (where.startsWith(FOLLOWER)) return 'a linked device';\n return where;\n}\n\nexport function sudoRequester(\n request: SudoRequest,\n agents: Readonly<AgentsState> | undefined,\n where?: string | null\n): { requester: ApprovalRequester; agentId: string } {\n const tag = tagOf(request.tag);\n const name = request.user;\n const sprinkle = sprinklesOf(Array.isArray(request.tags) ? request.tags.filter(text) : [])[0];\n if (sprinkle)\n return { requester: { kind: 'user', name, where: `the ${sprinkle} sprinkle` }, agentId: '' };\n if (tag?.kind === 'agent' && text(tag.agentId)) {\n const id = tag.agentId.startsWith('cone:') ? tag.agentId.slice('cone:'.length) : tag.agentId;\n const known = agents?.cones[id]?.name ?? agents?.scoops[id]?.name ?? name;\n return { requester: { kind: 'agent', name: known, agentId: id }, agentId: id };\n }\n if (tag?.kind === 'user' && text(tag.where)) {\n const given = cleanReason(where);\n const device = tag.where.startsWith(FOLLOWER) ? tag.where.slice(FOLLOWER.length) : '';\n return {\n requester: {\n kind: 'user',\n name,\n where: shownWhere(tag.where, given),\n ...(device ? { device } : {}),\n },\n agentId: '',\n };\n }\n return { requester: { kind: 'user', name }, agentId: '' };\n}\n\nconst STDIN: readonly unknown[] = ['tty', 'none', 'pipe', 'file'];\n\nfunction rootOnlyOf(value: unknown): Record<string, boolean> | undefined {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;\n const kept = Object.entries(value).filter(\n (entry): entry is [string, boolean] => typeof entry[1] === 'boolean'\n );\n return Object.fromEntries(kept);\n}\n\nfunction kernelFacts(request: SudoRequest): Partial<SudoDetail> {\n const rootOnly = rootOnlyOf(request.rootOnly);\n return {\n ...(STDIN.includes(request.stdin) ? { stdin: request.stdin } : {}),\n ...(rootOnly ? { rootOnly } : {}),\n ...(typeof request.always === 'boolean' ? { writable: request.always } : {}),\n };\n}\n\nexport function sudoDetail(request: SudoRequest): SudoDetail {\n const command = [request.path || request.argv[0], ...request.argv.slice(1)]\n .map((word) => shellWord(String(word)))\n .join(' ');\n return {\n command,\n ...(text(request.target) ? { target: request.target } : {}),\n ...(text(request.cwd) ? { cwd: request.cwd } : {}),\n ...(request.always === true ? { alwaysScope: 'cwd' as const } : {}),\n ...kernelFacts(request),\n };\n}\n\nfunction scoopLick(\n id: string,\n agentId: string,\n detail: SudoDetail,\n agents: Readonly<AgentsState> | undefined\n) {\n const scoop = agents?.scoops[agentId];\n if (!scoop) return undefined;\n const { command, target, cwd } = detail;\n const as = target ? ` as ${target}` : '';\n const at = cwd ? ` in ${cwd}` : '';\n return {\n channel: 'sudo-request' as const,\n source: id,\n title: `${scoop.name} waits for sudo`,\n text: `[scoop ${scoop.name} waits for a person to approve sudo]`,\n body: `${scoop.name} asked to run ${command}${as}${at}. A person answers it in the approvals dialog; you can't approve it. It ends when someone answers or it times out.`,\n target: `cone:${scoop.cone}` as const,\n };\n}\n\nexport interface SudoAttach {\n approvals: Approvals;\n agents?: () => Readonly<AgentsState> | undefined;\n licks?: Pick<Licks, 'deliver'>;\n}\n\ntype SudoLick = NonNullable<ReturnType<typeof scoopLick>>;\n\nexport function createSudo(options: SudoAttach): AgentSudo & { close(): void } {\n const { approvals } = options;\n const agents = () => options.agents?.();\n const waiting = new Map<string, SudoLick>();\n const send = (lick: SudoLick) =>\n void options.licks?.deliver(lick, BACKGROUND_CONTEXT).catch(() => undefined);\n const watch = (items: readonly Approval[]) => {\n for (const [id, lick] of waiting) {\n const item = items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.tier !== 'user') continue;\n waiting.delete(id);\n if (item?.state === 'pending') send(lick);\n }\n };\n const off = approvals.state.subscribe((items) => watch(items));\n return {\n approvals: approvals.state,\n async request(value, where, context) {\n const request = sudoRequest(value);\n if (!request) return { id: null, error: 'This is not a sudo request.' };\n const { requester, agentId } = sudoRequester(request, agents(), where);\n const detail = sudoDetail(request);\n const item = await approvals.request(\n {\n kind: 'sudo',\n agentId,\n requester,\n tier: 'user',\n always: request.always !== false,\n expiresAt: request.expiresAt,\n detail,\n },\n context\n );\n const lick = scoopLick(item.id, agentId, detail, agents());\n if (lick) {\n waiting.set(item.id, lick);\n watch(approvals.state.value as Approval[]);\n }\n return { id: item.id, error: null };\n },\n async withdraw(id, reason, context) {\n await approvals.withdraw(id, reason, context);\n },\n close() {\n off();\n waiting.clear();\n },\n };\n}\n\nexport function ownedSudo(sudo: AgentSudo): AgentSudo & { release(): void } {\n const mine = new Set<string>();\n const forget = () => {\n const open = new Set(\n (sudo.approvals.value as Approval[])\n .filter((item) => item.state === 'pending')\n .map(({ id }) => id)\n );\n for (const id of mine) if (!open.has(id)) mine.delete(id);\n };\n return {\n approvals: sudo.approvals,\n async request(request, where, context) {\n forget();\n const asked = await sudo.request(request, where, context);\n if (asked.id) mine.add(asked.id);\n return asked;\n },\n async withdraw(id, reason, context) {\n if (!mine.delete(id)) return;\n await sudo.withdraw(id, reason, context);\n },\n release() {\n forget();\n for (const id of mine)\n void sudo.withdraw(id, REASONS.disconnected, BACKGROUND_CONTEXT).catch(() => undefined);\n mine.clear();\n },\n };\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,0BAA0B;AAGnC,SAAS,mBAAmB;AAE5B;AAAA,EAGE;AAAA,EACA;AAAA,OAGK;AAoCP,MAAM,OAAO;AAEN,MAAM,YAAY,CAAC,SACxB,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,WAAW,KAAK,OAAO,CAAC;AAE5D,MAAM,OAAO,CAAC,UAAoC,OAAO,UAAU;AAE5D,SAAS,YAAY,OAAoC;AAC9D,QAAM,UAAU;AAChB,MAAI,OAAO,YAAY,YAAY,YAAY,
|
|
4
|
+
"sourcesContent": ["import type { Context, ReplicatedState } from '@earendil-works/chord';\nimport { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';\nimport type { AgentsState } from '../agents.ts';\nimport type { Licks } from '../licks/licks.ts';\nimport { sprinklesOf } from '../sprinkles/cgi.ts';\nimport type { Approvals } from './index.ts';\nimport {\n type Approval,\n type ApprovalRequester,\n cleanReason,\n REASONS,\n type SudoDetail,\n type SudoStdin,\n} from './record.ts';\n\nexport type SudoAnswer = 'once' | 'always' | 'deny';\n\nexport type SudoDenial = { answer: 'deny'; message: string };\n\nexport type SudoReply = SudoAnswer | SudoDenial;\n\nexport interface SudoRequest {\n id: string;\n kind: 'sudo';\n user: string;\n uid?: number;\n target?: string;\n argv: string[];\n path?: string;\n cwd?: string;\n pid?: number;\n tag?: string;\n tags?: string[];\n tty?: string;\n createdAt?: number;\n expiresAt: number;\n always?: boolean;\n stdin?: SudoStdin;\n rootOnly?: Record<string, boolean>;\n}\n\nexport type SudoAsked = { id: string; error: null } | { id: null; error: string };\n\nexport interface AgentSudo {\n readonly approvals: ReplicatedState<Approval[]>;\n request(request: SudoRequest, where: string | null, context: Context): Promise<SudoAsked>;\n withdraw(id: string, reason: string | null, context: Context): Promise<void>;\n}\n\nconst SAFE = /^[\\w@%+=:,./-]+$/;\n\nexport const shellWord = (word: string): string =>\n SAFE.test(word) ? word : `'${word.replaceAll(\"'\", `'\\\\''`)}'`;\n\nconst text = (value: unknown): value is string => typeof value === 'string';\n\nexport function sudoRequest(value: unknown): SudoRequest | null {\n const request = value as Partial<SudoRequest> | null;\n if (typeof request !== 'object' || request === null || request.kind !== 'sudo') return null;\n const { argv, user, expiresAt } = request;\n if (!Array.isArray(argv) || !argv.length || !argv.every(text)) return null;\n if (!text(user) || typeof expiresAt !== 'number' || !Number.isFinite(expiresAt)) return null;\n return request as SudoRequest;\n}\n\nfunction tagOf(tag: unknown): { kind?: unknown; agentId?: unknown; where?: unknown } | null {\n if (!text(tag)) return null;\n try {\n const parsed = JSON.parse(tag);\n return typeof parsed === 'object' && parsed !== null ? parsed : null;\n } catch {\n return null;\n }\n}\n\nconst TERMINAL = 'terminal:';\nconst FOLLOWER = 'follower:';\n\nfunction shownWhere(where: string, given: string | undefined): string {\n if (given) return given;\n if (where.startsWith(TERMINAL)) return 'a terminal';\n if (where.startsWith(FOLLOWER)) return 'a linked device';\n return where;\n}\n\nexport function sudoRequester(\n request: SudoRequest,\n agents: Readonly<AgentsState> | undefined,\n where?: string | null\n): { requester: ApprovalRequester; agentId: string } {\n const tag = tagOf(request.tag);\n const name = request.user;\n const sprinkle = sprinklesOf(Array.isArray(request.tags) ? request.tags.filter(text) : [])[0];\n if (sprinkle)\n return { requester: { kind: 'user', name, where: `the ${sprinkle} sprinkle` }, agentId: '' };\n if (tag?.kind === 'agent' && text(tag.agentId)) {\n const id = tag.agentId.startsWith('cone:') ? tag.agentId.slice('cone:'.length) : tag.agentId;\n const known = agents?.cones[id]?.name ?? agents?.scoops[id]?.name ?? name;\n return { requester: { kind: 'agent', name: known, agentId: id }, agentId: id };\n }\n if (tag?.kind === 'user' && text(tag.where)) {\n const given = cleanReason(where);\n const device = tag.where.startsWith(FOLLOWER) ? tag.where.slice(FOLLOWER.length) : '';\n return {\n requester: {\n kind: 'user',\n name,\n where: shownWhere(tag.where, given),\n ...(device ? { device } : {}),\n },\n agentId: '',\n };\n }\n return { requester: { kind: 'user', name }, agentId: '' };\n}\n\nconst STDIN: readonly unknown[] = ['tty', 'none', 'pipe', 'file'];\n\nfunction rootOnlyOf(value: unknown): Record<string, boolean> | undefined {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined;\n const kept = Object.entries(value).filter(\n (entry): entry is [string, boolean] => typeof entry[1] === 'boolean'\n );\n return Object.fromEntries(kept);\n}\n\nfunction kernelFacts(request: SudoRequest): Partial<SudoDetail> {\n const rootOnly = rootOnlyOf(request.rootOnly);\n return {\n ...(STDIN.includes(request.stdin) ? { stdin: request.stdin } : {}),\n ...(rootOnly ? { rootOnly } : {}),\n ...(typeof request.always === 'boolean' ? { writable: request.always } : {}),\n };\n}\n\nexport function sudoDetail(request: SudoRequest): SudoDetail {\n const command = [request.path || request.argv[0], ...request.argv.slice(1)]\n .map((word) => shellWord(String(word)))\n .join(' ');\n return {\n command,\n ...(text(request.target) ? { target: request.target } : {}),\n ...(text(request.cwd) ? { cwd: request.cwd } : {}),\n ...(request.always === true ? { alwaysScope: 'cwd' as const } : {}),\n ...kernelFacts(request),\n };\n}\n\nfunction scoopLick(\n id: string,\n agentId: string,\n detail: SudoDetail,\n agents: Readonly<AgentsState> | undefined\n) {\n const scoop = agents?.scoops[agentId];\n if (!scoop) return undefined;\n const { command, target, cwd } = detail;\n const as = target ? ` as ${target}` : '';\n const at = cwd ? ` in ${cwd}` : '';\n return {\n channel: 'sudo-request' as const,\n source: id,\n title: `${scoop.name} waits for sudo`,\n text: `[scoop ${scoop.name} waits for a person to approve sudo]`,\n body: `${scoop.name} asked to run ${command}${as}${at}. A person answers it in the approvals dialog; you can't approve it. It ends when someone answers or it times out.`,\n target: `cone:${scoop.cone}` as const,\n };\n}\n\nexport interface SudoAttach {\n approvals: Approvals;\n agents?: () => Readonly<AgentsState> | undefined;\n licks?: Pick<Licks, 'deliver'>;\n}\n\ntype SudoLick = NonNullable<ReturnType<typeof scoopLick>>;\n\nexport function createSudo(options: SudoAttach): AgentSudo & { close(): void } {\n const { approvals } = options;\n const agents = () => options.agents?.();\n const waiting = new Map<string, SudoLick>();\n const send = (lick: SudoLick) =>\n void options.licks?.deliver(lick, BACKGROUND_CONTEXT).catch(() => undefined);\n const watch = (items: readonly Approval[]) => {\n for (const [id, lick] of waiting) {\n const item = items.find((entry) => entry.id === id);\n if (item?.state === 'pending' && item.tier !== 'user') continue;\n waiting.delete(id);\n if (item?.state === 'pending') send(lick);\n }\n };\n const off = approvals.state.subscribe((items) => watch(items));\n return {\n approvals: approvals.state,\n async request(value, where, context) {\n const request = sudoRequest(value);\n if (!request) return { id: null, error: 'This is not a sudo request.' };\n const { requester, agentId } = sudoRequester(request, agents(), where);\n const detail = sudoDetail(request);\n const item = await approvals.request(\n {\n kind: 'sudo',\n agentId,\n requester,\n tier: 'user',\n always: request.always !== false,\n expiresAt: request.expiresAt,\n detail,\n },\n context\n );\n const lick = scoopLick(item.id, agentId, detail, agents());\n if (lick) {\n waiting.set(item.id, lick);\n watch(approvals.state.value as Approval[]);\n }\n return { id: item.id, error: null };\n },\n async withdraw(id, reason, context) {\n await approvals.withdraw(id, reason, context);\n },\n close() {\n off();\n waiting.clear();\n },\n };\n}\n\nexport function ownedSudo(sudo: AgentSudo): AgentSudo & { release(): void } {\n const mine = new Set<string>();\n const forget = () => {\n const open = new Set(\n (sudo.approvals.value as Approval[])\n .filter((item) => item.state === 'pending')\n .map(({ id }) => id)\n );\n for (const id of mine) if (!open.has(id)) mine.delete(id);\n };\n return {\n approvals: sudo.approvals,\n async request(request, where, context) {\n forget();\n const asked = await sudo.request(request, where, context);\n if (asked.id) mine.add(asked.id);\n return asked;\n },\n async withdraw(id, reason, context) {\n if (!mine.delete(id)) return;\n await sudo.withdraw(id, reason, context);\n },\n release() {\n forget();\n for (const id of mine)\n void sudo.withdraw(id, REASONS.disconnected, BACKGROUND_CONTEXT).catch(() => undefined);\n mine.clear();\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,0BAA0B;AAGnC,SAAS,mBAAmB;AAE5B;AAAA,EAGE;AAAA,EACA;AAAA,OAGK;AAoCP,MAAM,OAAO;AAEN,MAAM,YAAY,CAAC,SACxB,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,WAAW,KAAK,OAAO,CAAC;AAE5D,MAAM,OAAO,CAAC,UAAoC,OAAO,UAAU;AAE5D,SAAS,YAAY,OAAoC;AAC9D,QAAM,UAAU;AAChB,MAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,QAAQ,SAAS,OAAQ,QAAO;AACvF,QAAM,EAAE,MAAM,MAAM,UAAU,IAAI;AAClC,MAAI,CAAC,MAAM,QAAQ,IAAI,KAAK,CAAC,KAAK,UAAU,CAAC,KAAK,MAAM,IAAI,EAAG,QAAO;AACtE,MAAI,CAAC,KAAK,IAAI,KAAK,OAAO,cAAc,YAAY,CAAC,OAAO,SAAS,SAAS,EAAG,QAAO;AACxF,SAAO;AACT;AAEA,SAAS,MAAM,KAA6E;AAC1F,MAAI,CAAC,KAAK,GAAG,EAAG,QAAO;AACvB,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,WAAO,OAAO,WAAW,YAAY,WAAW,OAAO,SAAS;AAAA,EAClE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,MAAM,WAAW;AACjB,MAAM,WAAW;AAEjB,SAAS,WAAW,OAAe,OAAmC;AACpE,MAAI,MAAO,QAAO;AAClB,MAAI,MAAM,WAAW,QAAQ,EAAG,QAAO;AACvC,MAAI,MAAM,WAAW,QAAQ,EAAG,QAAO;AACvC,SAAO;AACT;AAEO,SAAS,cACd,SACA,QACA,OACmD;AACnD,QAAM,MAAM,MAAM,QAAQ,GAAG;AAC7B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.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/owner.ts"],
|
|
4
|
-
"sourcesContent": ["import type { SudoReply, SudoRequest } from './approvals/sudo.ts';\nimport { type ApproveOptions, askSudo, unavailable } from './approvals/sudo-client.ts';\nimport { type AgentConnection, connectAgent } from './client.ts';\nimport { type KernelSource, serveAdmin } from './kernel/users.ts';\nimport { holdLock } from './opfs-pool.ts';\nimport type { PortEndpoint } from './wire.ts';\n\nexport const AGENT_LOCK = 'slicc-agent';\n\nexport interface AgentWorker {\n postMessage(message: unknown, transfer: Transferable[]): void;\n terminate(): void;\n}\n\nexport interface PortOptions {\n readOnly?: boolean;\n pages?: boolean;\n guest?: { id: string; label: string };\n device?: string;\n}\n\nexport interface AgentOwner {\n connect(options?: PortOptions): Promise<AgentConnection>;\n port(options?: PortOptions): Promise<PortEndpoint & Transferable>;\n approve(request: SudoRequest, options?: ApproveOptions): Promise<SudoReply>;\n restart(): Promise<void>;\n release(): Promise<void>;\n}\n\nexport type { KernelSource } from './kernel/users.ts';\n\nexport interface OwnerOptions {\n worker: () => AgentWorker;\n kernel?: KernelSource;\n locks?: LockManager;\n held?: boolean;\n channel?: () => { port1: PortEndpoint & Transferable; port2: Transferable };\n}\n\nexport async function startAgent(options: OwnerOptions): Promise<AgentOwner> {\n const release = options.held\n ? () => undefined\n : await holdLock(options.locks ?? navigator.locks, AGENT_LOCK);\n const channel = options.channel ?? (() => new MessageChannel());\n const spawn = async (): Promise<AgentWorker> => {\n const created = options.worker();\n let admin: (PortEndpoint & Transferable) | undefined;\n try {\n if (options.kernel) {\n const port = await options.kernel.connect();\n if (!options.kernel.users) created.postMessage({ kernel: port }, [port]);\n else {\n const { port1, port2 } = channel();\n admin = port1;\n serveAdmin(port1, options.kernel);\n created.postMessage({ kernel: port, admin: port2 }, [port, port2]);\n }\n }\n } catch (error) {\n admin?.close?.();\n created.terminate();\n throw error;\n }\n if (!admin) return created;\n const served = admin;\n return {\n postMessage: (message, transfer) => created.postMessage(message, transfer),\n terminate() {\n served.close?.();\n created.terminate();\n },\n };\n };\n let worker: Promise<AgentWorker | undefined> = Promise.resolve().then(spawn);\n const asking = new Set<AbortController>();\n const stopAsking = () => {\n const waiting = [...asking];\n asking.clear();\n return () => {\n for (const stop of waiting) stop.abort();\n };\n };\n try {\n await worker;\n } catch (error) {\n release();\n throw error;\n }\n const open = async (portOptions: PortOptions = {}): Promise<PortEndpoint & Transferable> => {\n const ready = await worker;\n if (!ready) throw new Error('the agent was released');\n const { port1, port2 } = channel();\n const readOnly = portOptions.readOnly === true ? { readOnly: true } : {};\n const pages = portOptions.pages === false ? { pages: false } : {};\n const guest = portOptions.guest\n ? { guest: { id: String(portOptions.guest.id), label: String(portOptions.guest.label) } }\n : {};\n const device = portOptions.device ? { device: portOptions.device } : {};\n ready.postMessage({ connect: port2, ...readOnly, ...pages, ...guest, ...device }, [port2]);\n return port1;\n };\n return {\n async connect(portOptions) {\n return connectAgent(await open(portOptions));\n },\n port: open,\n async approve(request, approveOptions) {\n const stop = new AbortController();\n asking.add(stop);\n try {\n const port = await open().catch((error: unknown) => {\n throw unavailable(error);\n });\n return await askSudo(port, request, approveOptions, stop.signal);\n } finally {\n asking.delete(stop);\n }\n },\n restart() {\n const deny = stopAsking();\n worker = worker\n .catch(() => undefined)\n .then((old) => {\n old?.terminate();\n deny();\n return spawn();\n });\n return worker.then(() => undefined);\n },\n async release() {\n const deny = stopAsking();\n const previous = worker;\n worker = Promise.resolve(undefined);\n try {\n (await previous.catch(() => undefined))?.terminate();\n } finally {\n deny();\n release();\n }\n },\n };\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAA8B,SAAS,mBAAmB;AAC1D,SAA+B,oBAAoB;AACnD,SAA4B,kBAAkB;AAC9C,SAAS,gBAAgB;AAGlB,MAAM,aAAa;AAgC1B,eAAsB,WAAW,SAA4C;AAC3E,QAAM,UAAU,QAAQ,OACpB,MAAM,SAC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AACd,YAAM,OAAO,WAAW;AACxB,YAAM,WAAW;AACjB,eAAS,QAAQ,QAAQ,MAAS;AAClC,UAAI;AACF,SAAC,MAAM,SAAS,MAAM,MAAM,MAAS,IAAI,UAAU;AAAA,MACrD,UAAE;AACA,aAAK;AACL,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { SudoReply, SudoRequest } from './approvals/sudo.ts';\nimport { type ApproveOptions, askSudo, unavailable } from './approvals/sudo-client.ts';\nimport { type AgentConnection, connectAgent } from './client.ts';\nimport { type KernelSource, serveAdmin } from './kernel/users.ts';\nimport { holdLock } from './opfs-pool.ts';\nimport type { PortEndpoint } from './wire.ts';\n\nexport const AGENT_LOCK = 'slicc-agent';\n\nexport interface AgentWorker {\n postMessage(message: unknown, transfer: Transferable[]): void;\n terminate(): void;\n}\n\nexport interface PortOptions {\n readOnly?: boolean;\n pages?: boolean;\n guest?: { id: string; label: string };\n device?: string;\n}\n\nexport interface AgentOwner {\n connect(options?: PortOptions): Promise<AgentConnection>;\n port(options?: PortOptions): Promise<PortEndpoint & Transferable>;\n approve(request: SudoRequest, options?: ApproveOptions): Promise<SudoReply>;\n restart(): Promise<void>;\n release(): Promise<void>;\n}\n\nexport type { KernelSource } from './kernel/users.ts';\n\nexport interface OwnerOptions {\n worker: () => AgentWorker;\n kernel?: KernelSource;\n locks?: LockManager;\n held?: boolean;\n channel?: () => { port1: PortEndpoint & Transferable; port2: Transferable };\n}\n\nexport async function startAgent(options: OwnerOptions): Promise<AgentOwner> {\n const release = options.held\n ? () => undefined\n : await holdLock(options.locks ?? navigator.locks, AGENT_LOCK);\n const channel = options.channel ?? (() => new MessageChannel());\n const spawn = async (): Promise<AgentWorker> => {\n const created = options.worker();\n let admin: (PortEndpoint & Transferable) | undefined;\n try {\n if (options.kernel) {\n const port = await options.kernel.connect();\n if (!options.kernel.users) created.postMessage({ kernel: port }, [port]);\n else {\n const { port1, port2 } = channel();\n admin = port1;\n serveAdmin(port1, options.kernel);\n created.postMessage({ kernel: port, admin: port2 }, [port, port2]);\n }\n }\n } catch (error) {\n admin?.close?.();\n created.terminate();\n throw error;\n }\n if (!admin) return created;\n const served = admin;\n return {\n postMessage: (message, transfer) => created.postMessage(message, transfer),\n terminate() {\n served.close?.();\n created.terminate();\n },\n };\n };\n let worker: Promise<AgentWorker | undefined> = Promise.resolve().then(spawn);\n const asking = new Set<AbortController>();\n const stopAsking = () => {\n const waiting = [...asking];\n asking.clear();\n return () => {\n for (const stop of waiting) stop.abort();\n };\n };\n try {\n await worker;\n } catch (error) {\n release();\n throw error;\n }\n const open = async (portOptions: PortOptions = {}): Promise<PortEndpoint & Transferable> => {\n const ready = await worker;\n if (!ready) throw new Error('the agent was released');\n const { port1, port2 } = channel();\n const readOnly = portOptions.readOnly === true ? { readOnly: true } : {};\n const pages = portOptions.pages === false ? { pages: false } : {};\n const guest = portOptions.guest\n ? { guest: { id: String(portOptions.guest.id), label: String(portOptions.guest.label) } }\n : {};\n const device = portOptions.device ? { device: portOptions.device } : {};\n ready.postMessage({ connect: port2, ...readOnly, ...pages, ...guest, ...device }, [port2]);\n return port1;\n };\n return {\n async connect(portOptions) {\n return connectAgent(await open(portOptions));\n },\n port: open,\n async approve(request, approveOptions) {\n if (request?.kind !== 'sudo') throw unavailable();\n const stop = new AbortController();\n asking.add(stop);\n try {\n const port = await open().catch((error: unknown) => {\n throw unavailable(error);\n });\n return await askSudo(port, request, approveOptions, stop.signal);\n } finally {\n asking.delete(stop);\n }\n },\n restart() {\n const deny = stopAsking();\n worker = worker\n .catch(() => undefined)\n .then((old) => {\n old?.terminate();\n deny();\n return spawn();\n });\n return worker.then(() => undefined);\n },\n async release() {\n const deny = stopAsking();\n const previous = worker;\n worker = Promise.resolve(undefined);\n try {\n (await previous.catch(() => undefined))?.terminate();\n } finally {\n deny();\n release();\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAA8B,SAAS,mBAAmB;AAC1D,S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ACxB,eAAS,OACN,MAAM,MAAM,MAAS,EACrB,KAAK,CAAC,QAAQ;AACb,aAAK,UAAU;AACf,aAAK;AACL,eAAO,MAAM;AAAA,MACf,CAAC;AACH,aAAO,OAAO,KAAK,MAAM,MAAS;AAAA,IACpC;AAAA,IACA,MAAM,UAAU;AACd,YAAM,OAAO,WAAW;AACxB,YAAM,WAAW;AACjB,eAAS,QAAQ,QAAQ,MAAS;AAClC,UAAI;AACF,SAAC,MAAM,SAAS,MAAM,MAAM,MAAS,IAAI,UAAU;AAAA,MACrD,UAAE;AACA,aAAK;AACL,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,6 +10,7 @@ const SECRETS = "slicc-secrets";
|
|
|
10
10
|
const SECRETS_COMMAND = "/secrets";
|
|
11
11
|
const SHELL_GRANTS = ["fnox", "exec", "--shell-grants", "--"];
|
|
12
12
|
const MODEL_LINE = "Credentials are env vars (`$NAME`) holding placeholders, listed below with where each works (`fnox list` shows the fnox config). The vault fills in the real value only in the listed header, for the listed domain, method and path, over HTTPS (curl, git, fetch). Adding a rule means editing `/etc/fnox/config.toml` with sudo, which the user approves. `fnox exec` gives real values only for secrets the user enabled for exec, and the secrets listed as 'in every bash' already hold real values in your commands. Everything is logged, and stored values are replaced by their placeholder in everything you see; edit around placeholders, since files show them too. Never ask the user to paste a credential into the chat.";
|
|
13
|
+
const ASK_LINE = "When a secret you need is missing, ask the user for it: `fnox set NAME --ask` adds it to the fnox config, and `sealed ask NAME` keeps it in the vault only (`--prompt TEXT` says why you need it). The user types the value in a dialog, and the command prints only its placeholder. `fnox set` always asks for a new value and replaces an existing one, so use it only for a missing secret. Add `--reveal` to `sealed ask` only when a tool needs the plaintext itself, not where the vault fills it in a header, and pipe it straight into that tool (`sealed ask NAME --reveal | tool --password-stdin`): the user must allow every reveal, and you still see only the placeholder. A non-zero exit means the user declined or the request ended; don't ask again unless the user wants you to.";
|
|
13
14
|
function leaves(value, out, set) {
|
|
14
15
|
if (typeof value === "string") {
|
|
15
16
|
out.push({ get: () => value, set });
|
|
@@ -91,13 +92,13 @@ function where(name, granted) {
|
|
|
91
92
|
const NO_SECRETS = "No secrets are configured: the fnox config has no keys and the vault no sealed secrets.";
|
|
92
93
|
function renderSecrets(listing) {
|
|
93
94
|
if (listing.error !== null) return unavailableLine(listing.error);
|
|
94
|
-
if (!listing.names.length) return NO_SECRETS;
|
|
95
|
+
if (!listing.names.length) return [NO_SECRETS, "", ASK_LINE].join("\n");
|
|
95
96
|
const granted = !listing.exposed.length;
|
|
96
97
|
const lines = listing.names.map(
|
|
97
98
|
(name) => `- ${name.name} = ${name.placeholder ?? `$${name.name}`}${where(name, granted)}`
|
|
98
99
|
);
|
|
99
100
|
const off = granted ? [] : ["", exposedLine(listing.exposed)];
|
|
100
|
-
return [MODEL_LINE, "", ...lines, ...off].join("\n");
|
|
101
|
+
return [MODEL_LINE, ASK_LINE, "", ...lines, ...off].join("\n");
|
|
101
102
|
}
|
|
102
103
|
function secretsEntry(listing) {
|
|
103
104
|
return {
|
|
@@ -132,6 +133,7 @@ function secretsExtension(deps) {
|
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
export {
|
|
136
|
+
ASK_LINE,
|
|
135
137
|
MODEL_LINE,
|
|
136
138
|
NO_SECRETS,
|
|
137
139
|
SECRETS,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/secrets/extension.ts"],
|
|
4
|
-
"sourcesContent": ["import type { JsonValue } from '@earendil-works/chord';\nimport {\n defineExtension,\n type Extension,\n GenerationTask,\n hook,\n section,\n type ToolExecutionResult,\n ToolTask,\n} from '@earendil-works/pi-durable';\nimport type { Names, SecretListing, SecretName } from './names.ts';\nimport type { Scrub } from './scrub.ts';\nimport type { Vault } from './vault.ts';\nimport { exposedLine, listedLine, SECRETS_KIND, unavailableLine } from './view.ts';\n\nexport { exposedLine, listedLine, SECRETS_KIND, unavailableLine };\n\nexport const SECRETS = 'slicc-secrets';\nexport const SECRETS_COMMAND = '/secrets';\nexport const SHELL_GRANTS = ['fnox', 'exec', '--shell-grants', '--'] as const;\n\nexport const MODEL_LINE =\n \"Credentials are env vars (`$NAME`) holding placeholders, listed below with where each works (`fnox list` shows the fnox config). The vault fills in the real value only in the listed header, for the listed domain, method and path, over HTTPS (curl, git, fetch). Adding a rule means editing `/etc/fnox/config.toml` with sudo, which the user approves. `fnox exec` gives real values only for secrets the user enabled for exec, and the secrets listed as 'in every bash' already hold real values in your commands. Everything is logged, and stored values are replaced by their placeholder in everything you see; edit around placeholders, since files show them too. Never ask the user to paste a credential into the chat.\";\n\ntype Leaf = { get(): string; set(text: string): void };\n\nfunction leaves(value: JsonValue, out: Leaf[], set: (next: JsonValue) => void): void {\n if (typeof value === 'string') {\n out.push({ get: () => value, set });\n return;\n }\n if (Array.isArray(value)) {\n value.forEach((item, at) => {\n leaves(item, out, (next) => {\n value[at] = next;\n });\n });\n return;\n }\n if (value && typeof value === 'object')\n for (const [key, item] of Object.entries(value))\n leaves(item as JsonValue, out, (next) => {\n (value as Record<string, JsonValue>)[key] = next;\n });\n}\n\nexport async function scrubResult(\n result: ToolExecutionResult,\n scrub: Pick<Scrub, 'texts'>\n): Promise<ToolExecutionResult | undefined> {\n const content = [...(result.output ?? [])];\n const diagnostics = [...(result.diagnostics ?? [])];\n const copy = (value: JsonValue | undefined) =>\n value === undefined ? undefined : (structuredClone(value) as JsonValue);\n const details = copy(result.details);\n const structured = copy(result.structuredOutput);\n const found: Leaf[] = [];\n content.forEach((item, at) => {\n if (item.type === 'text')\n found.push({ get: () => item.text, set: (text) => void (content[at] = { ...item, text }) });\n });\n diagnostics.forEach((item, at) => {\n found.push({\n get: () => item.message,\n set: (message) => void (diagnostics[at] = { ...item, message }),\n });\n });\n let replaced = details;\n if (details !== undefined)\n leaves(details, found, (next) => {\n replaced = next;\n });\n let output = structured;\n if (structured !== undefined)\n leaves(structured, found, (next) => {\n output = next;\n });\n const before = found.map((leaf) => leaf.get());\n const after = await scrub.texts(before);\n if (after.every((text, at) => text === before[at])) return undefined;\n found.forEach((leaf, at) => {\n leaf.set(after[at] as string);\n });\n const kept = result.output as ToolExecutionResult['output'] & unknown[];\n if (kept) kept.splice(0, kept.length, ...content);\n return {\n ...result,\n ...(kept ? { output: kept } : {}),\n ...(result.diagnostics ? { diagnostics } : {}),\n ...(replaced === undefined ? {} : { details: replaced }),\n ...(output === undefined ? {} : { structuredOutput: output }),\n };\n}\n\nfunction where(name: SecretName, granted: boolean): string {\n const rules = name.rules.map((rule) =>\n [\n rule.domain,\n rule.header ? `header ${rule.header}` : '',\n rule.methods?.length ? rule.methods.join(' ') : '',\n rule.paths?.length ? rule.paths.join(' ') : '',\n rule.proposed ? 'proposed in the fnox config, not yet accepted by the vault' : '',\n ]\n .filter(Boolean)\n .join(', ')\n );\n const shell = name.exec === 'shell' && granted ? ['in every bash'] : [];\n const sealed = name.placeholder === null ? ['not sealed'] : [];\n const config = name.fnox ? [] : ['not in the fnox config'];\n const parts = [...rules, ...shell, ...sealed, ...config];\n return parts.length ? `: ${parts.join('; ')}` : '';\n}\n\nexport const NO_SECRETS =\n 'No secrets are configured: the fnox config has no keys and the vault no sealed secrets.';\n\nexport function renderSecrets(listing: SecretListing): string {\n if (listing.error !== null) return unavailableLine(listing.error);\n if (!listing.names.length) return NO_SECRETS;\n const granted = !listing.exposed.length;\n const lines = listing.names.map(\n (name) => `- ${name.name} = ${name.placeholder ?? `$${name.name}`}${where(name, granted)}`\n );\n const off = granted ? [] : ['', exposedLine(listing.exposed)];\n return [MODEL_LINE, '', ...lines, ...off].join('\\n');\n}\n\nexport function secretsEntry(listing: SecretListing) {\n return {\n kind: SECRETS_KIND,\n data: {\n names: structuredClone(listing.names) as unknown as JsonValue,\n error: listing.error,\n exposed: [...listing.exposed],\n },\n model: [{ role: 'user' as const, content: listedLine(listing), timestamp: Date.now() }],\n };\n}\n\nexport function granting(listing: SecretListing): boolean {\n return (\n listing.error === null &&\n !listing.exposed.length &&\n listing.names.some((name) => name.exec === 'shell')\n );\n}\n\nexport function shellGrants(names: Pick<Names, 'state'>) {\n return (argv: readonly string[]): readonly string[] =>\n granting(names.state.value) ? [...SHELL_GRANTS, ...argv] : argv;\n}\n\nexport function secretsExtension(deps: {\n names: Pick<Names, 'state'>;\n vault: Pick<Vault, 'ready' | 'texts'>;\n}): Extension {\n return defineExtension({\n name: SECRETS,\n sections: [section('secrets', () => renderSecrets(deps.names.state.value))],\n hooks: [\n hook(ToolTask, { afterTool: (_call, result) => scrubResult(result, deps.vault) }),\n hook(GenerationTask, {\n beforeRequest: async () => {\n await deps.vault.ready();\n return undefined;\n },\n }),\n ],\n });\n}\n"],
|
|
5
|
-
"mappings": "AACA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAIP,SAAS,aAAa,YAAY,cAAc,uBAAuB;AAIhE,MAAM,UAAU;AAChB,MAAM,kBAAkB;AACxB,MAAM,eAAe,CAAC,QAAQ,QAAQ,kBAAkB,IAAI;AAE5D,MAAM,aACX;AAIF,SAAS,OAAO,OAAkB,KAAa,KAAsC;AACnF,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,KAAK,EAAE,KAAK,MAAM,OAAO,IAAI,CAAC;AAClC;AAAA,EACF;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,UAAM,QAAQ,CAAC,MAAM,OAAO;AAC1B,aAAO,MAAM,KAAK,CAAC,SAAS;AAC1B,cAAM,EAAE,IAAI;AAAA,MACd,CAAC;AAAA,IACH,CAAC;AACD;AAAA,EACF;AACA,MAAI,SAAS,OAAO,UAAU;AAC5B,eAAW,CAAC,KAAK,IAAI,KAAK,OAAO,QAAQ,KAAK;AAC5C,aAAO,MAAmB,KAAK,CAAC,SAAS;AACvC,QAAC,MAAoC,GAAG,IAAI;AAAA,MAC9C,CAAC;AACP;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extension,\n GenerationTask,\n hook,\n section,\n type ToolExecutionResult,\n ToolTask,\n} from '@earendil-works/pi-durable';\nimport type { Names, SecretListing, SecretName } from './names.ts';\nimport type { Scrub } from './scrub.ts';\nimport type { Vault } from './vault.ts';\nimport { exposedLine, listedLine, SECRETS_KIND, unavailableLine } from './view.ts';\n\nexport { exposedLine, listedLine, SECRETS_KIND, unavailableLine };\n\nexport const SECRETS = 'slicc-secrets';\nexport const SECRETS_COMMAND = '/secrets';\nexport const SHELL_GRANTS = ['fnox', 'exec', '--shell-grants', '--'] as const;\n\nexport const MODEL_LINE =\n \"Credentials are env vars (`$NAME`) holding placeholders, listed below with where each works (`fnox list` shows the fnox config). The vault fills in the real value only in the listed header, for the listed domain, method and path, over HTTPS (curl, git, fetch). Adding a rule means editing `/etc/fnox/config.toml` with sudo, which the user approves. `fnox exec` gives real values only for secrets the user enabled for exec, and the secrets listed as 'in every bash' already hold real values in your commands. Everything is logged, and stored values are replaced by their placeholder in everything you see; edit around placeholders, since files show them too. Never ask the user to paste a credential into the chat.\";\n\nexport const ASK_LINE =\n \"When a secret you need is missing, ask the user for it: `fnox set NAME --ask` adds it to the fnox config, and `sealed ask NAME` keeps it in the vault only (`--prompt TEXT` says why you need it). The user types the value in a dialog, and the command prints only its placeholder. `fnox set` always asks for a new value and replaces an existing one, so use it only for a missing secret. Add `--reveal` to `sealed ask` only when a tool needs the plaintext itself, not where the vault fills it in a header, and pipe it straight into that tool (`sealed ask NAME --reveal | tool --password-stdin`): the user must allow every reveal, and you still see only the placeholder. A non-zero exit means the user declined or the request ended; don't ask again unless the user wants you to.\";\n\ntype Leaf = { get(): string; set(text: string): void };\n\nfunction leaves(value: JsonValue, out: Leaf[], set: (next: JsonValue) => void): void {\n if (typeof value === 'string') {\n out.push({ get: () => value, set });\n return;\n }\n if (Array.isArray(value)) {\n value.forEach((item, at) => {\n leaves(item, out, (next) => {\n value[at] = next;\n });\n });\n return;\n }\n if (value && typeof value === 'object')\n for (const [key, item] of Object.entries(value))\n leaves(item as JsonValue, out, (next) => {\n (value as Record<string, JsonValue>)[key] = next;\n });\n}\n\nexport async function scrubResult(\n result: ToolExecutionResult,\n scrub: Pick<Scrub, 'texts'>\n): Promise<ToolExecutionResult | undefined> {\n const content = [...(result.output ?? [])];\n const diagnostics = [...(result.diagnostics ?? [])];\n const copy = (value: JsonValue | undefined) =>\n value === undefined ? undefined : (structuredClone(value) as JsonValue);\n const details = copy(result.details);\n const structured = copy(result.structuredOutput);\n const found: Leaf[] = [];\n content.forEach((item, at) => {\n if (item.type === 'text')\n found.push({ get: () => item.text, set: (text) => void (content[at] = { ...item, text }) });\n });\n diagnostics.forEach((item, at) => {\n found.push({\n get: () => item.message,\n set: (message) => void (diagnostics[at] = { ...item, message }),\n });\n });\n let replaced = details;\n if (details !== undefined)\n leaves(details, found, (next) => {\n replaced = next;\n });\n let output = structured;\n if (structured !== undefined)\n leaves(structured, found, (next) => {\n output = next;\n });\n const before = found.map((leaf) => leaf.get());\n const after = await scrub.texts(before);\n if (after.every((text, at) => text === before[at])) return undefined;\n found.forEach((leaf, at) => {\n leaf.set(after[at] as string);\n });\n const kept = result.output as ToolExecutionResult['output'] & unknown[];\n if (kept) kept.splice(0, kept.length, ...content);\n return {\n ...result,\n ...(kept ? { output: kept } : {}),\n ...(result.diagnostics ? { diagnostics } : {}),\n ...(replaced === undefined ? {} : { details: replaced }),\n ...(output === undefined ? {} : { structuredOutput: output }),\n };\n}\n\nfunction where(name: SecretName, granted: boolean): string {\n const rules = name.rules.map((rule) =>\n [\n rule.domain,\n rule.header ? `header ${rule.header}` : '',\n rule.methods?.length ? rule.methods.join(' ') : '',\n rule.paths?.length ? rule.paths.join(' ') : '',\n rule.proposed ? 'proposed in the fnox config, not yet accepted by the vault' : '',\n ]\n .filter(Boolean)\n .join(', ')\n );\n const shell = name.exec === 'shell' && granted ? ['in every bash'] : [];\n const sealed = name.placeholder === null ? ['not sealed'] : [];\n const config = name.fnox ? [] : ['not in the fnox config'];\n const parts = [...rules, ...shell, ...sealed, ...config];\n return parts.length ? `: ${parts.join('; ')}` : '';\n}\n\nexport const NO_SECRETS =\n 'No secrets are configured: the fnox config has no keys and the vault no sealed secrets.';\n\nexport function renderSecrets(listing: SecretListing): string {\n if (listing.error !== null) return unavailableLine(listing.error);\n if (!listing.names.length) return [NO_SECRETS, '', ASK_LINE].join('\\n');\n const granted = !listing.exposed.length;\n const lines = listing.names.map(\n (name) => `- ${name.name} = ${name.placeholder ?? `$${name.name}`}${where(name, granted)}`\n );\n const off = granted ? [] : ['', exposedLine(listing.exposed)];\n return [MODEL_LINE, ASK_LINE, '', ...lines, ...off].join('\\n');\n}\n\nexport function secretsEntry(listing: SecretListing) {\n return {\n kind: SECRETS_KIND,\n data: {\n names: structuredClone(listing.names) as unknown as JsonValue,\n error: listing.error,\n exposed: [...listing.exposed],\n },\n model: [{ role: 'user' as const, content: listedLine(listing), timestamp: Date.now() }],\n };\n}\n\nexport function granting(listing: SecretListing): boolean {\n return (\n listing.error === null &&\n !listing.exposed.length &&\n listing.names.some((name) => name.exec === 'shell')\n );\n}\n\nexport function shellGrants(names: Pick<Names, 'state'>) {\n return (argv: readonly string[]): readonly string[] =>\n granting(names.state.value) ? [...SHELL_GRANTS, ...argv] : argv;\n}\n\nexport function secretsExtension(deps: {\n names: Pick<Names, 'state'>;\n vault: Pick<Vault, 'ready' | 'texts'>;\n}): Extension {\n return defineExtension({\n name: SECRETS,\n sections: [section('secrets', () => renderSecrets(deps.names.state.value))],\n hooks: [\n hook(ToolTask, { afterTool: (_call, result) => scrubResult(result, deps.vault) }),\n hook(GenerationTask, {\n beforeRequest: async () => {\n await deps.vault.ready();\n return undefined;\n },\n }),\n ],\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAIP,SAAS,aAAa,YAAY,cAAc,uBAAuB;AAIhE,MAAM,UAAU;AAChB,MAAM,kBAAkB;AAC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SAAS,SAAS,SAAiC;AACxD,SACE,QAAQ,UAAU,QAClB,CAAC,QAAQ,QAAQ,UACjB,QAAQ,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,OAAO;AAEtD;AAEO,SAAS,YAAY,OAA6B;AACvD,SAAO,CAAC,SACN,SAAS,MAAM,MAAM,KAAK,IAAI,CAAC,GAAG,cAAc,GAAG,IAAI,IAAI;AAC/D;AAEO,SAAS,iBAAiB,MAGnB;AACZ,SAAO,gBAAgB;AAAA,IACrB,MAAM;AAAA,IACN,UAAU,CAAC,QAAQ,WAAW,MAAM,cAAc,KAAK,MAAM,MAAM,KAAK,CAAC,CAAC;AAAA,IAC1E,OAAO;AAAA,MACL,KAAK,UAAU,EAAE,WAAW,CAAC,OAAO,WAAW,YAAY,QAAQ,KAAK,KAAK,EAAE,CAAC;AAAA,MAChF,KAAK,gBAAgB;AAAA,QACnB,eAAe,YAAY;AACzB,gBAAM,KAAK,MAAM,MAAM;AACvB,iBAAO;AAAA,QACT;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,6 +9,7 @@ export declare const SECRETS = "slicc-secrets";
|
|
|
9
9
|
export declare const SECRETS_COMMAND = "/secrets";
|
|
10
10
|
export declare const SHELL_GRANTS: readonly ['fnox', 'exec', '--shell-grants', '--'];
|
|
11
11
|
export declare const MODEL_LINE = "Credentials are env vars (`$NAME`) holding placeholders, listed below with where each works (`fnox list` shows the fnox config). The vault fills in the real value only in the listed header, for the listed domain, method and path, over HTTPS (curl, git, fetch). Adding a rule means editing `/etc/fnox/config.toml` with sudo, which the user approves. `fnox exec` gives real values only for secrets the user enabled for exec, and the secrets listed as 'in every bash' already hold real values in your commands. Everything is logged, and stored values are replaced by their placeholder in everything you see; edit around placeholders, since files show them too. Never ask the user to paste a credential into the chat.";
|
|
12
|
+
export declare const ASK_LINE = "When a secret you need is missing, ask the user for it: `fnox set NAME --ask` adds it to the fnox config, and `sealed ask NAME` keeps it in the vault only (`--prompt TEXT` says why you need it). The user types the value in a dialog, and the command prints only its placeholder. `fnox set` always asks for a new value and replaces an existing one, so use it only for a missing secret. Add `--reveal` to `sealed ask` only when a tool needs the plaintext itself, not where the vault fills it in a header, and pipe it straight into that tool (`sealed ask NAME --reveal | tool --password-stdin`): the user must allow every reveal, and you still see only the placeholder. A non-zero exit means the user declined or the request ended; don't ask again unless the user wants you to.";
|
|
12
13
|
export declare function scrubResult(result: ToolExecutionResult, scrub: Pick<Scrub, 'texts'>): Promise<ToolExecutionResult | undefined>;
|
|
13
14
|
export declare const NO_SECRETS = "No secrets are configured: the fnox config has no keys and the vault no sealed secrets.";
|
|
14
15
|
export declare function renderSecrets(listing: SecretListing): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-agent",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.21.1",
|
|
4
4
|
"description": "SLICC's agent core on pi durable: an agent worker, session storage, remoting and pi extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -73,18 +73,18 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@ai-ecoverse/slicc-jsh": "0.64.0",
|
|
76
|
-
"@ai-ecoverse/slicc-kernel": "1.
|
|
76
|
+
"@ai-ecoverse/slicc-kernel": "1.176.0",
|
|
77
77
|
"@ai-ecoverse/slicc-scrub": "1.1.0",
|
|
78
78
|
"@ai-ecoverse/slicc-shared-web": "2.13.10",
|
|
79
79
|
"@ai-ecoverse/slicc-spectrum": "1.112.1",
|
|
80
|
-
"@ai-ecoverse/wasi-fnox": "1.
|
|
80
|
+
"@ai-ecoverse/wasi-fnox": "1.45.0-2",
|
|
81
81
|
"@ai-ecoverse/wasm-bash": "5.3.0-23",
|
|
82
82
|
"@ai-ecoverse/wasm-coreutils": "9.12.0-15",
|
|
83
83
|
"@ai-ecoverse/wasm-git": "2.55.0-22",
|
|
84
84
|
"@biomejs/biome": "2.6.4",
|
|
85
85
|
"@types/node": "26.6.6",
|
|
86
86
|
"esbuild": "0.28.2",
|
|
87
|
-
"fake-indexeddb": "6.2.
|
|
87
|
+
"fake-indexeddb": "6.2.7",
|
|
88
88
|
"lefthook": "2.2.2",
|
|
89
89
|
"monocart-coverage-reports": "3.2.0",
|
|
90
90
|
"playwright-core": "1.64.1",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"typescript": "7.0.2"
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@ai-ecoverse/slicc-vault": "1.
|
|
96
|
+
"@ai-ecoverse/slicc-vault": "1.24.0",
|
|
97
97
|
"@aws-sdk/middleware-websocket": "^3.972.54",
|
|
98
98
|
"@earendil-works/chord": "1.5.0",
|
|
99
99
|
"@earendil-works/pi-ai": "1.5.0",
|