@bonesofspring/ai-rules 0.2.90 → 0.2.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.91
4
+
5
+ Records commit `9a558699` after `## 0.2.90`.
6
+
7
+ ### Output guard replaces every named tool result
8
+
9
+ - **The allowlist is gone.** `rewrite.ts` no longer checks a fixed tool set: a `tool-result` is rewritten whenever its name is non-empty and its text crosses the threshold, so `write` or an MCP call is covered like `shell`. A result with no name is left alone, and a `read` of `.opencode/rules/**` or `.ai.local/rules/**` stays exempt.
10
+ - **`stats.jsonl` rotates.** The plugin rotates `results.jsonl`, `usage.jsonl`, and `stats.jsonl` once in `setup()`. `context.jsonl` still does not: its dedupe set is seeded from the file.
11
+ - **Tests and docs follow.** `test-output-guard.mjs` swaps the non-allowlisted-tool case for `write` / `mcp_context7_query`, adds the unnamed-result case, and expects three rotations. The plugin README and `docs/OPENCODE.md` say "every named tool".
12
+
13
+ ### Rule attach gets its own log and a bounded session map
14
+
15
+ - **`rule-attach.log`.** `AI_RULES_RULE_ATTACH_DEBUG=1` now writes `.ai.local/team/output-guard/rule-attach.log` instead of `debug.log`. A skipped stem is logged with its reason — `attached`, `unreadable`, or `cap` — and is not injected.
16
+ - **32 sessions.** `MAX_ATTACHED_SESSIONS` bounds the in-memory `attached` map; a re-touch moves the session id to the end, and the oldest entry is dropped past the cap.
17
+ - **Mark after push.** A stem enters the in-memory set only after its message was pushed, so a `messages` value that is not an array no longer marks the stem attached.
18
+
19
+ ### Settings guard fails closed
20
+
21
+ - **A thrown guard asks.** An `evaluate` that throws returns `ask` with `shell guard failed` instead of `null`, which had lifted the static ask.
22
+ - **An empty action is not a shell check.** `commandFromPermission` requires `action` to be `shell` or `bash`; a missing or empty `action` returns `null`. The unit test covers both shapes.
23
+ - **Compatibility row.** `docs/OPENCODE-COMPATIBILITY.md` gains a `partial` settings-guard row naming the stubbed payload, the empty-action rule, and the thrown-guard `ask`.
24
+
25
+ ### Task sidebar: confirmed repository stop and store-driven billing rows
26
+
27
+ - **Repository stop needs a second confirm.** `engagePause` no longer falls back to `.ai.local/STOP` when the task sentinel cannot be written; it returns `null`. The sidebar asks "Stop repository" and then calls `engagePause(root, slug, "repo")`. A failed write shows `Cannot write the stop sentinel`.
28
+ - **Billing rows come from the store.** `billingRates` reads provider names from `.ai.local/models/providers`, dedupes and sorts them, and returns `[]` when no store is reachable instead of the hardcoded DeepSeek/Z.AI pair. `deepseekRate` and `zaiRate` keep the published-schedule fallback for a direct caller.
29
+ - **A non-finite window hour is dropped.** `asPeakWindow` returns `null` when `startHour` or `endHour` is missing or not finite, instead of coercing it to `0` and reading a null hour as peak.
30
+
31
+ ### Dogfood tree and CLI goldens
32
+
33
+ - **`sync-dogfood-opencode.sh` mirrors the shared plugins.** The script rsyncs the plugin tree into `packages/ai-rules/.opencode/plugins/` and copies the stack `globs.json`, so that tree catches up with `actions.ts`, `attach.ts`, `globs.json`, `prompt-face.mjs`, and the plugin `package.json`s.
34
+ - **Goldens recaptured.** All twelve `scripts/fixtures/cli-golden/opencode/*.json` files carry the new plugin hashes.
35
+
3
36
  ## 0.2.90
4
37
 
5
38
  Records the package commits after `## 0.2.89`: `59b43f32` (per-task worktree), `902fcb33` (OpenCode settings guard), `989ae95e` (attempt time split and session leases).
