Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b7eb969
docs: add performance remediation specs
vinilana Jul 11, 2026
16eac4f
perf: share semantic analysis during context init
vinilana Jul 11, 2026
aca5641
fix: bound subprocess output capture
vinilana Jul 11, 2026
095cefa
fix: bound and sanitize hook traces
vinilana Jul 11, 2026
850bfdd
fix LSP process lifecycle
vinilana Jul 11, 2026
328134f
fix: serialize trace writes across processes
vinilana Jul 11, 2026
209552d
fix: bound cache and persistent retention
vinilana Jul 11, 2026
3277628
perf: stream and bound runtime history
vinilana Jul 11, 2026
c905257
perf: complete bounded semantic analysis
vinilana Jul 11, 2026
892c94b
refactor: inject analysis bundle into generators
vinilana Jul 11, 2026
4a7d75c
fix: clamp subprocess diagnostic tails
vinilana Jul 11, 2026
3a43801
fix: bound MCP payloads
vinilana Jul 11, 2026
ac985bd
fix: bound LSP protocol framing
vinilana Jul 11, 2026
39f90fc
fix: enforce sanitized hook quota
vinilana Jul 11, 2026
a082f82
fix: close runtime history memory gaps
vinilana Jul 11, 2026
a505994
perf: reuse semantic fingerprint discovery
vinilana Jul 11, 2026
2a457ff
fix: close MCP payload boundary gaps
vinilana Jul 11, 2026
1b98d6a
fix: apply repository cache policies
vinilana Jul 11, 2026
fa4f6e9
perf: bound semantic freshness discovery
vinilana Jul 11, 2026
89bce54
fix: bound runtime page bytes
vinilana Jul 11, 2026
5e245f0
perf: bound semantic repository discovery
vinilana Jul 11, 2026
d022944
perf: bound UTF-8 hook previews
vinilana Jul 11, 2026
f890cfb
fix: reject partial freshness cache hits
vinilana Jul 11, 2026
036e7aa
perf: cap semantic directory scans
vinilana Jul 11, 2026
6aac917
fix: bound MCP explore I/O
vinilana Jul 11, 2026
08d1ccc
perf: bound raw repository traversal
vinilana Jul 11, 2026
9e2ba49
fix: address LSP lifecycle review findings
vinilana Jul 11, 2026
041b87f
fix: harden hook trace safety
vinilana Jul 11, 2026
01e87e0
fix: address subprocess lifecycle review
vinilana Jul 11, 2026
312229e
fix: address semantic analysis review findings
vinilana Jul 11, 2026
4fcf64c
fix: address cache retention review findings
vinilana Jul 11, 2026
b26ec23
fix: bound MCP exploration CPU and traversal
vinilana Jul 11, 2026
92ee57e
fix: close runtime history review gaps
vinilana Jul 11, 2026
d3317ba
fix: recover orphaned hook store locks
vinilana Jul 11, 2026
35a8f40
fix: recover orphaned trace takeovers
vinilana Jul 11, 2026
5806484
fix: recover legacy trace takeovers
vinilana Jul 11, 2026
0209c7f
fix: preserve live legacy hook locks
vinilana Jul 12, 2026
e61f431
fix: address follow-up review feedback
vinilana Jul 12, 2026
6fac863
Merge pull request #85 from vinilana/agent/f03-stream-runtime-history
vinilana Jul 12, 2026
325a124
Merge pull request #82 from vinilana/agent/f04-lsp-process-lifecycle
vinilana Jul 12, 2026
b1137ae
Merge pull request #81 from vinilana/agent/f01-bound-subprocess-output
vinilana Jul 12, 2026
c0047df
merge: resolve feature conflicts for PR 83
vinilana Jul 12, 2026
0d9a883
merge: resolve feature conflicts for PR 84
vinilana Jul 12, 2026
54893f8
merge: resolve feature conflicts for PR 86
vinilana Jul 12, 2026
6d11cd6
Merge pull request #84 from vinilana/agent/f07-cache-retention
vinilana Jul 12, 2026
0fe60cc
Merge pull request #86 from vinilana/agent/f06-bound-mcp-payloads
vinilana Jul 12, 2026
a373294
Merge pull request #83 from vinilana/agent/f02-sanitize-hook-payloads
vinilana Jul 12, 2026
a335e8e
merge: resolve feature conflicts for PR 80
vinilana Jul 12, 2026
b6d6a8a
Merge pull request #80 from vinilana/agent/f05-shared-semantic-analysis
vinilana Jul 12, 2026
92c2f1e
remove specs
vinilana Jul 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions .context/skills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ On-demand expertise for AI agents. Skills are task-specific procedures that get
| [Security Audit](./security-audit/SKILL.md) | Security review checklist for code and infrastructure | R, V | filled |
| [Test Generation](./test-generation/SKILL.md) | Generate comprehensive test cases for code | E, V | filled |

