Skip to content

feat(viewer-server): add /api/pi-hooks alias and memory tool routes - #2

Closed
ZeR020 wants to merge 8 commits into
stack/2-pi-hooks-adapterfrom
stack/3-viewer-routes
Closed

feat(viewer-server): add /api/pi-hooks alias and memory tool routes#2
ZeR020 wants to merge 8 commits into
stack/2-pi-hooks-adapterfrom
stack/3-viewer-routes

Conversation

@ZeR020

@ZeR020 ZeR020 commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Third stacked PR for pi support (kunickiaj#1430). Depends on layer 2 (stack/2-pi-hooks-adapter, #1) and layer 1 (kunickiaj#1473).

Opened on the fork because GitHub cannot use kunickiaj:stack/2-pi-hooks-adapter as a base.

Why

Pi needs a dedicated ingest URL that lands on the 0.41 canonical seam, plus the missing HTTP memory-tool routes thin clients use.

What

  • POST /api/pi-hooks: bounded parse → buildRawEventEnvelopeFromPiEvent → force source: "pi"ingestNormalizedEnvelope. No recordRawEvent / stripPrivateObj.
  • Memory-tool routes (remember, timeline, expand, schema, search_index, explain, distill_candidates).
  • POSTs use the shared bounded JSON parser; kinds from core REMEMBER_MEMORY_KINDS; string "false" is false.

Deliberate: MCP helper bodies stay copied in this layer (same as 066c03d). Extracting them into core is a follow-up, not this PR. Docs stay on layer 8.

Test plan

  • vitest run packages/viewer-server/src/routes/memory-tools.test.ts — 22/22

Stacked on: #1 / kunickiaj#1473
Related: kunickiaj#1430, kunickiaj#1429

Copilot AI lite review requested due to automatic review settings August 17, 2026 13:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

ZeR020 and others added 8 commits September 9, 2026 19:07
* feat(core): add pi event adapter for 0.41 ingest

Map pi extension events to AdapterEvent envelopes with source "pi"
and deterministic ids so later stacked routes can call ingestRawEvents
without a parallel writer.

* fix(core): hash pi event ids and discriminate shutdowns

Raw ingest rejects concatenated session/entry ids that contain
slash or plus. Hash identity components like Claude/Codex.

session_shutdown fell back to a fixed session_end id, so reload
then quit collapsed to one row. Derive idPart from reason when
entryId is missing or the generic session_end.

* fix(core): distinguish same-reason Pi shutdowns by payload ts

Generic session_end identity now includes the payload timestamp so two
/reload events insert separately while same-payload retries still skip.
Tag stored IDs with PI_EVENT_ID_ALGO=pi/1.

* test(core): satisfy biome noUnsafeOptionalChaining in pi-hooks tests

Biome 2.5.11 from main flags optional-chain casts followed by property
access. Keep the same assertions without that pattern.

* fix(core): fall back to generated ts for ts-less Pi shutdown ids

A generic-entryId shutdown without a payload ts produced the constant
`session_end:<reason>:` discriminator, so same-reason occurrences
collapsed to one row — losing the later lifecycle event, the exact
failure the identity contract forbids. Fall back to the generated
envelope ts (the claude-hooks eventIdTsSeed precedent) so occurrences
stay distinct; ts-carrying retries still dedupe because the payload
ts remains the discriminator.

Adds fake-timer coverage mirroring the claude-hooks generated-timestamp
test.
…ickiaj#1676)

## Description
Refresh the README and supporting docs around persistent coding memory across sessions, machines, and teammates.

- Add npm version/download and MIT badges, theme-aware synthetic screenshots, and a viewer walkthrough.
- Clarify automatic context injection, optional sync/sharing, and single-user remote MCP.
- Distinguish durable npm/manager installs from cached npx setup; correct Claude marketplace installation to require no separate setup command.
- Describe Codex as supported while retaining specific compatibility caveats and current OpenCode version boundaries.
- Add a reproducible synthetic viewer fixture with isolated temporary storage/configuration, disabled background services, and screenshot-maintenance instructions.

The screenshots contain invented data. The fixture is not a network sandbox, and screenshots do not measure extraction or retrieval quality. Unrelated UI changes and website changes are excluded.

## Type of Change
- [ ] 🚀 Feature (new functionality)
- [ ] 🐛 Bug fix (fixes an issue)
- [x] 📚 Documentation (docs-only change)
- [x] 🔧 Maintenance (refactor, chore, CI, etc.)
- [ ] 🧪 Testing (test-only changes)

## Testing
- [ ] Relevant checks pass locally (`pnpm run tsc`, `pnpm run lint`, `pnpm run test`)
- [ ] Added/updated tests for changes
- [x] Manually verified changes work as expected

Targeted validation rather than the full suite:
- Fixture TypeScript check passed with ES2024, NodeNext, and source conditions; its bytes match the previously browser-tested fixture.
- Biome checked through an included virtual filename; formatted output matches the script exactly. The normal root lint scope excludes this script.
- Synthetic fixture and marker-only invocation rejection exercised before preparing this worktree; screenshots visually reviewed.
- Relative links/anchors and both screenshot themes reviewed; badge endpoints resolved successfully.
- `git diff --cached --check` passed; independent reviewer found no remaining blockers.

## Checklist
- [x] Code follows project style (targeted fixture check; see scope above)
- [x] Self-review completed
- [x] Documentation updated (if needed)
- [x] No new warnings introduced
Pi events enter the 0.41 ingest seam through a dedicated compat route
that forces source "pi". Memory-tool POSTs reuse the bounded JSON
parser and the shared remember-kind catalog.
POST expand/explain/distill copied raw filter values into store queries.
Objects such as include_scope_ids:{x:1} were coerced to "[object Object]".
Validate scalar or scalar-array types and return 400 before SQLite.
@ZeR020
ZeR020 force-pushed the stack/3-viewer-routes branch from 53722e9 to 4494b1b Compare September 10, 2026 11:44
@ZeR020

ZeR020 commented Sep 10, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as kunickiaj/codemem#PR once opened — rebased onto main (layers 1–2 merged: kunickiaj#1473, kunickiaj#1546) with hashed-pi-id test updates. Closing this staging PR.

@ZeR020 ZeR020 closed this Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants