@bonesofspring/ai-rules 0.2.69 → 0.2.70
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 +6 -1
- package/package.json +1 -1
- package/presets/claude/next/commands/README.md +5 -0
- package/presets/claude/next/commands/ui-start.md +54 -0
- package/presets/claude/next/commands/ui-stop.md +43 -0
- package/presets/cursor/next/commands/README.md +5 -0
- package/presets/cursor/next/commands/ui-start.md +54 -0
- package/presets/cursor/next/commands/ui-stop.md +43 -0
- package/presets/mavis/next/adapter-map.json +17 -1
- package/presets/mavis/next/commands/README.md +5 -0
- package/presets/mavis/next/commands/ui-start.md +49 -0
- package/presets/mavis/next/commands/ui-stop.md +38 -0
- package/presets/opencode/next/adapter-map.json +17 -1
- package/presets/opencode/next/commands/README.md +5 -0
- package/presets/opencode/next/commands/ui-start.md +57 -0
- package/presets/opencode/next/commands/ui-stop.md +46 -0
- package/presets/opencode/plugins/output-guard/README.md +33 -0
- package/presets/opencode/plugins/output-guard/index.ts +225 -3
- package/presets/zcode/next/adapter-map.json +17 -1
- package/presets/zcode/next/commands/README.md +5 -0
- package/presets/zcode/next/commands/ui-start.md +57 -0
- package/presets/zcode/next/commands/ui-stop.md +46 -0
- package/scripts/report-context-cost.mjs +216 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.2.70
|
|
4
|
+
|
|
5
|
+
### `next` — `/ui-start` and `/ui-stop` return
|
|
6
|
+
|
|
7
|
+
- **Commands.** The Cursor source and Claude twin, plus the generated Mavis, OpenCode, and ZCode `next` trees, ship `ui-start` and `ui-stop`. `ui-start` stops a running `team-tasks-ui` compose stack, runs `team-db.mjs migrate-tasks`, then rebuilds and starts it; `ui-stop` takes the project down and stops only the API `/ui-start` started.
|
|
8
|
+
- **Scope.** The commands target repositories that contain `apps/team-tasks-ui`; both stop with a clear message when `apps/team-tasks-ui/scripts/stack.mjs` is absent.
|
|
4
9
|
|
|
5
10
|
### `resume_blocked` — the chain hook re-arms a blocked step
|
|
6
11
|
|
package/package.json
CHANGED
|
@@ -15,3 +15,8 @@ Slash-command definitions and on-demand scenarios. Copied to `.claude/commands/`
|
|
|
15
15
|
`/task-evil` is intentionally autonomous: no plan confirmation, no human gates, no questions; recommended assumptions are recorded in `decisions.md`, and only hard blockers stop the run. On OpenCode, the command selects the `task-evil` primary agent with a hard `question: deny`, broad shell access except `git commit`/`git push` (and `npx jest*`), and edits limited to `.ai.local/team/**`.
|
|
16
16
|
|
|
17
17
|
See also the preset root `README.md`. Artifacts: `.ai.local/team/README.md`.
|
|
18
|
+
|
|
19
|
+
## UI stack commands
|
|
20
|
+
|
|
21
|
+
- **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
|
|
22
|
+
- **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui-start
|
|
3
|
+
description: "Restart the team-tasks UI stack: stop it when running, refresh the task projection, then start."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Start the team-tasks UI
|
|
7
|
+
|
|
8
|
+
Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
|
|
9
|
+
from the current source, and guarantee the host team-db API the UI reads from.
|
|
10
|
+
|
|
11
|
+
## What to do
|
|
12
|
+
|
|
13
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
14
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node apps/team-tasks-ui/scripts/stack.mjs start
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
|
|
21
|
+
including the owner state. On success the script prints
|
|
22
|
+
`ui: http://127.0.0.1:4300` and
|
|
23
|
+
`api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
|
|
24
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
|
|
25
|
+
with a different compose command and do not start the API by hand.
|
|
26
|
+
4. The start is restart-safe: when the `team-tasks-ui` project is already
|
|
27
|
+
running, the script stops it first, runs `team-db.mjs migrate-tasks` against
|
|
28
|
+
the projection, then rebuilds the image from the current source and starts
|
|
29
|
+
again. A second start never binds a second stack or a second listener on the
|
|
30
|
+
published port.
|
|
31
|
+
|
|
32
|
+
## What the script does
|
|
33
|
+
|
|
34
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
35
|
+
`team-tasks-ui` project name.
|
|
36
|
+
- Stops a running `team-tasks-ui` project and the API this script started
|
|
37
|
+
before refreshing the projection.
|
|
38
|
+
- Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
|
|
39
|
+
after that stop and before the rebuild, so the UI serves the current task
|
|
40
|
+
projection.
|
|
41
|
+
- Seeds `team/runner.json` from the default when it is absent.
|
|
42
|
+
- Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
|
|
43
|
+
nothing answers on `127.0.0.1:4178`, and records that ownership in the
|
|
44
|
+
git-ignored `.ai.local/.ui/api.json` marker.
|
|
45
|
+
- Repairs a missing derived database once through `team-db.mjs sync`, and never
|
|
46
|
+
repairs an API this script did not start.
|
|
47
|
+
|
|
48
|
+
## Do not
|
|
49
|
+
|
|
50
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
51
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
52
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
|
|
53
|
+
or the team-db API.
|
|
54
|
+
- Open a browser, tail container logs, or start a second copy of the app.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui-stop
|
|
3
|
+
description: Stop the team-tasks UI compose project and the team-db API that /ui-start started.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Stop the team-tasks UI
|
|
7
|
+
|
|
8
|
+
Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
|
|
9
|
+
team-db API only when `/ui-start` started it.
|
|
10
|
+
|
|
11
|
+
## What to do
|
|
12
|
+
|
|
13
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
14
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node apps/team-tasks-ui/scripts/stack.mjs stop
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Quote the command's stdout verbatim. On an already stopped stack it prints
|
|
21
|
+
`nothing running` and exits 0.
|
|
22
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop.
|
|
23
|
+
4. The stop is idempotent: a second stop exits 0 and changes nothing.
|
|
24
|
+
|
|
25
|
+
## What the script does
|
|
26
|
+
|
|
27
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
28
|
+
`team-tasks-ui` project name, and removes that project's containers and
|
|
29
|
+
network.
|
|
30
|
+
- Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
|
|
31
|
+
command line is still `team-db.mjs serve`, then removes that marker.
|
|
32
|
+
- Leaves a foreign API alone: a process the marker does not prove is never
|
|
33
|
+
signalled.
|
|
34
|
+
|
|
35
|
+
## Do not
|
|
36
|
+
|
|
37
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
38
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
39
|
+
- Stop a container outside the `team-tasks-ui` project.
|
|
40
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
|
|
41
|
+
source.
|
|
42
|
+
- Kill a process on `127.0.0.1:4178` by port; only the ownership marker
|
|
43
|
+
authorizes a stop.
|
|
@@ -46,6 +46,11 @@ On OpenCode, `/task-evil` runs as the `task-evil` primary agent: the `question`
|
|
|
46
46
|
→ reviewer only
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## UI stack commands
|
|
50
|
+
|
|
51
|
+
- **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
|
|
52
|
+
- **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
|
|
53
|
+
|
|
49
54
|
## Related files
|
|
50
55
|
|
|
51
56
|
- Subagents: `../agents/` (**24** roles, including `task-router.md`, `codebase-analyzer.md`)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui-start
|
|
3
|
+
description: "Restart the team-tasks UI stack: stop it when running, refresh the task projection, then start."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Start the team-tasks UI
|
|
7
|
+
|
|
8
|
+
Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
|
|
9
|
+
from the current source, and guarantee the host team-db API the UI reads from.
|
|
10
|
+
|
|
11
|
+
## What to do
|
|
12
|
+
|
|
13
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
14
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node apps/team-tasks-ui/scripts/stack.mjs start
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
|
|
21
|
+
including the owner state. On success the script prints
|
|
22
|
+
`ui: http://127.0.0.1:4300` and
|
|
23
|
+
`api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
|
|
24
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
|
|
25
|
+
with a different compose command and do not start the API by hand.
|
|
26
|
+
4. The start is restart-safe: when the `team-tasks-ui` project is already
|
|
27
|
+
running, the script stops it first, runs `team-db.mjs migrate-tasks` against
|
|
28
|
+
the projection, then rebuilds the image from the current source and starts
|
|
29
|
+
again. A second start never binds a second stack or a second listener on the
|
|
30
|
+
published port.
|
|
31
|
+
|
|
32
|
+
## What the script does
|
|
33
|
+
|
|
34
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
35
|
+
`team-tasks-ui` project name.
|
|
36
|
+
- Stops a running `team-tasks-ui` project and the API this script started
|
|
37
|
+
before refreshing the projection.
|
|
38
|
+
- Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
|
|
39
|
+
after that stop and before the rebuild, so the UI serves the current task
|
|
40
|
+
projection.
|
|
41
|
+
- Seeds `team/runner.json` from the default when it is absent.
|
|
42
|
+
- Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
|
|
43
|
+
nothing answers on `127.0.0.1:4178`, and records that ownership in the
|
|
44
|
+
git-ignored `.ai.local/.ui/api.json` marker.
|
|
45
|
+
- Repairs a missing derived database once through `team-db.mjs sync`, and never
|
|
46
|
+
repairs an API this script did not start.
|
|
47
|
+
|
|
48
|
+
## Do not
|
|
49
|
+
|
|
50
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
51
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
52
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
|
|
53
|
+
or the team-db API.
|
|
54
|
+
- Open a browser, tail container logs, or start a second copy of the app.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui-stop
|
|
3
|
+
description: Stop the team-tasks UI compose project and the team-db API that /ui-start started.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Stop the team-tasks UI
|
|
7
|
+
|
|
8
|
+
Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
|
|
9
|
+
team-db API only when `/ui-start` started it.
|
|
10
|
+
|
|
11
|
+
## What to do
|
|
12
|
+
|
|
13
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
14
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node apps/team-tasks-ui/scripts/stack.mjs stop
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Quote the command's stdout verbatim. On an already stopped stack it prints
|
|
21
|
+
`nothing running` and exits 0.
|
|
22
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop.
|
|
23
|
+
4. The stop is idempotent: a second stop exits 0 and changes nothing.
|
|
24
|
+
|
|
25
|
+
## What the script does
|
|
26
|
+
|
|
27
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
28
|
+
`team-tasks-ui` project name, and removes that project's containers and
|
|
29
|
+
network.
|
|
30
|
+
- Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
|
|
31
|
+
command line is still `team-db.mjs serve`, then removes that marker.
|
|
32
|
+
- Leaves a foreign API alone: a process the marker does not prove is never
|
|
33
|
+
signalled.
|
|
34
|
+
|
|
35
|
+
## Do not
|
|
36
|
+
|
|
37
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
38
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
39
|
+
- Stop a container outside the `team-tasks-ui` project.
|
|
40
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
|
|
41
|
+
source.
|
|
42
|
+
- Kill a process on `127.0.0.1:4178` by port; only the ownership marker
|
|
43
|
+
authorizes a stop.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "mavis",
|
|
4
4
|
"stack": "next",
|
|
5
5
|
"semanticSource": "cursor/next",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "633684ed117315d643a4af6bfcaa880093da59c22aef618fafc931d070330711",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -527,6 +527,22 @@
|
|
|
527
527
|
"loadMode": "manual",
|
|
528
528
|
"reason": "No file-defined slash command API; keep as an explicit procedure plus exec --file"
|
|
529
529
|
},
|
|
530
|
+
{
|
|
531
|
+
"source": "commands/ui-start.md",
|
|
532
|
+
"target": "commands/ui-start.md",
|
|
533
|
+
"category": "commands",
|
|
534
|
+
"disposition": "transform",
|
|
535
|
+
"loadMode": "manual",
|
|
536
|
+
"reason": "No file-defined slash command API; keep as an explicit procedure plus exec --file"
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
"source": "commands/ui-stop.md",
|
|
540
|
+
"target": "commands/ui-stop.md",
|
|
541
|
+
"category": "commands",
|
|
542
|
+
"disposition": "transform",
|
|
543
|
+
"loadMode": "manual",
|
|
544
|
+
"reason": "No file-defined slash command API; keep as an explicit procedure plus exec --file"
|
|
545
|
+
},
|
|
530
546
|
{
|
|
531
547
|
"source": "commands/update.md",
|
|
532
548
|
"target": "commands/update.md",
|
|
@@ -46,6 +46,11 @@ On OpenCode, `/task-evil` runs as the `task-evil` primary agent: the `question`
|
|
|
46
46
|
→ reviewer only
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## UI stack commands
|
|
50
|
+
|
|
51
|
+
- **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
|
|
52
|
+
- **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
|
|
53
|
+
|
|
49
54
|
## Related files
|
|
50
55
|
|
|
51
56
|
- Subagents: `../agents/` (**24** roles, including `task-router.md`, `codebase-analyzer.md`)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Start the team-tasks UI
|
|
2
|
+
|
|
3
|
+
Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
|
|
4
|
+
from the current source, and guarantee the host team-db API the UI reads from.
|
|
5
|
+
|
|
6
|
+
## What to do
|
|
7
|
+
|
|
8
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
9
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
node apps/team-tasks-ui/scripts/stack.mjs start
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
|
|
16
|
+
including the owner state. On success the script prints
|
|
17
|
+
`ui: http://127.0.0.1:4300` and
|
|
18
|
+
`api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
|
|
19
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
|
|
20
|
+
with a different compose command and do not start the API by hand.
|
|
21
|
+
4. The start is restart-safe: when the `team-tasks-ui` project is already
|
|
22
|
+
running, the script stops it first, runs `team-db.mjs migrate-tasks` against
|
|
23
|
+
the projection, then rebuilds the image from the current source and starts
|
|
24
|
+
again. A second start never binds a second stack or a second listener on the
|
|
25
|
+
published port.
|
|
26
|
+
|
|
27
|
+
## What the script does
|
|
28
|
+
|
|
29
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
30
|
+
`team-tasks-ui` project name.
|
|
31
|
+
- Stops a running `team-tasks-ui` project and the API this script started
|
|
32
|
+
before refreshing the projection.
|
|
33
|
+
- Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
|
|
34
|
+
after that stop and before the rebuild, so the UI serves the current task
|
|
35
|
+
projection.
|
|
36
|
+
- Seeds `team/runner.json` from the default when it is absent.
|
|
37
|
+
- Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
|
|
38
|
+
nothing answers on `127.0.0.1:4178`, and records that ownership in the
|
|
39
|
+
git-ignored `.ai.local/.ui/api.json` marker.
|
|
40
|
+
- Repairs a missing derived database once through `team-db.mjs sync`, and never
|
|
41
|
+
repairs an API this script did not start.
|
|
42
|
+
|
|
43
|
+
## Do not
|
|
44
|
+
|
|
45
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
46
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
47
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
|
|
48
|
+
or the team-db API.
|
|
49
|
+
- Open a browser, tail container logs, or start a second copy of the app.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Stop the team-tasks UI
|
|
2
|
+
|
|
3
|
+
Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
|
|
4
|
+
team-db API only when `/ui-start` started it.
|
|
5
|
+
|
|
6
|
+
## What to do
|
|
7
|
+
|
|
8
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
9
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
node apps/team-tasks-ui/scripts/stack.mjs stop
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Quote the command's stdout verbatim. On an already stopped stack it prints
|
|
16
|
+
`nothing running` and exits 0.
|
|
17
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop.
|
|
18
|
+
4. The stop is idempotent: a second stop exits 0 and changes nothing.
|
|
19
|
+
|
|
20
|
+
## What the script does
|
|
21
|
+
|
|
22
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
23
|
+
`team-tasks-ui` project name, and removes that project's containers and
|
|
24
|
+
network.
|
|
25
|
+
- Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
|
|
26
|
+
command line is still `team-db.mjs serve`, then removes that marker.
|
|
27
|
+
- Leaves a foreign API alone: a process the marker does not prove is never
|
|
28
|
+
signalled.
|
|
29
|
+
|
|
30
|
+
## Do not
|
|
31
|
+
|
|
32
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
33
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
34
|
+
- Stop a container outside the `team-tasks-ui` project.
|
|
35
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
|
|
36
|
+
source.
|
|
37
|
+
- Kill a process on `127.0.0.1:4178` by port; only the ownership marker
|
|
38
|
+
authorizes a stop.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "opencode",
|
|
4
4
|
"stack": "next",
|
|
5
5
|
"semanticSource": "cursor/next",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "633684ed117315d643a4af6bfcaa880093da59c22aef618fafc931d070330711",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -527,6 +527,22 @@
|
|
|
527
527
|
"loadMode": "native-skill",
|
|
528
528
|
"reason": "Native slash commands under .opencode/commands; $ARGUMENTS kept"
|
|
529
529
|
},
|
|
530
|
+
{
|
|
531
|
+
"source": "commands/ui-start.md",
|
|
532
|
+
"target": "commands/ui-start.md",
|
|
533
|
+
"category": "commands",
|
|
534
|
+
"disposition": "transform",
|
|
535
|
+
"loadMode": "native-skill",
|
|
536
|
+
"reason": "Native slash commands under .opencode/commands; $ARGUMENTS kept"
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
"source": "commands/ui-stop.md",
|
|
540
|
+
"target": "commands/ui-stop.md",
|
|
541
|
+
"category": "commands",
|
|
542
|
+
"disposition": "transform",
|
|
543
|
+
"loadMode": "native-skill",
|
|
544
|
+
"reason": "Native slash commands under .opencode/commands; $ARGUMENTS kept"
|
|
545
|
+
},
|
|
530
546
|
{
|
|
531
547
|
"source": "commands/update.md",
|
|
532
548
|
"target": "commands/update.md",
|
|
@@ -46,6 +46,11 @@ On OpenCode, `/task-evil` runs as the `task-evil` primary agent: the `question`
|
|
|
46
46
|
→ reviewer only
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## UI stack commands
|
|
50
|
+
|
|
51
|
+
- **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
|
|
52
|
+
- **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
|
|
53
|
+
|
|
49
54
|
## Related files
|
|
50
55
|
|
|
51
56
|
- Subagents: `../agents/` (**24** roles, including `task-router.md`, `codebase-analyzer.md`)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Restart the team-tasks UI stack: stop it when running, refresh the task projection, then start."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Invocation arguments
|
|
6
|
+
|
|
7
|
+
$ARGUMENTS
|
|
8
|
+
|
|
9
|
+
# Start the team-tasks UI
|
|
10
|
+
|
|
11
|
+
Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
|
|
12
|
+
from the current source, and guarantee the host team-db API the UI reads from.
|
|
13
|
+
|
|
14
|
+
## What to do
|
|
15
|
+
|
|
16
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
17
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
node apps/team-tasks-ui/scripts/stack.mjs start
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
|
|
24
|
+
including the owner state. On success the script prints
|
|
25
|
+
`ui: http://127.0.0.1:4300` and
|
|
26
|
+
`api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
|
|
27
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
|
|
28
|
+
with a different compose command and do not start the API by hand.
|
|
29
|
+
4. The start is restart-safe: when the `team-tasks-ui` project is already
|
|
30
|
+
running, the script stops it first, runs `team-db.mjs migrate-tasks` against
|
|
31
|
+
the projection, then rebuilds the image from the current source and starts
|
|
32
|
+
again. A second start never binds a second stack or a second listener on the
|
|
33
|
+
published port.
|
|
34
|
+
|
|
35
|
+
## What the script does
|
|
36
|
+
|
|
37
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
38
|
+
`team-tasks-ui` project name.
|
|
39
|
+
- Stops a running `team-tasks-ui` project and the API this script started
|
|
40
|
+
before refreshing the projection.
|
|
41
|
+
- Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
|
|
42
|
+
after that stop and before the rebuild, so the UI serves the current task
|
|
43
|
+
projection.
|
|
44
|
+
- Seeds `team/runner.json` from the default when it is absent.
|
|
45
|
+
- Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
|
|
46
|
+
nothing answers on `127.0.0.1:4178`, and records that ownership in the
|
|
47
|
+
git-ignored `.ai.local/.ui/api.json` marker.
|
|
48
|
+
- Repairs a missing derived database once through `team-db.mjs sync`, and never
|
|
49
|
+
repairs an API this script did not start.
|
|
50
|
+
|
|
51
|
+
## Do not
|
|
52
|
+
|
|
53
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
54
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
55
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
|
|
56
|
+
or the team-db API.
|
|
57
|
+
- Open a browser, tail container logs, or start a second copy of the app.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Stop the team-tasks UI compose project and the team-db API that /ui-start started."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Invocation arguments
|
|
6
|
+
|
|
7
|
+
$ARGUMENTS
|
|
8
|
+
|
|
9
|
+
# Stop the team-tasks UI
|
|
10
|
+
|
|
11
|
+
Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
|
|
12
|
+
team-db API only when `/ui-start` started it.
|
|
13
|
+
|
|
14
|
+
## What to do
|
|
15
|
+
|
|
16
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
17
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
node apps/team-tasks-ui/scripts/stack.mjs stop
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Quote the command's stdout verbatim. On an already stopped stack it prints
|
|
24
|
+
`nothing running` and exits 0.
|
|
25
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop.
|
|
26
|
+
4. The stop is idempotent: a second stop exits 0 and changes nothing.
|
|
27
|
+
|
|
28
|
+
## What the script does
|
|
29
|
+
|
|
30
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
31
|
+
`team-tasks-ui` project name, and removes that project's containers and
|
|
32
|
+
network.
|
|
33
|
+
- Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
|
|
34
|
+
command line is still `team-db.mjs serve`, then removes that marker.
|
|
35
|
+
- Leaves a foreign API alone: a process the marker does not prove is never
|
|
36
|
+
signalled.
|
|
37
|
+
|
|
38
|
+
## Do not
|
|
39
|
+
|
|
40
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
41
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
42
|
+
- Stop a container outside the `team-tasks-ui` project.
|
|
43
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
|
|
44
|
+
source.
|
|
45
|
+
- Kill a process on `127.0.0.1:4178` by port; only the ownership marker
|
|
46
|
+
authorizes a stop.
|
|
@@ -16,6 +16,7 @@ outgoing model call; persisted history is untouched.
|
|
|
16
16
|
| Replacement | 40-line / 2 KB head + 15-line / 1 KB tail + path + hints |
|
|
17
17
|
| Saved file | `.ai.local/team/output-guard/<sessionID>/outputs/<callID>-<tool>.txt`, 2 MiB cap |
|
|
18
18
|
| Stats | `.ai.local/team/output-guard/stats.jsonl` (one row per replacement) |
|
|
19
|
+
| Ledgers | `results.jsonl`, `usage.jsonl`, `context.jsonl` — see [Ledgers](#ledgers) |
|
|
19
20
|
| Kill switch | `AI_RULES_OUTPUT_GUARD=0` |
|
|
20
21
|
| Debug | `AI_RULES_OUTPUT_GUARD_DEBUG=1` → `output-guard/debug.log` |
|
|
21
22
|
| Host | OpenCode V2 with `ctx.session.hook`; a host without it no-ops |
|
|
@@ -24,6 +25,38 @@ The replacement keeps the first and last lines because a test log often carries
|
|
|
24
25
|
the failure at the end. A JSON-looking result is still replaced, with a
|
|
25
26
|
`[json: full document at the path]` note so the agent can `jq` the file.
|
|
26
27
|
|
|
28
|
+
## Ledgers
|
|
29
|
+
|
|
30
|
+
All four files live in `.ai.local/team/output-guard/`. None but `results.jsonl`
|
|
31
|
+
and `usage.jsonl` rotate.
|
|
32
|
+
|
|
33
|
+
| File | Row | Written when |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `stats.jsonl` | `sessionID`, `callID`, `tool`, `beforeBytes`, `afterBytes`, `path` | a result is replaced |
|
|
36
|
+
| `results.jsonl` | `sessionID`, `callID`, `tool`, `command`, `rawBytes`, `returnedBytes`, `replaced`, `path` | a tool result is seen |
|
|
37
|
+
| `usage.jsonl` | `sessionID`, `messageID`, `agent`, `model`, `input`, `output`, `reasoning`, `cacheRead`, `cacheWrite`, `cost`, `finish` | a message carries token counts |
|
|
38
|
+
| `context.jsonl` | `sessionID`, `toolset`, `tools`, `toolSchemaBytes`, `systemBytes`, `byTool[]`, `mcpServers[]` | a session's toolset changes |
|
|
39
|
+
|
|
40
|
+
`usage.jsonl` covers the session running the hook **and the child sessions it
|
|
41
|
+
discovers**. A child row adds `parentSessionID`; a root row, and every row
|
|
42
|
+
written before this field existed, has no such key — absence means "root or
|
|
43
|
+
unattributed". A session tags its own rows from `session.get({ sessionID })`
|
|
44
|
+
`parentID`, so a child that runs its own `context` hook still writes child rows.
|
|
45
|
+
Discovery is the backstop for a child whose hook never reaches this plugin:
|
|
46
|
+
`session.created` (host v2 `event.subscribe`, payload `data.parentID`) catches
|
|
47
|
+
children created after setup, and `session.list({ directory, parentID })`
|
|
48
|
+
catches children that already existed. A child is read with
|
|
49
|
+
`session.context({ sessionID })`, the same call the root uses.
|
|
50
|
+
|
|
51
|
+
`context.jsonl` keeps one row per distinct `(sessionID, toolset hash)`.
|
|
52
|
+
`toolSchemaBytes` is the summed UTF-8 size of every `{description, input}` tool
|
|
53
|
+
schema at dispatch; `byTool[]` is `{name, bytes}` per tool; `systemBytes` is the
|
|
54
|
+
summed size of the system part texts. `mcpServers[]` is `{name, tools, bytes}`
|
|
55
|
+
for configured MCP servers whose name prefixes at least one tool
|
|
56
|
+
(`<server>_<tool>`); the key is **omitted** when the MCP list call fails, so a
|
|
57
|
+
reader never mistakes a failed call for a measured zero. A session with no
|
|
58
|
+
tools writes no row.
|
|
59
|
+
|
|
27
60
|
## Why a hook, not a rule
|
|
28
61
|
|
|
29
62
|
A prose line asks the agent to pipe output; context-mode measured that path at
|
|
@@ -12,8 +12,13 @@
|
|
|
12
12
|
* AI_RULES_OUTPUT_GUARD_BYTES (default 8192). Debug:
|
|
13
13
|
* AI_RULES_OUTPUT_GUARD_DEBUG=1. Ledger rotation: once in `setup()` at
|
|
14
14
|
* AI_RULES_OUTPUT_GUARD_ROTATE_BYTES (default 8 MiB, 0 disables), two archives.
|
|
15
|
+
*
|
|
16
|
+
* Telemetry beside the guard: `usage.jsonl` reads the token rows of the session
|
|
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.
|
|
15
19
|
*/
|
|
16
20
|
|
|
21
|
+
import { createHash } from "node:crypto"
|
|
17
22
|
import fs from "node:fs"
|
|
18
23
|
import path from "node:path"
|
|
19
24
|
import { Plugin } from "@opencode/plugin"
|
|
@@ -27,6 +32,7 @@ const HEAD_BYTES = 2048
|
|
|
27
32
|
const TAIL_BYTES = 1024
|
|
28
33
|
const HEAD_LINES = 40
|
|
29
34
|
const TAIL_LINES = 15
|
|
35
|
+
const MAX_TRACKED_SESSIONS = 12
|
|
30
36
|
const ALLOWLIST = new Set(["shell", "bash", "read", "grep", "glob", "webfetch"])
|
|
31
37
|
|
|
32
38
|
const findTeamRoot = (start: string): string | null => {
|
|
@@ -110,6 +116,86 @@ const readNumber = (name: string, fallback: number): number => {
|
|
|
110
116
|
return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
const recordOf = (value: unknown): Record<string, unknown> =>
|
|
120
|
+
value !== null && typeof value === "object" ? (value as Record<string, unknown>) : {}
|
|
121
|
+
|
|
122
|
+
/** `session.list` answers `{ data }` over the client and a bare array in-process. */
|
|
123
|
+
const rowsOf = (value: unknown): unknown[] => {
|
|
124
|
+
if (Array.isArray(value)) return value
|
|
125
|
+
const data = recordOf(value).data
|
|
126
|
+
return Array.isArray(data) ? data : []
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const utf8Bytes = (value: string): number => Buffer.byteLength(value, "utf8")
|
|
130
|
+
|
|
131
|
+
type ToolRow = { name: string; bytes: number; schema: string }
|
|
132
|
+
type ServerRow = { name: string; tools: number; bytes: number }
|
|
133
|
+
|
|
134
|
+
const toolRows = (tools: unknown): ToolRow[] => {
|
|
135
|
+
const rows: ToolRow[] = []
|
|
136
|
+
for (const [name, schema] of Object.entries(recordOf(tools)).sort(([left], [right]) =>
|
|
137
|
+
left.localeCompare(right),
|
|
138
|
+
)) {
|
|
139
|
+
const serialized = JSON.stringify(schema) ?? ""
|
|
140
|
+
rows.push({ name, bytes: utf8Bytes(serialized), schema: serialized })
|
|
141
|
+
}
|
|
142
|
+
return rows
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const sumBytes = (rows: Array<{ bytes: number }>): number =>
|
|
146
|
+
rows.reduce((total, row) => total + row.bytes, 0)
|
|
147
|
+
|
|
148
|
+
const systemBytes = (system: unknown): number => {
|
|
149
|
+
if (!Array.isArray(system)) return 0
|
|
150
|
+
let total = 0
|
|
151
|
+
for (const part of system) {
|
|
152
|
+
const text = recordOf(part).text
|
|
153
|
+
if (typeof text === "string") total += utf8Bytes(text)
|
|
154
|
+
}
|
|
155
|
+
return total
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** MCP tools are named `<server>_<tool>`; a server with no dispatched schema is left out. */
|
|
159
|
+
const serverRows = (names: string[], tools: ToolRow[]): ServerRow[] => {
|
|
160
|
+
const rows: ServerRow[] = []
|
|
161
|
+
for (const name of names.sort((left, right) => left.localeCompare(right))) {
|
|
162
|
+
const matched = tools.filter((tool) => tool.name.startsWith(`${name}_`))
|
|
163
|
+
if (matched.length === 0) continue
|
|
164
|
+
rows.push({ name, tools: matched.length, bytes: sumBytes(matched) })
|
|
165
|
+
}
|
|
166
|
+
return rows
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const toolsetHash = (rows: ToolRow[]): string =>
|
|
170
|
+
createHash("sha256")
|
|
171
|
+
.update(rows.map((row) => `${row.name}\n${row.schema}`).join("\n"))
|
|
172
|
+
.digest("hex")
|
|
173
|
+
.slice(0, 16)
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `context.jsonl` is not rotated, so the keys already on disk seed the dedupe set:
|
|
177
|
+
* a plugin reload must not repeat a `(sessionID, toolset)` row.
|
|
178
|
+
*/
|
|
179
|
+
const loadToolsets = (outputDir: string): Set<string> => {
|
|
180
|
+
const seen = new Set<string>()
|
|
181
|
+
try {
|
|
182
|
+
for (const line of fs.readFileSync(path.join(outputDir, "context.jsonl"), "utf8").split("\n")) {
|
|
183
|
+
if (line.trim() === "") continue
|
|
184
|
+
try {
|
|
185
|
+
const row = recordOf(JSON.parse(line))
|
|
186
|
+
if (typeof row.sessionID === "string" && typeof row.toolset === "string") {
|
|
187
|
+
seen.add(`${row.sessionID}|${row.toolset}`)
|
|
188
|
+
}
|
|
189
|
+
} catch {
|
|
190
|
+
/* a torn last line must not stop the plugin */
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch {
|
|
194
|
+
/* no snapshot ledger yet */
|
|
195
|
+
}
|
|
196
|
+
return seen
|
|
197
|
+
}
|
|
198
|
+
|
|
113
199
|
type ToolItem = {
|
|
114
200
|
type?: string
|
|
115
201
|
id?: string
|
|
@@ -195,8 +281,81 @@ export default Plugin.define({
|
|
|
195
281
|
const statsRecorded = new Set<string>()
|
|
196
282
|
const resultsSeen = new Set<string>()
|
|
197
283
|
const usageSeen = new Set<string>()
|
|
284
|
+
const toolsetsSeen = loadToolsets(outputDir)
|
|
285
|
+
const childrenByParent = new Map<string, Set<string>>()
|
|
198
286
|
|
|
199
|
-
const
|
|
287
|
+
const rememberChild = (parentID: string, childID: string) => {
|
|
288
|
+
const known = childrenByParent.get(parentID)
|
|
289
|
+
if (known) known.add(childID)
|
|
290
|
+
else childrenByParent.set(parentID, new Set([childID]))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// A session's own rows are tagged from its `parentID`, so a child that runs
|
|
294
|
+
// its own hook still lands as a child row. Parent-side discovery below is
|
|
295
|
+
// the backstop for a child whose hook never reached this plugin.
|
|
296
|
+
const parentOf = async (sessionID: string): Promise<string | undefined> => {
|
|
297
|
+
if (typeof ctx.session?.get !== "function") return undefined
|
|
298
|
+
try {
|
|
299
|
+
const parentID = recordOf(await ctx.session.get({ sessionID })).parentID
|
|
300
|
+
return typeof parentID === "string" && parentID !== sessionID ? parentID : undefined
|
|
301
|
+
} catch {
|
|
302
|
+
return undefined
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// `session.created` covers children created after setup, `list({ parentID })`
|
|
307
|
+
// covers the ones that existed before it.
|
|
308
|
+
const watchChildren = () => {
|
|
309
|
+
try {
|
|
310
|
+
if (typeof ctx.event?.subscribe !== "function") return
|
|
311
|
+
const events = ctx.event.subscribe({ types: ["session.created"] })
|
|
312
|
+
void (async () => {
|
|
313
|
+
try {
|
|
314
|
+
for await (const event of events) {
|
|
315
|
+
// Payload sits under `data` in host v2 and under `properties` in v1.
|
|
316
|
+
const payload = recordOf(recordOf(event).data ?? recordOf(event).properties)
|
|
317
|
+
const parentID = payload.parentID
|
|
318
|
+
const childID = payload.sessionID
|
|
319
|
+
if (
|
|
320
|
+
typeof parentID === "string" &&
|
|
321
|
+
typeof childID === "string" &&
|
|
322
|
+
parentID !== childID
|
|
323
|
+
) {
|
|
324
|
+
rememberChild(parentID, childID)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
} catch {
|
|
328
|
+
/* the stream is an optimization; list() still finds the child */
|
|
329
|
+
}
|
|
330
|
+
})()
|
|
331
|
+
} catch {
|
|
332
|
+
/* a host without an event domain keeps the list path */
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const childrenOf = async (parentID: string): Promise<string[]> => {
|
|
337
|
+
const known = new Set(childrenByParent.get(parentID) ?? [])
|
|
338
|
+
if (typeof ctx.session?.list !== "function") return [...known]
|
|
339
|
+
try {
|
|
340
|
+
const response = await ctx.session.list({
|
|
341
|
+
directory: ctx.location.directory,
|
|
342
|
+
parentID,
|
|
343
|
+
archived: false,
|
|
344
|
+
limit: MAX_TRACKED_SESSIONS,
|
|
345
|
+
})
|
|
346
|
+
for (const row of rowsOf(response)) {
|
|
347
|
+
const id = recordOf(row).id
|
|
348
|
+
if (typeof id !== "string" || id === parentID) continue
|
|
349
|
+
known.add(id)
|
|
350
|
+
rememberChild(parentID, id)
|
|
351
|
+
}
|
|
352
|
+
} catch {
|
|
353
|
+
/* the event path may still know the child */
|
|
354
|
+
}
|
|
355
|
+
return [...known].slice(0, MAX_TRACKED_SESSIONS)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const recordSession = async (sessionID: string, parentSessionID?: string) => {
|
|
200
359
|
try {
|
|
201
360
|
const messages = await ctx.session.context({ sessionID })
|
|
202
361
|
if (!Array.isArray(messages)) return
|
|
@@ -219,7 +378,7 @@ export default Plugin.define({
|
|
|
219
378
|
const key = `${sessionID}|${id}`
|
|
220
379
|
if (usageSeen.has(key)) continue
|
|
221
380
|
usageSeen.add(key)
|
|
222
|
-
|
|
381
|
+
const row: Record<string, unknown> = {
|
|
223
382
|
at: new Date().toISOString(),
|
|
224
383
|
sessionID,
|
|
225
384
|
messageID: id,
|
|
@@ -232,13 +391,69 @@ export default Plugin.define({
|
|
|
232
391
|
cacheWrite: typeof tokens.cache?.write === "number" ? tokens.cache.write : 0,
|
|
233
392
|
cost: typeof message.cost === "number" ? message.cost : 0,
|
|
234
393
|
finish: typeof message.finish === "string" ? message.finish : "",
|
|
235
|
-
}
|
|
394
|
+
}
|
|
395
|
+
if (parentSessionID !== undefined) row.parentSessionID = parentSessionID
|
|
396
|
+
appendJsonl(outputDir, "usage.jsonl", row)
|
|
236
397
|
}
|
|
237
398
|
} catch {
|
|
238
399
|
/* fail open: usage is an observation, not a guard input */
|
|
239
400
|
}
|
|
240
401
|
}
|
|
241
402
|
|
|
403
|
+
const recordUsage = async (sessionID: string) => {
|
|
404
|
+
const queue: Array<{ id: string; parentSessionID?: string }> = [
|
|
405
|
+
{ id: sessionID, parentSessionID: await parentOf(sessionID) },
|
|
406
|
+
]
|
|
407
|
+
const visited = new Set([sessionID])
|
|
408
|
+
for (let index = 0; index < queue.length && index < MAX_TRACKED_SESSIONS; index += 1) {
|
|
409
|
+
const current = queue[index]
|
|
410
|
+
await recordSession(current.id, current.parentSessionID)
|
|
411
|
+
for (const child of await childrenOf(current.id)) {
|
|
412
|
+
if (visited.has(child)) continue
|
|
413
|
+
visited.add(child)
|
|
414
|
+
queue.push({ id: child, parentSessionID: current.id })
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const mcpServerNames = async (): Promise<string[] | null> => {
|
|
420
|
+
if (typeof ctx.mcp?.list !== "function") return null
|
|
421
|
+
try {
|
|
422
|
+
return rowsOf(await ctx.mcp.list({}))
|
|
423
|
+
.map((row) => recordOf(row).name)
|
|
424
|
+
.filter((name): name is string => typeof name === "string" && name !== "")
|
|
425
|
+
} catch {
|
|
426
|
+
return null
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const recordToolset = async (sessionID: string, source: unknown) => {
|
|
431
|
+
const request = recordOf(source)
|
|
432
|
+
const tools = toolRows(request.tools)
|
|
433
|
+
if (tools.length === 0) return
|
|
434
|
+
const toolset = toolsetHash(tools)
|
|
435
|
+
const key = `${sessionID}|${toolset}`
|
|
436
|
+
if (toolsetsSeen.has(key)) return
|
|
437
|
+
toolsetsSeen.add(key)
|
|
438
|
+
const byTool = tools.map(({ name, bytes }) => ({ name, bytes }))
|
|
439
|
+
const row: Record<string, unknown> = {
|
|
440
|
+
at: new Date().toISOString(),
|
|
441
|
+
sessionID,
|
|
442
|
+
toolset,
|
|
443
|
+
tools: byTool.length,
|
|
444
|
+
toolSchemaBytes: sumBytes(byTool),
|
|
445
|
+
systemBytes: systemBytes(request.system),
|
|
446
|
+
byTool,
|
|
447
|
+
}
|
|
448
|
+
// No `mcpServers` key when the list call failed: an empty array would read
|
|
449
|
+
// as "measured zero" in the report.
|
|
450
|
+
const names = await mcpServerNames()
|
|
451
|
+
if (names !== null) row.mcpServers = serverRows(names, byTool)
|
|
452
|
+
appendJsonl(outputDir, "context.jsonl", row)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
watchChildren()
|
|
456
|
+
|
|
242
457
|
await ctx.session.hook("context", async (event) => {
|
|
243
458
|
try {
|
|
244
459
|
const sessionID = typeof event.sessionID === "string" ? event.sessionID : "session"
|
|
@@ -284,6 +499,13 @@ export default Plugin.define({
|
|
|
284
499
|
path: changed?.path ?? "",
|
|
285
500
|
})
|
|
286
501
|
}
|
|
502
|
+
// Last, and guarded on its own: a snapshot failure must not change the
|
|
503
|
+
// rewrite that already mutated `event.messages`.
|
|
504
|
+
try {
|
|
505
|
+
await recordToolset(sessionID, event)
|
|
506
|
+
} catch {
|
|
507
|
+
/* the snapshot is an observation, not a guard input */
|
|
508
|
+
}
|
|
287
509
|
} catch (error) {
|
|
288
510
|
if (process.env.AI_RULES_OUTPUT_GUARD_DEBUG === "1") {
|
|
289
511
|
appendJsonl(outputDir, "debug.log", {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"platform": "zcode",
|
|
4
4
|
"stack": "next",
|
|
5
5
|
"semanticSource": "cursor/next",
|
|
6
|
-
"sourceRevision": "
|
|
6
|
+
"sourceRevision": "633684ed117315d643a4af6bfcaa880093da59c22aef618fafc931d070330711",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
9
9
|
"source": "AGENTS.md",
|
|
@@ -527,6 +527,22 @@
|
|
|
527
527
|
"loadMode": "native-skill",
|
|
528
528
|
"reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
|
|
529
529
|
},
|
|
530
|
+
{
|
|
531
|
+
"source": "commands/ui-start.md",
|
|
532
|
+
"target": "commands/ui-start.md",
|
|
533
|
+
"category": "commands",
|
|
534
|
+
"disposition": "transform",
|
|
535
|
+
"loadMode": "native-skill",
|
|
536
|
+
"reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
"source": "commands/ui-stop.md",
|
|
540
|
+
"target": "commands/ui-stop.md",
|
|
541
|
+
"category": "commands",
|
|
542
|
+
"disposition": "transform",
|
|
543
|
+
"loadMode": "native-skill",
|
|
544
|
+
"reason": "Native slash commands under .zcode/commands; $ARGUMENTS kept (probe P-3)"
|
|
545
|
+
},
|
|
530
546
|
{
|
|
531
547
|
"source": "commands/update.md",
|
|
532
548
|
"target": "commands/update.md",
|
|
@@ -46,6 +46,11 @@ On OpenCode, `/task-evil` runs as the `task-evil` primary agent: the `question`
|
|
|
46
46
|
→ reviewer only
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## UI stack commands
|
|
50
|
+
|
|
51
|
+
- **`/ui-start`** — stop the running `team-tasks-ui` stack, run `team-db.mjs migrate-tasks`, then rebuild and start it.
|
|
52
|
+
- **`/ui-stop`** — stop the `team-tasks-ui` stack and the team-db API that `/ui-start` started.
|
|
53
|
+
|
|
49
54
|
## Related files
|
|
50
55
|
|
|
51
56
|
- Subagents: `../agents/` (**24** roles, including `task-router.md`, `codebase-analyzer.md`)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Restart the team-tasks UI stack: stop it when running, refresh the task projection, then start."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Invocation arguments
|
|
6
|
+
|
|
7
|
+
$ARGUMENTS
|
|
8
|
+
|
|
9
|
+
# Start the team-tasks UI
|
|
10
|
+
|
|
11
|
+
Bring up `apps/team-tasks-ui` through its own Docker Compose project, rebuilt
|
|
12
|
+
from the current source, and guarantee the host team-db API the UI reads from.
|
|
13
|
+
|
|
14
|
+
## What to do
|
|
15
|
+
|
|
16
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
17
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
node apps/team-tasks-ui/scripts/stack.mjs start
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Quote the command's stdout verbatim: the `ui:` line and the `api:` line,
|
|
24
|
+
including the owner state. On success the script prints
|
|
25
|
+
`ui: http://127.0.0.1:4300` and
|
|
26
|
+
`api: http://127.0.0.1:4178 (owner: pre-existing|started-by-this-script)`.
|
|
27
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop. Do not retry
|
|
28
|
+
with a different compose command and do not start the API by hand.
|
|
29
|
+
4. The start is restart-safe: when the `team-tasks-ui` project is already
|
|
30
|
+
running, the script stops it first, runs `team-db.mjs migrate-tasks` against
|
|
31
|
+
the projection, then rebuilds the image from the current source and starts
|
|
32
|
+
again. A second start never binds a second stack or a second listener on the
|
|
33
|
+
published port.
|
|
34
|
+
|
|
35
|
+
## What the script does
|
|
36
|
+
|
|
37
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
38
|
+
`team-tasks-ui` project name.
|
|
39
|
+
- Stops a running `team-tasks-ui` project and the API this script started
|
|
40
|
+
before refreshing the projection.
|
|
41
|
+
- Runs `node .ai.local/scripts/team-db.mjs migrate-tasks --quiet --no-rebuild`
|
|
42
|
+
after that stop and before the rebuild, so the UI serves the current task
|
|
43
|
+
projection.
|
|
44
|
+
- Seeds `team/runner.json` from the default when it is absent.
|
|
45
|
+
- Starts the host API with `node .ai.local/scripts/team-db.mjs serve` only when
|
|
46
|
+
nothing answers on `127.0.0.1:4178`, and records that ownership in the
|
|
47
|
+
git-ignored `.ai.local/.ui/api.json` marker.
|
|
48
|
+
- Repairs a missing derived database once through `team-db.mjs sync`, and never
|
|
49
|
+
repairs an API this script did not start.
|
|
50
|
+
|
|
51
|
+
## Do not
|
|
52
|
+
|
|
53
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
54
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
55
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, the app source,
|
|
56
|
+
or the team-db API.
|
|
57
|
+
- Open a browser, tail container logs, or start a second copy of the app.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Stop the team-tasks UI compose project and the team-db API that /ui-start started."
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
## Invocation arguments
|
|
6
|
+
|
|
7
|
+
$ARGUMENTS
|
|
8
|
+
|
|
9
|
+
# Stop the team-tasks UI
|
|
10
|
+
|
|
11
|
+
Take down the `apps/team-tasks-ui` Docker Compose project and stop the host
|
|
12
|
+
team-db API only when `/ui-start` started it.
|
|
13
|
+
|
|
14
|
+
## What to do
|
|
15
|
+
|
|
16
|
+
1. If `apps/team-tasks-ui/scripts/stack.mjs` is absent, stop and report that this
|
|
17
|
+
repository has no team-tasks UI. Otherwise, from the repository root, run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
node apps/team-tasks-ui/scripts/stack.mjs stop
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Quote the command's stdout verbatim. On an already stopped stack it prints
|
|
24
|
+
`nothing running` and exits 0.
|
|
25
|
+
3. On a non-zero exit, quote the `error:` line verbatim and stop.
|
|
26
|
+
4. The stop is idempotent: a second stop exits 0 and changes nothing.
|
|
27
|
+
|
|
28
|
+
## What the script does
|
|
29
|
+
|
|
30
|
+
- Pins every project call to `apps/team-tasks-ui/docker-compose.yml` and the
|
|
31
|
+
`team-tasks-ui` project name, and removes that project's containers and
|
|
32
|
+
network.
|
|
33
|
+
- Stops only the API process recorded in `.ai.local/.ui/api.json` whose live
|
|
34
|
+
command line is still `team-db.mjs serve`, then removes that marker.
|
|
35
|
+
- Leaves a foreign API alone: a process the marker does not prove is never
|
|
36
|
+
signalled.
|
|
37
|
+
|
|
38
|
+
## Do not
|
|
39
|
+
|
|
40
|
+
- Write `status.json`, `metrics.json`, or any task or lifecycle file.
|
|
41
|
+
- Run `docker stop`, `docker rm`, `docker kill`, or a bare `docker compose down`.
|
|
42
|
+
- Stop a container outside the `team-tasks-ui` project.
|
|
43
|
+
- Edit `apps/team-tasks-ui/docker-compose.yml`, the Dockerfile, or the app
|
|
44
|
+
source.
|
|
45
|
+
- Kill a process on `127.0.0.1:4178` by port; only the ownership marker
|
|
46
|
+
authorizes a stop.
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* Fixed context cost of the preset: per host the always-on files, their bytes,
|
|
4
4
|
* and a labelled `bytes / 4` estimate; per Cursor fixture the attached lines
|
|
5
5
|
* against its cap; per task the artifact bytes; the `usage_recorded` totals;
|
|
6
|
-
* the OpenCode output-guard replacement totals.
|
|
6
|
+
* the OpenCode output-guard replacement totals; the hook-time MCP schema split.
|
|
7
7
|
*
|
|
8
|
-
* Counts the bytes of *inputs* — prompt files
|
|
9
|
-
*
|
|
8
|
+
* Counts the bytes of *inputs* — prompt files, task artifacts, and the tool
|
|
9
|
+
* schemas the output-guard snapshot recorded — not the tokens of a session.
|
|
10
|
+
* Read-only: prints to stdout, writes nothing.
|
|
10
11
|
*
|
|
11
12
|
* Usage (any cwd; the repo root is resolved from this file):
|
|
12
13
|
* node packages/ai-rules/scripts/report-context-cost.mjs [--json]
|
|
@@ -58,6 +59,39 @@ function readJson(file) {
|
|
|
58
59
|
return JSON.parse(text);
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
/** The report's only unit conversion, always labelled `EST.TOKENS`. */
|
|
63
|
+
const estimateTokens = (bytes) => Math.round(bytes / 4);
|
|
64
|
+
|
|
65
|
+
/** A byte count that is absent or unusable reads as `null`, never as zero. */
|
|
66
|
+
function numericBytes(value) {
|
|
67
|
+
if (value === null || value === undefined) return null;
|
|
68
|
+
if (typeof value === 'string' && value.trim() === '') return null;
|
|
69
|
+
const number = Number(value);
|
|
70
|
+
return Number.isFinite(number) && number >= 0 ? number : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** JSONL rows; unparsable lines are counted and skipped, an absent file reads as empty. */
|
|
74
|
+
function readJsonlRows(file) {
|
|
75
|
+
let text;
|
|
76
|
+
try {
|
|
77
|
+
text = fs.readFileSync(file, 'utf8');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code === 'ENOENT') return { rows: [], invalid: 0, present: false };
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
const rows = [];
|
|
83
|
+
let invalid = 0;
|
|
84
|
+
for (const line of text.split('\n')) {
|
|
85
|
+
if (line.trim() === '') continue;
|
|
86
|
+
try {
|
|
87
|
+
rows.push(JSON.parse(line));
|
|
88
|
+
} catch {
|
|
89
|
+
invalid += 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { rows, invalid, present: true };
|
|
93
|
+
}
|
|
94
|
+
|
|
61
95
|
function splitFrontmatter(text) {
|
|
62
96
|
if (!text.startsWith('---')) return { frontmatter: '', body: text };
|
|
63
97
|
const end = text.indexOf('\n---', 3);
|
|
@@ -102,7 +136,7 @@ function hostEntry(rule, candidates) {
|
|
|
102
136
|
rule: missing.length === 0 ? rule : `${rule} (missing: ${missing.sort().join(', ')})`,
|
|
103
137
|
alwaysOnFiles: alwaysOnFiles.sort(),
|
|
104
138
|
alwaysOnBytes: bytes,
|
|
105
|
-
estimatedTokens:
|
|
139
|
+
estimatedTokens: estimateTokens(bytes),
|
|
106
140
|
};
|
|
107
141
|
}
|
|
108
142
|
|
|
@@ -307,6 +341,135 @@ export function summarizeOutputGuard(rows) {
|
|
|
307
341
|
};
|
|
308
342
|
}
|
|
309
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Attribute the hook-time schema snapshot. The plugin writes one row per
|
|
346
|
+
* `(sessionID, toolset)`; a reload can repeat a key, so the first row wins.
|
|
347
|
+
*
|
|
348
|
+
* `mcpServers` is *absent* when the plugin's MCP list call failed, and an empty
|
|
349
|
+
* array is a measured zero — the two must not read the same. A server with no
|
|
350
|
+
* dispatched schema is omitted by the writer, so an empty array means "none of
|
|
351
|
+
* the listed servers owned a tool", not "no server is configured".
|
|
352
|
+
*/
|
|
353
|
+
export function summarizeMcpSnapshots(rows) {
|
|
354
|
+
const seen = new Set();
|
|
355
|
+
const snapshots = [];
|
|
356
|
+
let invalid = 0;
|
|
357
|
+
for (const row of Array.isArray(rows) ? rows : []) {
|
|
358
|
+
if (!row || typeof row !== 'object') {
|
|
359
|
+
invalid += 1;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const sessionID = typeof row.sessionID === 'string' ? row.sessionID : '';
|
|
363
|
+
const toolset = typeof row.toolset === 'string' ? row.toolset : '';
|
|
364
|
+
const toolSchemaBytes = numericBytes(row.toolSchemaBytes);
|
|
365
|
+
if (sessionID === '' || toolset === '' || toolSchemaBytes === null) {
|
|
366
|
+
invalid += 1;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
const key = `${sessionID}|${toolset}`;
|
|
370
|
+
if (seen.has(key)) continue;
|
|
371
|
+
seen.add(key);
|
|
372
|
+
snapshots.push({
|
|
373
|
+
at: typeof row.at === 'string' ? row.at : '',
|
|
374
|
+
sessionID,
|
|
375
|
+
toolset,
|
|
376
|
+
tools: numericBytes(row.tools),
|
|
377
|
+
toolSchemaBytes,
|
|
378
|
+
systemBytes: numericBytes(row.systemBytes),
|
|
379
|
+
mcpServers: Array.isArray(row.mcpServers) ? row.mcpServers : null,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const groups = new Map();
|
|
384
|
+
for (const snapshot of snapshots) {
|
|
385
|
+
const group = groups.get(snapshot.toolset) ?? {
|
|
386
|
+
toolset: snapshot.toolset,
|
|
387
|
+
count: 0,
|
|
388
|
+
latest: snapshot,
|
|
389
|
+
captured: null,
|
|
390
|
+
};
|
|
391
|
+
group.count += 1;
|
|
392
|
+
const at = Date.parse(snapshot.at);
|
|
393
|
+
if (Number.isFinite(at) && at > Date.parse(group.latest.at)) group.latest = snapshot;
|
|
394
|
+
if (snapshot.mcpServers !== null) {
|
|
395
|
+
if (group.captured === null) {
|
|
396
|
+
group.captured = snapshot;
|
|
397
|
+
} else {
|
|
398
|
+
const previous = Date.parse(group.captured.at);
|
|
399
|
+
if (Number.isFinite(at) && (!Number.isFinite(previous) || at >= previous)) {
|
|
400
|
+
group.captured = snapshot;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
groups.set(snapshot.toolset, group);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const toolsets = [...groups.values()]
|
|
408
|
+
.sort((a, b) => b.latest.toolSchemaBytes - a.latest.toolSchemaBytes || a.toolset.localeCompare(b.toolset))
|
|
409
|
+
.map((group) => {
|
|
410
|
+
// A newer snapshot whose MCP list call failed does not erase an older
|
|
411
|
+
// measurement; the printed `at` names the row the split came from.
|
|
412
|
+
const latest = group.captured ?? group.latest;
|
|
413
|
+
const captured = latest.mcpServers !== null;
|
|
414
|
+
const servers = captured
|
|
415
|
+
? latest.mcpServers.map((server) => {
|
|
416
|
+
const record = server && typeof server === 'object' ? server : {};
|
|
417
|
+
const bytes = numericBytes(record.bytes) ?? 0;
|
|
418
|
+
return {
|
|
419
|
+
name: typeof record.name === 'string' && record.name !== '' ? record.name : '(unnamed)',
|
|
420
|
+
tools: numericBytes(record.tools),
|
|
421
|
+
bytes,
|
|
422
|
+
estTokens: estimateTokens(bytes),
|
|
423
|
+
};
|
|
424
|
+
})
|
|
425
|
+
: [];
|
|
426
|
+
const mcpBytes = captured
|
|
427
|
+
? servers.reduce((sum, server) => sum + server.bytes, 0)
|
|
428
|
+
: null;
|
|
429
|
+
const builtInBytes = captured ? Math.max(0, latest.toolSchemaBytes - mcpBytes) : null;
|
|
430
|
+
const remainderBytes =
|
|
431
|
+
captured && latest.systemBytes !== null ? builtInBytes + latest.systemBytes : null;
|
|
432
|
+
return {
|
|
433
|
+
toolset: group.toolset,
|
|
434
|
+
snapshots: group.count,
|
|
435
|
+
at: latest.at,
|
|
436
|
+
sessionID: latest.sessionID,
|
|
437
|
+
tools: latest.tools,
|
|
438
|
+
toolSchemaBytes: latest.toolSchemaBytes,
|
|
439
|
+
systemBytes: latest.systemBytes,
|
|
440
|
+
mcp: {
|
|
441
|
+
captured,
|
|
442
|
+
bytes: mcpBytes,
|
|
443
|
+
estTokens: mcpBytes === null ? null : estimateTokens(mcpBytes),
|
|
444
|
+
servers,
|
|
445
|
+
},
|
|
446
|
+
nonMcp: {
|
|
447
|
+
builtInBytes,
|
|
448
|
+
builtInTokens: builtInBytes === null ? null : estimateTokens(builtInBytes),
|
|
449
|
+
systemBytes: latest.systemBytes,
|
|
450
|
+
systemTokens: latest.systemBytes === null ? null : estimateTokens(latest.systemBytes),
|
|
451
|
+
bytes: remainderBytes,
|
|
452
|
+
estTokens: remainderBytes === null ? null : estimateTokens(remainderBytes),
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
return {
|
|
458
|
+
present: snapshots.length > 0,
|
|
459
|
+
snapshots: snapshots.length,
|
|
460
|
+
sessions: new Set(snapshots.map((snapshot) => snapshot.sessionID)).size,
|
|
461
|
+
invalid,
|
|
462
|
+
toolsets,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function mcpSchemasReport() {
|
|
467
|
+
const file = path.join(repoRoot, '.ai.local', 'team', 'output-guard', 'context.jsonl');
|
|
468
|
+
const ledger = readJsonlRows(file);
|
|
469
|
+
const summary = summarizeMcpSnapshots(ledger.rows);
|
|
470
|
+
return { file: toRepoPath(file), ...summary, invalid: summary.invalid + ledger.invalid };
|
|
471
|
+
}
|
|
472
|
+
|
|
310
473
|
function outputGuardReport() {
|
|
311
474
|
const file = path.join(repoRoot, '.ai.local', 'team', 'output-guard', 'stats.jsonl');
|
|
312
475
|
let text;
|
|
@@ -343,6 +506,7 @@ function buildReport() {
|
|
|
343
506
|
tasks: taskReport(slugs),
|
|
344
507
|
usage: usageReport(slugs),
|
|
345
508
|
outputGuard: outputGuardReport(),
|
|
509
|
+
mcpSchemas: mcpSchemasReport(),
|
|
346
510
|
};
|
|
347
511
|
}
|
|
348
512
|
|
|
@@ -361,7 +525,54 @@ function humanReport(report) {
|
|
|
361
525
|
lines.push('');
|
|
362
526
|
lines.push('EST.TOKENS = round(bytes / 4) — an estimate, not a measurement.');
|
|
363
527
|
lines.push('');
|
|
364
|
-
|
|
528
|
+
const mcp = report.mcpSchemas;
|
|
529
|
+
lines.push('MCP SCHEMAS — tool schemas at hook time (context.jsonl, deduped by sessionID+toolset)');
|
|
530
|
+
if (!mcp.present) {
|
|
531
|
+
lines.push(`not captured — no snapshot in ${mcp.file}`);
|
|
532
|
+
} else {
|
|
533
|
+
lines.push(
|
|
534
|
+
`${formatInt(mcp.snapshots)} snapshots · ${formatInt(mcp.sessions)} sessions with a toolset · ` +
|
|
535
|
+
`${formatInt(mcp.toolsets.length)} toolset${mcp.toolsets.length === 1 ? '' : 's'}${mcp.invalid > 0 ? ` · ${formatInt(mcp.invalid)} invalid` : ''}`,
|
|
536
|
+
);
|
|
537
|
+
for (const entry of mcp.toolsets) {
|
|
538
|
+
lines.push(
|
|
539
|
+
`toolset ${entry.toolset} · ${formatInt(entry.snapshots)} row(s) · snapshot ${
|
|
540
|
+
entry.at === '' ? 'at unknown' : entry.at
|
|
541
|
+
} · ${entry.sessionID} · ${entry.tools === null ? '?' : formatInt(entry.tools)} tools`,
|
|
542
|
+
);
|
|
543
|
+
lines.push(
|
|
544
|
+
` tool schemas ${padStart(formatInt(entry.toolSchemaBytes), 12)} B${padStart(`EST.TOKENS ${formatInt(estimateTokens(entry.toolSchemaBytes))}`, 20)}`,
|
|
545
|
+
);
|
|
546
|
+
if (entry.mcp.captured) {
|
|
547
|
+
lines.push(
|
|
548
|
+
` mcp ${padStart(formatInt(entry.mcp.bytes), 12)} B${padStart(`EST.TOKENS ${formatInt(entry.mcp.estTokens)}`, 20)}` +
|
|
549
|
+
` [measured: ${entry.mcp.bytes === 0 ? 'mcpServers=[] — no listed server owns a schema' : `${entry.mcp.servers.length} server(s)`}]`,
|
|
550
|
+
);
|
|
551
|
+
for (const server of entry.mcp.servers) {
|
|
552
|
+
lines.push(
|
|
553
|
+
` ${padEnd(server.name, 20)}${padStart(formatInt(server.tools ?? 0), 3)} tools` +
|
|
554
|
+
`${padStart(formatInt(server.bytes), 12)} B${padStart(`EST.TOKENS ${formatInt(server.estTokens)}`, 20)}`,
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
lines.push(' mcp not captured — the snapshot carries no mcpServers (the list call failed)');
|
|
559
|
+
}
|
|
560
|
+
if (entry.nonMcp.bytes === null) {
|
|
561
|
+
lines.push(' non-mcp not captured — MCP bytes cannot be separated from the schema total');
|
|
562
|
+
} else {
|
|
563
|
+
lines.push(
|
|
564
|
+
` non-mcp ${padStart(formatInt(entry.nonMcp.bytes), 12)} B${padStart(
|
|
565
|
+
`EST.TOKENS ${formatInt(entry.nonMcp.estTokens)}`,
|
|
566
|
+
20,
|
|
567
|
+
)} [${formatInt(entry.nonMcp.builtInBytes)} B built-in schemas + ${formatInt(
|
|
568
|
+
entry.nonMcp.systemBytes ?? 0,
|
|
569
|
+
)} B system parts]`,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
lines.push('');
|
|
575
|
+
lines.push('CURSOR FIXTURES — attached non-empty lines (reads .cursor/rules; caps from check-next-attached-budget.mjs)');
|
|
365
576
|
for (const fixture of report.fixtures) {
|
|
366
577
|
lines.push(
|
|
367
578
|
`${padEnd(fixture.key, 8)}${padEnd(`${fixture.attachedLines}/${fixture.cap}`, 14)}headroom ${fixture.headroom}`,
|