### Performance Safety Skills

| Skill | Description | Related Spec |
|-------|-------------|--------------|
| [Bound Subprocess Output](./bound-subprocess-output/SKILL.md) | Prevent unbounded stdout and stderr retention | [F-01](../../specs/performance/f-01-bound-subprocess-output.md) |
| [Sanitize Hook Payloads](./sanitize-hook-payloads/SKILL.md) | Keep hook inputs and traces bounded and redacted | [F-02](../../specs/performance/f-02-sanitize-hook-payloads.md) |
| [Stream Runtime History](./stream-runtime-history/SKILL.md) | Paginate traces, replay, datasets, and retention | [F-03](../../specs/performance/f-03-stream-runtime-history.md) |
| [Manage LSP Process Lifecycle](./manage-lsp-process-lifecycle/SKILL.md) | Prevent orphan language-server processes | [F-04](../../specs/performance/f-04-lsp-process-lifecycle.md) |
| [Share Semantic Analysis](./share-semantic-analysis/SKILL.md) | Reuse repository scans and semantic analysis | [F-05](../../specs/performance/f-05-shared-semantic-analysis.md) |
| [Bound MCP Payloads](./bound-mcp-payloads/SKILL.md) | Bound inputs, responses, serialization, and logging | [F-06](../../specs/performance/f-06-bound-mcp-payloads.md) |
| [Govern Cache Retention](./govern-cache-retention/SKILL.md) | Add cache budgets, TTL, invalidation, and cleanup | [F-07](../../specs/performance/f-07-cache-retention.md) |

## Creating Custom Skills

Create a new skill by adding a directory with a `SKILL.md` file:
Expand All @@ -43,21 +55,12 @@ Create a new skill by adding a directory with a `SKILL.md` file:

```yaml
---
type: skill
name: my-skill
description: When to use this skill
skillSlug: my-skill
phases: [P, E, V] # Optional: PREVC phases
mode: false # Optional: mode command?
status: filled
scaffoldVersion: "2.0.0"
description: What the skill does and the concrete tasks that should trigger it
---

# My Skill

## When to Use
[Description of when this skill applies]

## Instructions
1. Step one
2. Step two
Expand All @@ -66,6 +69,11 @@ scaffoldVersion: "2.0.0"
[Usage examples]
```

Keep only `name` and `description` in frontmatter. Put all trigger conditions in
`description`, because discovery reads metadata before loading the skill body. The
folder name is the stable skill slug. Add `agents/openai.yaml` when UI metadata is
needed.

## PREVC Phase Mapping

| Phase | Name | Skills |
Expand Down
52 changes: 52 additions & 0 deletions .context/skills/bound-mcp-payloads/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: bound-mcp-payloads
description: Implement or review bounded MCP inputs and responses. Use for gateway response helpers, MCP Zod schemas, list actions, cursor pagination, maxEvents, JSON serialization, audit logging, response metadata, artifact exports, or payload-size and client-compatibility changes.
---

# Bound MCP Payloads

Serialize once, paginate at the source, and keep transport metadata small.

## Workflow

1. Identify the harness result cardinality before shaping the MCP response.
2. Reuse harness cursor pagination; never paginate only after serialization.
3. Set Zod defaults and maxima for counts, string lengths, array lengths, and patterns.
4. Add serialized-byte validation for nested unknown objects.
5. Derive bounded audit metadata before serialization.
6. Serialize response content once and measure UTF-8 bytes.
7. Return a smaller-page hint or artifact reference when the response exceeds budget.
8. Test boundary values and existing client behavior.

## Required invariants

- Never JSON.parse response text for logging.
- Never truncate JSON at an arbitrary byte position.
- Never pretty-print large machine payloads.
- Never expose an unlimited list action.
- Never put content, prompts, messages, or secrets in audit metadata.
- Keep MCP adaptation thin; pagination belongs to harness.
- Preserve content text for clients that ignore _meta.

