feat: add TypeScript preprocessing extension (v0.2.0) - #3
Conversation
Hooks Pi's input event to compress Korean /ko-* input to a tight English task via Haiku before the expensive model sees it. Delivers the core thesis: actual input-side token savings (40-65% typical) on every turn. - extension/index.ts — input + before_agent_start + agent_end hooks - extension/preprocessor.ts — Haiku compresses Korean → English via fetch - extension/postprocessor.ts — Haiku translator (wired up in v0.3) - extension/system-prompts.ts — compressor + translator system prompts - extension/token-estimator.ts — char-based estimation; opt-in dashboard - extension/config.ts — reads pi-ko.dashboard from Pi settings.json - tsconfig.json — editor-only TypeScript config - docs/extension.md — dashboard config, --ko-direct reference - CI/publish tarball allowlist updated for extension/ and tsconfig.json Output-side savings (expensive model → English → Haiku → Korean) require a post-streaming rewrite hook not yet in the Pi extension API; postprocessor is implemented and ready for v0.3.
23b9011 to
291e496
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23b9011820
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
|
|
||
| ctx.ui.setStatus("pi-ko", undefined); | ||
| return { action: "transform", text: result.compressed }; |
There was a problem hiding this comment.
Validate compressor output before rewriting the prompt
This transform is applied unconditionally, so if Haiku returns a malformed line (e.g., safety refusal, truncation, or any output that drops the /ko-* prefix), the original command is replaced anyway. In Pi's event order, input transforms run before prompt-template expansion, so losing the slash command causes the ko prompt template (and its safety constraints) to be skipped for that turn. Guard result.compressed with PIKO_PROMPT_RE (or similar schema checks) and fall back to event.text when validation fails.
Useful? React with 👍 / 👎.
|
|
||
| const langInstruction = state.direct | ||
| ? "\n\nIMPORTANT (pi-ko --ko-direct): Respond in Korean." | ||
| : "\n\nIMPORTANT (pi-ko): Respond in Korean. Preserve all code, paths, identifiers, log lines, and error messages verbatim in their original language."; |
There was a problem hiding this comment.
Respect explicit English response requests
This system-prompt injection forces Korean on every /ko-* turn, which overrides the templates' documented behavior of allowing English when the user explicitly asks for it. As a result, requests like “영어로 답해줘” are likely ignored after this change. The language override should be conditional on user intent (or at least avoid hard-forcing Korean when the input requests English).
Useful? React with 👍 / 👎.
Summary
inputevent to intercept every/ko-*turn and compress the Korean input to a tight English task via Haiku — before the expensive model sees it/ko-*turn--ko-directflag registered (reserved for v0.3 output pipeline)pi-ko.dashboard: truein Pi settingsextension/andtsconfig.jsonKnown gap: Full output-side savings (expensive model → English → Haiku → Korean) require a post-streaming rewrite hook not yet in the Pi extension API.
postprocessor.tsis written and wired up for v0.3 when the API supports it. In v0.2 the expensive model responds in Korean directly (same as v0.1), but receives compressed English input.New files
extension/index.tsinput+before_agent_start+agent_endhooksextension/preprocessor.tsextension/postprocessor.tsextension/system-prompts.tsextension/token-estimator.tsextension/config.tspi-ko.dashboardfrom Pi'ssettings.jsontsconfig.jsondocs/extension.md--ko-directreference, token methodologyTest plan
pi install -l ./pi-ko→pi listshows extension entry alongside prompts/skills/ko-review 이 PR 치명적인 버그 위주로만 봐줘. 스타일 지적은 빼고.— Pi verbose log shows compressed English input; response is Koreannpm pack --dry-run— tarball includesextension/,tsconfig.json, no unexpected filesbash scripts/lint.shpasses locallypi-ko.dashboard: truein~/.pi/agent/settings.json