Skip to content

Add Oh My Pi as a second configurable agent - #1

Merged
dncore merged 3 commits into
dncore:mainfrom
CaffreySun:add-oh-my-pi-support
Sep 16, 2026
Merged

dncore merged 3 commits into
dncore:mainfrom
CaffreySun:add-oh-my-pi-support

Conversation

@CaffreySun

@CaffreySun CaffreySun commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Adds Oh My Pi (omp — upstream Pi rebranded, @oh-my-pi/pi-coding-agent) as a sixth configurable agent beside Claude Code, Grok, Codex, Pi and Antigravity. Rebased onto 2421f3d; the feature and the Pi/Oh My Pi convergence are two separate commits.

Why its integration has a different shape

Oh My Pi loads every *.ts in ~/.omp/agent/extensions/ when a session starts — the same mechanism Pi uses — so its integration is one file the runtime owns outright rather than lines inside a file the agent owns:

  • install = write that file (snapshot → back up → atomic write → read back, via ConfigTransaction.performText)
  • remove = delete that file, and only while it still carries the // shim: line the record says was written; a copy is taken first
  • a file without our ownership marker is never touched — ConfigurationError.foreignFile, nothing written

ExtensionTemplate is now the one generated source for both extension-file agents, with the event set as an explicit parameter. Sharing it also shared three things that had been in one file only: the environment payload channel (AGENTPET_PAYLOAD_BASE64, so Pi's extension loses the 30ms stdin race too), the context reading at each settle, and the write path.

What it reports

extension event pet shows
tool_approval_requested waiting — the approval gate, omp's counterpart of a permission prompt
tool_execution_start carrying ask waiting — the ask tool is a question put to the user
agent_start, tool start/end, tool_approval_resolved running
agent_end celebrating, then idle — the extension drops willContinue itself, which is the retry case
context_update (sent at each settle, not listened for) described, not moved: model, context usage
session_start / session_shutdown same reasoning as Claude Code's

turn_start/turn_end are deliberately unmapped (omp's turn is one model call, not one prompt). whenToolName is the new rule condition the ask-tool mapping needs, and it reads through EventNormalizer.string(payload, field) so a dotted path can satisfy it the way the engine reads it.

agent_settled does not exist in omp 18.1.22 (checked against the installed package's on(...) overloads), and session_stop is the pre-settle gate that may be followed by a continuation — so the settle is agent_end minus willContinue. That is the one place the two event sets cannot be the same file.

Two defects this work found, now on main

  • ConfigTransaction.pruneBackups pruned by file name, which is chronological only while one file name uses the directory — so the backup taken during a call could be the first one that call deleted, leaving the path just printed dead. f865c95, ordered by modification date.
  • EventCapture.capturableKeys knew only one spelling of the session id, so a payload that used the other was spooled without one and replayed as a phantom row. 55194e9.
  • The shim's second payload source, AGENTPET_PAYLOAD_BASE64, landed as 1cb66a6, and df57b40 moved Pi's extension onto it.

They are therefore not part of this diff; #2 was closed as superseded.

Verification

  • 547 tests (swift test --parallel); CI's gates run locally — swift build --build-tests, both lint scans (clean; thanks for 69b37f7), Scripts/build-app.sh + plutil -lint, --selftest.
  • The shared template's two generated files pass node --check, including one built from a shim path containing a newline.
  • Adversarial review over every delta (7 rounds for the rebase and the convergence, 2 for the re-rebase, 2 for the ownership fold), each with partitioned reviewers and independent verification, each ending at zero valid findings. The cost note leaking into Pi's file, the shared parameter's unguarded Pi half, an unescaped comment line, two test cases that could not fail, and a set of stale doc claims came out of them.
  • On a real machine against omp 18.1.22: the file is picked up at session start, a real session delivers the lifecycle sequence with one session id and the working directory, the app's log shows Oh My Pi · 950be5 · tmp · Needs input — ask while a question is pending, and --unconfigure omp removes exactly that file.

The shared ownership rule (adopted)

Presence and removal ask one question for both agents — is every line the record says was written still in the file — and they move together, so a file that fails presence cannot be deleted by a different check. ExtensionTemplate.markerLine is the one definition of the // shim: line: the generated file writes it and Pi's record stores it verbatim. A v0.9.6 record needs no branch; its entry is the marker line, which the file it wrote still contains, and both generations have tests. Pi's uninstall backs up through ConfigTransaction.backUp, so the retention policy covers it too; backUp is internal for that reason (its doc comment says so), and PiConfigurator lost the backup directory and the jsStringLiteral only its old presence check used.

Scope

No version, workflow or release-metadata changes; the Homebrew template's version "__VERSION__" is untouched (its diff is the caveat, which now names both extension directories and prints --unconfigure for claude-code, pi and omp). The hunks that look unrelated are consequences of the sixth agent: agent lists, the status tables, mechanism-driven wording (hooks: vs extension:), the glyph enumeration, and the # N tests line.

Scope, one line of note: ConfigTransaction.backUp is widened from private to internal so both extension-file configurators share one backup policy; nothing else outside Sources/, Tests/, the two READMEs, docs/ARCHITECTURE.md and the cask caveat is touched.

Not included: cost for Oh My Pi (the panel's cost item has no source; model and context now arrive), and Pi itself stays as it is on main.

@dncore

dncore commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Thanks for this — it's careful work, and two pieces of it fix live bugs on main, so I want the direction clear before the rebase rather than in the middle of it.

Heads-up: main moved today

v0.9.6 (released an hour ago) landed five-agent support — Grok, Pi, Codex and Antigravity — and it touched a lot of the same files this PR does. This PR is based on b2f1c1d, the commit right before that. I checked the branch out in a worktree: its own suite passes on that base (471/471). Merging it into current main, however, conflicts in eight files:

README.md
README.zh-CN.md
Sources/AgentPetApp/AgentGlyph.swift
Sources/AgentPetApp/CommandLine.swift
Sources/AgentPetApp/UI/AgentPetModel.swift
Sources/AgentPetCore/Bridge/AgentProfiles.swift
Sources/AgentPetCore/Bridge/EventNormalizer.swift
Sources/AgentPetCore/Integration/AgentIntegrationRegistry.swift

Everything else (ConfigTransaction, the shim, AgentsView, the tests, the cask template, docs/ARCHITECTURE.md) merges textually. Notes on the semantic joins are below.

What should survive the rebase exactly as written

  • AGENTPET_PAYLOAD_BASE64, with the measured story (30 ms of a busy loop is enough to lose the session id) and the e2e test that keeps stdin open and never writes to it. The same race exists in the extension we just shipped for Pi — this is the right fix for both, so please don't drop it in the rebase.
  • The ownership discipline in ExtensionFileConfigurator: a marker with no path and no version in it, removal only while the recorded // shim: line is present, refusal of foreign and undecodable files, read-back verification, and a backup before the delete.
  • The reports-only extension with its source-level assertions (block:, sendMessage, node:fs, ctx.ui all absent), the deterministic-source test, and the honest disclosure of the speculative-execution side effect with the src/speculation/host.ts reference. That paragraph is exactly the kind of cost statement this repo wants.
  • The two fixes: pruneBackups() ordering by modification date (with the regression test — backups were pruned by file name, so a second integration writing to the same backup directory could have its own just-taken backup pruned by the same call; the repo's backup directory already has several file names in it thanks to today's integrations, so this is live on main), and the sessionId/toolName capture keys (same story — a spooled event without its session id replays as a phantom row).

Revision direction, in the order I'd do it

  1. Rebase onto current main. Resolution notes:
    • AgentIntegrationRegistry.all() and AgentProfiles.all: keep all six agents — yours plus the four added today. IntegrationMechanism coexists with a field main added today (postConfigureHint); both are worth keeping.
    • After the rebase, mark Pi as .extensionFile too: Pi got a configurator today, and it is the same mechanism (one file in a directory the agent scans, ~/.pi/agent/extensions/). The mechanism field should describe both pi and omp, or the UI wording it drives is already saying the wrong thing for one of them.
    • EventNormalizer: whenToolName slots in beside the parameters main added (notificationTypeField, whenReason, backgroundTasksField, suppressedWhenFalseField, requiresNonEmptyField). One request: read the tool name through the shared EventNormalizer.string(payload, field) reader instead of payload[field] directly. That reader now walks dotted paths (toolCall.name) and reads the first element of string arrays — that's how Antigravity's tool names work — and a rule condition that bypasses it can't ever match a nested field.
    • READMEs and docs/ARCHITECTURE.md: main's text now describes five configurable agents and §6.7 grew an Oh My Pi-shaped hole with a much longer status-line table. Keep your mapping table, the new §8.8, the cask caveats, and the row you added to §6.7; rebase the surrounding prose onto the new text rather than the old "only Claude Code is configurable" framing.
  2. Pi/Oh My Pi convergence — worth a short design note in the PR (or in §8.8): pi 0.85 and omp 18.x share the extension API but differ on exactly the events this maps. omp has tool_approval_requested/tool_approval_resolved and agent_end.willContinue (your capture). pi has no approval events — its waiting signal is ui_prompt_start — and the settle we use there is agent_settled, because a plain agent_end can still be followed by an auto-retry or compaction (our capture, 0.85.1). Shape the generated source so one function serves both event sets, or make the difference an explicit parameter. And one consistency point: the extension we ship for Pi also sends a context_update from ctx.getContextUsage(); you held that back for omp on purpose — that's a fine call, just say so in §8.8 so the two extensions don't read as inconsistent by accident.
  3. One question: does omp 18.1.22 have agent_settled? If it does, it's the more precise "the turn is really over" signal than agent_end; your willContinue filter already covers the retry case, so this is a nit either way — but if agent_settled exists, prefer it and the two agents line up.
  4. Optional, and possibly the fastest path: split this into two PRs — (a) the two bug fixes plus their regression tests, which can land on main immediately, and (b) the Oh My Pi feature, rebased. If you'd rather keep it as one, that's fine too; the fixes just shouldn't wait on the reconciliation.

Everything else — the mapping table, the mechanism-driven wording, the tests, the docs — reads ready to go. Ping me on the rebase if any of the conflict resolution is ambiguous; happy to help with the join.

@CaffreySun

Copy link
Copy Markdown
Contributor Author

Answering the one question first, then what I'm doing about the rest.

agent_settled does not exist in omp 18.1.22. The on(...) overloads in the installed package (extensibility/extensions/types.ts) cover agent_start, agent_end, session_stop, turn_start, turn_end — nothing by that name. The two settle-adjacent signals are:

  • agent_end, whose payload carries willContinue — the agent loop ended, and the flag says whether a retry or continuation is already scheduled. That is what the extension uses: it drops the event when willContinue is true, so what is left is a settle.
  • session_stop is not a better fit. Its own doc: fired "when a main-agent turn is about to settle; handlers may request one continuation turn" — it is the pre-settle gate (where a Stop-hook injects context), so it can fire on a turn that then continues. As an observer I would be reporting a settle that may not happen.

So for omp the pair really is agent_end + the willContinue filter; there is no more precise event to prefer. That reasoning goes into §8.8 with the other join notes.

Split done: #2 carries the two fixes — pruning by age, and the second spelling of session_id/toolName — each with a regression test verified as a negative control, 511 tests green on current main. Nothing in it depends on the omp feature, so it does not have to wait for the reconciliation.

Rebase in progress, along the lines you laid out: all six agents kept in both registries; IntegrationMechanism beside postConfigureHint; Pi marked .extensionFile; whenToolName reading through EventNormalizer.string(_:_:) so a dotted path like toolCall.name can satisfy it. And I'd rather converge the two extension-file integrations than ship a second generator: one template with the event set as an explicit parameter, AGENTPET_PAYLOAD_BASE64 applied to the Pi extension as well (its stdin race is the same one), and a context reading at settle for omp so it matches what Pi's extension already sends. Docs rebased onto your prose rather than the old framing.

I'll force-push the rebase onto this branch and ping you; if any join turns out ambiguous I'll ask rather than guess.

@CaffreySun

Copy link
Copy Markdown
Contributor Author

Rebased onto 2421f3d and converged, along the lines you laid out. Two commits now: the feature, and the convergence.

The joins you called out

  • Six agents in both registries; IntegrationMechanism sits beside postConfigureHint rather than replacing it.
  • Pi is .extensionFile, so the mechanic-driven wording is right for both it and Oh My Pi.
  • whenToolName reads through EventNormalizer.string(payload, field), so a dotted toolCall.name satisfies it the same way the engine reads it.
  • Docs rebased onto your prose. Your §6.7b and the new §6.7/§6.7b material stay; my §8.8, the mapping table and the row I added to §6.7 stay. I also synced the two rows in the Chinese status table that still said "only Claude Code" / "Grok/Codex/Pi not built" — they were left behind when the English table moved.
  • agent_settled: it does not exist in omp 18.1.22 (checked the on(...) overloads in the installed package). session_stop is the pre-settle gate and can be followed by a continuation, so the settle is agent_end minus willContinue. That reasoning is now in §8.8 and in the profile's comment.

Convergence

ExtensionTemplate is now the one generated source, with the event set as an explicit parameter — the events are the only thing that differs, and they differ in both directions (agent_settled missing on omp; a plain agent_end not being a settle on Pi). Sharing it also shared three things that had been in one file only:

  • the environment payload channel, so the Pi extension no longer has the 30ms race;
  • the context reading at each settle, so omp matches Pi;
  • the write path (ConfigTransaction.performText), so the Oh My Pi configurator no longer carries its own copy of snapshot / backup / atomic write / read-back.

Payload spelling converges on what Pi's extension already sent (session_id / cwd / toolName), which also retires the camelCase session key — the capture allowlist keeps both spellings anyway, for wires that are camelCase themselves.

One thing I did not decide for you

The two configurators still recognise their own file differently: Pi on its marker plus the recorded shim path, Oh My Pi on the marker plus the recorded // shim: line. The second is strictly stronger — that line carries both the path and the agent id — so folding Pi onto it is a one-line change to PiConfigurator.entriesPresent. I left it alone because it changes a rule that shipped today; say the word and I'll make that the shared rule.

Heads-up, unrelated to this PR: main's CI is red on its own lint. Tests/AgentPetCoreTests/AntigravityStatusLineTests.swift:52 has /Users/dev/Documents, and the lint's exemption list only allows /Users/x and /Users/someone. Last push to main failed on it, and every PR's lint job fails with it. Left untouched here on purpose.

Evidence: 542 tests (swift test --parallel), and CI's gates run locally — swift build --build-tests, both lint scans, Scripts/build-app.sh + plutil -lint, --selftest. An adversarial review loop over this diff — seven rounds, partitioned reviewers with independent verification, ending at zero valid findings — is where those came from; every one is fixed before this push.

Also: the two fixes from #2 are still contained here, so they'll drop out of this diff once #2 lands.

dncore added a commit that referenced this pull request Sep 15, 2026
A backup's name starts with the file it came from, so `agentpet.json.…`
sorted before `settings.json.…` no matter how new it was — and the
moment a second integration backed a file up into the same directory,
the backup taken during that very call was the first one pruned and the
path the caller had just been handed was gone. Age now comes from the
filesystem, with the name only as a tiebreak inside one clock tick.

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
dncore added a commit that referenced this pull request Sep 15, 2026
An in-process extension names the session `sessionId`; the capture
allowlist only knew the hook spelling `session_id`, so an event spooled
while the app was down replayed under a process-derived name — a second
row beside the real one. Both spellings of the session id and the tool
name are now captured; the list stays hand-written for the reason its
comment gives (a profile's summaryField is the user's own prompt).

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
dncore added a commit that referenced this pull request Sep 15, 2026
An extension that spawns the shim from inside the agent's own runtime
writes to a pipe queued on an event loop the agent may be holding —
measured, 30 ms of a busy loop is enough for the shim's stdin deadline
to expire and the event to arrive with no session id. The shim now
reads AGENTPET_PAYLOAD_BASE64 first and falls back to stdin, so the
hook contract is untouched and an in-process reporter has nothing to
be late for.

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@dncore

dncore commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Quick follow-up: rather than let the fixes wait on the rebase, I've landed three pieces of this on main now — each with a regression test, and with you credited in the commit (Ported from #1; author CaffreySun plus a Co-Authored-By):

  • f865c95 — pruneBackups() ordered by modification date. The name-ordering bug was live on main: the backup directory went multi-source the moment a second integration started backing files up into it.
  • 55194e9 — sessionId / toolName added to the capture allowlist, with the spool regression covered.
  • 1cb66a6 — AGENTPET_PAYLOAD_BASE64 read by the shim ahead of stdin (the stdin contract is byte-for-byte unchanged), covered by the e2e that leaves stdin open and never writes to it.

And df57b40 moves our Pi extension onto the same environment-payload mechanism — your measurement applies to it verbatim.

So when you rebase, expect those hunks to already be present; keep the parts of your branch that build on them (the ExtensionFileConfigurator, the Oh My Pi profile, the mechanism plumbing, the docs). Two notes for the rebase itself:

  • whenToolName should read through EventNormalizer.string(payload, field) rather than indexing the dictionary, so it can match dotted paths like toolCall.name — that reader is how the newer profiles reach nested fields.
  • The shim's environment-payload support is now on main, so the extension you generate can rely on it without carrying that change with you.

Everything else stands as reviewed — happy to help with any of the reconciliation.

@dncore

dncore commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Status from this side, then the rebase recipe, then the decision you asked for.

Your agent_settled answer is accepted. The session_stop reasoning is the part I wanted on the record — a pre-settle gate that may be followed by a continuation is the wrong thing for an observer to report — and agent_end minus willContinue is the settle. Putting it in §8.8 and the profile comment is exactly where it should live.

Your lint heads-up was right, and the fault was ours. Tests/AgentPetCoreTests/AntigravityStatusLineTests.swift:52 used /Users/dev/Documents as a "generic" sandbox path; the exemption list is only /Users/x and /Users/someone. It has been failing since v0.9.6 (2421f3d) — the release pipeline stays green when it happens, I was watching the wrong job, and every PR against main showed the red. Fixed in 69b37f7; main's lint has been green since. Nothing in your branch caused it.

Your wording fix from #2 (1a0bad5) is on main too, as 4e5ab50. You were right on every count: Grok's captured wire carries both spellings of each core field (so nothing of ours ever lost a session to the camelCase gap), the extensions we ship send session_id with a camelCase toolName, and Antigravity's wire is camelCase throughout — which the old "hooks use session_id" phrasing missed as well. The spool test is agent-neutral now, as you had it.

One more rebase and this is ready. The branch sits on 2421f3d, before the four ported commits, so merging it into current main conflicts in seven files — every one a duplicate of something main already carries. I resolved the merge locally to verify it (not to merge on your behalf), and this is what came out:

file resolution
EventCapture.swift, Sources/agentpet-hook/main.swift, ConfigTransaction.swift take main's — identical in substance
ConfigTransactionTests.swift, EventSpoolTests.swift take main's regression tests
PiConfigurator.swift take yours (the converged one)
BridgeEndToEndTests.swift merges silently, but your environmentPayload() lands beside main's, same name — keep main's, drop yours
docs/ARCHITECTURE.md manual — main's §6.7b grew (the three ported mechanisms, the Pi switch); your §8.8, your §6.7 row and the zh table sync go on top. The one file I did not verify

One line main does not have and yours needs: ConfigTransaction.backUp must be internal, not private — ExtensionFileConfigurator calls it. Keep the doc comment you wrote on it.

With that resolution: swift build --build-tests clean, 543 tests green on swift test --parallel over main + your branch. Nothing structural is left; it is a rebase, not a redesign.

The decision you asked for: yes, fold Pi onto the shared rule — with one amendment. The rule to share is exactly what ExtensionFileConfigurator already does — presence and uninstall driven by the recorded entries (a file is ours while every recorded command is still in it), not "contains the shim line" as an extra check. Two specifics:

  • Presence and uninstall must move together. Changing only entriesPresent leaves a file that fails the presence check being deleted by the marker check — the mismatch is the thing the shared rule exists to remove.
  • Pi's record entry becomes the markerLine going forward. Old records need no branch: a v0.9.6 record's command is the marker string, the old file still contains it, so under the same rule it reads present and uninstalls cleanly. New records get the shim line, which the new files carry. One rule, both generations.

If you would rather not hand-merge the architecture doc, say so and I will push the resolved merge as a branch you can start from — the tests above are from it. Otherwise: force-push when ready and I will run the suite on the head.

Oh My Pi is a rebranded Pi (`@oh-my-pi/pi-coding-agent`): the same extension
API, `~/.omp/agent` instead of `~/.pi/agent`. It is the first agent here
whose integration is a *file* rather than an edit — it loads every `*.ts` in
`~/.omp/agent/extensions/` at session start — so the runtime installs one
file it owns outright: snapshot, back up, write atomically, read back,
refuse to touch a file that does not carry the marker it recorded, and
delete only while the recorded `// shim:` line is still in it.

Two things about the integration are worth knowing before reading the diff.

What it reports is the extension's own event set, so the profile maps
`tool_approval_requested` to waiting (the approval gate — the counterpart of
Claude Code's permission prompt) and `tool_execution_start` carrying `ask`
to waitingInput (the `ask` tool *is* a question put to the user). `agent_end`
is dropped by the extension itself when the payload says `willContinue` — a
retry is already scheduled, so the turn has not settled. A new rule
condition, `whenToolName`, exists so the narrow rule can precede the general
one for the same event.

The payload reaches the shim in the environment, not down a pipe. The
extension runs inside the agent's own runtime, where a write to a pipe is
queued on an event loop the agent may be holding: measured, 30ms of a busy
stretch between spawning the shim and writing to it was enough for the
shim's 20ms stdin deadline to expire, and the event then arrived with no
session id at all — a row the pet could never fill. `AGENTPET_PAYLOAD_BASE64`
is handed to the process by the kernel at spawn time. The stdin path is
untouched, byte for byte, for Claude Code, Grok and Codex.

Two defects surfaced while wiring it up, both triggered by there being a
second integration in the runtime:

- Backups were pruned by file name, which is chronological only while every
  backup in the directory came from the same file: `agentpet.ts.…` sorts
  before `settings.json.…` however new it is, so the backup taken during a
  call was the first one that call deleted, and the path it had just printed
  was already gone. Pruning goes by modification date now, and the new test
  fails against the old ordering.
- The spool and event-log allowlist knew only Claude Code's `session_id` and
  `tool_name`, so a spooled Oh My Pi event lost its session: replaying it
  after a restart drew that session under a process-derived name, beside the
  real one. Both spellings are kept, and the test pins it.

Verified against omp 18.1.22 on this machine: the file is picked up at
session start (no `--extension` flag), a real session delivers
`session_start / agent_start / tool_execution_start / tool_execution_end /
agent_end / session_shutdown` with one session id and the working directory,
the app's own verbose log shows the row `Oh My Pi · 950be5 · tmp · Needs
input — ask` while a question is pending, and `--unconfigure omp` removes
exactly that file and leaves the two extensions that were already there.
471 tests.

The cost is stated in the installed file's header as well as in the docs: any
extension handler on one of the four tool-lifecycle events turns off Oh My
Pi's experimental speculative local reads
(`tools.speculativeExecution.enabled`, off by default) while the file is
installed; this file takes the two approval events, which is what makes an
approval show as "Needs input".

Not included: model, context and cost for Oh My Pi (§6.7 records why), and Pi
itself stays detect-only.
Pi and Oh My Pi extend their agent the same way — one marked file the runtime
owns, in a directory the agent scans — so they now share the generated file,
with the event set as an explicit parameter (ExtensionTemplate).

The events are the only thing that really differs, and they differ in both
directions: `agent_settled` does not exist in omp 18.1.22 (checked event by
event against the installed package), and a plain `agent_end` is not a settle
on Pi, which may still retry or run a queued follow-up after it. One file
could not be right for both, which is what the parameter encodes.

Sharing the file also shares the fixes that were in only one of them:

- The payload travels in the environment for both (AGENTPET_PAYLOAD_BASE64),
  not down a pipe — the race the Pi extension had shipped with, measured at
  30ms of busy loop.
- The context reading (ctx.getContextUsage() / ctx.model) is taken at every
  settle for both, in the one reduced shape the status-line taps use.
- The write goes through ConfigTransaction.performText for both, so the Oh My
  Pi path no longer carries its own copy of snapshot / backup / atomic write /
  read-back.

Field spelling converges on what Pi's extension already sent — `session_id`,
`cwd`, `toolName` — so each profile has one reader and the generator has one
payload builder.

Six rounds of adversarial review followed, and their fixes are folded into
this commit rather than left as a trail of "fix the review" commits: the cost
note is per event set (it had leaked Oh My Pi's paragraph into Pi's file), the
Pi half of the event-set parameter is now guarded by a test that reads the
generated file, the docs stopped describing the pre-convergence world in the
places this commit created, and the CLI labels one quantity the same way on
every surface.

Not unified yet, and worth a decision rather than a guess: the two
configurators still recognise their own file differently. Pi checks its marker
plus the recorded shim path; Oh My Pi checks the marker plus the recorded
`// shim:` line, which is strictly stronger — that line carries both the path
and the agent id. Folding Pi onto it is a one-line change to
`PiConfigurator.entriesPresent`, but it changes a rule that shipped today, so
it is proposed rather than taken.

542 tests.

The review of this commit's delta is folded in: the generated file's comment
line is comment-safe now (a path with a line separator used to end the comment
and break the file, while the record still claimed it present), the cost note
is no longer prefixed twice, `report()`'s payload build is wrapped again, the
Pi suite pins its event set instead of deriving it from the file under test,
the profile's field names are tied to both payload builders, and the docs
stopped claiming Oh My Pi awaits this branch.
You asked for this and specified how, and it is the same change the review
round was asking for from the other side: the docs claimed one backup policy
covered every edit while Pi's uninstall wrote its own copy straight into the
directory, bypassing the retention pass.

- Presence and removal now ask one question for both agents: is every line the
  record says was written still in the file. They move together, as you asked
  — a file that fails presence cannot be deleted by a different rule.
- Pi's record entry is the `// shim:` line from here on, defined once in
  `ExtensionTemplate.markerLine` and both written into the file and recorded
  verbatim. A v0.9.6 record needs no branch: its entry is the marker line, the
  old file still contains it, so it reads present and uninstalls cleanly. Both
  generations have tests.
- Pi's uninstall backs up through `ConfigTransaction.backUp`, so the retention
  policy bounds it too; `PiConfigurator` no longer keeps a backup directory of
  its own, nor the `jsStringLiteral` only its old presence check used.
- The tests that pinned the old rule were rewritten rather than dropped: a
  moved shim is drift because the entry carries the path, and that case fails
  if the rule stops reading the record (checked by breaking it).

Docs: §6.7b and §8.8 describe one rule for both agents and name what still
differs — the marker string, the refusal error, the cost note, the event set.
Counts moved to 546.

The review of this delta is folded in too: the entry `configure` records is
pinned by a test, the v0.9.6 case uses the frozen literal rather than the
constant it is meant to outlive, a case makes the retention policy visible
(the hand-rolled backup this replaced fails it), and two texts that still
described the pre-fold rule were corrected.
@CaffreySun

Copy link
Copy Markdown
Contributor Author

Rebased onto 4e5ab50 and took the decision — with your two amendments.

The rule is shared now. Presence and removal ask one question for both agents: is every line the record says was written still in the file. They move together, as you said — the same call decides both, so a file cannot fail presence and still be deleted by a different check. ExtensionTemplate.markerLine is the one definition of the // shim: line: the generated file writes it and Pi's record stores it verbatim.

Old records need no branch, exactly as you described. A v0.9.6 record's entry is the marker line, the file it wrote still contains it, so it reads present and uninstalls cleanly; both generations have tests (olderRecordStillWorks, and a case that asserts an empty record removes nothing).

Two things fell out of doing it:

  • Pi's uninstall now backs up through ConfigTransaction.backUp, so the retention policy covers it too. That also settled a finding from my own review round: the docs claimed one policy covered every edit while Pi wrote its own copy straight into the directory, bypassing the pruning. Behaviour for Pi is otherwise unchanged.
  • PiConfigurator lost the backup directory it no longer needs and the jsStringLiteral only its old presence check used. Self.marker still gates overwriting (the refuse-a-foreign-file path), which is a different question from presence, so it stays.

The rebase matched your table. I had already resolved the same seven files the same way before your message arrived — main's for the three ported files and their two regression tests, the converged PiConfigurator, my duplicate environmentPayload() dropped (main's covers it; the Oh My Pi chain test stays), ConfigTransaction.backUp kept internal with its doc comment. The one file you had not verified, docs/ARCHITECTURE.md, is hand-merged: your port bullet and §6.7b stand, my §8.8 and §6.7 row go on top, and the zh status table is synced with the English one.

Thanks for the lint fix, and for taking the #2 wording as 4e5ab50 — the allowlist comment reads right now, including the part about our own extensions sending session_id. #2 is closed as superseded.

The branch is force-pushed at d52efda: three commits — the feature, the convergence, and this fold — with the review churn folded into the two it belongs to, and the tree byte-identical to the one that came out of the last round.

Verification: 546 tests on swift test --parallel, CI's gates run locally (swift build --build-tests, both lint scans — clean now, Scripts/build-app.sh + plutil -lint, --selftest), and an adversarial review loop over each delta — 7 rounds on the rebase and the convergence, 2 on the re-rebase, 2 on this fold, each ending at zero valid findings. One thing I checked by breaking it: the drift case fails if presence stops reading the record, and the payload-key case fails if either payload renames session_id.

@dncore
dncore merged commit 2d08d24 into dncore:main Sep 16, 2026
2 checks passed
@dncore

dncore commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Merged and released. main is at 2d08d24 (rebase-merged, your three commits with authorship intact), and it shipped as v0.10.0 — https://github.com/dncore/agent-pet-runtime/releases/tag/v0.10.0 — with the release notes crediting you and the Homebrew cask synced. The merged tree ran 547 tests green before the tag, and the release pipeline passed on the shipped artifact.

Nothing further needed from you here. The v0.9.6-record test using the frozen literal instead of the constant is the detail I would have asked for if you had not gotten there first.

@CaffreySun
CaffreySun deleted the add-oh-my-pi-support branch September 16, 2026 02:49
dncore added a commit that referenced this pull request Sep 21, 2026
A backup's name starts with the file it came from, so `agentpet.json.…`
sorted before `settings.json.…` no matter how new it was — and the
moment a second integration backed a file up into the same directory,
the backup taken during that very call was the first one pruned and the
path the caller had just been handed was gone. Age now comes from the
filesystem, with the name only as a tiebreak inside one clock tick.

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
dncore added a commit that referenced this pull request Sep 21, 2026
An in-process extension names the session `sessionId`; the capture
allowlist only knew the hook spelling `session_id`, so an event spooled
while the app was down replayed under a process-derived name — a second
row beside the real one. Both spellings of the session id and the tool
name are now captured; the list stays hand-written for the reason its
comment gives (a profile's summaryField is the user's own prompt).

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
dncore added a commit that referenced this pull request Sep 21, 2026
An extension that spawns the shim from inside the agent's own runtime
writes to a pipe queued on an event loop the agent may be holding —
measured, 30 ms of a busy loop is enough for the shim's stdin deadline
to expire and the event to arrive with no session id. The shim now
reads AGENTPET_PAYLOAD_BASE64 first and falls back to stdin, so the
hook contract is untouched and an in-process reporter has nothing to
be late for.

Ported from #1; author CaffreySun.

Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
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.

2 participants