Skip to content

feat: add TypeScript preprocessing extension (v0.2.0) - #3

Open
nathanhuh wants to merge 2 commits into
mainfrom
feat/v0.2.0-extension
Open

feat: add TypeScript preprocessing extension (v0.2.0)#3
nathanhuh wants to merge 2 commits into
mainfrom
feat/v0.2.0-extension

Conversation

@nathanhuh

@nathanhuh nathanhuh commented May 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a TypeScript extension that hooks Pi's input event to intercept every /ko-* turn and compress the Korean 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 /ko-* turn
  • --ko-direct flag registered (reserved for v0.3 output pipeline)
  • Opt-in token dashboard via pi-ko.dashboard: true in Pi settings
  • CI/publish tarball allowlist updated for extension/ and tsconfig.json

Known gap: Full output-side savings (expensive model → English → Haiku → Korean) require a post-streaming rewrite hook not yet in the Pi extension API. postprocessor.ts is 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

File Purpose
extension/index.ts Extension entry; input + before_agent_start + agent_end hooks
extension/preprocessor.ts Haiku compresses Korean → English via Anthropic API
extension/postprocessor.ts Haiku translator for v0.3 output pipeline
extension/system-prompts.ts Compressor + translator system prompts (mirrors v0.1 intent-mapping table)
extension/token-estimator.ts Char-based token estimation; dashboard formatter
extension/config.ts Reads pi-ko.dashboard from Pi's settings.json
tsconfig.json Editor-only TypeScript config
docs/extension.md Dashboard config, --ko-direct reference, token methodology

Test plan

  • pi install -l ./pi-kopi list shows extension entry alongside prompts/skills
  • /ko-review 이 PR 치명적인 버그 위주로만 봐줘. 스타일 지적은 빼고. — Pi verbose log shows compressed English input; response is Korean
  • npm pack --dry-run — tarball includes extension/, tsconfig.json, no unexpected files
  • bash scripts/lint.sh passes locally
  • Token dashboard renders after setting pi-ko.dashboard: true in ~/.pi/agent/settings.json
  • All v0.1 MVP test cases produce same observable Korean output (no intent-disambiguation regression)

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.
@nathanhuh
nathanhuh force-pushed the feat/v0.2.0-extension branch from 23b9011 to 291e496 Compare May 6, 2026 11:00

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment thread extension/index.ts
});

ctx.ui.setStatus("pi-ko", undefined);
return { action: "transform", text: result.compressed };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread extension/index.ts

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.";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

1 participant