@@ -36,7 +36,8 @@ Allowed status values are `confirmed`, `partial`, `unknown`, `manual`, and `no-e
36
36
  | Workspace Skill discovery | `confirmed` | opencode.ai/docs/skills | `.opencode/skills/<name>/SKILL.md` | Native `skill` tool |
37
37
  | Project MCP | `confirmed` | opencode.ai/docs/mcp-servers | `opencode.json` `mcp` | Merge on init |
38
38
  | TUI plugin discovery | `confirmed` | opencode.ai/docs/plugins | `.opencode/plugins/<name>/` loads automatically | Ships `task-status` TUI sidebar, `output-guard`, `rule-attach` |
39
- | Tool-output guard (server plugin) | `confirmed` | opencode.ai/docs/build/plugins/server + live probe 2026-11-13 | `ctx.session.hook("context")` mutates assembled messages before dispatch | Ships `output-guard`; a host without the hook no-ops |
39
+ | Tool-output guard (server plugin) | `confirmed` | opencode.ai/docs/build/plugins/server + live probe 2026-11-13 | `ctx.session.hook("context")` mutates assembled messages before dispatch | Ships `output-guard`; every named tool result over the threshold is replaced; a rule read is exempt; a host without the hook no-ops |
40
+ | Settings guard (server plugin) | `partial` | unit test of the adapter; no live permission payload | Stubbed `permission.evaluate` sees `{ action: "shell" \| "bash", resources: [command] }`. A missing or empty `action` is ignored. A thrown guard becomes `ask` | Ships `settings-guard`. The `prompt` hook appends autoroute text only onto `prompt` or `parts`. A `messages`-shaped prompt event is unchanged |
40
41
  | Project hooks (`hooks.json`) | `manual` | probe 2026-11-25 on OpenCode v2.4.1: `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` and passes other names through unvalidated to a bus nothing triggers; no `subagentStop`, and `tool.execute.after` produced 0 timing rows in 32,841 ledger rows (575 `subagent` calls) | The event that would end a step carries no attemptId | Manual `chain-team-phases.sh` |
41
42
  | Slash commands | `confirmed` | opencode.ai/docs/commands | `.opencode/commands/<name>.md` | Native `/task` |
42
43
  | Plugin / skill / MCP combo | `confirmed` | skills + mcp docs | MCP inflates context | Gate unused servers in operator config |
package/docs/OPENCODE.md CHANGED
@@ -78,7 +78,7 @@ printf '%s\n' '{"status":"completed","attemptId":"<from-status.json>"}' \
78
78
  | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh
79
79
  ```
80
80
 
81
- Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`: on OpenCode v2.4.1 `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` only, so no plugin observes a subagent return and the chain stays a manual run. The `task-status` plugin writes this tab's pin to `.ai.local/team/.session-leases/<sessionID>.json` and tries to set `AI_RULES_SESSION_ID` on `shell.env`. That registration is best-effort: if the host rejects the name, the lease file remains, and a later hook call in the same tab resolves the pin when the session id is already in the environment. `active-task.json` stays the list of live slugs. The other shipped plugins are `output-guard` (compaction) and `rule-attach` (path-glob rule delivery).
81
+ Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`: on OpenCode v2.4.1 `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` only, so no plugin observes a subagent return and the chain stays a manual run. The `task-status` plugin writes this tab's pin to `.ai.local/team/.session-leases/<sessionID>.json` and tries to set `AI_RULES_SESSION_ID` on `shell.env`. That registration is best-effort: if the host rejects the name, the lease file remains, and a later hook call in the same tab resolves the pin when the session id is already in the environment. `active-task.json` stays the list of live slugs. The other shipped plugins are `output-guard` (compaction of every named tool result), `rule-attach` (path-glob rule delivery), and `settings-guard` (shell-guard permission plus the autoroute prompt).
82
82
 
83
83
  Full team layout: `.ai.local/team/README.md`.
84
84
 
@@ -86,7 +86,7 @@ Full team layout: `.ai.local/team/README.md`.
86
86
 
87
87
  `.opencode/plugins/output-guard/` ships with every OpenCode preset. It registers
88
88
  `ctx.session.hook("context")`, which receives the assembled model messages before
89
- dispatch. A `tool-result` over 8 KB is written to
89
+ dispatch. A named `tool-result` over 8 KB is written to
90
90
  `.ai.local/team/output-guard/<sessionID>/outputs/` and replaced with a bounded
