@bonesofspring/ai-rules 0.2.70 → 0.2.71
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,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.71
|
|
4
|
+
|
|
5
|
+
### `team-tasks-ui` — catalog price tiers, model metadata, notes
|
|
6
|
+
|
|
7
|
+
- **Model record.** `version`, `releasedAt`, `notes`, `price.cacheReadPer1MTokens`, and named `price.tiers` (`time` / `context` / `promotion`) join the model contract: `catalog.schema.json`, the `catalog-refresh` write validator, the app schema, DTOs, mapper, model form, and `ModelDetailPage`. The form edits the scalar fields and carries scheduler-authored tiers through unchanged; the detail page lists each tier's kind and, for a context tier, its `from N tokens` boundary.
|
|
8
|
+
- **Providers and windows.** `notes` is written by both catalog writers, edited on the window form, and rendered on the provider detail page.
|
|
9
|
+
- **Validation.** Duplicate tier names, a `minContextTokens` on a non-context tier, a cache-read price without the input/output split, an over-long `version` / `notes`, and a non-ISO `releasedAt` are refused before a file lands.
|
|
10
|
+
- **Refresh keeps tiers.** `writeProviderModels` merges a refreshed `price` into the stored one instead of replacing it, so a scheduler run keeps the tiers and cache-read price the feed does not carry.
|
|
11
|
+
- **Tests.** `catalog.mapper.spec.ts` and `schema.spec.ts` extend, `catalogModelForm.data.spec.ts` is new: the added fields, the tier rules, and the write mapping.
|
|
12
|
+
|
|
13
|
+
### `team-tasks-ui` — window summaries in Moscow time
|
|
14
|
+
|
|
15
|
+
- **One display zone.** `windowShapeLabel` renders every window in `Europe/Moscow`: a weekly window is shifted from its own zone at `now` (a DST zone changes the shift mid-year), its weekdays move with a midnight-crossing shift, and an absolute range is formatted in Moscow. An unknown source zone falls back to the stored hours and zone instead of failing the page.
|
|
16
|
+
- **`formatTimestamp`** takes an optional `timeZone`; formatters are cached per zone.
|
|
17
|
+
- **Tests.** `windowShapeLabel.spec.ts` covers the shift, the day wrap, DST, and the unknown-zone fallback.
|
|
18
|
+
|
|
19
|
+
### `catalog` — provider-direct pricing sync (repo-local)
|
|
20
|
+
|
|
21
|
+
- **Sync runner.** `opencode-models-sync.mjs` reconciles `.ai.local/catalog/**` from the live OpenCode provider/model feed, adds the metadata the feed omits, and writes DeepSeek peak/off-peak prices plus provider-scoped peak windows. Manual records are never overwritten, and a record the source stops naming is frozen with its last committed note.
|
|
22
|
+
- **Provider-direct sources.** `deepseek-pricing.mjs` and `zai-pricing.mjs` read one markdown notice each. Z.AI's documented quota multipliers are recorded as notes, never as a USD price, and a document whose duplicated statements disagree throws instead of guessing — the last committed catalog stays.
|
|
23
|
+
- **Schedule.** The `opencode-models-sync` job runs at 08:00 and 20:00 `Europe/Moscow` with `concurrency: skip` through the repo's scheduler.
|
|
24
|
+
- **Tests.** `opencode-models-sync.test.mjs`, `deepseek-pricing.test.mjs`, `zai-pricing.test.mjs`, and the extended `catalog-refresh.test.mjs` cover ownership, freezing, offline runs, and the parsers.
|
|
25
|
+
|
|
26
|
+
### `opencode` — output-guard discovery off the hot path
|
|
27
|
+
|
|
28
|
+
- **Detached walk.** The context hook no longer awaits usage discovery. After the in-place rewrite it starts one `session.get`, then at most 12 tracked sessions with one `session.context` and one `session.list` each (≤25 RPCs), and never awaits the walk, so the tool result cannot depend on it.
|
|
29
|
+
- **Bounded wait.** `AI_RULES_OUTPUT_GUARD_DISCOVERY_MS` (default 250 ms) bounds how long the hook waits, not the walk: the walk keeps running and a late response still appends its row. Nothing cancels an RPC already in flight, and the plugin README states both bounds.
|
|
30
|
+
- **Goldens and tests.** The 11 opencode CLI goldens are recaptured for the new `README.md` / `index.ts` hashes; `test-output-guard.mjs` grows to 33 cases and covers the detached walk, the deadline, and the isolation of a failing discovery.
|
|
31
|
+
|
|
32
|
+
### `scripts` — `measure.mjs --strict`
|
|
33
|
+
|
|
34
|
+
- **Section verdicts.** Every `sections.rN` now pairs its `reported {at,text,figures}` claim with measured `data`, a `reproduced` boolean, `unreproducible` reasons, and the section's `ordering` claim, so a consumer reads the JSON instead of the prose.
|
|
35
|
+
- **Exit codes.** `--strict` exits 1 on a scored out-of-band check or a failed comparable `ordering` claim, after printing the report; `referenceOnly` totals and a bare `reproduced: false` never fail. `--strict --live` is refused — a grown ledger is not a reproduction.
|
|
36
|
+
- **Tests.** `test-measure.mjs` covers the verdict shape, the `r4.ordering` claim, `strictFailures`, and the usage error.
|
|
37
|
+
|
|
38
|
+
### `team-db` — delete-refusal messages stop tripping the SQL-injection rule
|
|
39
|
+
|
|
40
|
+
- **Wording.** The API fallbacks for a refused `jobs delete` / `task delete` now read `removing <id> was refused` and `removal of <slug>` instead of `the delete of …`. The old template literal placed a SQL keyword next to an interpolated `context.params` value, so Semgrep's `tainted-sql-string` rule (CWE-89) reported the error text as a SQL string built from request input; every statement in the module is a parameterized `better-sqlite3` query, which made it a false positive.
|
|
41
|
+
- **Unchanged contract.** Error codes from `mapTeamDbCode`, HTTP statuses, `details`, and both delete operations are untouched — only the fallback `message` text.
|
|
42
|
+
- **Fixtures.** The CLI golden hash snapshots are recaptured by `fix:generated` for the new `team-db-api.mjs` and `.template-base.json` digests.
|
|
43
|
+
|
|
3
44
|
## 0.2.70
|
|
4
45
|
|
|
5
46
|
### `next` — `/ui-start` and `/ui-stop` return
|
package/package.json
CHANGED
|
@@ -1897,7 +1897,7 @@ const deleteJob = async (context) => {
|
|
|
1897
1897
|
});
|
|
1898
1898
|
if (result.ok !== true) {
|
|
1899
1899
|
const code = typeof result.code === 'string' ? result.code : 'E_INTERNAL';
|
|
1900
|
-
fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? `
|
|
1900
|
+
fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(result.message ?? `removing ${id} was refused`));
|
|
1901
1901
|
}
|
|
1902
1902
|
return { json: { ok: true, id: String(result.id ?? id), runsRemoved: Number(result.runsRemoved ?? 0) } };
|
|
1903
1903
|
};
|
|
@@ -1984,17 +1984,17 @@ const runDeleteChild = async (slug, context) => {
|
|
|
1984
1984
|
const parsed = await runTeamDbChild(['delete', '--slug', slug], {
|
|
1985
1985
|
settings: context.settings,
|
|
1986
1986
|
timeoutMs: SYNC_CHILD_TIMEOUT_MS,
|
|
1987
|
-
label: `
|
|
1987
|
+
label: `removal of ${slug}`,
|
|
1988
1988
|
});
|
|
1989
1989
|
if (parsed.ok === false) {
|
|
1990
1990
|
const code = typeof parsed.code === 'string' ? parsed.code : 'E_INTERNAL';
|
|
1991
1991
|
// The guard fires only when the target is the active slug, so the detail
|
|
1992
1992
|
// names it exactly; the message the child printed names it too.
|
|
1993
1993
|
const details = code === 'E_ACTIVE_TASK' ? { activeSlug: slug } : undefined;
|
|
1994
|
-
fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(parsed.message ?? `
|
|
1994
|
+
fail(mapTeamDbCode(code), mapTeamDbCode(code, true), String(parsed.message ?? `removing ${slug} was refused`), details);
|
|
1995
1995
|
}
|
|
1996
1996
|
if (parsed.ok !== true || typeof parsed.slug !== 'string') {
|
|
1997
|
-
fail('E_INTERNAL', 500, `
|
|
1997
|
+
fail('E_INTERNAL', 500, `removing ${slug} reported neither a success nor a documented refusal`);
|
|
1998
1998
|
}
|
|
1999
1999
|
return { slug: parsed.slug };
|
|
2000
2000
|
};
|
|
@@ -48,6 +48,14 @@ children created after setup, and `session.list({ directory, parentID })`
|
|
|
48
48
|
catches children that already existed. A child is read with
|
|
49
49
|
`session.context({ sessionID })`, the same call the root uses.
|
|
50
50
|
|
|
51
|
+
Discovery is bounded and off the hot path: one `session.get`, then at most
|
|
52
|
+
`MAX_TRACKED_SESSIONS = 12` sessions, each read with one `session.context` and
|
|
53
|
+
one `session.list` — ≤25 RPCs per hook. It starts after the rewrite and is not
|
|
54
|
+
awaited, so the tool result never depends on it. `AI_RULES_OUTPUT_GUARD_DISCOVERY_MS`
|
|
55
|
+
(default 250 ms) bounds how long the plugin waits for the whole walk, not the walk
|
|
56
|
+
itself: the walk keeps running and a late response still appends its row; rows are
|
|
57
|
+
absent only when the host never answers.
|
|
58
|
+
|
|
51
59
|
`context.jsonl` keeps one row per distinct `(sessionID, toolset hash)`.
|
|
52
60
|
`toolSchemaBytes` is the summed UTF-8 size of every `{description, input}` tool
|
|
53
61
|
schema at dispatch; `byTool[]` is `{name, bytes}` per tool; `systemBytes` is the
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Telemetry beside the guard: `usage.jsonl` reads the token rows of the session
|
|
17
17
|
* and of the child sessions it discovers, and `context.jsonl` keeps one row per
|
|
18
|
-
* `(sessionID, toolset)` for the MCP schema split. Neither rotates.
|
|
18
|
+
* `(sessionID, toolset)` for the MCP schema split. Neither rotates. Child
|
|
19
|
+
* discovery starts after the rewrite, is never awaited, and stops being waited
|
|
20
|
+
* for at AI_RULES_OUTPUT_GUARD_DISCOVERY_MS (default 250 ms); it cannot be
|
|
21
|
+
* cancelled.
|
|
19
22
|
*/
|
|
20
23
|
|
|
21
24
|
import { createHash } from "node:crypto"
|
|
@@ -33,6 +36,7 @@ const TAIL_BYTES = 1024
|
|
|
33
36
|
const HEAD_LINES = 40
|
|
34
37
|
const TAIL_LINES = 15
|
|
35
38
|
const MAX_TRACKED_SESSIONS = 12
|
|
39
|
+
const DEFAULT_DISCOVERY_MS = 250
|
|
36
40
|
const ALLOWLIST = new Set(["shell", "bash", "read", "grep", "glob", "webfetch"])
|
|
37
41
|
|
|
38
42
|
const findTeamRoot = (start: string): string | null => {
|
|
@@ -272,6 +276,9 @@ export default Plugin.define({
|
|
|
272
276
|
const outputDir = process.env.AI_RULES_OUTPUT_GUARD_DIR
|
|
273
277
|
? path.resolve(process.env.AI_RULES_OUTPUT_GUARD_DIR)
|
|
274
278
|
: path.join(root, "output-guard")
|
|
279
|
+
// Wait bound for the detached discovery; the work bound is
|
|
280
|
+
// MAX_TRACKED_SESSIONS. Neither cancels an RPC already in flight.
|
|
281
|
+
const discoveryMs = readNumber("AI_RULES_OUTPUT_GUARD_DISCOVERY_MS", DEFAULT_DISCOVERY_MS)
|
|
275
282
|
// Rotation is setup-only: the context hook must never stat or rename a ledger.
|
|
276
283
|
const rotateBytes = parseRotateBytes(process.env[ROTATE_BYTES_ENV])
|
|
277
284
|
rotateLedger(path.join(outputDir, "results.jsonl"), rotateBytes)
|
|
@@ -416,6 +423,25 @@ export default Plugin.define({
|
|
|
416
423
|
}
|
|
417
424
|
}
|
|
418
425
|
|
|
426
|
+
// The hook hands discovery off instead of awaiting it: `recordUsage` is
|
|
427
|
+
// given the session id only, so the in-place rewrite of `event.messages`
|
|
428
|
+
// cannot reach it. One timer per task, `unref`'d so it holds nothing open,
|
|
429
|
+
// cleared when the race settles. The race bounds the wait, not the work:
|
|
430
|
+
// the walk keeps running and a late response still appends its row; rows
|
|
431
|
+
// are absent only when the host never answers.
|
|
432
|
+
const detachDiscovery = (sessionID: string) => {
|
|
433
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
434
|
+
const deadline = new Promise<void>((resolve) => {
|
|
435
|
+
timer = setTimeout(resolve, discoveryMs)
|
|
436
|
+
timer.unref()
|
|
437
|
+
})
|
|
438
|
+
void Promise.race([recordUsage(sessionID), deadline])
|
|
439
|
+
.catch(() => {
|
|
440
|
+
/* usage is an observation, not a guard input */
|
|
441
|
+
})
|
|
442
|
+
.finally(() => clearTimeout(timer))
|
|
443
|
+
}
|
|
444
|
+
|
|
419
445
|
const mcpServerNames = async (): Promise<string[] | null> => {
|
|
420
446
|
if (typeof ctx.mcp?.list !== "function") return null
|
|
421
447
|
try {
|
|
@@ -457,7 +483,6 @@ export default Plugin.define({
|
|
|
457
483
|
await ctx.session.hook("context", async (event) => {
|
|
458
484
|
try {
|
|
459
485
|
const sessionID = typeof event.sessionID === "string" ? event.sessionID : "session"
|
|
460
|
-
await recordUsage(sessionID)
|
|
461
486
|
const { calls, results } = collectToolActivity(event.messages)
|
|
462
487
|
const save = ({ tool, id, text }: { tool: string; id: string; text: string }) => {
|
|
463
488
|
const key = `${sessionID}|${id}|${tool}`
|
|
@@ -499,6 +524,9 @@ export default Plugin.define({
|
|
|
499
524
|
path: changed?.path ?? "",
|
|
500
525
|
})
|
|
501
526
|
}
|
|
527
|
+
// Detached after the rewrite: the tool result must never depend on
|
|
528
|
+
// discovery, and the deadline keeps a hung host from holding a task.
|
|
529
|
+
detachDiscovery(sessionID)
|
|
502
530
|
// Last, and guarded on its own: a snapshot failure must not change the
|
|
503
531
|
// rewrite that already mutated `event.messages`.
|
|
504
532
|
try {
|