## Response choices

Use, in order:

1. a normal bounded page;
2. a smaller suggested page after pageTooLarge;
3. an artifact/export reference for intentionally large output;
4. a typed rejection for oversized input.

Do not increase the payload budget to accommodate an unbounded API.

## Dotcontext routing

- Keep reusable data limits in harness.
- Keep schema and response shaping in src/mcp/gateway or src/mcp/server.
- Update MCP docs and package smoke tests for public contract changes.
- Follow [F-06](../../../specs/performance/f-06-bound-mcp-payloads.md).

## Review gate

Require evidence that normal responses serialize once, list defaults are bounded, limit+1 is rejected, audit metadata stays content-free, and no successful response silently exceeds budget.

4 changes: 4 additions & 0 deletions .context/skills/bound-mcp-payloads/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Bound MCP Payloads"
short_description: "Keep MCP responses paginated and bounded"
default_prompt: "Use $bound-mcp-payloads to review MCP response size, pagination, serialization, and logging."
52 changes: 52 additions & 0 deletions .context/skills/bound-subprocess-output/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: bound-subprocess-output
description: Implement or review child-process execution with bounded stdout and stderr memory. Use for Node spawn wrappers, sensors, test runners, acceptance commands, timeout handling, output tails, truncation, or any change that captures subprocess output in the dotcontext harness.
---

# Bound Subprocess Output

Keep memory proportional to configured diagnostics, never to total child output.

## Workflow

1. Identify what the caller actually needs: exit code, a tail, structured output, or a durable export.
2. Define separate byte limits for stdout, stderr, structured result files, and combined output before editing code.
3. Retain data online with a ring/tail buffer. Do not collect all chunks and trim at process exit.
4. Track total, retained, and dropped bytes without logging content.
5. Define explicit behavior for timeout, output ceiling, spawn error, non-zero exit, and malformed structured output.
6. Preserve shell:false and argv-array execution.
7. Add volume tests that exceed every limit.

## Required invariants

- Never let an array of chunks scale with total output.
- Never call Buffer.concat over the full historical stream.
- Measure limits in UTF-8 bytes, not JavaScript string length.
- Bound stdout and stderr independently.
- Apply hard ceilings while the process is running.
- Kill and reap the child when a hard ceiling or timeout fires.
- Expose truncated, droppedBytes, and termination reason.
- Persist only bounded tails in traces and plan tracking.

## Structured test output

Write large machine-readable results to a temporary file when a parser needs more than a tail. Check file size before reading, parse only required fields, and remove the file in finally. Keep console streams bounded even when using a result file.

## Dotcontext routing

- Put pure bounding rules in src/harness/domain.
- Keep subprocess orchestration in the existing harness execution or adapter boundary.
- Apply the same collector to sensors and plan acceptance.
- Follow [F-01](../../../specs/performance/f-01-bound-subprocess-output.md).

## Review gate

Reject the change if any answer is no:

- Is there a documented default and absolute maximum?
- Does memory stay bounded before process exit?
- Does every failure path reap the child?
- Are truncation counters visible?
- Does a 100 MiB-output regression test pass without retaining 100 MiB?
- Do npm run build and npm test -- --runInBand pass?

4 changes: 4 additions & 0 deletions .context/skills/bound-subprocess-output/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Bound Subprocess Output"
short_description: "Prevent unbounded child-process output"
default_prompt: "Use $bound-subprocess-output to implement or review bounded stdout and stderr capture."
61 changes: 61 additions & 0 deletions .context/skills/govern-cache-retention/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: govern-cache-retention
description: Design, implement, or review bounded cache and persistent-index lifecycle. Use for ContextCache, SemanticContextBuilder, tree-sitter analysis cache, MCP session cache, hook host-session bindings, checkpoints, TTL, LRU, byte budgets, invalidation, cleanup timers, disposal, migration, or runtime retention configuration.
---

# Govern Cache Retention

Require every cache and persistent index to declare how it stops growing and becomes fresh again.

## Workflow

1. Inventory keys, values, entry count, estimated bytes, and ownership lifetime.
2. Define maximum entries, maximum estimated bytes, TTL, and single-entry behavior.
3. Choose a freshness signal tied to the source, not only elapsed time.
4. Use LRU within TTL and evict proactively on set and lifecycle cleanup.
5. Make timers unref, bounded, and disposable.
6. Clear process-local caches on server stop.
7. Add lazy, dual-read migration for persistent shape changes.
8. Protect active sessions and preserve rollback readability.