91
91
  head + tail. The 8–20 KB band uses the structured shape: a whole-line gap is a `sed -n` range, a mid-line cut is a `tail -c` byte window, and JSON keys are listed only when they sit in that gap. Above 20 KB stays the flat renderer.
92
92
  `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the flat renderer inside the band.
@@ -99,6 +99,24 @@ including one without `/task`.
99
99
  - `AI_RULES_OUTPUT_GUARD=0` disables it; `AI_RULES_OUTPUT_GUARD_BYTES` changes the threshold.
100
100
  - The change affects only the outgoing model call; persisted history is untouched.
101
101
  - Hosts without `ctx.session.hook` no-op. It is a token-economy mechanism, not a security boundary.
102
+ - `results.jsonl`, `usage.jsonl`, and `stats.jsonl` rotate when the plugin starts. `context.jsonl` does not.
103
+
104
+ ## Settings guard (server plugin)
105
+
106
+ `.opencode/plugins/settings-guard/` ships with every OpenCode preset. It imports
107
+ `evaluate` from `.opencode/hooks/guard-shell-command.mjs` and applies it on
108
+ `ctx.permission.hook("evaluate")`. A configured `deny` never reaches the plugin.
109
+ `allow` lifts the static ask only for a plain `git commit` or `git push` the
110
+ guard already classified. `ask` sets the permission effect to `ask`. A thrown
111
+ `evaluate` becomes `ask` with the message `shell guard failed`. An event whose
112
+ `action` is not `shell` or `bash` is left unchanged. When the permission hook
113
+ is absent, `ctx.tool.hook("execute.before")` throws on `ask`.
114
+
115
+ The same plugin's `prompt` session hook appends the autoroute directive when
116
+ `AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS` is true and the live-slug count is under
117
+ `AI_RULES_MAX_PARALLEL_TASKS`. It writes a `parts` text entry or extends a
118
+ string `prompt`. A payload that has neither is left unchanged. The live host
119
+ shape of that event is not probed here; the unit test drives `{ prompt }`.
102
120
 
103
121
  ## Task status sidebar (TUI plugin)
104
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.90",
3
+ "version": "0.2.91",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -13,7 +13,7 @@ call; persisted history is untouched.
13
13
  | Item | Value |
14
14
  |---|---|
15
15
  | Trigger | `tool-result` text over **8192 B** (`AI_RULES_OUTPUT_GUARD_BYTES`) |
16
- | Tools | `shell`, `bash`, `read`, `grep`, `glob`, `webfetch` — a `read` of `.opencode/rules/**` or `.ai.local/rules/**` is never replaced |
16
+ | Tools | every named tool. A `read` of `.opencode/rules/**` or `.ai.local/rules/**` is never replaced. A result with no tool name is left alone |
17
17
  | Replacement (8–20 KB band) | structured head + tail: named elision, top-level JSON keys that sit in the gap, a `grep -n '<term>'` hint for a whole-line gap that carries a usable term, or `tail -c` when a line is cut mid-way |
18
18
  | Replacement (over 20 KB) | 40-line / 2 KB head + 15-line / 1 KB tail + path + hints |
19
19
  | Shape override | `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the legacy renderer in the band |
@@ -40,8 +40,9 @@ adds a `[json: full document at the path]` note so the agent can `jq` the file.
40
40
 
41
41
  ## Ledgers
42
42
 
43
- All four files live in `.ai.local/team/output-guard/`. None but `results.jsonl`
44
- and `usage.jsonl` rotate.
43
+ All four files live in `.ai.local/team/output-guard/`. `results.jsonl`,
44
+ `usage.jsonl`, and `stats.jsonl` rotate once when the plugin starts.
45
+ `context.jsonl` does not: the dedupe set is seeded from the file.
45
46
 
46
47
  | File | Row | Written when |
47
48
  |---|---|---|
@@ -19,7 +19,9 @@
19
19
  *
20
20
  * Telemetry beside the guard: `usage.jsonl` reads the token rows of the session
21
21
  * and of the child sessions it discovers, and `context.jsonl` keeps one row per
22
- * `(sessionID, toolset)` for the MCP schema split. Neither rotates. Child
22
+ * `(sessionID, toolset)` for the MCP schema split. `results.jsonl`, `usage.jsonl`,
23
+ * and `stats.jsonl` rotate once in `setup()`. `context.jsonl` does not: its
24
+ * dedupe set is seeded from the file. Child
23
25
  * discovery starts after the rewrite, is never awaited, and stops being waited
24
26
  * for at AI_RULES_OUTPUT_GUARD_DISCOVERY_MS (default 250 ms); it cannot be
25
27
  * cancelled.
@@ -51,7 +53,6 @@ const MAX_TRACKED_SESSIONS = 12
51
53
  const DEFAULT_DISCOVERY_MS = 250
52
54
  /** The bound on every timing map; a late `after` must not grow a session's heap. */
