Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions docs/dev/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,21 @@ four defaults, and `resolveHidden` (session, then global, then the defaults; the
at each call and sends them as the host's `hideList` in ascending precedence (`hostHideList`, which sorts by
`resolveHidden`'s own order, so the host's last match is the entry `resolveHidden` names). A host without
`hello.hideList` gets no call while a `hide` applies.
- **A path the host reports `hiddenBy` asks** before any `allow` (`namesHidden` in `judgeCall`), and the card names the
rule from `ShFactsPlace.hideRules`. A library proposal refuses such a path, as it refuses a secret one.
- **A path the host reports `hiddenBy` asks** before any `allow` (`hiddenPathOf` in `judgeCall`, carried as the
judgement's `hidden`), and the card names the rule from `ShFactsPlace.hideRules`; `askWhyOf` gives it the cause
`hidden-path`. A default is named in `DEFAULT_RULE_WORDS` (`files-hide.ts`), which `hideRuleWords` merges, so the card
line and the ask's line say the same words. A library proposal refuses such a path, as it refuses a secret one.
- **The view shows the four defaults in every session**, with or without a stored `files` rule: unlike other consumers'
one default row, they hold files whatever was written.
- **`propose_files_rule` is the propose_manifest pattern.** The precheck (`checkFilesRuleProposal`) refuses what the
worker would not add, with no card; the card is checked again and frozen at the gate (`filesRuleCardFor`, `renderIn`
type `files-rule`); the resolve stores only that card's rule (`approveFilesRule`), at the session, or globally when
the answer carries `persist` and the card offered "Always"; the tool's run reads the outcome once. Every resolve path
drops a decision's `arguments`, so a forged one never chooses the rule. A `show` preview of a `/files/...` pattern
walks the browser copy's listing and keeps a path only when `resolveHidden` with the proposal says it decides, so the
card's list is the reader's own decision; any other pattern asks the host's `glob`, at most 1000.
- **The policy page writes global rows itself** (`POLICIES` ops `addFiles`, `removeFiles`), through `addFilesRule` and
`removeFilesRule` with no session, so removing a global `hide` confirms with what would then decide, as a view does.
- **A `hide` row's label ends with its limits** (`hideLimits`): the hard-link line always, the late-file line only when
`shellStatus().host.platform` is `linux`. In the label, since e3's view test allows a row no other key.

Expand Down
57 changes: 38 additions & 19 deletions docs/spec/POLICIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -835,18 +835,26 @@ in the policy store, the four defaults as built-in rows, the layer rule and its
`policy.files` command, the view's rows (`src/sw/files-hide-view.ts`), and the `/files` reader in the offscreen document
bound by the resolved list (`src/session/files-hide-rule.ts`), which Python's mount and `ml.fs` both read through. The
second PR (window-ml-host #58 and this repository's half) binds a program the shell starts: every `spawn` goes through
`spawnBound` (`src/sw/sw-spawn.ts`) and carries the list, below. NOT built: the model's proposal card, the offer when a
root is added, and the four defaults in the view of a session with no `files` rule: as for every consumer, a default row
appears once the consumer has a rule (a stated gap, closed before PR C merges, with the three tests that pin it). In the
browser copy, which has no symlinks, `default:link-target` and `default:linked-template` hold nothing, and the
linked-template refusal of a `show` is the host's to make. Three choices made in building it, on the red team's findings
at #2088: the policy page's generic edit and remove refuse a `files` row (an `allow` saved over a `hide` held nothing,
and one click removed a `hide` with no confirmation), so a hiding rule is removed only from a session's view, which
confirms, and DevTools Settings' own form for these rows is PR C; a `hide` that matches a directory holds everything
under it, as the offer's one row for a credential directory needs, while a `show` releases only what it matches; and
`ml.current.policies` carries no `files` row. The reason given at #2088, that a hidden file reads as absent, does not
hold: its NAME is listed ("What a hidden file shows", below). Whether the model may read its own hiding rules is decided
with the masked-file design; until then the row stays out.
`spawnBound` (`src/sw/sw-spawn.ts`) and carries the list, below. The third (PR C1) adds the model's proposal,
`propose_files_rule` (`src/tools/propose-files-rule-tool.ts`, its check and card in `src/sw/files-rule-proposal.ts` and
`src/sw/sw-files-proposal.ts`), the ask's cause line for a call naming a hidden path (`hidden-path`), the four defaults
in every session's view whether or not a `files` rule is stored (they hold files with no rule written, unlike every
other consumer's default row), and DevTools Settings' own form for these rows. NOT built: the offer when a root is
added. In the browser copy, which has no symlinks, `default:link-target` and `default:linked-template` hold nothing.
A linked group released whole or not at all is NOT built either: window-ml-host's main releases a template on a `show`
(its PROTOCOL.md, `hideList`) even when a held name links to it; the ruled design is window-ml-host #63 (open), below,
with files-host's worker-line PR. Until then `propose_files_rule` refuses, before any card, every `show` whose pattern's
last segment can match a dotenv template (`.env.example`, `.env.sample`, `.env.template`, a glob such as `.env.*` or
`.env.exampl?` included), whether or not a link points at it; a person's own `show` written on the policy page is not
checked this way. Files-host's worker-line PR lifts that refusal once a host that reports `unappliedShows` is the
minimum the extension accepts. Three choices made in building it, on the red
team's findings at #2088: the policy page's generic edit and remove refuse a `files` row (an `allow` saved over a `hide`
held nothing, and one click removed a `hide` with no confirmation), so the page draws its own row and form for them,
and removing a `hide` there, as from a session's view, first names what would decide instead; a `hide` that matches a
directory holds everything under it, as the offer's one row for a credential directory needs, while a `show` releases
only what it matches; and `ml.current.policies` carries no `files` row. The reason given at #2088, that a hidden file
reads as absent, does not hold: its NAME is listed ("What a hidden file shows", below). Whether the model may read its
own hiding rules is decided with the masked-file design; until then the row stays out.

**One list, two verbs, the policy store's.** A hiding rule is a `StoredPolicy` with consumer `files`, effect `hide` or
`show`, and `source` a path or a glob. Scope `global`, or `run`, which is the session's and keyed by its hash, as for
Expand All @@ -864,11 +872,14 @@ lifetime rules (it survives a resume and is removed at archive) are the ones abo
- **A pattern** is an absolute path inside a root, or a glob within the roots using `*`, `?` and `[…]` inside one path
segment; `**` is refused, since on Linux every match is a mask the host builds by walking the tree. At most 512
characters, and at most 256 entries a scope.
- **A `show` that cannot be applied whole is refused with its reason, never half-applied.** In the
`ln -s .env.example .env` shape, `show .env.example` would leave `.env` listed as held while on Linux a read through
`.env` lands on the now-unmasked template (on macOS `.env` stays refused by its name, but the same bytes read under
the template's). So the entry is refused, naming `.env` as the link that resolves to it; `show .env` with it is the
entry that applies whole.
- **A `show` that cannot be applied whole is not applied, never half-applied** (window-ml-host #63, open; NOT built
until it and files-host's worker-line PR merge). In the `ln -s .env.example .env` shape, `show .env.example` alone
would leave `.env` listed as held while on Linux a read through `.env` lands on the now-unmasked template (on macOS
`.env` stays refused by its name, but the same bytes read under the template's). So the host refuses nothing: the
root-top names that reach one file are a group, released whole or not at all. A `show` that decided a member of a
group not released is not applied, the call still runs, and the host reports it as `unappliedShows: [{ id, link,
heldBy? }]`; the worker's line to the person names the rule and the link. `show .env` with it is the entry that
releases the group. Until then the model's proposal refuses every `show` that can reach a template (above).
- **`mask <pattern>`, a third effect, is ruled and not built** (ruling 113, 2026-11-24; SECRET_HANDLES.md, "A masked
file"). It lists the file, shows its keys with each value replaced, takes writes through the extension's own code
and puts the real values back, and is read-only to a program not allowed for it. `default:dotenv` becomes a `mask`.
Expand All @@ -889,9 +900,17 @@ and `default:linked-template` (a template a held name resolves to). They are bui
removed, only overridden.

**Who writes and who proposes.** The main path is the MODEL'S PROPOSAL: a card that shows the exact entry and, for a
`show`, the paths it would release at that moment (the host's `glob`, bounded). It offers "this session" (the default)
`show`, the paths it would release at that moment (the host's `glob`, bounded). The card lists at most 50 paths and
counts up to 1000 ("and N more"); a host walk that stopped early says so, and a host that did not answer says the files
are not listed. For a `/files/...` pattern the list is the browser copy's files, read through the same matcher and name
mask as the `/files` reader, until the sync slice gives the host the session's files. It offers "this session" (the default)
and "always" (global). A session `show` that overrides a global `hide` names that entry, verbatim, before the paths, and
offers no "always": a global `show` under a global `hide` is the person's own edit on the policy page. A glob releases
offers no "always": a global `show` under a global `hide` is the person's own edit on the policy page. With 256 rules for
every session already stored, the card offers no "always" and says why; a session already holding 256 is refused before
any card. "Always" is the approval's `persist`; an answer that carries it on a card that offered none adds nothing.
Only a person's answer adds a rule: an answer a policy gave adds nothing, and the tool then answers as for no approval.
A scope that fills while the card is open refuses at the answer, and the model reads `Refused: your rules for every
session already number 256.` (global) or `Refused: this session already holds 256 hiding rules.` (session). A glob releases
what matches LATER too, and the card says so beside the paths it lists. Nothing changes until the person approves. A
person may also write an entry directly, in DevTools Settings, from the file browser's right-click (ruling 24), or with
"always" on a card that offers it; that is expected to be rare. A page, `change_setting` and `ml.settings` can neither
Expand Down
10 changes: 10 additions & 0 deletions docs/spec/PROMPT_BUDGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ a token); the default kit's tools, 29,907 → 30,744. No other tool's text diffe
registered worker tools compared, ml.sh and `answer` on). The `usage.prompt_tokens` delta is measured at the next prompt
review, with bench's rerun on the merge.

## `propose_files_rule` reaches every run with ml.sh (2026-11-30)

`propose_files_rule` (POLICIES.md, "Hiding files") is offered beside `propose_manifest`, to a run the worker builds
while ml.sh is offered, so its definition is paid on every call of such a run. It is 972 characters as sent (name,
description, parameters, as JSON); `propose_manifest`'s is 1,665. Two hint sentences reach the model where it is
offered: one appended to `hiddenSecrets`' JSDoc in the contract, which `agent_api_docs` serves (about 105 characters,
read only when the model asks for those docs), and `ml.table`'s hidden-file error, which names the tool only in a run
that offers it. No hint follows a denial. The `usage.prompt_tokens` delta is measured at the next prompt review, with
the bench, as for `change_setting` below.

## `change_setting` reaches every run the worker builds (2026-11-17)

`change_setting` (MODEL_SETTINGS.md) is offered by `startUserRun` to every run the worker builds, beside
Expand Down
78 changes: 78 additions & 0 deletions docs/spec/export.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,9 @@
],
"additionalProperties": true
},
{
"$ref": "#/$defs/FilesRuleCard"
},
{
"type": "object",
"properties": {
Expand Down Expand Up @@ -2599,6 +2602,9 @@
],
"additionalProperties": true
},
{
"$ref": "#/$defs/FilesRuleCard"
},
{
"type": "object",
"properties": {
Expand Down Expand Up @@ -3384,6 +3390,78 @@
],
"additionalProperties": true
},
"FilesRuleCard": {
"type": "object",
"description": "propose_files_rule's card (sw/files-rule-proposal.ts), as the worker builds it and every surface draws it: the rule, the model's reason (scrubbed and cut, so a renderer escapes it), for a show the files it matches now, and whether the card offers \"Always\". The worker stores only the rule this card showed.",
"properties": {
"type": {
"type": "string",
"const": "files-rule"
},
"effect": {
"anyOf": [
{
"type": "string",
"enum": [
"hide",
"show"
]
},
{
"type": "string",
"description": "This shape is UNSTABLE: it grows as the extension does and is NOT covered by the schema version. The members here are the ones known when this file was generated — read the ones you recognise and tolerate others."
}
]
},
"title": {
"type": "string"
},
"reason": {
"description": "`The model says: \"<reason>\"`, the reason cut and scrubbed.",
"type": "string"
},
"rule": {
"description": "The rule verbatim, `<effect> <pattern>`, drawn in a code block.",
"type": "string"
},
"before": {
"description": "Sentences drawn before the paths (the override case).",
"type": "array",
"items": {
"type": "string"
}
},
"paths": {
"description": "The paths a show matches now, relative to their root; absent for a hide.",
"type": "array",
"items": {
"type": "string"
}
},
"after": {
"description": "Sentences drawn after the paths.",
"type": "array",
"items": {
"type": "string"
}
},
"always": {
"description": "Whether the card offers \"Always\" (a global rule); false over a global hide, or with the global layer full.",
"type": "boolean"
}
},
"required": [
"type",
"effect",
"title",
"reason",
"rule",
"before",
"after",
"always"
],
"additionalProperties": true
},
"FetchAttempt": {
"type": "object",
"description": "One rung of the Markdown ladder, as it actually ran. Recorded for every attempt — including the ones that were skipped — because the failure modes here are INVISIBLE in the body alone: a stub twin is a valid 200 Markdown document that is simply the wrong page, and a site-authored twin is content written specifically to be read by agents (GitBook appends an \"Agent Instructions\" section), so \"which URL did these bytes come from\" is provenance for an injection surface, not decoration.",
Expand Down
4 changes: 2 additions & 2 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ const GENRES = {
},
// The model's proposal tools: a policy or a manifest or library it drafts, the card the person sees, what is stored.
propose: {
about: "propose_policy and propose_manifest (a program manifest or a tier 3 library): the drafts, their cards, what is stored on approval",
files: ["propose-library.test.mjs", "propose-library-redteam.test.mjs", "propose-manifest.test.mjs", "python-install.test.mjs", "propose-policy-redteam.test.mjs", "propose-policy.test.mjs"],
about: "propose_policy, propose_manifest (a program manifest or a tier 3 library) and propose_files_rule (a hiding rule): the drafts, their cards, what is stored on approval",
files: ["files-rule-proposal.test.mjs", "propose-library.test.mjs", "propose-library-redteam.test.mjs", "propose-manifest.test.mjs", "python-install.test.mjs", "propose-policy-redteam.test.mjs", "propose-policy.test.mjs"],
},
// The policy store's own tests by name prefix: the worker's ask over a policy, a policy lifted from a call, the model's proposals of one, and the effective view of a session.
policy: {
Expand Down
15 changes: 14 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Background service worker: owns config, builds per-format request bodies,

Check warning on line 1 in src/background.ts

View workflow job for this annotation

GitHub Actions / tools

src/background.ts is 1726 lines (+13 in this change, was 1713, and 9.6% of the repo's edit cost) — over 800. consider refactoring this into separate logical modules (`node scripts/move-symbols.mjs` does the move), and moving the tests that cover them into per-module files where that follows.
// extracts replies, and makes the privileged (host-permissioned) fetches. All
// server JSON is genuinely opaque, so it's typed `any`; our own data uses the
// shared contract types.
Expand Down Expand Up @@ -75,7 +75,7 @@
import { asIsTokens, forBackendFromPage, forPage, forTurn, scanTurn, withAsIs } from "./sw/sw-scrub"; // error text bound for a page, without the config's secrets; a page's model request, without a registered secret
import { TurnUnreadable } from "./secret-registry";
import { secretRegistryOp } from "./sw/sw-secret-registry";
import { filesHideList, signalFilesHideChanges } from "./sw/sw-files-hide";
import { addFilesRule, filesHideList, removeFilesRule, signalFilesHideChanges } from "./sw/sw-files-hide";
import { pythonPrewarm, pythonExec, pythonInterrupt, relayPyStdout, deletePythonRun, dropPythonLibraries, pythonReaped, filesAttached, filesSecretForms, filesSpliced, filesQuota, filesLost, pythonStarted, pythonDone } from "./sw/sw-python";
import { focusLineFor } from "./sw/sw-focus";
import { chatHashFor, openChatPage } from "./sw/sw-open-chat";
Expand Down Expand Up @@ -814,6 +814,19 @@
// Removing a hide widens: only a session's view removes one, and it shows what that exposes first.
if (id && isFilesRule(id)) { sendResponse({ error: "a hiding rule is removed from its session's view, which shows what it exposes first" }); return; }
if (!id || !removePolicy(id)) { sendResponse({ error: "no such policy" }); return; }
} else if (p.op === "addFiles") {
// The policy page's own form for a hiding rule for every session: the one write path `policy.files` uses.
const source = str(p.source, POLICY_SOURCE_MAX);
if (!source || (p.effect !== "hide" && p.effect !== "show")) { sendResponse({ error: "a hiding rule needs hide or show and a path or a glob" }); return; }
const r = addFilesRule("", { effect: p.effect, source, scope: "global" });
if ("refused" in r) { sendResponse({ error: `Refused: ${r.refused}.` }); return; }
} else if (p.op === "removeFiles") {
// A global hiding rule's remove: a widening one needs `confirm: true`, and refuses with the ids of what would
// then decide, as a session's view does (the global rows are every session's).
const id = str(p.id, 100);
if (!id || !isFilesRule(id)) { sendResponse({ error: "no such hiding rule" }); return; }
const r = removeFilesRule("", id, p.confirm === true);
if (!r.removed) { sendResponse(r.why === "confirm" ? { error: "confirm", data: { exposes: r.exposes ?? [] } } : { error: "no such hiding rule" }); return; }
} else if (p.op === "session") {
// One session's effective view (docs/spec/POLICIES.md, "The effective view"): a read, so no change to answer with.
const hash = str(p.hash, 100);
Expand Down
Loading
Loading