## Required cache contract

Document:

- normalized key;
- entry and byte limits;
- TTL;
- freshness signal;
- eviction order;
- sweep trigger;
- dispose behavior;
- metrics;
- behavior when one entry exceeds budget.

Reject a cache implementation that omits any item.

## Persistent indexes

Avoid one ever-growing JSON document on a hot path. Partition bindings or records when lookup and rewrite cost scale with total history. Keep summaries in session.json and move growing checkpoint payloads to append-only or individual records.

## Required invariants

- Never expire only when the exact stale key is read again.
- Never leave a referenced interval after stop.
- Never retain stale semantic context after source identity changes.
- Never ignore cacheEnabled.
- Never prune active workflow state.
- Never require destructive migration to roll back.
- Clamp unsafe configuration values.

## Dotcontext routing

- Put generic LRU/retention rules in harness domain/application.
- Keep MCP and integration caches owned and disposed by their surfaces.
- Coordinate repository pruning with runtime history.
- Follow [F-07](../../../specs/performance/f-07-cache-retention.md).

## Review gate

Test entry eviction, byte eviction, TTL sweep, freshness invalidation, stop cleanup, stale binding removal, checkpoint migration, unsafe config clamps, and legacy reads.

4 changes: 4 additions & 0 deletions .context/skills/govern-cache-retention/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Govern Cache Retention"
short_description: "Add cache limits, TTLs, and cleanup"
default_prompt: "Use $govern-cache-retention to design bounded caches and lifecycle-aware persistent indexes."
50 changes: 50 additions & 0 deletions .context/skills/manage-lsp-process-lifecycle/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: manage-lsp-process-lifecycle
description: Implement or review language-server child-process ownership and cleanup. Use for LSPLayer, optional semantic LSP mode, spawn initialization, request timeouts, buffers, pending requests, retries, circuit breakers, graceful shutdown, SIGTERM/SIGKILL escalation, or orphan-process regressions.
---

# Manage LSP Process Lifecycle

Give every process one owner and a terminal state.

## Workflow

1. Model one handle containing process, state, buffer, pending requests, timers, and project identity.
2. Deduplicate initialization with one Promise per language/project.
3. Treat initialize rejection, timeout, spawn error, and early exit as terminal failures.
4. Terminate the child on every failed initialization path.
5. Suppress retries for the current analysis after failure.
6. Make shutdown idempotent during starting, ready, failed, and stopping states.
7. Escalate from protocol shutdown to exit, SIGTERM, and bounded SIGKILL.
8. Wait for close and remove listeners/timers before releasing ownership.

## Required invariants

- Never overwrite a tracked process handle with a new child.
- Never let cleanup mean only deleting Maps.
- Never reject requests owned by another server handle.
- Never retry initialization once per symbol.
- Never resolve shutdown while a managed child remains alive.
- Preserve the useLSP=false fallback and non-LSP semantic behavior.

## Testing

Use executable fake servers that:

- reject initialize;
- never answer initialize;
- crash after spawn;
- ignore protocol shutdown;
- answer normally;
- run concurrently for different languages.

Assert OS child exit, spawn count, pending request cleanup, timer cleanup, and forced-kill metadata. Checking Map size alone is insufficient.

## Dotcontext routing

Keep ownership in src/harness/adapters/out/semantic/lsp and keep CodebaseAnalyzer responsible only for choosing whether to use LSP. Follow [F-04](../../../specs/performance/f-04-lsp-process-lifecycle.md).

## Review gate

Reject any change that lacks a zero-child assertion for failure and shutdown, or that introduces an unbounded retry path.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Manage LSP Process Lifecycle"
short_description: "Prevent orphan language-server processes"
default_prompt: "Use $manage-lsp-process-lifecycle to implement or review safe LSP startup, failure, and shutdown paths."
50 changes: 50 additions & 0 deletions .context/skills/sanitize-hook-payloads/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: sanitize-hook-payloads
description: Design, implement, or review safe lifecycle-hook payload capture and trace persistence. Use for Claude Code, Codex, or Pi hook dispatch; PostToolUse Write/Edit/Bash mapping; stdin parsing; trace redaction; trace quotas; rotation; or hook privacy and performance changes.
---

# Sanitize Hook Payloads

