Adds four hermetic checks to scripts/test-export.mjs that read package.json with
node:fs (no npm shell-out): scripts.export exists and is non-empty; it invokes
bin/opencode-teamwork.mjs with the export subcommand; the aggregate test script
includes test:export; and it still runs the five pre-existing suites in order
with test:export last. No existing check is modified.
Add lib/export.mjs: buildExportData(projectRoot, sessionId) reads a Teamwork
run directory into a structured object (never throws; invalid or missing runs
return an error string), and renderExport(data, {format}) renders one
self-contained offline HTML document (default) or GitHub-flavoured Markdown.
- sessionId allowlist; task ids validated as single path segments
- symlink refusal on run root, verify/ and every read (lstat + O_NOFOLLOW)
- bounded reads; events.jsonl drives per-task and run timing
- every dynamic string HTML-escaped; absolute URLs defanged in HTML output
- zero dependencies (node: builtins only)
- 6c: root with nonzero tokens + second child session on the same taskId;
asserts the SUMMED bucket so last-writer-wins/absolute writes fail.
- seedSessionDb: probe node:sqlite / sqlite3 CLI once; if neither exists,
print '⊘ skipped attribution DB tests: no node:sqlite and no sqlite3 CLI'
and skip 6a-6d. Seeding errors with a backend present still propagate.
- teamwork_task_update accepts optional agent; recorded agent resolves explicit ->
calling session agent (ctx.session.get, then snapshots bySession) -> plan agent.
Derivation is fail-open with a 2s bound; every value passes clean(value, 64).
- teamwork_cost: non-root spend buckets to input.taskId when given; without it the
agent-name bucketing is unchanged.
- costs.json gains additive byTaskTokens (per-bucket token deltas) in the same
locked section and the tree / single-session paths; manual addUsd adds no tokens.
- byTaskTokens initialised on new costs.json and tolerated when absent.
- SEC-2: task ids must match a single safe segment; report path must stay
inside the run dir; invalid ids are reported in the task note, never read.
- SEC-3: renderTimeline strips C0/C1 control chars from every data-derived
string before rendering (applies with and without colour).
- SEC-4: file reads are capped at 8 MiB (fstat + bounded read); an oversized
events.jsonl is treated as unreadable (derived mode) instead of loaded.
Output shape, derived-mode semantics and the read-only invariant are unchanged.
- isSafeTaskId: ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$, rejects . and ..
- validated at worktree entry point (all actions) before any path/branch is built
- containmentError: relative(runWorktreesDir, targetDir) must be non-empty, non-absolute, not '..'
- containment asserted before mkdirSync/rmSync/worktree add for sentinel and worker/verifier setup;
rmSync re-proves containment immediately before deletion