53
55
  const MAX_TIMING_ENTRIES = 256
54
- const ALLOWLIST = new Set(["shell", "bash", "read", "grep", "glob", "webfetch"])
55
56
 
56
57
  const findTeamRoot = (start: string): string | null => {
57
58
  let dir = path.resolve(start)
@@ -304,7 +305,6 @@ export default Plugin.define({
304
305
  tailBytes: TAIL_BYTES,
305
306
  headLines: HEAD_LINES,
306
307
  tailLines: TAIL_LINES,
307
- allowlist: ALLOWLIST,
308
308
  marker: MARKER,
309
309
  shape: process.env.AI_RULES_OUTPUT_GUARD_SHAPE === "flat" ? ("flat" as const) : ("structured" as const),
310
310
  }
@@ -318,6 +318,7 @@ export default Plugin.define({
318
318
  const rotateBytes = parseRotateBytes(process.env[ROTATE_BYTES_ENV])
319
319
  rotateLedger(path.join(outputDir, "results.jsonl"), rotateBytes)
320
320
  rotateLedger(path.join(outputDir, "usage.jsonl"), rotateBytes)
321
+ rotateLedger(path.join(outputDir, "stats.jsonl"), rotateBytes)
321
322
  const projectRoot = path.resolve(root, "..", "..")
322
323
  const savedPaths = new Map<string, string>()
323
324
  const statsRecorded = new Set<string>()
@@ -12,7 +12,6 @@ export type OutputGuardOptions = {
12
12
  tailBytes: number
13
13
  headLines: number
14
14
  tailLines: number
15
- allowlist: ReadonlySet<string>
16
15
  marker: string
17
16
  /** `"flat"` forces the legacy renderer inside the band; default is structured. */
18
17
  shape?: "flat" | "structured"
@@ -268,7 +267,7 @@ export function rewriteMessages(
268
267
  for (const item of content as ToolResult[]) {
269
268
  if (item?.type !== "tool-result") continue
270
269
  const tool = typeof item.name === "string" ? item.name : ""
271
- if (tool === "" || !options.allowlist.has(tool)) continue
270
+ if (tool === "") continue
272
271
  const result = item.result
273
272
  if (result?.type !== "text" || typeof result.value !== "string") continue
274
273
  const value = result.value
@@ -23,7 +23,7 @@ to a plugin.
23
23
  | Dedupe | per `(sessionID, stem)`, and the marker in the assembled messages wins over the in-memory set |
24
24
  | Budget | `MAX_ATTACH_LINES = 420` non-empty lines per attach — the largest `check-next-attached-budget.mjs` fixture cap. A stem that does not fit is skipped, never truncated |
25
25
  | Kill switch | `AI_RULES_RULE_ATTACH=0` |
26
- | Debug | `AI_RULES_RULE_ATTACH_DEBUG=1` → `.ai.local/team/output-guard/debug.log` |
26
+ | Debug | `AI_RULES_RULE_ATTACH_DEBUG=1` → `.ai.local/team/output-guard/rule-attach.log`. A skipped stem (already attached, unreadable, over the line cap) is logged there and is not injected |
27
27
  | Host | OpenCode V2 with `ctx.session.hook`; a host without it no-ops |
28
28
 
29
29
  Injects text only: no shell, no `child_process`, nothing the model wrote is
@@ -9,7 +9,7 @@
9
9
  * Three bounds, all in `attach.ts`: only a stem whose glob matches a touched
10
10
  * path is attached, each stem once per session, and the bodies stay inside the
11
11
  * line budget. `AI_RULES_RULE_ATTACH=0` disables the plugin; debug output goes
12
- * to `.ai.local/team/output-guard/debug.log` through `AI_RULES_RULE_ATTACH_DEBUG=1`.
12
+ * to `.ai.local/team/output-guard/rule-attach.log` through `AI_RULES_RULE_ATTACH_DEBUG=1`.
13
13
  *
14
14
  * Injected text is a trailing user message carrying `[ai-rules rule-attach]`
15
15
  * and the rule body. It carries text only — no shell, no `child_process`, and
@@ -95,17 +95,30 @@ const carries = (messages: unknown, stem: string): boolean => {
95
95
  return false
96
96
  }
97
97
 
98
+ const MAX_ATTACHED_SESSIONS = 32
99
+
98
100
  const debugLog = (projectRoot: string, message: string): void => {
99
101
  if (process.env.AI_RULES_RULE_ATTACH_DEBUG !== "1") return
100
102
  try {
101
103
  const dir = path.join(projectRoot, ".ai.local", "team", "output-guard")
102
104
  fs.mkdirSync(dir, { recursive: true })
103
- fs.appendFileSync(path.join(dir, "debug.log"), `${new Date().toISOString()} rule-attach ${message}\n`)
105
+ fs.appendFileSync(path.join(dir, "rule-attach.log"), `${new Date().toISOString()} ${message}\n`)
104
106
  } catch {
105
107
  /* an unlogged attach is still a correct attach */
106
108
  }
107
109
  }
108
110
 
111
+ /** Keep the newest sessions. A re-touch moves the id to the end of the map. */
112
+ const rememberSession = (attached: Map<string, Set<string>>, sessionID: string, stems: Set<string>): void => {
113
+ if (attached.has(sessionID)) attached.delete(sessionID)
114
+ attached.set(sessionID, stems)
115
+ while (attached.size > MAX_ATTACHED_SESSIONS) {
116
+ const oldest = attached.keys().next().value
117
+ if (oldest === undefined) break
118
+ attached.delete(oldest)
119
+ }
120
+ }
121
+
109
122
  export default Plugin.define({
110
123
  id: "ai-rules.rule-attach",
111
124
  async setup(ctx) {
@@ -147,16 +160,22 @@ export default Plugin.define({
147
160
  attached: already,
148
161
  readRule,
149
162
  })
163
+ if (plan.skipped.length > 0) {
164
+ debugLog(
165
+ projectRoot,
166
+ `skipped ${plan.skipped.map((entry) => `${entry.stem}:${entry.reason}`).join(",")} (session ${sessionID})`,
167
+ )
168
+ }
150
169
  const fresh = plan.inject.filter((entry) => !carries(record.messages, entry.stem))
151
170
  if (fresh.length === 0) return
152
- for (const entry of fresh) already.add(entry.stem)
153
- attached.set(sessionID, already)
154
171
  const messages = record.messages
155
172
  if (!Array.isArray(messages)) return
156
173
  messages.push({
157
174
  role: "user",
158
175
  content: [{ type: "text", text: fresh.map((entry) => entry.text).join("\n") }],
159
176
  })
177
+ for (const entry of fresh) already.add(entry.stem)
178
+ rememberSession(attached, sessionID, already)
160
179
  debugLog(projectRoot, `attached ${fresh.map((entry) => entry.stem).join(",")} (session ${sessionID})`)
161
180
  } catch (error) {
162
181
  debugLog(projectRoot, `attach failed: ${error instanceof Error ? error.message : String(error)}`)
@@ -10,8 +10,11 @@ The plugin imports `evaluate` from `.opencode/hooks/guard-shell-command.mjs`.
10
10
  |---|---|---|
11
11
  | `allow` on a plain `git commit` / `git push` | effect `allow` (the static ask is lifted) | no throw; the static ask remains |
12
12
  | `ask` | effect `ask`, with the guard's message | throw, so the command does not run |
13
+ | `evaluate` throws | effect `ask`, message `shell guard failed` | throw, so the command does not run |
13
14
  | `allow` on anything else | unchanged | unchanged |
14
15
 
16
+ An event whose `action` is not `shell` or `bash` is not a shell check. A missing or empty `action` is left unchanged.
17
+
15
18
  `false`, a missing file, and a broken file stay `ask`. `true` allows only a plain commit or push. Destructive, alias, and indirect shapes stay `ask`.
16
19
 
17
20
  ## Autoroute — `AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS`
@@ -53,7 +53,7 @@ export default Plugin.define({
53
53
  const decision = await guard({ command }, { root: projectRoot })
54
54
  return decision && typeof decision.permission === "string" ? decision : null
55
55
  } catch {
56
- return null
56
+ return { permission: "ask", user_message: "shell guard failed" }
57
57
  }
58
58
  }
59
59
 
@@ -27,7 +27,7 @@ const firstText = (values) => {
27
27
  export const commandFromPermission = (event) => {
28
28
  const record = recordOf(event);
29
29
  const action = typeof record.action === 'string' ? record.action : '';
30
- if (action !== '' && action !== 'shell' && action !== 'bash') return null;
30
+ if (action !== 'shell' && action !== 'bash') return null;
31
31
  const fromResources = firstText(record.resources);
32
32
  if (fromResources !== null) return fromResources;
33
33
  const metadata = recordOf(record.metadata);
@@ -12,8 +12,8 @@ Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/s
12
12
  - the step row carries a progress bar, e.g. `3/7 ███░░░░░ · attempt 1 · 3h 35m`; a parallel wave reads `3/7 ███░░░░░ · 3 agents · 42m` and clocks from the oldest start; a `status.json` written before any attempt reads `3/7 · no attempt started` instead of hiding the plan
13
13
  - the `eta` row reads `~52m · p90 3h 32m`: estimated time to finish the remaining plan steps. It hides while the run waits on a human gate, is paused, blocked, waiting for a receipt, or is done. A stale run keeps it — the estimate is historical, not live — and with fewer than 3 ledgers the row reads `—` instead of disappearing
14
14
  - clicking any row opens a details dialog with 3-cell side padding: `goal.md`, pipeline steps with the current one marked, artifacts from `artifact-manifest.json`, the last manifest entries, the prompt, the last update age and the ETA with its ledger count. The body scrolls with ↑/↓, PgUp/PgDn, Home/End or the mouse wheel; `esc` closes it.
15
- - a live task shows `■ stop` in the header; click → confirm → writes the task-scoped `.ai.local/team/tasks/<slug>/STOP` (the repo-wide `.ai.local/STOP` only when the task directory is gone). The in-flight attempt finishes, no next step starts. A task with a stop sentinel shows `▶ resume` instead: confirm clears it. Saying `/task-continue <slug>` (or `продолжай` / `continue`) in a matched session is the keyboard path. <!-- i18n-keep: E4 -->
16
- - a `DeepSeek` row under the fields reads `[peak]` in red or `[off-peak]` in green: the current DeepSeek billing window, read from the same models store as the team-tasks UI — the peak `windows` linked to the `DeepSeek` provider under the nearest `.ai.local/models` above the project directory. Window semantics are shared with the UI: a weekly window covers `[startHour, endHour)` — the end hour is exclusive — and `startHour > endHour` wraps across midnight. Without a store the row falls back to the published schedule shipped with the plugin: 09:00–12:00 and 14:00–18:00 Asia/Shanghai, Monday–Friday. Chinese public holidays are off-peak all day but are not tracked, so a holiday weekday still reads `peak` inside a window
15
+ - a live task shows `■ stop` in the header; click → confirm → writes the task-scoped `.ai.local/team/tasks/<slug>/STOP`. If that directory cannot be written, a second confirm asks before the repo-wide `.ai.local/STOP` is written. The in-flight attempt finishes, no next step starts. A task with a stop sentinel shows `▶ resume` instead: confirm clears it. Saying `/task-continue <slug>` (or `продолжай` / `continue`) in a matched session is the keyboard path. <!-- i18n-keep: E4 -->
16
+ - one `[peak]` / `[off-peak]` row per provider in the nearest `.ai.local/models` store (the same `providers` / `links` / `windows` records the team-tasks UI reads). No store, no rows. A weekly window covers `[startHour, endHour)` — the end hour is exclusive — and `startHour > endHour` wraps across midnight. A missing or non-finite hour drops that window. Chinese public holidays are off-peak all day but are not tracked, so a holiday weekday still reads `peak` inside a window
17
17
  - a `Z.AI` row reads the same `[peak]`/`[off-peak]` for the GLM Coding Plan: the peak `windows` linked to the `Z.AI` provider in the same store (Monday–Friday 14:00–18:00 Asia/Singapore; weekends deduct at off-peak rates all day). Without a store it falls back to that published schedule. Quota consumption percentages and reset times are intentionally not shown: the plan quota is server-side and no usage API is documented
18
18
  - a stale task reads `◌ stale · 8d 17h ago` with a muted tone instead of pretending to run
19
19
  - the open flag lives in `context.storage.store("panel", { initial: { open: true } })`, so it survives restarts; the live view stays in `context.storage.memory`
@@ -21,7 +21,7 @@ Modelled on the built-in MCP sidebar plugin (`packages/tui/src/feature-plugins/s
21
21
 
22
22
  ## Data
23
23
 
24
- Reads the nearest `.ai.local/team/` above the session directory, and the provider peak windows (DeepSeek, Z.AI) from the nearest `.ai.local/models/` — the same `providers`/`links`/`windows` records `apps/team-tasks-ui` reads (`MODELS_ROOT` points at the models directory; the deprecated `CATALOG_ROOT` still works for one release):
24
+ Reads the nearest `.ai.local/team/` above the session directory, and the provider peak windows from the nearest `.ai.local/models/` — the same `providers`/`links`/`windows` records `apps/team-tasks-ui` reads (`MODELS_ROOT` points at the models directory; the deprecated `CATALOG_ROOT` still works for one release). The sidebar lists only providers that store names:
25
25
 
26
26
  - `tasks/<slug>/prompt.md` — the original prompt, the session-matching anchor
27
27
  - `tasks/<slug>/prompt-log.md` — the follow-up log, shown in the details dialog only
@@ -107,7 +107,7 @@ The sidebar is session-scoped and follows `session.sidebar.toggle` (`ctrl+x b`).
107
107
 
108
108
  ## Limits
109
109
 
110
- - The stop button writes the task-scoped `tasks/<slug>/STOP`; the repo-wide `.ai.local/STOP` is the fallback when that directory is gone and remains the operator's own pause, so it blocks new steps for every task.
110
+ - The stop button writes the task-scoped `tasks/<slug>/STOP`. The repo-wide `.ai.local/STOP` is written only after a second confirm, when the task directory cannot be written. It blocks new steps for every task.
111
111
  - The resume intent clears a task-scoped sentinel only for the session's pinned task; a repository-wide `.ai.local/STOP` is lifted only by an explicit `/task-continue <slug>`, never by a text match in an unrelated session. <!-- i18n-keep: E4 -->
112
112
  - Mapping relies on prompt text: a task without `prompt.md` cannot be matched, so its tab falls back to the prompt view. A session whose first message is not the prompt (for example a resumed tab opened with a bare `продолжай`) needs `/task-continue <slug>`. <!-- i18n-keep: E4 -->
113
113
  - With a remote server, messages come from the server but the prompt files are read from the client filesystem; a failed message fetch keeps the last view and marks it `offline` for a minute.
@@ -8,8 +8,8 @@
8
8
  * covers `[startHour, endHour)` — the end hour is exclusive, so the published
9
9
  * "14:00-18:00" schedule ends at 18:00 — and `startHour > endHour` spans
10
10
  * midnight; absolute windows match `[startAt, endAt]`. When no store is
11
- * reachable — a project that never ran the sync — the published schedule
12
- * shipped below applies unchanged.
11
+ * reachable, `billingRates` returns no rows. `deepseekRate` and `zaiRate`
12
+ * still fall back to the published schedule below for a direct caller.
13
13
  *
14
14
  * Chinese public holidays are off-peak all day, but a holiday calendar is not
15
15
  * shipped here, so a holiday weekday still reads `peak` inside a window.
@@ -105,14 +105,20 @@ const resolveModelsRoot = (directory: string | undefined): string | undefined =>
105
105
  return undefined
106
106
  }
107
107
 
108
+ const finiteHour = (value: number | undefined): number | null =>
109
+ typeof value === "number" && Number.isFinite(value) ? value : null
110
+
108
111
  const asPeakWindow = (window: CatalogWindow): PeakWindow | null => {
109
112
  if (window.kind !== "peak") return null
110
113
  if (window.shape === "weekly" && Array.isArray(window.weekdays)) {
114
+ const startHour = finiteHour(window.startHour)
115
+ const endHour = finiteHour(window.endHour)
116
+ if (startHour === null || endHour === null) return null
111
117
  return {
112
118
  shape: "weekly",
113
119
  weekdays: window.weekdays,
114
- startHour: window.startHour ?? 0,
115
- endHour: window.endHour ?? 0,
120
+ startHour,
121
+ endHour,
116
122
  timezone: window.timezone ?? "UTC",
117
123
  }
118
124
  }
@@ -221,7 +227,16 @@ export const deepseekRate = (now: Date, directory?: string): DeepseekRate =>
221
227
  export const zaiRate = (now: Date, directory?: string): DeepseekRate =>
222
228
  providerRate("Z.AI", now, directory)
223
229
 
224
- export const billingRates = (at: Date, directory?: string) => [
225
- { label: "DeepSeek" as const, rate: deepseekRate(at, directory) },
226
- { label: "Z.AI" as const, rate: zaiRate(at, directory) },
227
- ]
230
+ /** Providers present in the models store, in name order. No store, no rows. */
231
+ export const billingRates = (at: Date, directory?: string): Array<{ label: string; rate: ProviderRate }> => {
232
+ const root = resolveModelsRoot(directory)
233
+ if (root === undefined) return []
234
+ const names = [
235
+ ...new Set(
236
+ readRecords<CatalogProvider>(path.join(root, "providers"))
237
+ .map((provider) => provider?.name)
238
+ .filter((name): name is string => typeof name === "string" && name !== ""),
239
+ ),
240
+ ].sort((left, right) => left.localeCompare(right))
241
+ return names.map((label) => ({ label, rate: providerRate(label, at, directory) }))
242
+ }
@@ -252,14 +252,18 @@ const pauseStartedAt = (root: string, slug: string | undefined, scope: PauseScop
252
252
  .sort((left, right) => left - right)[0]
253
253
  }
254
254
 
255
- /** The scope actually written, or `null` when no sentinel could be written. */
256
- export const engagePause = (root: string, slug?: string): PauseScope | null => {
257
- if (slug) {
255
+ /**
256
+ * The scope actually written, or `null` when nothing was written.
257
+ * A slug writes only the task sentinel. The repository sentinel is written
258
+ * when `scope` is `"repo"`, which the sidebar does after a second confirm.
259
+ */
260
+ export const engagePause = (root: string, slug?: string, scope?: PauseScope): PauseScope | null => {
261
+ if (scope !== "repo" && slug) {
258
262
  try {
259
263
  fs.writeFileSync(taskSentinel(root, slug), pausePayload("task"), "utf8")
260
264
  return "task"
261
265
  } catch {
262
- // A task directory can disappear under a stale view; fall back to the repo sentinel.
266
+ return null
263
267
  }
264
268
  }
265
269
  const overlay = overlayDir(root)
@@ -52,12 +52,21 @@ const TaskSidebar = () => {
52
52
  label: { confirm: "Stop", cancel: "Cancel" },
53
53
  })
54
54
  if (!confirmed) return
55
- const written = engagePause(view.root, view.slug)
55
+ let written = engagePause(view.root, view.slug)
56
56
  if (!written) {
57
- context.ui.toast.show({ title: "Task", message: "Cannot write .ai.local/STOP", variant: "error" })
57
+ const confirmedRepo = await context.ui.dialog.confirm({
58
+ title: "Stop repository",
59
+ message: `The ${view.slug} task directory is not writable. Write a repository-wide stop?`,
60
+ label: { confirm: "Stop repository", cancel: "Cancel" },
61
+ })
62
+ if (!confirmedRepo) return
63
+ written = engagePause(view.root, view.slug, "repo")
64
+ }
65
+ if (!written) {
66
+ context.ui.toast.show({ title: "Task", message: "Cannot write the stop sentinel", variant: "error" })
58
67
  return
59
68
  }
60
- const where = written === "repo" ? `repository-wide (the ${view.slug} task dir was unwritable)` : `for ${view.slug}`
69
+ const where = written === "repo" ? "repository-wide" : `for ${view.slug}`
61
70
  context.ui.toast.show({ title: "Task", message: `Soft stop engaged ${where}`, variant: "warning" })
62
71
  }
63
72