Treat host hook envelopes as untrusted, potentially huge, and potentially secret-bearing.

## Workflow

1. Trace the envelope from host stdin through normalization, mapping, and appendTrace.
2. Set an input byte ceiling before parsing JSON.
3. Reduce tool input to an allowlisted metadata summary before it reaches runtime state.
4. Apply recursive redaction and serialized-size limits as defense in depth.
5. Rotate traces by bytes and preserve atomic append behavior.
6. Keep host hooks non-blocking while recording a bounded failure reason.
7. Test equivalent envelopes for Claude Code, Codex, and Pi.

## Tool summaries

- Write: keep path, byte length, hash, and contentOmitted.
- Edit: keep path, old/new lengths, hashes, and range metadata.
- Bash: keep classification, basename, and a bounded preview.
- Unknown: keep scalar metadata and key names only.

Redact content, old_string, new_string, patch, prompt, messages, authorization, tokens, passwords, secrets, and API keys case-insensitively.

## Required invariants

- Never persist raw Write or Edit bodies.
- Never echo rejected stdin.
- Never rely only on host-provided sizes.
- Measure the serialized trace before writing.
- Keep trace rotation compatible with legacy trace.jsonl.
- Never delete the active segment.
- Keep safety ceilings effective even when configuration is malformed.

## Dotcontext routing

- Keep host field mapping in src/integrations.
- Keep stdin limits in src/cli.
- Keep reusable sanitization and trace policy in src/harness.
- Update hook installer tests and public hook docs when observable behavior changes.
- Follow [F-02](../../../specs/performance/f-02-sanitize-hook-payloads.md).

## Review gate

Verify a multi-megabyte Write produces a small trace, sensitive fixtures never appear on disk, oversized stdin stays non-blocking, rotation survives concurrent appends, and package smoke tests pass.

4 changes: 4 additions & 0 deletions .context/skills/sanitize-hook-payloads/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Sanitize Hook Payloads"
short_description: "Keep hook traces small and safe"
default_prompt: "Use $sanitize-hook-payloads to review hook input capture, redaction, and trace size limits."
44 changes: 44 additions & 0 deletions .context/skills/share-semantic-analysis/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: share-semantic-analysis
description: Consolidate or review repository discovery, semantic parsing, functional-pattern detection, codebase fingerprints, and snapshot generation. Use for context init, DocumentationGenerator, AgentGenerator, SemanticSnapshotService, CodebaseAnalyzer, FileMapper, analysis caching, or large-monorepo performance work.
---

# Share Semantic Analysis

Compute one bounded analysis bundle per operation and reuse it.

## Workflow

1. Map every repository scan, glob, file read, parse, fingerprint, and derived output in the operation.
2. Define one AnalysisBundle owner at the harness application boundary.
3. Discover relevant files once with shared ignores.
4. Parse each selected file once and derive symbols, architecture, and functional patterns from the same analyses.
5. Pass the same bundle to documentation, agent, plan, and snapshot consumers.
6. Apply file-count, per-file byte, total-byte, and concurrency limits.
7. Mark partial analysis and skipped reasons explicitly.
8. Release operation-scoped caches in finally.

## Fingerprinting

Enumerate only relevant files. Reuse content hashes when path, size, and mtime are unchanged. Include dirty files when using git identity. Limit stabilization retries and keep the previous snapshot readable until publication succeeds.

## Required invariants

- Never perform a second semantic read only to derive functional patterns.
- Never let generators silently create independent analyzers in the main context-init path.
- Never glob the entire repository and filter relevance only afterward.
- Never call an analysis complete after a configured limit was hit.
- Honor cacheEnabled.
- Keep snapshot publication atomic.

## Dotcontext routing

- Own AnalysisBundle in src/harness/application/context.
- Keep parsing in semantic adapters.
- Inject data into generators instead of importing transport state.
- Follow [F-05](../../../specs/performance/f-05-shared-semantic-analysis.md).

## Review gate

Instrument tests to count discovery calls, file reads, parse calls, maximum concurrency, bytes read, and fingerprint attempts. Require one parse per selected file in default type=both context init.

4 changes: 4 additions & 0 deletions .context/skills/share-semantic-analysis/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interface:
display_name: "Share Semantic Analysis"
short_description: "Avoid duplicate repository analysis work"
default_prompt: "Use $share-semantic-analysis to consolidate codebase scans, fingerprints, and semantic analysis."
Loading
Loading