@entelligentsia/forgecli 0.21.0 → 1.0.3
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/CHANGELOG.md +44 -0
- package/README.md +31 -33
- package/dist/CHANGELOG-forge-plugin.md +142 -0
- package/dist/CHANGELOG-pi.md +24 -1
- package/dist/bin/forgecli.d.ts +2 -0
- package/dist/bin/forgecli.js +6 -0
- package/dist/bin/forgecli.js.map +1 -0
- package/dist/extensions/forgecli/add-pipeline.js +1 -1
- package/dist/extensions/forgecli/add-pipeline.js.map +1 -1
- package/dist/extensions/forgecli/add-task.js +1 -1
- package/dist/extensions/forgecli/add-task.js.map +1 -1
- package/dist/extensions/forgecli/approve.js +17 -2
- package/dist/extensions/forgecli/approve.js.map +1 -1
- package/dist/extensions/forgecli/audience-gate.js +1 -1
- package/dist/extensions/forgecli/audience-gate.js.map +1 -1
- package/dist/extensions/forgecli/calibrate.js +11 -8
- package/dist/extensions/forgecli/calibrate.js.map +1 -1
- package/dist/extensions/forgecli/collate.js +1 -1
- package/dist/extensions/forgecli/collate.js.map +1 -1
- package/dist/extensions/forgecli/commit.js +17 -2
- package/dist/extensions/forgecli/commit.js.map +1 -1
- package/dist/extensions/forgecli/enhance.js +1 -1
- package/dist/extensions/forgecli/enhance.js.map +1 -1
- package/dist/extensions/forgecli/fix-bug.d.ts +1 -2
- package/dist/extensions/forgecli/fix-bug.js +678 -609
- package/dist/extensions/forgecli/fix-bug.js.map +1 -1
- package/dist/extensions/forgecli/forge-artifact-tool.d.ts +6 -8
- package/dist/extensions/forgecli/forge-artifact-tool.js +94 -197
- package/dist/extensions/forgecli/forge-artifact-tool.js.map +1 -1
- package/dist/extensions/forgecli/forge-commands.js +57 -18
- package/dist/extensions/forgecli/forge-commands.js.map +1 -1
- package/dist/extensions/forgecli/forge-init/phase4-register.js +6 -7
- package/dist/extensions/forgecli/forge-init/phase4-register.js.map +1 -1
- package/dist/extensions/forgecli/forge-init/run-phases.d.ts +4 -0
- package/dist/extensions/forgecli/forge-init/run-phases.js +304 -0
- package/dist/extensions/forgecli/forge-init/run-phases.js.map +1 -0
- package/dist/extensions/forgecli/forge-init/verifiers.d.ts +14 -5
- package/dist/extensions/forgecli/forge-init/verifiers.js +79 -62
- package/dist/extensions/forgecli/forge-init/verifiers.js.map +1 -1
- package/dist/extensions/forgecli/forge-init.js +131 -76
- package/dist/extensions/forgecli/forge-init.js.map +1 -1
- package/dist/extensions/forgecli/forge-subagent.d.ts +26 -0
- package/dist/extensions/forgecli/forge-subagent.js +42 -18
- package/dist/extensions/forgecli/forge-subagent.js.map +1 -1
- package/dist/extensions/forgecli/forge-tools.d.ts +34 -4
- package/dist/extensions/forgecli/forge-tools.js +191 -79
- package/dist/extensions/forgecli/forge-tools.js.map +1 -1
- package/dist/extensions/forgecli/health-check.js +3 -3
- package/dist/extensions/forgecli/health-check.js.map +1 -1
- package/dist/extensions/forgecli/hook-dispatcher.d.ts +1 -1
- package/dist/extensions/forgecli/hooks/check-update.d.ts +8 -0
- package/dist/extensions/forgecli/hooks/check-update.js +29 -1
- package/dist/extensions/forgecli/hooks/check-update.js.map +1 -1
- package/dist/extensions/forgecli/hooks/post-init-hook.js +6 -6
- package/dist/extensions/forgecli/hooks/post-init-hook.js.map +1 -1
- package/dist/extensions/forgecli/hooks/post-sprint-hook.js +6 -6
- package/dist/extensions/forgecli/hooks/post-sprint-hook.js.map +1 -1
- package/dist/extensions/forgecli/hooks/triage-error.js +1 -0
- package/dist/extensions/forgecli/hooks/triage-error.js.map +1 -1
- package/dist/extensions/forgecli/implement.js +20 -2
- package/dist/extensions/forgecli/implement.js.map +1 -1
- package/dist/extensions/forgecli/index.js +39 -32
- package/dist/extensions/forgecli/index.js.map +1 -1
- package/dist/extensions/forgecli/lib/pipeline-guard.d.ts +41 -0
- package/dist/extensions/forgecli/lib/pipeline-guard.js +100 -0
- package/dist/extensions/forgecli/lib/pipeline-guard.js.map +1 -0
- package/dist/extensions/forgecli/loaders/persona-skill-loader.js +2 -2
- package/dist/extensions/forgecli/loaders/persona-skill-loader.js.map +1 -1
- package/dist/extensions/forgecli/migrate.d.ts +3 -0
- package/dist/extensions/forgecli/migrate.js +4 -2
- package/dist/extensions/forgecli/migrate.js.map +1 -1
- package/dist/extensions/forgecli/plan.js +21 -2
- package/dist/extensions/forgecli/plan.js.map +1 -1
- package/dist/extensions/forgecli/quiz-agent.js +7 -7
- package/dist/extensions/forgecli/quiz-agent.js.map +1 -1
- package/dist/extensions/forgecli/regenerate.js +49 -18
- package/dist/extensions/forgecli/regenerate.js.map +1 -1
- package/dist/extensions/forgecli/remove-command.js +1 -1
- package/dist/extensions/forgecli/remove-command.js.map +1 -1
- package/dist/extensions/forgecli/report-bug.js +1 -1
- package/dist/extensions/forgecli/report-bug.js.map +1 -1
- package/dist/extensions/forgecli/retrospective.js +9 -9
- package/dist/extensions/forgecli/retrospective.js.map +1 -1
- package/dist/extensions/forgecli/review-code.d.ts +13 -0
- package/dist/extensions/forgecli/review-code.js +62 -3
- package/dist/extensions/forgecli/review-code.js.map +1 -1
- package/dist/extensions/forgecli/review-plan.d.ts +13 -0
- package/dist/extensions/forgecli/review-plan.js +65 -3
- package/dist/extensions/forgecli/review-plan.js.map +1 -1
- package/dist/extensions/forgecli/run-task.js +461 -391
- package/dist/extensions/forgecli/run-task.js.map +1 -1
- package/dist/extensions/forgecli/session-registry.d.ts +12 -0
- package/dist/extensions/forgecli/session-registry.js +23 -0
- package/dist/extensions/forgecli/session-registry.js.map +1 -1
- package/dist/extensions/forgecli/skill-curator-subagent.d.ts +2 -1
- package/dist/extensions/forgecli/skill-curator-subagent.js +2 -1
- package/dist/extensions/forgecli/skill-curator-subagent.js.map +1 -1
- package/dist/extensions/forgecli/sprint-intake.js +6 -6
- package/dist/extensions/forgecli/sprint-intake.js.map +1 -1
- package/dist/extensions/forgecli/sprint-plan.js +9 -9
- package/dist/extensions/forgecli/sprint-plan.js.map +1 -1
- package/dist/extensions/forgecli/status-command.js +1 -1
- package/dist/extensions/forgecli/status-command.js.map +1 -1
- package/dist/extensions/forgecli/store-query.js +11 -11
- package/dist/extensions/forgecli/store-query.js.map +1 -1
- package/dist/extensions/forgecli/store-repair.js +7 -7
- package/dist/extensions/forgecli/store-repair.js.map +1 -1
- package/dist/extensions/forgecli/subagent/caller-context.d.ts +35 -11
- package/dist/extensions/forgecli/subagent/caller-context.js +49 -21
- package/dist/extensions/forgecli/subagent/caller-context.js.map +1 -1
- package/dist/extensions/forgecli/subagent/orchestrator-transcript.d.ts +66 -0
- package/dist/extensions/forgecli/subagent/orchestrator-transcript.js +66 -0
- package/dist/extensions/forgecli/subagent/orchestrator-transcript.js.map +1 -0
- package/dist/extensions/forgecli/subagent/phase-guard.d.ts +34 -0
- package/dist/extensions/forgecli/subagent/phase-guard.js +139 -0
- package/dist/extensions/forgecli/subagent/phase-guard.js.map +1 -0
- package/dist/extensions/forgecli/subagent/phase-summary-map.d.ts +1 -0
- package/dist/extensions/forgecli/subagent/phase-summary-map.js +22 -0
- package/dist/extensions/forgecli/subagent/phase-summary-map.js.map +1 -0
- package/dist/extensions/forgecli/thread-switcher.js +2 -2
- package/dist/extensions/forgecli/thread-switcher.js.map +1 -1
- package/dist/extensions/forgecli/validate.js +17 -2
- package/dist/extensions/forgecli/validate.js.map +1 -1
- package/dist/extensions/forgecli/viewport-events.d.ts +4 -0
- package/dist/extensions/forgecli/viewport-events.js +18 -1
- package/dist/extensions/forgecli/viewport-events.js.map +1 -1
- package/dist/extensions/forgecli/viewport-renderer.d.ts +12 -2
- package/dist/extensions/forgecli/viewport-renderer.js +8 -6
- package/dist/extensions/forgecli/viewport-renderer.js.map +1 -1
- package/dist/forge-payload/.base-pack/commands/check-agent.md +22 -0
- package/dist/forge-payload/.base-pack/commands/new-sprint.md +22 -0
- package/dist/forge-payload/.base-pack/commands/plan-sprint.md +22 -0
- package/dist/forge-payload/.base-pack/commands/quiz-agent.md +2 -18
- package/dist/forge-payload/.base-pack/commands/retro.md +22 -0
- package/dist/forge-payload/.base-pack/commands/retrospective.md +2 -18
- package/dist/forge-payload/.base-pack/commands/sprint-intake.md +2 -18
- package/dist/forge-payload/.base-pack/commands/sprint-plan.md +2 -18
- package/dist/forge-payload/.base-pack/workflows/_fragments/friction-emit.md +2 -2
- package/dist/forge-payload/.base-pack/workflows/_fragments/generation-instructions.md +4 -4
- package/dist/forge-payload/.base-pack/workflows/_fragments/iron-laws.md +1 -1
- package/dist/forge-payload/.base-pack/workflows/architect_approve.md +13 -1
- package/dist/forge-payload/.base-pack/workflows/commit_task.md +12 -1
- package/dist/forge-payload/.base-pack/workflows/enhance.md +6 -6
- package/dist/forge-payload/.base-pack/workflows/fix_bug.md +11 -29
- package/dist/forge-payload/.base-pack/workflows/implement_plan.md +14 -2
- package/dist/forge-payload/.base-pack/workflows/migrate_structural.md +2 -2
- package/dist/forge-payload/.base-pack/workflows/orchestrate_task.md +20 -4
- package/dist/forge-payload/.base-pack/workflows/plan_task.md +14 -2
- package/dist/forge-payload/.base-pack/workflows/review_code.md +37 -7
- package/dist/forge-payload/.base-pack/workflows/review_plan.md +36 -6
- package/dist/forge-payload/.base-pack/workflows/run_sprint.md +2 -2
- package/dist/forge-payload/.base-pack/workflows/triage.md +190 -0
- package/dist/forge-payload/.base-pack/workflows/validate_task.md +37 -7
- package/dist/forge-payload/.claude-plugin/plugin.json +1 -1
- package/dist/forge-payload/.schemas/config.schema.json +0 -5
- package/dist/forge-payload/.schemas/enum-catalog.json +9 -13
- package/dist/forge-payload/.schemas/migrations.json +63 -0
- package/dist/forge-payload/agents/tomoshibi.md +150 -6
- package/dist/forge-payload/commands/add-pipeline.md +1 -1
- package/dist/forge-payload/commands/add-task.md +1 -1
- package/dist/forge-payload/commands/calibrate.md +4 -350
- package/dist/forge-payload/commands/check-agent.md +38 -0
- package/dist/forge-payload/commands/config.md +3 -113
- package/dist/forge-payload/commands/enhance.md +5 -32
- package/dist/forge-payload/commands/health.md +155 -13
- package/dist/forge-payload/commands/init.md +25 -31
- package/dist/forge-payload/commands/migrate.md +6 -154
- package/dist/forge-payload/commands/quiz-agent.md +2 -34
- package/dist/forge-payload/commands/rebuild.md +664 -0
- package/dist/forge-payload/commands/regenerate.md +2 -774
- package/dist/forge-payload/commands/remove.md +10 -13
- package/dist/forge-payload/commands/repair.md +187 -0
- package/dist/forge-payload/commands/search.md +73 -0
- package/dist/forge-payload/commands/status.md +105 -0
- package/dist/forge-payload/commands/store-query.md +2 -69
- package/dist/forge-payload/commands/store-repair.md +2 -183
- package/dist/forge-payload/commands/update-tools.md +4 -50
- package/dist/forge-payload/commands/update.md +64 -58
- package/dist/forge-payload/hooks/check-update.cjs +1 -1
- package/dist/forge-payload/hooks/post-init.cjs +2 -2
- package/dist/forge-payload/hooks/post-sprint.cjs +2 -2
- package/dist/forge-payload/hooks/triage-error.cjs +11 -10
- package/dist/forge-payload/init/phases/phase-1-collect.md +138 -0
- package/dist/forge-payload/init/phases/phase-2-discover.md +127 -0
- package/dist/forge-payload/init/phases/phase-3-materialize.md +113 -0
- package/dist/forge-payload/init/phases/phase-4-register.md +159 -0
- package/dist/forge-payload/integrity.json +21 -24
- package/dist/forge-payload/meta/fragments/tool-discipline.md +41 -0
- package/dist/forge-payload/meta/templates/meta-retro.md +28 -0
- package/dist/forge-payload/meta/workflows/_fragments/friction-emit.md +2 -2
- package/dist/forge-payload/meta/workflows/_fragments/generation-instructions.md +4 -4
- package/dist/forge-payload/meta/workflows/_fragments/iron-laws.md +1 -1
- package/dist/forge-payload/meta/workflows/meta-approve.md +13 -1
- package/dist/forge-payload/meta/workflows/meta-bug-triage.md +210 -0
- package/dist/forge-payload/meta/workflows/meta-check-agent.md +138 -0
- package/dist/forge-payload/meta/workflows/meta-commit.md +12 -1
- package/dist/forge-payload/meta/workflows/meta-enhance.md +5 -5
- package/dist/forge-payload/meta/workflows/meta-fix-bug.md +11 -29
- package/dist/forge-payload/meta/workflows/meta-implement.md +13 -1
- package/dist/forge-payload/meta/workflows/meta-migrate.md +3 -3
- package/dist/forge-payload/meta/workflows/meta-new-sprint.md +84 -0
- package/dist/forge-payload/meta/workflows/meta-orchestrate.md +20 -4
- package/dist/forge-payload/meta/workflows/meta-plan-sprint.md +152 -0
- package/dist/forge-payload/meta/workflows/meta-plan-task.md +13 -1
- package/dist/forge-payload/meta/workflows/meta-retro.md +73 -0
- package/dist/forge-payload/meta/workflows/meta-review-implementation.md +37 -7
- package/dist/forge-payload/meta/workflows/meta-review-plan.md +36 -6
- package/dist/forge-payload/meta/workflows/meta-validate.md +37 -7
- package/dist/forge-payload/schemas/config.schema.json +0 -5
- package/dist/forge-payload/schemas/enum-catalog.json +9 -13
- package/dist/forge-payload/schemas/structure-manifest.json +25 -8
- package/dist/forge-payload/tools/artifact.cjs +324 -0
- package/dist/forge-payload/tools/banners.cjs +3 -4
- package/dist/forge-payload/tools/build-context-pack.cjs +1 -1
- package/dist/forge-payload/tools/check-structure.cjs +8 -3
- package/dist/forge-payload/tools/store-cli.cjs +67 -7
- package/dist/forge-payload/tools/substitute-placeholders.cjs +1 -1
- package/dist/forge-payload/tools/verify-apply.cjs +75 -0
- package/dist/forge-payload/tools/verify-phase.cjs +259 -0
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +0 -17
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +21 -38
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +5 -4
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +5 -2
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/CHANGELOG.md +24 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js +2 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.d.ts +1 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.js +52 -22
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +16 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +45 -50
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +43 -81
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.js +27 -12
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js +2 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js +3 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js +5 -5
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.d.ts +2 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js +37 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js +9 -8
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js +20 -35
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts +3 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js +64 -7
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js +15 -3
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.d.ts +3 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.js +14 -8
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.d.ts +30 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.js +124 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.js.map +1 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.d.ts +2 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.js +31 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.js.map +1 -0
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.d.ts +7 -27
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js +75 -115
- package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js.map +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/docs/terminal-setup.md +6 -0
- package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/sandbox/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/with-deps/package.json +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +12 -14
- package/node_modules/@earendil-works/pi-coding-agent/package.json +5 -5
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts +3 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +53 -0
- package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js.map +1 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +4 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +2 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +13 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
- package/node_modules/@earendil-works/pi-tui/package.json +2 -2
- package/node_modules/@entelligentsia/forge-compress/dist/compressor.d.ts +6 -0
- package/node_modules/@entelligentsia/forge-compress/dist/compressor.js +137 -0
- package/node_modules/@entelligentsia/forge-compress/dist/entropy.d.ts +3 -0
- package/node_modules/@entelligentsia/forge-compress/dist/entropy.js +99 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/entity.d.ts +8 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/entity.js +149 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/index.d.ts +7 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/index.js +4 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/markdown.d.ts +5 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/markdown.js +92 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/query.d.ts +7 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/query.js +60 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/validate.d.ts +1 -0
- package/node_modules/@entelligentsia/forge-compress/dist/forge/validate.js +82 -0
- package/node_modules/@entelligentsia/forge-compress/dist/index.d.ts +6 -0
- package/node_modules/@entelligentsia/forge-compress/dist/index.js +5 -0
- package/node_modules/@entelligentsia/forge-compress/dist/progressive.d.ts +1 -0
- package/node_modules/@entelligentsia/forge-compress/dist/progressive.js +108 -0
- package/node_modules/@entelligentsia/forge-compress/dist/strip.d.ts +4 -0
- package/node_modules/@entelligentsia/forge-compress/dist/strip.js +55 -0
- package/node_modules/@entelligentsia/forge-compress/dist/tokens.d.ts +2 -0
- package/node_modules/@entelligentsia/forge-compress/dist/tokens.js +17 -0
- package/node_modules/@entelligentsia/forge-compress/package.json +45 -0
- package/node_modules/@entelligentsia/forge-compress/src/__tests__/compress.test.ts +409 -0
- package/node_modules/@entelligentsia/forge-compress/src/compressor.ts +147 -0
- package/node_modules/@entelligentsia/forge-compress/src/entropy.ts +105 -0
- package/node_modules/@entelligentsia/forge-compress/src/forge/entity.ts +184 -0
- package/node_modules/@entelligentsia/forge-compress/src/forge/index.ts +10 -0
- package/node_modules/@entelligentsia/forge-compress/src/forge/markdown.ts +122 -0
- package/node_modules/@entelligentsia/forge-compress/src/forge/query.ts +105 -0
- package/node_modules/@entelligentsia/forge-compress/src/forge/validate.ts +86 -0
- package/node_modules/@entelligentsia/forge-compress/src/index.ts +22 -0
- package/node_modules/@entelligentsia/forge-compress/src/progressive.ts +123 -0
- package/node_modules/@entelligentsia/forge-compress/src/strip.ts +58 -0
- package/node_modules/@entelligentsia/forge-compress/src/tokens.ts +19 -0
- package/package.json +10 -15
- package/dist/extensions/forgecli/forge-init/phase-descriptors.d.ts +0 -72
- package/dist/extensions/forgecli/forge-init/phase-descriptors.js +0 -359
- package/dist/extensions/forgecli/forge-init/phase-descriptors.js.map +0 -1
- package/dist/extensions/forgecli/forge-init/prompts.d.ts +0 -10
- package/dist/extensions/forgecli/forge-init/prompts.js +0 -91
- package/dist/extensions/forgecli/forge-init/prompts.js.map +0 -1
- package/dist/extensions/forgecli/lib/store-error-remediation.d.ts +0 -65
- package/dist/extensions/forgecli/lib/store-error-remediation.js +0 -298
- package/dist/extensions/forgecli/lib/store-error-remediation.js.map +0 -1
- package/dist/forge-payload/hooks/check-update.js +0 -378
- package/dist/forge-payload/hooks/forge-permissions.js +0 -164
- package/dist/forge-payload/hooks/triage-error.js +0 -77
- package/dist/forge-payload/hooks/validate-write.js +0 -250
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { countTokens } from "./tokens.js";
|
|
2
|
+
export function shannonEntropy(text) {
|
|
3
|
+
if (!text)
|
|
4
|
+
return 0;
|
|
5
|
+
const freq = new Map();
|
|
6
|
+
for (const ch of text) {
|
|
7
|
+
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
8
|
+
}
|
|
9
|
+
const len = text.length;
|
|
10
|
+
let entropy = 0;
|
|
11
|
+
for (const count of freq.values()) {
|
|
12
|
+
const p = count / len;
|
|
13
|
+
if (p > 0)
|
|
14
|
+
entropy -= p * Math.log2(p);
|
|
15
|
+
}
|
|
16
|
+
return entropy;
|
|
17
|
+
}
|
|
18
|
+
export function normalizedTokenEntropy(text) {
|
|
19
|
+
if (!text || text.trim().length === 0)
|
|
20
|
+
return 0;
|
|
21
|
+
const words = text.trim().split(/\s+/);
|
|
22
|
+
if (words.length <= 1) {
|
|
23
|
+
const charEntropy = shannonEntropy(text.trim());
|
|
24
|
+
return Math.min(1, charEntropy / 4.5);
|
|
25
|
+
}
|
|
26
|
+
const freq = new Map();
|
|
27
|
+
for (const w of words) {
|
|
28
|
+
freq.set(w, (freq.get(w) ?? 0) + 1);
|
|
29
|
+
}
|
|
30
|
+
const n = words.length;
|
|
31
|
+
const uniqueRatio = freq.size / n;
|
|
32
|
+
let entropy = 0;
|
|
33
|
+
for (const count of freq.values()) {
|
|
34
|
+
const p = count / n;
|
|
35
|
+
if (p > 0)
|
|
36
|
+
entropy -= p * Math.log2(p);
|
|
37
|
+
}
|
|
38
|
+
const maxEntropy = Math.log2(n);
|
|
39
|
+
const normalized = maxEntropy > 0 ? entropy / maxEntropy : 0;
|
|
40
|
+
return Math.min(1, normalized * 0.7 + uniqueRatio * 0.3);
|
|
41
|
+
}
|
|
42
|
+
function renderIb(lines, scores, threshold) {
|
|
43
|
+
const out = [];
|
|
44
|
+
let omitRun = 0;
|
|
45
|
+
for (let i = 0; i < lines.length; i++) {
|
|
46
|
+
if (scores[i] >= threshold) {
|
|
47
|
+
if (omitRun > 0) {
|
|
48
|
+
out.push(`// ... ${omitRun} low-info lines omitted`);
|
|
49
|
+
omitRun = 0;
|
|
50
|
+
}
|
|
51
|
+
out.push(lines[i]);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
omitRun++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (omitRun > 0) {
|
|
58
|
+
out.push(`// ... ${omitRun} low-info lines omitted`);
|
|
59
|
+
}
|
|
60
|
+
return out.join("\n");
|
|
61
|
+
}
|
|
62
|
+
export function compressIb(text, targetRatio) {
|
|
63
|
+
if (!text)
|
|
64
|
+
return "";
|
|
65
|
+
const inputTokens = countTokens(text);
|
|
66
|
+
if (inputTokens === 0)
|
|
67
|
+
return text;
|
|
68
|
+
const ratio = Math.max(0.02, Math.min(1.0, targetRatio));
|
|
69
|
+
const lines = text.split("\n");
|
|
70
|
+
const scores = lines.map((ln) => normalizedTokenEntropy(ln));
|
|
71
|
+
let lo = 0;
|
|
72
|
+
let hi = 1;
|
|
73
|
+
let best = renderIb(lines, scores, 0);
|
|
74
|
+
let bestDiff = Infinity;
|
|
75
|
+
const consider = (thr) => {
|
|
76
|
+
const cand = renderIb(lines, scores, thr);
|
|
77
|
+
const r = countTokens(cand) / inputTokens;
|
|
78
|
+
const diff = Math.abs(r - ratio);
|
|
79
|
+
if (diff < bestDiff) {
|
|
80
|
+
bestDiff = diff;
|
|
81
|
+
best = cand;
|
|
82
|
+
}
|
|
83
|
+
return r;
|
|
84
|
+
};
|
|
85
|
+
for (let i = 0; i < 26; i++) {
|
|
86
|
+
const mid = (lo + hi) / 2;
|
|
87
|
+
const r = consider(mid);
|
|
88
|
+
if (r > ratio) {
|
|
89
|
+
lo = mid;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
hi = mid;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
for (const thr of [0, 1, lo, hi, (lo + hi) / 2]) {
|
|
96
|
+
consider(thr);
|
|
97
|
+
}
|
|
98
|
+
return best;
|
|
99
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface CompressEntityOptions {
|
|
2
|
+
keepSummaries?: boolean | "latest" | "all";
|
|
3
|
+
maxKeyChanges?: number;
|
|
4
|
+
flatFormat?: boolean;
|
|
5
|
+
maxTokens?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function compressEntity(input: string, opts?: CompressEntityOptions): string;
|
|
8
|
+
export declare function compressEntityList(input: string, opts?: CompressEntityOptions): string;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { countTokens } from "../tokens.js";
|
|
2
|
+
const PHASE_ORDER = [
|
|
3
|
+
"plan",
|
|
4
|
+
"triage",
|
|
5
|
+
"review_plan",
|
|
6
|
+
"implementation",
|
|
7
|
+
"code_review",
|
|
8
|
+
"validation",
|
|
9
|
+
"approve",
|
|
10
|
+
];
|
|
11
|
+
export function compressEntity(input, opts) {
|
|
12
|
+
let entity;
|
|
13
|
+
try {
|
|
14
|
+
entity = JSON.parse(input);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return input;
|
|
18
|
+
}
|
|
19
|
+
const keepSummaries = opts?.keepSummaries ?? "latest";
|
|
20
|
+
const maxKeyChanges = opts?.maxKeyChanges ?? 3;
|
|
21
|
+
const result = {};
|
|
22
|
+
const idKey = findIdKey(entity);
|
|
23
|
+
if (idKey)
|
|
24
|
+
result[idKey] = entity[idKey];
|
|
25
|
+
if (entity.title)
|
|
26
|
+
result.title = entity.title;
|
|
27
|
+
if (entity.status)
|
|
28
|
+
result.status = entity.status;
|
|
29
|
+
if (entity.sprintId)
|
|
30
|
+
result.sprintId = entity.sprintId;
|
|
31
|
+
if (entity.feature_id)
|
|
32
|
+
result.feature_id = entity.feature_id;
|
|
33
|
+
if (entity.severity)
|
|
34
|
+
result.severity = entity.severity;
|
|
35
|
+
if (entity.estimate)
|
|
36
|
+
result.estimate = entity.estimate;
|
|
37
|
+
if (entity.executionMode)
|
|
38
|
+
result.executionMode = entity.executionMode;
|
|
39
|
+
if (entity.pipeline)
|
|
40
|
+
result.pipeline = entity.pipeline;
|
|
41
|
+
if (Array.isArray(entity.taskIds)) {
|
|
42
|
+
result.taskIds = entity.taskIds;
|
|
43
|
+
result.taskCount = entity.taskIds.length;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(entity.dependencies) && entity.dependencies.length > 0) {
|
|
46
|
+
result.dependencies = entity.dependencies;
|
|
47
|
+
}
|
|
48
|
+
const summaries = entity.summaries;
|
|
49
|
+
if (summaries && typeof summaries === "object") {
|
|
50
|
+
if (keepSummaries === "all") {
|
|
51
|
+
result.summaries = compressSummaries(summaries, maxKeyChanges);
|
|
52
|
+
}
|
|
53
|
+
else if (keepSummaries === "latest") {
|
|
54
|
+
const latest = findLatestPhase(summaries);
|
|
55
|
+
if (latest) {
|
|
56
|
+
result.latestPhase = latest.phase;
|
|
57
|
+
result.latestSummary = compressOneSummary(latest.summary, maxKeyChanges);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (opts?.flatFormat) {
|
|
62
|
+
return formatFlat(result);
|
|
63
|
+
}
|
|
64
|
+
let output = JSON.stringify(result, null, 2);
|
|
65
|
+
if (opts?.maxTokens && countTokens(output) > opts.maxTokens) {
|
|
66
|
+
output = JSON.stringify(result);
|
|
67
|
+
}
|
|
68
|
+
return output;
|
|
69
|
+
}
|
|
70
|
+
export function compressEntityList(input, opts) {
|
|
71
|
+
let entities;
|
|
72
|
+
try {
|
|
73
|
+
entities = JSON.parse(input);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return input;
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(entities))
|
|
79
|
+
return input;
|
|
80
|
+
const compressed = entities.map((e) => JSON.parse(compressEntity(JSON.stringify(e), { ...opts, flatFormat: false })));
|
|
81
|
+
let output = JSON.stringify(compressed, null, 2);
|
|
82
|
+
if (opts?.maxTokens && countTokens(output) > opts.maxTokens) {
|
|
83
|
+
output = JSON.stringify(compressed);
|
|
84
|
+
}
|
|
85
|
+
return output;
|
|
86
|
+
}
|
|
87
|
+
function findIdKey(entity) {
|
|
88
|
+
for (const key of ["taskId", "sprintId", "bugId", "featureId", "id"]) {
|
|
89
|
+
if (entity[key])
|
|
90
|
+
return key;
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
function compressSummaries(summaries, maxKeyChanges) {
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const phase of PHASE_ORDER) {
|
|
97
|
+
if (summaries[phase]) {
|
|
98
|
+
result[phase] = compressOneSummary(summaries[phase], maxKeyChanges);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function compressOneSummary(summary, maxKeyChanges) {
|
|
104
|
+
const result = {};
|
|
105
|
+
if (summary.objective)
|
|
106
|
+
result.objective = summary.objective;
|
|
107
|
+
if (summary.verdict)
|
|
108
|
+
result.verdict = summary.verdict;
|
|
109
|
+
if (summary.key_changes && summary.key_changes.length > 0) {
|
|
110
|
+
const shown = summary.key_changes.slice(0, maxKeyChanges);
|
|
111
|
+
const extra = summary.key_changes.length - maxKeyChanges;
|
|
112
|
+
result.key_changes = extra > 0 ? [...shown, `+${extra} more`] : shown;
|
|
113
|
+
}
|
|
114
|
+
if (summary.route)
|
|
115
|
+
result.route = summary.route;
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
function findLatestPhase(summaries) {
|
|
119
|
+
for (let i = PHASE_ORDER.length - 1; i >= 0; i--) {
|
|
120
|
+
const phase = PHASE_ORDER[i];
|
|
121
|
+
if (summaries[phase]) {
|
|
122
|
+
return { phase, summary: summaries[phase] };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
function formatFlat(obj, prefix = "") {
|
|
128
|
+
const lines = [];
|
|
129
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
130
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
131
|
+
if (value === null || value === undefined)
|
|
132
|
+
continue;
|
|
133
|
+
if (Array.isArray(value)) {
|
|
134
|
+
if (value.length <= 5 && value.every((v) => typeof v === "string")) {
|
|
135
|
+
lines.push(`${fullKey}: ${value.join(", ")}`);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
lines.push(`${fullKey}: [${value.length} items]`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (typeof value === "object") {
|
|
142
|
+
lines.push(formatFlat(value, fullKey));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
lines.push(`${fullKey}: ${value}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return lines.filter(Boolean).join("\n");
|
|
149
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { compressStoreQuery } from "./query.js";
|
|
2
|
+
export type { CompressQueryOptions } from "./query.js";
|
|
3
|
+
export { compressEntity, compressEntityList } from "./entity.js";
|
|
4
|
+
export type { CompressEntityOptions } from "./entity.js";
|
|
5
|
+
export { compressMarkdown } from "./markdown.js";
|
|
6
|
+
export type { CompressMarkdownOptions } from "./markdown.js";
|
|
7
|
+
export { compressValidateStore } from "./validate.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { countTokens, truncateToTokenBudget } from "../tokens.js";
|
|
2
|
+
export function compressMarkdown(input, opts) {
|
|
3
|
+
if (!input.trim())
|
|
4
|
+
return "";
|
|
5
|
+
const mode = opts?.mode ?? "map";
|
|
6
|
+
const maxTokens = opts?.maxTokens ?? Infinity;
|
|
7
|
+
switch (mode) {
|
|
8
|
+
case "headings":
|
|
9
|
+
return compressHeadings(input, maxTokens);
|
|
10
|
+
case "truncate":
|
|
11
|
+
return truncateToTokenBudget(input, maxTokens);
|
|
12
|
+
case "map":
|
|
13
|
+
default:
|
|
14
|
+
return compressMap(input, maxTokens);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function compressMap(input, maxTokens) {
|
|
18
|
+
const lines = input.split("\n");
|
|
19
|
+
const picked = [];
|
|
20
|
+
let inFrontmatter = false;
|
|
21
|
+
let frontmatterDone = false;
|
|
22
|
+
for (let i = 0; i < lines.length; i++) {
|
|
23
|
+
const line = lines[i];
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
if (i === 0 && trimmed === "---") {
|
|
26
|
+
inFrontmatter = true;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (inFrontmatter) {
|
|
30
|
+
if (trimmed === "---") {
|
|
31
|
+
inFrontmatter = false;
|
|
32
|
+
frontmatterDone = true;
|
|
33
|
+
}
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (trimmed.startsWith("#")) {
|
|
37
|
+
picked.push(line);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (trimmed.startsWith("- **") ||
|
|
41
|
+
trimmed.startsWith("* **") ||
|
|
42
|
+
trimmed.startsWith("| ") ||
|
|
43
|
+
trimmed.startsWith("```")) {
|
|
44
|
+
picked.push(line);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (trimmed.startsWith("- [ ]") ||
|
|
48
|
+
trimmed.startsWith("- [x]") ||
|
|
49
|
+
trimmed.startsWith("- [X]")) {
|
|
50
|
+
picked.push(line);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (i === 0 || (frontmatterDone && picked.length === 0)) {
|
|
54
|
+
picked.push(line);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (picked.length === 0) {
|
|
58
|
+
return truncateToTokenBudget(input, maxTokens);
|
|
59
|
+
}
|
|
60
|
+
const totalLines = lines.length;
|
|
61
|
+
const keptLines = picked.length;
|
|
62
|
+
const omitted = totalLines - keptLines;
|
|
63
|
+
let result = picked.join("\n");
|
|
64
|
+
if (omitted > 0) {
|
|
65
|
+
result += `\n\n[${omitted} body lines omitted — ${totalLines} total]`;
|
|
66
|
+
}
|
|
67
|
+
if (countTokens(result) > maxTokens) {
|
|
68
|
+
result = truncateToTokenBudget(result, maxTokens);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function compressHeadings(input, maxTokens) {
|
|
73
|
+
const lines = input.split("\n");
|
|
74
|
+
const headings = [];
|
|
75
|
+
let depth = 0;
|
|
76
|
+
for (const line of lines) {
|
|
77
|
+
const match = line.match(/^(#{1,6})\s+(.+)/);
|
|
78
|
+
if (match) {
|
|
79
|
+
const level = match[1].length;
|
|
80
|
+
const indent = " ".repeat(level - 1);
|
|
81
|
+
headings.push(`${indent}${match[2]}`);
|
|
82
|
+
depth = Math.max(depth, level);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (headings.length === 0) {
|
|
86
|
+
return truncateToTokenBudget(input, maxTokens);
|
|
87
|
+
}
|
|
88
|
+
const result = `${headings.length} sections (depth ${depth}):\n${headings.join("\n")}`;
|
|
89
|
+
return countTokens(result) > maxTokens
|
|
90
|
+
? truncateToTokenBudget(result, maxTokens)
|
|
91
|
+
: result;
|
|
92
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { countTokens } from "../tokens.js";
|
|
2
|
+
export function compressStoreQuery(input, opts) {
|
|
3
|
+
let envelope;
|
|
4
|
+
try {
|
|
5
|
+
envelope = JSON.parse(input);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return input;
|
|
9
|
+
}
|
|
10
|
+
if (!envelope.results || !Array.isArray(envelope.results))
|
|
11
|
+
return input;
|
|
12
|
+
const keepExcerpts = opts?.keepExcerpts ?? false;
|
|
13
|
+
const maxExcerptLines = opts?.maxExcerptLines ?? 5;
|
|
14
|
+
const maxResults = opts?.maxResults ?? envelope.results.length;
|
|
15
|
+
const results = envelope.results.slice(0, maxResults).map((r) => {
|
|
16
|
+
const entry = {
|
|
17
|
+
id: r.id,
|
|
18
|
+
title: r.title,
|
|
19
|
+
status: r.status,
|
|
20
|
+
type: r.type,
|
|
21
|
+
};
|
|
22
|
+
if (r.relationships && Object.keys(r.relationships).length > 0) {
|
|
23
|
+
const rels = {};
|
|
24
|
+
for (const [k, v] of Object.entries(r.relationships)) {
|
|
25
|
+
if (v !== null && v !== undefined)
|
|
26
|
+
rels[k] = v;
|
|
27
|
+
}
|
|
28
|
+
if (Object.keys(rels).length > 0)
|
|
29
|
+
entry.relationships = rels;
|
|
30
|
+
}
|
|
31
|
+
if (keepExcerpts && r.excerpt) {
|
|
32
|
+
const lines = r.excerpt.split("\n");
|
|
33
|
+
entry.excerpt =
|
|
34
|
+
lines.length > maxExcerptLines
|
|
35
|
+
? lines.slice(0, maxExcerptLines).join("\n") +
|
|
36
|
+
`\n... (${lines.length - maxExcerptLines} more lines)`
|
|
37
|
+
: r.excerpt;
|
|
38
|
+
}
|
|
39
|
+
return entry;
|
|
40
|
+
});
|
|
41
|
+
const compact = { results };
|
|
42
|
+
if (envelope.query)
|
|
43
|
+
compact.query = envelope.query;
|
|
44
|
+
if (envelope.path)
|
|
45
|
+
compact.path = envelope.path;
|
|
46
|
+
if (typeof envelope.count === "number")
|
|
47
|
+
compact.count = envelope.count;
|
|
48
|
+
if (typeof envelope.totalMatched === "number")
|
|
49
|
+
compact.totalMatched = envelope.totalMatched;
|
|
50
|
+
if (typeof envelope.returned === "number")
|
|
51
|
+
compact.returned = envelope.returned;
|
|
52
|
+
if (envelope.results.length > maxResults) {
|
|
53
|
+
compact.truncated = envelope.results.length - maxResults;
|
|
54
|
+
}
|
|
55
|
+
let output = JSON.stringify(compact, null, 2);
|
|
56
|
+
if (opts?.maxTokens && countTokens(output) > opts.maxTokens) {
|
|
57
|
+
output = JSON.stringify(compact);
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compressValidateStore(input: string): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export function compressValidateStore(input) {
|
|
2
|
+
let report;
|
|
3
|
+
try {
|
|
4
|
+
report = JSON.parse(input);
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return compressPlainValidation(input);
|
|
8
|
+
}
|
|
9
|
+
const errors = (report.errors ?? []);
|
|
10
|
+
const warnings = (report.warnings ?? []);
|
|
11
|
+
const fixes = (report.fixes ?? []);
|
|
12
|
+
const summary = report.summary;
|
|
13
|
+
const parts = [];
|
|
14
|
+
if (summary) {
|
|
15
|
+
const counts = Object.entries(summary)
|
|
16
|
+
.filter(([, v]) => v > 0)
|
|
17
|
+
.map(([k, v]) => `${v} ${k}`)
|
|
18
|
+
.join(", ");
|
|
19
|
+
if (counts)
|
|
20
|
+
parts.push(counts);
|
|
21
|
+
}
|
|
22
|
+
if (errors.length > 0) {
|
|
23
|
+
const grouped = groupBy(errors, "category");
|
|
24
|
+
for (const [cat, items] of Object.entries(grouped)) {
|
|
25
|
+
parts.push(`ERR ${cat} (${items.length}):`);
|
|
26
|
+
for (const item of items.slice(0, 5)) {
|
|
27
|
+
parts.push(` ${item.id}: ${item.message}`);
|
|
28
|
+
}
|
|
29
|
+
if (items.length > 5)
|
|
30
|
+
parts.push(` ... +${items.length - 5} more`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (warnings.length > 0) {
|
|
34
|
+
const grouped = groupBy(warnings, "category");
|
|
35
|
+
for (const [cat, items] of Object.entries(grouped)) {
|
|
36
|
+
parts.push(`WARN ${cat} (${items.length}):`);
|
|
37
|
+
for (const item of items.slice(0, 3)) {
|
|
38
|
+
parts.push(` ${item.id}: ${item.message}`);
|
|
39
|
+
}
|
|
40
|
+
if (items.length > 3)
|
|
41
|
+
parts.push(` ... +${items.length - 3} more`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (fixes.length > 0) {
|
|
45
|
+
const applied = fixes.filter((f) => f.applied).length;
|
|
46
|
+
parts.push(`${fixes.length} fixes (${applied} applied)`);
|
|
47
|
+
}
|
|
48
|
+
if (parts.length === 0)
|
|
49
|
+
return "ok (store valid)";
|
|
50
|
+
return parts.join("\n");
|
|
51
|
+
}
|
|
52
|
+
function compressPlainValidation(input) {
|
|
53
|
+
const lines = input.split("\n").filter((l) => l.trim());
|
|
54
|
+
if (lines.length <= 10)
|
|
55
|
+
return input;
|
|
56
|
+
const errors = lines.filter((l) => l.includes("ERROR"));
|
|
57
|
+
const warns = lines.filter((l) => l.includes("WARN"));
|
|
58
|
+
const fixed = lines.filter((l) => l.includes("FIXED"));
|
|
59
|
+
const parts = [];
|
|
60
|
+
if (errors.length > 0) {
|
|
61
|
+
parts.push(`${errors.length} errors:`);
|
|
62
|
+
for (const e of errors.slice(0, 5))
|
|
63
|
+
parts.push(` ${e.trim()}`);
|
|
64
|
+
if (errors.length > 5)
|
|
65
|
+
parts.push(` ... +${errors.length - 5} more`);
|
|
66
|
+
}
|
|
67
|
+
if (warns.length > 0)
|
|
68
|
+
parts.push(`${warns.length} warnings`);
|
|
69
|
+
if (fixed.length > 0)
|
|
70
|
+
parts.push(`${fixed.length} fixed`);
|
|
71
|
+
return parts.length > 0 ? parts.join("\n") : input;
|
|
72
|
+
}
|
|
73
|
+
function groupBy(items, key) {
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const item of items) {
|
|
76
|
+
const k = String(item[key] ?? "unknown");
|
|
77
|
+
if (!result[k])
|
|
78
|
+
result[k] = [];
|
|
79
|
+
result[k].push(item);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { compressStoreQuery, compressEntity, compressEntityList, compressMarkdown, compressValidateStore, } from "./forge/index.js";
|
|
2
|
+
export type { CompressQueryOptions, CompressEntityOptions, CompressMarkdownOptions, } from "./forge/index.js";
|
|
3
|
+
export { countTokens, truncateToTokenBudget } from "./tokens.js";
|
|
4
|
+
export { compressIb } from "./entropy.js";
|
|
5
|
+
export { compressProgressive } from "./progressive.js";
|
|
6
|
+
export { lightweightCleanup, verbatimCompact, stripAnsi, } from "./compressor.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { compressStoreQuery, compressEntity, compressEntityList, compressMarkdown, compressValidateStore, } from "./forge/index.js";
|
|
2
|
+
export { countTokens, truncateToTokenBudget } from "./tokens.js";
|
|
3
|
+
export { compressIb } from "./entropy.js";
|
|
4
|
+
export { compressProgressive } from "./progressive.js";
|
|
5
|
+
export { lightweightCleanup, verbatimCompact, stripAnsi, } from "./compressor.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compressProgressive(segments: string[], budgetTokens: number): string[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { truncateToTokenBudget } from "./tokens.js";
|
|
2
|
+
const LAMBDA = 1.35;
|
|
3
|
+
function expWeights(n) {
|
|
4
|
+
return Array.from({ length: n }, (_, i) => Math.exp(LAMBDA * i));
|
|
5
|
+
}
|
|
6
|
+
function allocateBudget(budgetTokens, weights) {
|
|
7
|
+
const n = weights.length;
|
|
8
|
+
if (n === 0 || budgetTokens === 0)
|
|
9
|
+
return new Array(n).fill(0);
|
|
10
|
+
const sumW = Math.max(weights.reduce((a, b) => a + b, 0), Number.EPSILON);
|
|
11
|
+
const base = new Array(n).fill(0);
|
|
12
|
+
const frac = new Array(n).fill(0);
|
|
13
|
+
for (let i = 0; i < n; i++) {
|
|
14
|
+
const exact = (budgetTokens * weights[i]) / sumW;
|
|
15
|
+
base[i] = Math.floor(exact);
|
|
16
|
+
frac[i] = exact - base[i];
|
|
17
|
+
}
|
|
18
|
+
const given = base.reduce((a, b) => a + b, 0);
|
|
19
|
+
const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => frac[b] - frac[a]);
|
|
20
|
+
let extra = budgetTokens - given;
|
|
21
|
+
for (const i of order) {
|
|
22
|
+
if (extra <= 0)
|
|
23
|
+
break;
|
|
24
|
+
base[i]++;
|
|
25
|
+
extra--;
|
|
26
|
+
}
|
|
27
|
+
return base;
|
|
28
|
+
}
|
|
29
|
+
function tierForIndex(i, n) {
|
|
30
|
+
if (n <= 1)
|
|
31
|
+
return 2;
|
|
32
|
+
const r = i / (n - 1);
|
|
33
|
+
if (r < 1 / 3)
|
|
34
|
+
return 0;
|
|
35
|
+
if (r < 2 / 3)
|
|
36
|
+
return 1;
|
|
37
|
+
return 2;
|
|
38
|
+
}
|
|
39
|
+
const STRUCTURE_KEYWORDS = [
|
|
40
|
+
"fn ",
|
|
41
|
+
"pub ",
|
|
42
|
+
"struct ",
|
|
43
|
+
"enum ",
|
|
44
|
+
"trait ",
|
|
45
|
+
"impl ",
|
|
46
|
+
"mod ",
|
|
47
|
+
"use ",
|
|
48
|
+
"def ",
|
|
49
|
+
"class ",
|
|
50
|
+
"function ",
|
|
51
|
+
"export ",
|
|
52
|
+
"import ",
|
|
53
|
+
"const ",
|
|
54
|
+
"interface ",
|
|
55
|
+
];
|
|
56
|
+
function mapLike(s, maxTokens) {
|
|
57
|
+
const picked = [];
|
|
58
|
+
const lines = s.split("\n");
|
|
59
|
+
for (let i = 0; i < lines.length; i++) {
|
|
60
|
+
if (i === 0 || STRUCTURE_KEYWORDS.some((k) => lines[i].includes(k))) {
|
|
61
|
+
picked.push(lines[i]);
|
|
62
|
+
}
|
|
63
|
+
if (picked.length >= 48)
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (picked.length === 0 && lines.length > 0) {
|
|
67
|
+
picked.push(lines[0]);
|
|
68
|
+
}
|
|
69
|
+
return truncateToTokenBudget(picked.join("\n"), Math.max(4, maxTokens));
|
|
70
|
+
}
|
|
71
|
+
function oneLineSummary(segIdx, s, maxTokens) {
|
|
72
|
+
const preview = s.split("\n")[0]?.slice(0, 120) ?? "";
|
|
73
|
+
const lineCount = s.split("\n").length;
|
|
74
|
+
const draft = `// seg[${segIdx}] ${lineCount} lines, ${s.length} chars | ${preview}`;
|
|
75
|
+
return truncateToTokenBudget(draft, Math.max(8, maxTokens));
|
|
76
|
+
}
|
|
77
|
+
export function compressProgressive(segments, budgetTokens) {
|
|
78
|
+
const n = segments.length;
|
|
79
|
+
if (n === 0)
|
|
80
|
+
return [];
|
|
81
|
+
if (budgetTokens === 0)
|
|
82
|
+
return segments.map(() => "");
|
|
83
|
+
const weights = expWeights(n);
|
|
84
|
+
const allocs = allocateBudget(budgetTokens, weights);
|
|
85
|
+
const out = [];
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
const alloc = allocs[i];
|
|
88
|
+
const tier = tierForIndex(i, n);
|
|
89
|
+
if (alloc === 0) {
|
|
90
|
+
out.push("");
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
let compressed;
|
|
94
|
+
switch (tier) {
|
|
95
|
+
case 2:
|
|
96
|
+
compressed = truncateToTokenBudget(segments[i], alloc);
|
|
97
|
+
break;
|
|
98
|
+
case 1:
|
|
99
|
+
compressed = mapLike(segments[i], alloc);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
compressed = oneLineSummary(i, segments[i], alloc);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
out.push(truncateToTokenBudget(compressed, alloc));
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|