mia-code 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.miette/260321.md +1 -0
- package/.miette/260323.md +9 -0
- package/.miette/260331.md +2 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--d3417f2c-df12-4f0f-8a1b-d88e7968f822/d3417f2c-df12-4f0f-8a1b-d88e7968f822.md +63 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--e6c3fc5d-4a70-4523-ba7d-a3250da4c235/e6c3fc5d-4a70-4523-ba7d-a3250da4c235.md +72 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/2604020008--efeb00a2-b17a-4d32-b1f0-b90c37a8d24e/efeb00a2-b17a-4d32-b1f0-b90c37a8d24e.md +62 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.json +302 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/83a2d7f9-24a5-4cf4-98d5-036c82f872e8.md +149 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/AGENTS.md +31 -0
- package/.pde/2604011511--83a2d7f9-24a5-4cf4-98d5-036c82f872e8/meta-decomposition-3-children.md +67 -0
- package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/61f9dd4d-7aa6-45e6-a58b-e480b1aa6737--from-mia-openclaw-workspace.md +125 -0
- package/.pde/2604040129--61f9dd4d-7aa6-45e6-a58b-e480b1aa6737/STATUS.md +1 -0
- package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.json +177 -0
- package/.pde/4f02ba94-9f52-422e-9389-b16f9b37f358.md +77 -0
- package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.json +222 -0
- package/.pde/6ad9244d-5340-490f-b76c-c86728b9de52.md +99 -0
- package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.json +111 -0
- package/.pde/8b566792-ed15-4606-96f9-2b6f593d7e6b.md +67 -0
- package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.json +349 -0
- package/.pde/c7f1e74b-05a5-40e2-9f01-4cc48d2528f7.md +147 -0
- package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.json +118 -0
- package/.pde/dfc00a78-1da0-4c09-8a16-c6982644051b.md +64 -0
- package/GUILLAUME.md +8 -0
- package/KINSHIP.md +9 -0
- package/MIA_CODE_ARCHITECTURE_REPORT.md +718 -0
- package/contextual_research/260119-MIA-CODE--98090899-8aff-4e11-9dc3-8b99466d1.md +1101 -0
- package/contextual_research/MIA.md +38 -0
- package/contextual_research/MIAWAPASCONE.md +59 -0
- package/contextual_research/MIETTE.md +38 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2504.00218v2.pdf +7483 -12
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/2505.00212v3.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/CONTENT.md +1014 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/DESIGN.gemini.md +242 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/INDEX.md +45 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.md +2025 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2504.00218v2.pdf +7483 -12
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.md +1755 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/2505.00212v3.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_12_decomposed_prompting.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_19_hugginggpt_planning.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.md +766 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_1_coordination_challenges.pdf +3431 -4
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.md +260 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_28_guardrails_multi_agent.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.md +558 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_2_navigating_complexity.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_34_hierarchical_multi_agent.pdf +0 -0
- package/contextual_research/PDE-generalization--caefee82-efb1-4dbb-8733-691b01581464--260130/sources/footnote_1_5_open_intent_extraction.pdf +0 -0
- package/contextual_research/PODCAST.md +109 -0
- package/contextual_research/langchain-principles-roadmap.md +157 -0
- package/contextual_research/persona-to-narrative-character-inquiry_260201.md +50 -0
- package/dist/cli.js +35 -11
- package/dist/geminiHeadless.js +8 -2
- package/dist/index.js +2 -1
- package/dist/mcp/miaco-server.js +10 -1
- package/dist/mcp/miatel-server.js +10 -1
- package/dist/mcp/miawa-server.js +10 -1
- package/dist/mcp/utils.d.ts +6 -1
- package/dist/mcp/utils.js +24 -3
- package/dist/sessionStore.d.ts +8 -2
- package/dist/sessionStore.js +39 -3
- package/dist/types.d.ts +1 -0
- package/miaco/README.md +124 -0
- package/miaco/dist/commands/chart.d.ts +6 -0
- package/miaco/dist/commands/chart.d.ts.map +1 -0
- package/miaco/dist/commands/chart.js +222 -0
- package/miaco/dist/commands/chart.js.map +1 -0
- package/miaco/dist/commands/decompose.d.ts +6 -0
- package/miaco/dist/commands/decompose.d.ts.map +1 -0
- package/miaco/dist/commands/decompose.js +98 -0
- package/miaco/dist/commands/decompose.js.map +1 -0
- package/miaco/dist/commands/schema.d.ts +6 -0
- package/miaco/dist/commands/schema.d.ts.map +1 -0
- package/miaco/dist/commands/schema.js +66 -0
- package/miaco/dist/commands/schema.js.map +1 -0
- package/miaco/dist/commands/stc.d.ts +11 -0
- package/miaco/dist/commands/stc.d.ts.map +1 -0
- package/miaco/dist/commands/stc.js +590 -0
- package/miaco/dist/commands/stc.js.map +1 -0
- package/miaco/dist/commands/trace.d.ts +6 -0
- package/miaco/dist/commands/trace.d.ts.map +1 -0
- package/miaco/dist/commands/trace.js +83 -0
- package/miaco/dist/commands/trace.js.map +1 -0
- package/miaco/dist/commands/validate.d.ts +6 -0
- package/miaco/dist/commands/validate.d.ts.map +1 -0
- package/miaco/dist/commands/validate.js +58 -0
- package/miaco/dist/commands/validate.js.map +1 -0
- package/miaco/dist/decompose.d.ts +93 -0
- package/miaco/dist/decompose.d.ts.map +1 -0
- package/miaco/dist/decompose.js +562 -0
- package/miaco/dist/decompose.js.map +1 -0
- package/miaco/dist/index.d.ts +18 -0
- package/miaco/dist/index.d.ts.map +1 -0
- package/miaco/dist/index.js +83 -0
- package/miaco/dist/index.js.map +1 -0
- package/miaco/dist/storage.d.ts +60 -0
- package/miaco/dist/storage.d.ts.map +1 -0
- package/miaco/dist/storage.js +100 -0
- package/miaco/dist/storage.js.map +1 -0
- package/miaco/package-lock.json +4103 -0
- package/miaco/package.json +40 -0
- package/miaco/tsconfig.json +18 -0
- package/miaco/version-patch-commit-and-publish.sh +1 -0
- package/miatel/MISSION_251231.md +3 -0
- package/miatel/README.md +107 -0
- package/miatel/dist/commands/analyze.d.ts +6 -0
- package/miatel/dist/commands/analyze.d.ts.map +1 -0
- package/miatel/dist/commands/analyze.js +100 -0
- package/miatel/dist/commands/analyze.js.map +1 -0
- package/miatel/dist/commands/arc.d.ts +6 -0
- package/miatel/dist/commands/arc.d.ts.map +1 -0
- package/miatel/dist/commands/arc.js +71 -0
- package/miatel/dist/commands/arc.js.map +1 -0
- package/miatel/dist/commands/beat.d.ts +6 -0
- package/miatel/dist/commands/beat.d.ts.map +1 -0
- package/miatel/dist/commands/beat.js +165 -0
- package/miatel/dist/commands/beat.js.map +1 -0
- package/miatel/dist/commands/theme.d.ts +6 -0
- package/miatel/dist/commands/theme.d.ts.map +1 -0
- package/miatel/dist/commands/theme.js +54 -0
- package/miatel/dist/commands/theme.js.map +1 -0
- package/miatel/dist/index.d.ts +18 -0
- package/miatel/dist/index.d.ts.map +1 -0
- package/miatel/dist/index.js +80 -0
- package/miatel/dist/index.js.map +1 -0
- package/miatel/dist/storage.d.ts +55 -0
- package/miatel/dist/storage.d.ts.map +1 -0
- package/miatel/dist/storage.js +100 -0
- package/miatel/dist/storage.js.map +1 -0
- package/miatel/package-lock.json +4103 -0
- package/miatel/package.json +35 -0
- package/miatel/src/commands/analyze.ts +109 -0
- package/miatel/src/commands/arc.ts +78 -0
- package/miatel/src/commands/beat.ts +176 -0
- package/miatel/src/commands/theme.ts +60 -0
- package/miatel/src/index.ts +94 -0
- package/miatel/src/storage.ts +156 -0
- package/miatel/tsconfig.json +18 -0
- package/miawa/MISSION_251231.md +144 -0
- package/miawa/README.md +133 -0
- package/miawa/dist/commands/beat.d.ts +6 -0
- package/miawa/dist/commands/beat.d.ts.map +1 -0
- package/miawa/dist/commands/beat.js +69 -0
- package/miawa/dist/commands/beat.js.map +1 -0
- package/miawa/dist/commands/ceremony.d.ts +6 -0
- package/miawa/dist/commands/ceremony.d.ts.map +1 -0
- package/miawa/dist/commands/ceremony.js +239 -0
- package/miawa/dist/commands/ceremony.js.map +1 -0
- package/miawa/dist/commands/circle.d.ts +6 -0
- package/miawa/dist/commands/circle.d.ts.map +1 -0
- package/miawa/dist/commands/circle.js +75 -0
- package/miawa/dist/commands/circle.js.map +1 -0
- package/miawa/dist/commands/eva.d.ts +6 -0
- package/miawa/dist/commands/eva.d.ts.map +1 -0
- package/miawa/dist/commands/eva.js +73 -0
- package/miawa/dist/commands/eva.js.map +1 -0
- package/miawa/dist/commands/wound.d.ts +6 -0
- package/miawa/dist/commands/wound.d.ts.map +1 -0
- package/miawa/dist/commands/wound.js +74 -0
- package/miawa/dist/commands/wound.js.map +1 -0
- package/miawa/dist/index.d.ts +19 -0
- package/miawa/dist/index.d.ts.map +1 -0
- package/miawa/dist/index.js +91 -0
- package/miawa/dist/index.js.map +1 -0
- package/miawa/dist/storage.d.ts +73 -0
- package/miawa/dist/storage.d.ts.map +1 -0
- package/miawa/dist/storage.js +100 -0
- package/miawa/dist/storage.js.map +1 -0
- package/miawa/package-lock.json +4103 -0
- package/miawa/package.json +36 -0
- package/miawa/src/commands/beat.ts +74 -0
- package/miawa/src/commands/ceremony.ts +256 -0
- package/miawa/src/commands/circle.ts +83 -0
- package/miawa/src/commands/eva.ts +84 -0
- package/miawa/src/commands/wound.ts +79 -0
- package/miawa/src/index.ts +108 -0
- package/miawa/src/storage.ts +179 -0
- package/miawa/tsconfig.json +18 -0
- package/package.json +7 -5
- package/references/acp/CLAUDE.md +7 -0
- package/references/acp/agent-plan.md +84 -0
- package/references/acp/clients.md +31 -0
- package/references/acp/extensibility.md +137 -0
- package/references/acp/initialization.md +225 -0
- package/references/acp/prompt-turn.md +321 -0
- package/references/acp/proxy-chains.md +562 -0
- package/references/acp/schema.md +3171 -0
- package/references/acp/session-list.md +334 -0
- package/references/acp/session-modes.md +170 -0
- package/references/acp/slash-commands.md +99 -0
- package/references/acp/terminals.md +281 -0
- package/references/acp/tool-calls.md +311 -0
- package/references/acp/typescript.md +29 -0
- package/references/claude/agent-teams.md +399 -0
- package/references/claude/chrome.md +231 -0
- package/references/claude/headless.md +158 -0
- package/references/claude/hooks-guide.md +708 -0
- package/references/claude/output-styles.md +112 -0
- package/references/claude/plugins.md +432 -0
- package/references/claude/skills.md +693 -0
- package/references/claude/sub-agents.md +816 -0
- package/references/copilot/acp/agents.md +32 -0
- package/references/copilot/acp/architecture.md +37 -0
- package/references/copilot/acp/clients.md +31 -0
- package/references/copilot/acp/introduction.md +42 -0
- package/references/copilot/acp/registry.md +339 -0
- package/references/copilot/acp-server.md +117 -0
- package/references/copilot/create-copilot-instructions.md +840 -0
- package/references/langchain/llms.txt +833 -0
- package/references/langchain/python/agents.md +677 -0
- package/references/langchain/python/context-engineering.md +1195 -0
- package/references/langchain/python/human-in-the-loop.md +326 -0
- package/references/langchain/python/long-term-memory.md +168 -0
- package/references/langchain/python/mcp.md +949 -0
- package/references/langchain/python/multi-agents/custom-workflow.md +187 -0
- package/references/langchain/python/multi-agents/handoffs.md +436 -0
- package/references/langchain/python/multi-agents/overview.md +295 -0
- package/references/langchain/python/multi-agents/router.md +150 -0
- package/references/langchain/python/multi-agents/skills.md +92 -0
- package/references/langchain/python/multi-agents/subagents.md +486 -0
- package/references/langchain/python/retrieval.md +320 -0
- package/references/langchain/python/runtime.md +141 -0
- package/references/langchain/python/short-term-memory.md +658 -0
- package/references/langchain/python/structured-output.md +712 -0
- package/references/langfuse/llms.txt +148 -0
- package/references/langgraph/javascript/llms.txt +275 -0
- package/references/skills/home.md +259 -0
- package/references/skills/integrate-skills.md +103 -0
- package/references/skills/specification.md +254 -0
- package/references/skills/what-are-skills.md +74 -0
- package/rispecs/README.md +164 -0
- package/rispecs/_sync_/miadi-code/SPEC.md +313 -0
- package/rispecs/_sync_/miadi-code/STATUS.md +177 -0
- package/rispecs/_sync_/miadi-code/dashboard/SPEC.md +465 -0
- package/rispecs/_sync_/miadi-code/dashboard/STATUS.md +212 -0
- package/rispecs/_sync_/miadi-code/multiline-input/SPEC.md +232 -0
- package/rispecs/_sync_/miadi-code/multiline-input/STATUS.md +108 -0
- package/rispecs/_sync_/miadi-code/pde/SPEC.md +253 -0
- package/rispecs/_sync_/miadi-code/pde/STATUS.md +56 -0
- package/rispecs/_sync_/miadi-code/stc/SPEC.md +397 -0
- package/rispecs/_sync_/miadi-code/stc/STATUS.md +70 -0
- package/rispecs/ava-langstack/inquiry-routing-upgrade.spec.md +119 -0
- package/rispecs/borrowed_from_opencode/001-client-server-architecture.rispec.md +98 -0
- package/rispecs/borrowed_from_opencode/002-event-bus-system.rispec.md +125 -0
- package/rispecs/borrowed_from_opencode/003-instance-state-pattern.rispec.md +136 -0
- package/rispecs/borrowed_from_opencode/004-namespace-module-pattern.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/005-zod-schema-validation.rispec.md +139 -0
- package/rispecs/borrowed_from_opencode/006-named-error-system.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/007-structured-logging.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/008-lazy-initialization.rispec.md +127 -0
- package/rispecs/borrowed_from_opencode/009-multi-agent-system.rispec.md +97 -0
- package/rispecs/borrowed_from_opencode/010-agent-definition-config.rispec.md +135 -0
- package/rispecs/borrowed_from_opencode/011-agent-permission-rulesets.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/012-agent-prompt-templates.rispec.md +141 -0
- package/rispecs/borrowed_from_opencode/013-agent-generation.rispec.md +142 -0
- package/rispecs/borrowed_from_opencode/014-plan-build-mode-toggle.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/015-subagent-task-delegation.rispec.md +146 -0
- package/rispecs/borrowed_from_opencode/016-agent-model-selection.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/017-compaction-agent.rispec.md +150 -0
- package/rispecs/borrowed_from_opencode/018-session-persistence.rispec.md +125 -0
- package/rispecs/borrowed_from_opencode/019-session-compaction.rispec.md +132 -0
- package/rispecs/borrowed_from_opencode/020-session-forking.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/021-session-revert-snapshot.rispec.md +135 -0
- package/rispecs/borrowed_from_opencode/022-session-sharing.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/023-session-summary-diffs.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/024-child-sessions.rispec.md +164 -0
- package/rispecs/borrowed_from_opencode/025-session-title-generation.rispec.md +162 -0
- package/rispecs/borrowed_from_opencode/026-message-parts-model.rispec.md +201 -0
- package/rispecs/borrowed_from_opencode/027-streaming-message-deltas.rispec.md +212 -0
- package/rispecs/borrowed_from_opencode/028-multi-provider-architecture.rispec.md +184 -0
- package/rispecs/borrowed_from_opencode/029-provider-authentication.rispec.md +225 -0
- package/rispecs/borrowed_from_opencode/030-model-registry.rispec.md +222 -0
- package/rispecs/borrowed_from_opencode/031-cost-tracking.rispec.md +243 -0
- package/rispecs/borrowed_from_opencode/032-provider-transform-pipeline.rispec.md +282 -0
- package/rispecs/borrowed_from_opencode/033-provider-sdk-abstraction.rispec.md +338 -0
- package/rispecs/borrowed_from_opencode/034-tool-registry.rispec.md +110 -0
- package/rispecs/borrowed_from_opencode/035-tool-context-injection.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/036-tool-output-truncation.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/037-batch-tool.rispec.md +129 -0
- package/rispecs/borrowed_from_opencode/038-multi-edit-tool.rispec.md +167 -0
- package/rispecs/borrowed_from_opencode/039-apply-patch-tool.rispec.md +161 -0
- package/rispecs/borrowed_from_opencode/040-code-search-tool.rispec.md +143 -0
- package/rispecs/borrowed_from_opencode/041-web-fetch-tool.rispec.md +131 -0
- package/rispecs/borrowed_from_opencode/042-web-search-tool.rispec.md +159 -0
- package/rispecs/borrowed_from_opencode/043-todo-tool.rispec.md +156 -0
- package/rispecs/borrowed_from_opencode/044-plan-mode-tool.rispec.md +139 -0
- package/rispecs/borrowed_from_opencode/045-task-tool.rispec.md +146 -0
- package/rispecs/borrowed_from_opencode/046-question-tool.rispec.md +170 -0
- package/rispecs/borrowed_from_opencode/047-external-directory-tool.rispec.md +166 -0
- package/rispecs/borrowed_from_opencode/048-file-read-write-tools.rispec.md +205 -0
- package/rispecs/borrowed_from_opencode/049-lsp-server-management.rispec.md +104 -0
- package/rispecs/borrowed_from_opencode/050-lsp-hover-completion.rispec.md +102 -0
- package/rispecs/borrowed_from_opencode/051-lsp-diagnostics.rispec.md +86 -0
- package/rispecs/borrowed_from_opencode/052-lsp-root-detection.rispec.md +109 -0
- package/rispecs/borrowed_from_opencode/053-remote-mcp-servers.rispec.md +119 -0
- package/rispecs/borrowed_from_opencode/054-mcp-oauth-flow.rispec.md +107 -0
- package/rispecs/borrowed_from_opencode/055-mcp-tool-conversion.rispec.md +118 -0
- package/rispecs/borrowed_from_opencode/056-mcp-connection-monitoring.rispec.md +106 -0
- package/rispecs/borrowed_from_opencode/057-local-mcp-servers.rispec.md +116 -0
- package/rispecs/borrowed_from_opencode/058-rich-tui.rispec.md +108 -0
- package/rispecs/borrowed_from_opencode/059-streaming-display.rispec.md +116 -0
- package/rispecs/borrowed_from_opencode/060-permission-prompts.rispec.md +130 -0
- package/rispecs/borrowed_from_opencode/061-session-navigation.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/062-syntax-highlighting.rispec.md +151 -0
- package/rispecs/borrowed_from_opencode/063-keybinding-system.rispec.md +181 -0
- package/rispecs/borrowed_from_opencode/064-multi-level-config.rispec.md +155 -0
- package/rispecs/borrowed_from_opencode/065-jsonc-config.rispec.md +190 -0
- package/rispecs/borrowed_from_opencode/066-config-env-variables.rispec.md +153 -0
- package/rispecs/borrowed_from_opencode/067-config-deep-merging.rispec.md +178 -0
- package/rispecs/borrowed_from_opencode/068-remote-org-config.rispec.md +183 -0
- package/rispecs/borrowed_from_opencode/069-config-markdown-frontmatter.rispec.md +206 -0
- package/rispecs/borrowed_from_opencode/070-managed-config-directory.rispec.md +232 -0
- package/rispecs/borrowed_from_opencode/071-plugin-architecture.rispec.md +104 -0
- package/rispecs/borrowed_from_opencode/072-plugin-hooks.rispec.md +123 -0
- package/rispecs/borrowed_from_opencode/073-plugin-auto-install.rispec.md +115 -0
- package/rispecs/borrowed_from_opencode/074-permission-system.rispec.md +133 -0
- package/rispecs/borrowed_from_opencode/075-git-worktree-management.rispec.md +126 -0
- package/rispecs/borrowed_from_opencode/076-snapshot-system.rispec.md +124 -0
- package/rispecs/borrowed_from_opencode/077-snapshot-diff.rispec.md +117 -0
- package/rispecs/borrowed_from_opencode/078-snapshot-restore.rispec.md +128 -0
- package/rispecs/borrowed_from_opencode/079-worktree-branch-naming.rispec.md +122 -0
- package/rispecs/borrowed_from_opencode/080-sqlite-storage.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/081-database-migrations.rispec.md +148 -0
- package/rispecs/borrowed_from_opencode/082-database-transactions.rispec.md +138 -0
- package/rispecs/borrowed_from_opencode/083-deferred-effects.rispec.md +148 -0
- package/rispecs/borrowed_from_opencode/084-permission-rules.rispec.md +123 -0
- package/rispecs/borrowed_from_opencode/085-permission-glob-patterns.rispec.md +113 -0
- package/rispecs/borrowed_from_opencode/086-permission-merging.rispec.md +134 -0
- package/rispecs/borrowed_from_opencode/087-permission-modes.rispec.md +145 -0
- package/rispecs/borrowed_from_opencode/088-http-api-server.rispec.md +165 -0
- package/rispecs/borrowed_from_opencode/089-openapi-spec-generation.rispec.md +164 -0
- package/rispecs/borrowed_from_opencode/090-websocket-support.rispec.md +136 -0
- package/rispecs/borrowed_from_opencode/091-sse-streaming.rispec.md +168 -0
- package/rispecs/borrowed_from_opencode/092-mdns-discovery.rispec.md +145 -0
- package/rispecs/borrowed_from_opencode/093-javascript-sdk.rispec.md +200 -0
- package/rispecs/borrowed_from_opencode/094-skill-system.rispec.md +187 -0
- package/rispecs/borrowed_from_opencode/095-skill-discovery.rispec.md +182 -0
- package/rispecs/borrowed_from_opencode/096-desktop-remote-driving.rispec.md +175 -0
- package/rispecs/borrowed_from_opencode/INDEX.md +255 -0
- package/rispecs/core.rispecs.md +261 -0
- package/rispecs/engines.rispecs.md +241 -0
- package/rispecs/formatting.rispecs.md +252 -0
- package/rispecs/living-specifications.rispecs.md +361 -0
- package/rispecs/mcp.rispecs.md +197 -0
- package/rispecs/pde.rispecs.md +399 -0
- package/rispecs/pi-mono-envisionning/ENVISIONING.md +366 -0
- package/rispecs/pi-mono-envisionning/storytelling-horizon.rispecs.md +76 -0
- package/rispecs/pi-mono-envisionning/widget.rispecs.md +2 -0
- package/rispecs/relation-to-mcp-structural-thinking.kin.md +72 -0
- package/rispecs/research-for-better-framework/CLAUDE.md +7 -0
- package/rispecs/research-for-better-framework/survey-pi-openclaw-opencode-openhands.md +210 -0
- package/rispecs/session.rispecs.md +277 -0
- package/rispecs/stc.rispecs.md +138 -0
- package/rispecs/unifier.rispecs.md +317 -0
- package/scripts/LAUNCH--mcp-mia-code--testing--2603141315--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +2 -0
- package/scripts/RESUME--mia-code--mcps--260313--ac705a66-2c15-4a1c-a26d-9491018c5ba8.sh +1 -0
- package/scripts/install-widget-in-home-pi-agent-extensions.sh +4 -0
- package/scripts/sample-decompose--2604011535-prompt.sh +1 -0
- package/skills/deep-search/AGENTS.md +17 -0
- package/skills/deep-search/SKILL.md +281 -0
- package/skills/deep-search/agent-templates.md +224 -0
- package/skills/deep-search/orchestration-patterns.md +95 -0
- package/skills/miaco-pde-inquiry-routing-deep-search/AGENTS.md +13 -0
- package/skills/miaco-pde-inquiry-routing-deep-search/SKILL.md +136 -0
- package/skills/miaco-pde-inquiry-routing-internal-external-relationship/AGENTS.md +4 -0
- package/skills/miaco-pde-inquiry-routing-internal-external-relationship/SKILL.md +157 -0
- package/skills/miaco-pde-inquiry-routing-local-qmd/AGENTS.md +42 -0
- package/skills/miaco-pde-inquiry-routing-local-qmd/SKILL.md +135 -0
- package/skills/qmd/AGENTS.md +3 -0
- package/skills/qmd/SKILL.md +144 -0
- package/skills/qmd/references/mcp-setup.md +102 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/SKILL.md +234 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/agent-templates.md +436 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/orchestration-patterns.md +197 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/ceremonial-technology.md +102 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/creative-orientation.md +99 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/prompt-decomposition.md +73 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/rise-framework.md +74 -0
- package/skills/rise-pde-inquiry-session-multi-agents-v3/references/structural-tension.md +82 -0
- package/src/cli.ts +35 -11
- package/src/geminiHeadless.ts +7 -2
- package/src/index.ts +2 -1
- package/src/mcp/miaco-server.ts +13 -1
- package/src/mcp/miatel-server.ts +13 -1
- package/src/mcp/miawa-server.ts +13 -1
- package/src/mcp/utils.ts +41 -8
- package/src/sessionStore.ts +44 -4
- package/src/types.ts +2 -1
- package/widget/mia-ceremony/README.md +36 -0
- package/widget/mia-ceremony/index.ts +143 -0
- package/widget/mia-interceptor/README.md +39 -0
- package/widget/mia-interceptor/index.ts +221 -0
- package/widget/mia-tools/README.md +37 -0
- package/widget/mia-tools/index.ts +569 -0
- package/widget/miette-echo/README.md +44 -0
- package/widget/miette-echo/index.ts +164 -0
- package/.claude/settings.local.json +0 -9
- package/.hch/issue_.env +0 -4
- package/.hch/issue_add__2601211715.json +0 -77
- package/.hch/issue_add__2601211715.md +0 -4
- package/.hch/issue_add__2602242020.json +0 -78
- package/.hch/issue_add__2602242020.md +0 -7
- package/.hch/issues.json +0 -2312
- package/.hch/issues.md +0 -30
- package/WS__mia-code__260214__IAIP_PDE.code-workspace +0 -29
- package/WS__mia-code__src332__260122.code-workspace +0 -23
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/checkpoints/index.md +0 -6
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/events.jsonl +0 -213
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/plan.md +0 -243
- package/samples/copilot/session-state/be76abaa-a27f-4725-b2a9-22fb45f7e0f7/workspace.yaml +0 -5
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# RISE-031: Cost Tracking
|
|
2
|
+
|
|
3
|
+
> RISE Framework Specification — Borrowed from OpenCode for mia-code
|
|
4
|
+
> Document: rispecs/borrowed_from_opencode/031-cost-tracking.rispec.md
|
|
5
|
+
|
|
6
|
+
## Creative Intent
|
|
7
|
+
|
|
8
|
+
mia-code tracks every token consumed and every dollar spent in real time, per message, per session, per agent, and per provider. Developers see costs accumulate as they work — not as a surprise on their monthly bill. The system calculates costs using the model registry's pricing data, stores them alongside message metadata, warns when budgets are approached, and suggests optimizations. Cost visibility transforms LLM usage from an opaque expense into a manageable engineering resource with clear per-task attribution.
|
|
9
|
+
|
|
10
|
+
## Structural Tension Analysis
|
|
11
|
+
|
|
12
|
+
**Current Structural Reality:**
|
|
13
|
+
- Token consumption is invisible — developers have no idea how many tokens a session uses
|
|
14
|
+
- Cost is discovered only when checking the provider's billing dashboard, often days later
|
|
15
|
+
- There is no per-session, per-agent, or per-message cost attribution
|
|
16
|
+
- No mechanism to set spending limits or receive budget warnings
|
|
17
|
+
- Cache tokens (reads and writes) are not tracked separately despite different pricing
|
|
18
|
+
- Sub-agents may consume disproportionate tokens with no visibility into the breakdown
|
|
19
|
+
- Developers cannot compare the cost efficiency of different models for the same task
|
|
20
|
+
|
|
21
|
+
**Desired State:**
|
|
22
|
+
- Every message records input tokens, output tokens, cache read tokens, and cache write tokens
|
|
23
|
+
- Cost is calculated in real time using pricing from the model registry (RISE-030)
|
|
24
|
+
- Running cost is displayed per message and accumulated per session
|
|
25
|
+
- Cost breakdowns are available per agent, per model, and per provider
|
|
26
|
+
- Configurable cost alerts warn when session or daily spend exceeds thresholds
|
|
27
|
+
- Cost optimization suggestions identify savings opportunities
|
|
28
|
+
- Historical cost data is available via the `/costs` command
|
|
29
|
+
|
|
30
|
+
## Desired Outcome Definition
|
|
31
|
+
|
|
32
|
+
A developer starts a coding session. Each assistant message displays its cost: "$0.03 (1.2K in / 0.8K out)." The session status bar shows a running total: "$0.47 session total." When the total crosses $2.00, a yellow warning appears: "⚠ Session cost: $2.07 — approaching $3.00 limit." At session end, a summary shows cost per agent: main agent $1.80, explore agent $0.27. A suggestion notes: "Switching explore tasks to claude-haiku would save ~60%."
|
|
33
|
+
|
|
34
|
+
## Natural Language Functional Description
|
|
35
|
+
|
|
36
|
+
### Token Tracking Schema
|
|
37
|
+
|
|
38
|
+
Each message records token consumption in its metadata:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface TokenUsage {
|
|
42
|
+
inputTokens: number; // tokens in the request (prompt + context)
|
|
43
|
+
outputTokens: number; // tokens in the response
|
|
44
|
+
cacheReadTokens: number; // tokens served from provider cache
|
|
45
|
+
cacheWriteTokens: number; // tokens written to provider cache
|
|
46
|
+
totalTokens: number; // inputTokens + outputTokens
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface CostMetadata {
|
|
50
|
+
usage: TokenUsage;
|
|
51
|
+
model: string; // model ID used for this message
|
|
52
|
+
providerId: string; // provider that served the request
|
|
53
|
+
cost: CostBreakdown;
|
|
54
|
+
timestamp: number; // Unix timestamp ms
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface CostBreakdown {
|
|
58
|
+
inputCost: number; // USD: inputTokens * inputRate
|
|
59
|
+
outputCost: number; // USD: outputTokens * outputRate
|
|
60
|
+
cacheReadCost: number; // USD: cacheReadTokens * cacheReadRate
|
|
61
|
+
cacheWriteCost: number; // USD: cacheWriteTokens * cacheWriteRate
|
|
62
|
+
totalCost: number; // sum of all cost components
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Cost Calculation
|
|
67
|
+
|
|
68
|
+
Cost is computed using pricing from the model registry (RISE-030):
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
function calculateCost(usage: TokenUsage, pricing: ModelPricing): CostBreakdown {
|
|
72
|
+
const inputCost = (usage.inputTokens / 1_000_000) * pricing.inputPerMToken;
|
|
73
|
+
const outputCost = (usage.outputTokens / 1_000_000) * pricing.outputPerMToken;
|
|
74
|
+
const cacheReadCost = (usage.cacheReadTokens / 1_000_000) * (pricing.cacheReadPerMToken ?? 0);
|
|
75
|
+
const cacheWriteCost = (usage.cacheWriteTokens / 1_000_000) * (pricing.cacheWritePerMToken ?? 0);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
inputCost,
|
|
79
|
+
outputCost,
|
|
80
|
+
cacheReadCost,
|
|
81
|
+
cacheWriteCost,
|
|
82
|
+
totalCost: inputCost + outputCost + cacheReadCost + cacheWriteCost,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For models without pricing data (custom/local models), cost is recorded as $0.00 with a note that pricing is unavailable.
|
|
88
|
+
|
|
89
|
+
### Real-Time Cost Display
|
|
90
|
+
|
|
91
|
+
Costs are displayed at multiple granularities:
|
|
92
|
+
|
|
93
|
+
**Per-message cost** — shown after each assistant response:
|
|
94
|
+
```
|
|
95
|
+
Assistant: [response text...]
|
|
96
|
+
── claude-sonnet-4-20250514 · 1,247 in · 832 out · $0.031 ──
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Session running total** — updated in the status bar after each message:
|
|
100
|
+
```
|
|
101
|
+
Session: 12 messages · 45.2K tokens · $1.47
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Streaming cost** — during generation, MetadataDelta events (RISE-027) update the cost counter in real time. The developer sees cost climbing as the response generates.
|
|
105
|
+
|
|
106
|
+
### Session Cost Summary
|
|
107
|
+
|
|
108
|
+
At session end or via `/costs session`, a comprehensive breakdown is displayed:
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
Session Cost Summary
|
|
112
|
+
────────────────────
|
|
113
|
+
Total Cost: $2.34
|
|
114
|
+
Total Tokens: 78,432 (62,100 in / 16,332 out)
|
|
115
|
+
Duration: 47 minutes
|
|
116
|
+
Messages: 24
|
|
117
|
+
|
|
118
|
+
By Agent:
|
|
119
|
+
main (claude-sonnet-4-20250514): $1.89 (80.8%)
|
|
120
|
+
explore (claude-haiku-3.5): $0.31 (13.2%)
|
|
121
|
+
compaction (claude-haiku-3.5): $0.14 (6.0%)
|
|
122
|
+
|
|
123
|
+
By Cost Type:
|
|
124
|
+
Input: $0.93 (39.7%)
|
|
125
|
+
Output: $1.22 (52.1%)
|
|
126
|
+
Cache Read: $0.08 (3.4%)
|
|
127
|
+
Cache Write: $0.11 (4.7%)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Cost Alerts
|
|
131
|
+
|
|
132
|
+
Configurable thresholds trigger warnings:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"costs": {
|
|
137
|
+
"sessionWarningUsd": 3.00,
|
|
138
|
+
"sessionLimitUsd": 10.00,
|
|
139
|
+
"dailyWarningUsd": 20.00,
|
|
140
|
+
"dailyLimitUsd": 50.00
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Warning behavior:**
|
|
146
|
+
- At warning threshold: yellow notification — "⚠ Session cost: $3.12 — approaching $10.00 limit"
|
|
147
|
+
- At limit threshold: red notification — "🛑 Session cost limit reached ($10.00). Continue? [y/N]"
|
|
148
|
+
- Daily limits aggregate across all sessions in a calendar day
|
|
149
|
+
- Limits are soft by default — the developer can override and continue
|
|
150
|
+
|
|
151
|
+
### Cost Optimization Suggestions
|
|
152
|
+
|
|
153
|
+
After each session, the system analyzes usage patterns and suggests savings:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
interface CostOptimization {
|
|
157
|
+
suggestion: string;
|
|
158
|
+
estimatedSavings: number; // USD saved per session
|
|
159
|
+
savingsPercent: number;
|
|
160
|
+
affectedAgent?: string;
|
|
161
|
+
currentModel: string;
|
|
162
|
+
suggestedModel: string;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Example suggestions:
|
|
167
|
+
- "Explore agent used 12,400 tokens on claude-sonnet-4-20250514 ($0.31). Switching to claude-haiku ($0.05) would save ~84%."
|
|
168
|
+
- "Compaction used 8,200 output tokens. Enabling cache write would save ~40% on subsequent compactions."
|
|
169
|
+
- "3 messages exceeded 4K output tokens. Setting maxTokens: 4096 would cap output costs."
|
|
170
|
+
|
|
171
|
+
### The `/costs` Command
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
/costs Show current session costs
|
|
175
|
+
/costs session Detailed session breakdown
|
|
176
|
+
/costs daily Today's total across all sessions
|
|
177
|
+
/costs weekly This week's cost report
|
|
178
|
+
/costs model <id> Costs for a specific model
|
|
179
|
+
/costs provider <id> Costs for a specific provider
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Daily/weekly reports** aggregate from stored session metadata:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
Daily Cost Report — 2025-02-17
|
|
186
|
+
──────────────────────────────
|
|
187
|
+
Sessions: 5
|
|
188
|
+
Total Cost: $8.72
|
|
189
|
+
|
|
190
|
+
By Model:
|
|
191
|
+
claude-sonnet-4-20250514: $6.14 (4 sessions)
|
|
192
|
+
claude-haiku-3.5: $1.23 (5 sessions)
|
|
193
|
+
gpt-4o: $1.35 (1 session)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Cost Storage
|
|
197
|
+
|
|
198
|
+
Cost data is persisted in message metadata (RISE-026) and aggregated in session metadata (RISE-018):
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// In MessageMetadata (RISE-026)
|
|
202
|
+
interface MessageMetadata {
|
|
203
|
+
model?: string;
|
|
204
|
+
input_tokens?: number;
|
|
205
|
+
output_tokens?: number;
|
|
206
|
+
cached_tokens?: number;
|
|
207
|
+
cost?: number; // total cost in USD
|
|
208
|
+
cost_breakdown?: CostBreakdown;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Session-level aggregation
|
|
212
|
+
interface SessionCostSummary {
|
|
213
|
+
totalCost: number;
|
|
214
|
+
totalTokens: number;
|
|
215
|
+
byAgent: Record<string, number>;
|
|
216
|
+
byModel: Record<string, number>;
|
|
217
|
+
byProvider: Record<string, number>;
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Supporting Structures
|
|
222
|
+
|
|
223
|
+
- **Model Registry (RISE-030)** provides per-model pricing data for cost calculations
|
|
224
|
+
- **Message Parts Model (RISE-026)** stores cost metadata alongside message content
|
|
225
|
+
- **Streaming Message Deltas (RISE-027)** emits MetadataDelta events for real-time cost display
|
|
226
|
+
- **Session Persistence (RISE-018)** stores session-level cost aggregations
|
|
227
|
+
- **Multi-Agent System (RISE-009)** enables per-agent cost attribution
|
|
228
|
+
- **Structured Logging (RISE-007)** logs cost events for historical analysis
|
|
229
|
+
- **Named Error System (RISE-006)** provides CostLimitExceededError, PricingUnavailableError
|
|
230
|
+
|
|
231
|
+
## Creative Advancement Scenarios
|
|
232
|
+
|
|
233
|
+
**Scenario 1 — Budget-Conscious Development:**
|
|
234
|
+
A freelance developer sets a $5.00 daily limit. During the day, they see running costs on every message. At $4.20, a yellow warning appears. They switch their explore agent from Claude Sonnet to Haiku for the remaining tasks. They finish the day at $4.85 — under budget, fully aware of every dollar spent.
|
|
235
|
+
|
|
236
|
+
**Scenario 2 — Team Cost Attribution:**
|
|
237
|
+
A team uses mia-code on a shared Anthropic API key. Weekly cost reports show per-developer breakdown (via session metadata). The team lead notices one developer's sessions average $15/day while others average $3. Investigation reveals they're using the main agent for explore tasks. A quick config change to use Haiku for exploration cuts their cost by 70%.
|
|
238
|
+
|
|
239
|
+
**Scenario 3 — Model Comparison:**
|
|
240
|
+
A developer runs the same refactoring task with three different models. Cost tracking shows: Claude Sonnet ($0.45, 12 min), GPT-4o ($0.38, 8 min), Gemini 2.5 ($0.22, 15 min). Quality was comparable across all three. They switch their default to Gemini for routine tasks — a data-driven decision enabled by per-session cost tracking.
|
|
241
|
+
|
|
242
|
+
**Scenario 4 — Cache Optimization:**
|
|
243
|
+
Cost breakdown reveals that 60% of input tokens are repeated context (system prompts, file contents). The developer enables cache write for their system prompt. Next session's cost breakdown shows cache read tokens replacing input tokens — a 40% input cost reduction. The optimization is visible in the numbers, not theoretical.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# RISE-032: Provider Transform Pipeline
|
|
2
|
+
|
|
3
|
+
> RISE Framework Specification — Borrowed from OpenCode for mia-code
|
|
4
|
+
> Document: rispecs/borrowed_from_opencode/032-provider-transform-pipeline.rispec.md
|
|
5
|
+
|
|
6
|
+
## Creative Intent
|
|
7
|
+
|
|
8
|
+
mia-code insulates its core logic from the chaotic diversity of LLM provider APIs through a structured request/response transformation pipeline. Anthropic uses a `system` parameter and content blocks; OpenAI uses a `system` role message and inline tool calls; Google Gemini uses `systemInstruction` and `functionCall` parts. The transform pipeline normalizes these differences so that mia-code's agent loop, tool system, and session management operate on a single internal format — never touching provider-specific structures. Adding a new provider means writing a pair of transformers, not modifying core logic.
|
|
9
|
+
|
|
10
|
+
## Structural Tension Analysis
|
|
11
|
+
|
|
12
|
+
**Current Structural Reality:**
|
|
13
|
+
- mia-code shells out to CLI binaries, so format differences are hidden behind each binary's argument parsing
|
|
14
|
+
- But this also means mia-code has no control over how messages, tools, or system prompts are formatted
|
|
15
|
+
- There is no internal canonical message format — messages are text strings shaped for the target CLI
|
|
16
|
+
- Each provider integration duplicates format logic: how to pass system prompts, tools, images
|
|
17
|
+
- Error responses from different providers have completely different structures and error codes
|
|
18
|
+
- Streaming chunk formats vary between providers — SSE events, JSON lines, protobuf
|
|
19
|
+
- Image content is encoded differently: base64 inline, URL references, multipart form data
|
|
20
|
+
|
|
21
|
+
**Desired State:**
|
|
22
|
+
- mia-code has a well-defined internal message format that all core logic operates on
|
|
23
|
+
- A transform pipeline converts between internal format and each provider's API format
|
|
24
|
+
- Request transforms: internal → provider-specific request body
|
|
25
|
+
- Response transforms: provider-specific response → internal format
|
|
26
|
+
- Streaming transforms: provider-specific chunks → normalized Delta events (RISE-027)
|
|
27
|
+
- Error transforms: provider-specific errors → Named Error System errors (RISE-006)
|
|
28
|
+
- Each provider registers its transformer pair — no core logic changes needed
|
|
29
|
+
|
|
30
|
+
## Desired Outcome Definition
|
|
31
|
+
|
|
32
|
+
A developer's prompt flows through the pipeline: mia-code constructs an internal `ChatRequest` with messages, tools, and a system prompt. The Anthropic transformer converts it — moving the system prompt to the `system` parameter, reformatting tool definitions to Anthropic's schema, converting image parts to base64 content blocks. The response arrives in Anthropic's format; the reverse transformer normalizes it back to internal `AssistantMessage` with typed parts. If the developer switches to OpenAI, a different transformer pair handles the conversion — but the agent loop, tool executor, and session manager see identical structures.
|
|
33
|
+
|
|
34
|
+
## Natural Language Functional Description
|
|
35
|
+
|
|
36
|
+
### Internal Message Format
|
|
37
|
+
|
|
38
|
+
The canonical internal format that all mia-code core logic operates on:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface InternalChatRequest {
|
|
42
|
+
messages: InternalMessage[];
|
|
43
|
+
systemPrompt?: string;
|
|
44
|
+
tools?: InternalToolDefinition[];
|
|
45
|
+
model: string;
|
|
46
|
+
options: {
|
|
47
|
+
temperature?: number;
|
|
48
|
+
maxTokens?: number;
|
|
49
|
+
stopSequences?: string[];
|
|
50
|
+
responseFormat?: "text" | "json";
|
|
51
|
+
stream: boolean;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface InternalMessage {
|
|
56
|
+
role: "user" | "assistant";
|
|
57
|
+
parts: InternalPart[]; // uses RISE-026 part types
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface InternalToolDefinition {
|
|
61
|
+
name: string;
|
|
62
|
+
description: string;
|
|
63
|
+
inputSchema: Record<string, unknown>; // JSON Schema
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Transform Pipeline Architecture
|
|
68
|
+
|
|
69
|
+
The pipeline has three stages for requests and three for responses:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
Request Flow:
|
|
73
|
+
InternalChatRequest
|
|
74
|
+
→ [Pre-Transform Hooks]
|
|
75
|
+
→ [Provider Request Transformer]
|
|
76
|
+
→ Provider-specific API request body
|
|
77
|
+
|
|
78
|
+
Response Flow:
|
|
79
|
+
Provider-specific API response
|
|
80
|
+
→ [Provider Response Transformer]
|
|
81
|
+
→ [Post-Transform Hooks]
|
|
82
|
+
→ InternalAssistantMessage
|
|
83
|
+
|
|
84
|
+
Streaming Flow:
|
|
85
|
+
Provider-specific stream chunk
|
|
86
|
+
→ [Provider Stream Transformer]
|
|
87
|
+
→ Normalized Delta event (RISE-027)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Transformer Interface
|
|
91
|
+
|
|
92
|
+
Each provider registers a transformer implementing:
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
interface ProviderTransformer {
|
|
96
|
+
providerId: string;
|
|
97
|
+
|
|
98
|
+
// Request direction: internal → provider
|
|
99
|
+
transformRequest(request: InternalChatRequest): ProviderRequest;
|
|
100
|
+
|
|
101
|
+
// Response direction: provider → internal
|
|
102
|
+
transformResponse(response: ProviderResponse): InternalAssistantMessage;
|
|
103
|
+
|
|
104
|
+
// Streaming: provider chunk → normalized delta
|
|
105
|
+
transformStreamChunk(chunk: ProviderStreamChunk): Delta[];
|
|
106
|
+
|
|
107
|
+
// Errors: provider error → named error
|
|
108
|
+
transformError(error: ProviderError): MiaCodeError;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### System Prompt Handling
|
|
113
|
+
|
|
114
|
+
System prompts are handled differently by each provider:
|
|
115
|
+
|
|
116
|
+
| Provider | System Prompt Location |
|
|
117
|
+
|---|---|
|
|
118
|
+
| Anthropic | Top-level `system` parameter (string or content blocks) |
|
|
119
|
+
| OpenAI | First message with `role: "system"` |
|
|
120
|
+
| Google Gemini | `systemInstruction` field in request body |
|
|
121
|
+
| Mistral | First message with `role: "system"` |
|
|
122
|
+
| Cohere | `preamble` field |
|
|
123
|
+
|
|
124
|
+
The request transformer moves the internal `systemPrompt` string to the correct location:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Anthropic transformer
|
|
128
|
+
transformRequest(request: InternalChatRequest): AnthropicRequest {
|
|
129
|
+
return {
|
|
130
|
+
model: request.model,
|
|
131
|
+
system: request.systemPrompt, // top-level parameter
|
|
132
|
+
messages: request.messages.map(m => this.transformMessage(m)),
|
|
133
|
+
tools: request.tools?.map(t => this.transformTool(t)),
|
|
134
|
+
max_tokens: request.options.maxTokens ?? 8192,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// OpenAI transformer
|
|
139
|
+
transformRequest(request: InternalChatRequest): OpenAIRequest {
|
|
140
|
+
const messages = [];
|
|
141
|
+
if (request.systemPrompt) {
|
|
142
|
+
messages.push({ role: "system", content: request.systemPrompt });
|
|
143
|
+
}
|
|
144
|
+
messages.push(...request.messages.map(m => this.transformMessage(m)));
|
|
145
|
+
return {
|
|
146
|
+
model: request.model,
|
|
147
|
+
messages,
|
|
148
|
+
tools: request.tools?.map(t => this.transformTool(t)),
|
|
149
|
+
max_tokens: request.options.maxTokens,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Tool Call Format Normalization
|
|
155
|
+
|
|
156
|
+
Tool definitions and tool calls vary significantly:
|
|
157
|
+
|
|
158
|
+
**Anthropic format:**
|
|
159
|
+
```json
|
|
160
|
+
{ "name": "edit_file", "input": { "path": "src/app.ts", "content": "..." } }
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**OpenAI format:**
|
|
164
|
+
```json
|
|
165
|
+
{ "id": "call_abc", "type": "function", "function": { "name": "edit_file", "arguments": "{\"path\":\"src/app.ts\"}" } }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Gemini format:**
|
|
169
|
+
```json
|
|
170
|
+
{ "functionCall": { "name": "edit_file", "args": { "path": "src/app.ts" } } }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The response transformer normalizes all of these to the internal `ToolCallPart` (RISE-026):
|
|
174
|
+
```typescript
|
|
175
|
+
{ type: "tool_call", tool_call_id: "...", tool_name: "edit_file", arguments: { path: "src/app.ts" } }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Image Content Transformation
|
|
179
|
+
|
|
180
|
+
Image encoding varies by provider:
|
|
181
|
+
|
|
182
|
+
| Provider | Image Format |
|
|
183
|
+
|---|---|
|
|
184
|
+
| Anthropic | `{ type: "image", source: { type: "base64", media_type, data } }` |
|
|
185
|
+
| OpenAI | `{ type: "image_url", image_url: { url: "data:image/png;base64,..." } }` |
|
|
186
|
+
| Gemini | `{ inlineData: { mimeType, data } }` |
|
|
187
|
+
|
|
188
|
+
The request transformer converts internal `ImagePart` to provider-specific encoding:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// Internal ImagePart → Anthropic content block
|
|
192
|
+
transformImagePart(part: ImagePart): AnthropicContentBlock {
|
|
193
|
+
return {
|
|
194
|
+
type: "image",
|
|
195
|
+
source: { type: "base64", media_type: part.mime_type, data: part.data },
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Internal ImagePart → OpenAI content part
|
|
200
|
+
transformImagePart(part: ImagePart): OpenAIContentPart {
|
|
201
|
+
return {
|
|
202
|
+
type: "image_url",
|
|
203
|
+
image_url: { url: `data:${part.mime_type};base64,${part.data}` },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Streaming Chunk Normalization
|
|
209
|
+
|
|
210
|
+
Each provider emits streaming chunks in different formats:
|
|
211
|
+
|
|
212
|
+
- **Anthropic:** `content_block_start`, `content_block_delta`, `message_delta` events
|
|
213
|
+
- **OpenAI:** `chat.completion.chunk` with `choices[0].delta`
|
|
214
|
+
- **Gemini:** `generateContent` response chunks with `candidates[0].content`
|
|
215
|
+
|
|
216
|
+
The stream transformer converts each provider's chunk format into the normalized Delta types defined in RISE-027 (TextDelta, ToolCallStart, ToolCallDelta, etc.).
|
|
217
|
+
|
|
218
|
+
### Error Response Mapping
|
|
219
|
+
|
|
220
|
+
Provider error responses are mapped to the Named Error System (RISE-006):
|
|
221
|
+
|
|
222
|
+
| Provider Error | Internal Error |
|
|
223
|
+
|---|---|
|
|
224
|
+
| Anthropic `overloaded_error` | `ProviderOverloadedError` |
|
|
225
|
+
| OpenAI `rate_limit_exceeded` | `RateLimitError` |
|
|
226
|
+
| Gemini `RESOURCE_EXHAUSTED` | `RateLimitError` |
|
|
227
|
+
| Anthropic `authentication_error` | `AuthenticationError` |
|
|
228
|
+
| OpenAI `invalid_api_key` | `AuthenticationError` |
|
|
229
|
+
| Any `context_length_exceeded` | `ContextOverflowError` |
|
|
230
|
+
| Any HTTP 500/502/503 | `ProviderServerError` |
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
transformError(error: ProviderError): MiaCodeError {
|
|
234
|
+
if (error.status === 429 || error.code === "rate_limit_exceeded") {
|
|
235
|
+
return new RateLimitError(this.providerId, {
|
|
236
|
+
retryAfter: error.headers?.["retry-after"],
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
// ... other mappings
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Custom Transform Hooks
|
|
244
|
+
|
|
245
|
+
Providers can register pre- and post-transform hooks for cross-cutting concerns:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
interface TransformHook {
|
|
249
|
+
name: string;
|
|
250
|
+
phase: "pre-request" | "post-response";
|
|
251
|
+
execute(data: unknown): unknown;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Use cases for hooks:
|
|
256
|
+
- **Prompt caching:** inject cache control headers for Anthropic's prompt caching
|
|
257
|
+
- **Content filtering:** strip or flag sensitive content before sending to certain providers
|
|
258
|
+
- **Logging:** capture raw request/response for debugging without polluting transformer logic
|
|
259
|
+
- **Metrics:** record transform latency and payload sizes
|
|
260
|
+
|
|
261
|
+
## Supporting Structures
|
|
262
|
+
|
|
263
|
+
- **Multi-Provider Architecture (RISE-028)** routes requests to the correct provider and transformer pair
|
|
264
|
+
- **Provider SDK Abstraction (RISE-033)** sends the transformed request and receives the raw response
|
|
265
|
+
- **Message Parts Model (RISE-026)** defines the internal part types the pipeline normalizes to/from
|
|
266
|
+
- **Streaming Message Deltas (RISE-027)** defines the Delta types the stream transformer produces
|
|
267
|
+
- **Named Error System (RISE-006)** provides the error types that provider errors are mapped to
|
|
268
|
+
- **Zod Schema Validation (RISE-005)** validates transformer output against internal schemas
|
|
269
|
+
|
|
270
|
+
## Creative Advancement Scenarios
|
|
271
|
+
|
|
272
|
+
**Scenario 1 — Transparent Provider Switch:**
|
|
273
|
+
A developer switches from Anthropic to OpenAI mid-project. The agent loop, tool executor, and session manager are entirely unaware — they continue operating on internal message formats. Only the transformer pair changes. The developer's tools, system prompts, and conversation history work identically because the pipeline handles all format differences.
|
|
274
|
+
|
|
275
|
+
**Scenario 2 — New Provider in an Afternoon:**
|
|
276
|
+
A developer wants to add support for a new provider (Fireworks AI) that uses an OpenAI-compatible API. They extend the OpenAI transformer, override the endpoint URL, and adjust one tool call format field. No changes to mia-code's core logic, agent system, or tool infrastructure. The new provider is usable within hours.
|
|
277
|
+
|
|
278
|
+
**Scenario 3 — Image Context Across Providers:**
|
|
279
|
+
A developer pastes a screenshot. The internal `ImagePart` is created once. When sent to Anthropic, the transformer wraps it in a `source.base64` content block. If the fallback triggers and it goes to OpenAI instead, the transformer creates a `data:` URL. The developer doesn't know or care — their screenshot just works with any provider.
|
|
280
|
+
|
|
281
|
+
**Scenario 4 — Error Normalization:**
|
|
282
|
+
Anthropic returns an `overloaded_error` with a custom JSON body. OpenAI returns a `429` with a `retry-after` header. Gemini returns a `RESOURCE_EXHAUSTED` gRPC status. The pipeline normalizes all three to a `RateLimitError` with a consistent interface. The retry logic handles one error type, not three provider-specific ones.
|