@north-light/crouter 0.3.154
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/README.md +48 -0
- package/bin/crouter +4 -0
- package/bin/crtr +4 -0
- package/bin/crtrd +4 -0
- package/bin/runtime-generation-manifest.mjs +263 -0
- package/bin/runtime-selector.mjs +378 -0
- package/dist/api/__tests__/client.test.d.ts +1 -0
- package/dist/api/__tests__/client.test.js +274 -0
- package/dist/api/client.d.ts +249 -0
- package/dist/api/client.js +616 -0
- package/dist/api/dto/attach.d.ts +16 -0
- package/dist/api/dto/attach.js +13 -0
- package/dist/api/dto/broker.d.ts +45 -0
- package/dist/api/dto/broker.js +20 -0
- package/dist/api/dto/canvas.d.ts +253 -0
- package/dist/api/dto/canvas.js +2 -0
- package/dist/api/dto/common.d.ts +27 -0
- package/dist/api/dto/common.js +15 -0
- package/dist/api/dto/config.d.ts +19 -0
- package/dist/api/dto/config.js +3 -0
- package/dist/api/dto/crons.d.ts +124 -0
- package/dist/api/dto/crons.js +10 -0
- package/dist/api/dto/files.d.ts +11 -0
- package/dist/api/dto/files.js +7 -0
- package/dist/api/dto/focus.d.ts +24 -0
- package/dist/api/dto/focus.js +10 -0
- package/dist/api/dto/health.d.ts +41 -0
- package/dist/api/dto/health.js +2 -0
- package/dist/api/dto/human.d.ts +57 -0
- package/dist/api/dto/human.js +4 -0
- package/dist/api/dto/inbox.d.ts +105 -0
- package/dist/api/dto/inbox.js +10 -0
- package/dist/api/dto/lifecycle.d.ts +79 -0
- package/dist/api/dto/lifecycle.js +3 -0
- package/dist/api/dto/messages.d.ts +55 -0
- package/dist/api/dto/messages.js +2 -0
- package/dist/api/dto/modelauth.d.ts +41 -0
- package/dist/api/dto/modelauth.js +3 -0
- package/dist/api/dto/nodes.d.ts +209 -0
- package/dist/api/dto/nodes.js +3 -0
- package/dist/api/dto/profiles.d.ts +14 -0
- package/dist/api/dto/profiles.js +3 -0
- package/dist/api/dto/reports.d.ts +41 -0
- package/dist/api/dto/reports.js +2 -0
- package/dist/api/dto/subscriptions.d.ts +14 -0
- package/dist/api/dto/subscriptions.js +2 -0
- package/dist/api/dto/worktree.d.ts +19 -0
- package/dist/api/dto/worktree.js +6 -0
- package/dist/api/errors.d.ts +19 -0
- package/dist/api/errors.js +30 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.js +25 -0
- package/dist/api/routes.d.ts +64 -0
- package/dist/api/routes.js +92 -0
- package/dist/build-root.d.ts +43 -0
- package/dist/build-root.js +96 -0
- package/dist/builtin-memory/00-runtime-base.md +51 -0
- package/dist/builtin-memory/01-spine/00-has-manager.md +23 -0
- package/dist/builtin-memory/01-spine/01-no-manager.md +10 -0
- package/dist/builtin-memory/02-lifecycle/00-terminal.md +19 -0
- package/dist/builtin-memory/02-lifecycle/01-resident.md +10 -0
- package/dist/builtin-memory/04-base-worker.md +18 -0
- package/dist/builtin-memory/04-orchestration-kernel.md +109 -0
- package/dist/builtin-memory/05-kinds/advisor/00-base.md +19 -0
- package/dist/builtin-memory/05-kinds/advisor/01-orchestrator.md +26 -0
- package/dist/builtin-memory/05-kinds/design/00-base.md +20 -0
- package/dist/builtin-memory/05-kinds/design/01-orchestrator.md +13 -0
- package/dist/builtin-memory/05-kinds/developer/00-base.md +22 -0
- package/dist/builtin-memory/05-kinds/developer/01-orchestrator.md +21 -0
- package/dist/builtin-memory/05-kinds/explore/00-base.md +20 -0
- package/dist/builtin-memory/05-kinds/explore/01-orchestrator.md +16 -0
- package/dist/builtin-memory/05-kinds/general/00-base.md +15 -0
- package/dist/builtin-memory/05-kinds/general/01-orchestrator.md +11 -0
- package/dist/builtin-memory/05-kinds/plan/00-base.md +20 -0
- package/dist/builtin-memory/05-kinds/plan/01-orchestrator.md +17 -0
- package/dist/builtin-memory/05-kinds/plan/reviewers/architecture-fit.md +17 -0
- package/dist/builtin-memory/05-kinds/plan/reviewers/code-smells.md +17 -0
- package/dist/builtin-memory/05-kinds/plan/reviewers/pattern-consistency.md +19 -0
- package/dist/builtin-memory/05-kinds/plan/reviewers/requirements-coverage.md +17 -0
- package/dist/builtin-memory/05-kinds/plan/reviewers/security.md +20 -0
- package/dist/builtin-memory/05-kinds/product/00-base.md +25 -0
- package/dist/builtin-memory/05-kinds/product/01-orchestrator.md +15 -0
- package/dist/builtin-memory/05-kinds/product/teardown.md +15 -0
- package/dist/builtin-memory/05-kinds/review/00-base.md +19 -0
- package/dist/builtin-memory/05-kinds/review/01-orchestrator.md +17 -0
- package/dist/builtin-memory/05-kinds/spec/00-base.md +20 -0
- package/dist/builtin-memory/05-kinds/spec/01-orchestrator.md +15 -0
- package/dist/builtin-memory/05-kinds/spec/requirements.md +13 -0
- package/dist/builtin-memory/design.md +62 -0
- package/dist/builtin-memory/development.md +120 -0
- package/dist/builtin-memory/internal/INDEX.md +26 -0
- package/dist/builtin-memory/internal/agent-shaping.md +77 -0
- package/dist/builtin-memory/internal/examples/INDEX.md +15 -0
- package/dist/builtin-memory/internal/examples/imessage-assistant.md +100 -0
- package/dist/builtin-memory/internal/marketplaces.md +164 -0
- package/dist/builtin-memory/internal/nodes-and-canvas.md +51 -0
- package/dist/builtin-memory/internal/plugins.md +249 -0
- package/dist/builtin-memory/internal/storage-tiers.md +41 -0
- package/dist/builtin-memory/planning.md +43 -0
- package/dist/builtin-memory/product.md +80 -0
- package/dist/builtin-memory/spec.md +98 -0
- package/dist/builtin-memory/wedged-child-on-runaway-bash.md +34 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/README.md +47 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/claude-plugin-commands.test.ts +49 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/crtr-commands.test.ts +93 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/memory-slash-commands.test.ts +194 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/provider-rotation.test.ts +2632 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/statusline.test.ts +68 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/claude-plugin-commands.ts +492 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/crouter-help.ts +95 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/crtr-commands/filters.json +7 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/crtr-commands/index.ts +191 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/frontmatter-rules/index.ts +448 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/frontmatter-rules/test.ts +119 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +195 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +1232 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/statusline.ts +255 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/strip-skills-docs.ts +47 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/sysprompt-window.ts +19 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/lib/package.json +3 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/lib/subscription-state.js +1 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/lib/subscription-state.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/LICENSE +13 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/README.md +172 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/bin.mjs +11 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +225 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/errors.js +57 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/index.js +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/log.js +11 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/Alias.js +116 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/util.js +11 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/dist/visit.js +233 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/index.js +5 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/browser/package.json +3 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/cli.d.ts +8 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/cli.mjs +201 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/composer.js +224 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/Document.js +337 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/doc/directives.js +178 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/errors.d.ts +21 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/errors.js +62 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/index.d.ts +25 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/index.js +50 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/log.d.ts +3 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/log.js +19 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Alias.js +118 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/options.d.ts +350 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/cst.js +112 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/parse/parser.js +980 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/public-api.js +107 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/tags.js +99 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/test-events.js +134 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/util.d.ts +16 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/util.js +28 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/visit.d.ts +102 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/dist/visit.js +236 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/package.json +97 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/node_modules/yaml/util.js +2 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/package-lock.json +3385 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/package.json +25 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/tsconfig.json +10 -0
- package/dist/builtin-pi-packages/pi-mode-switch/README.md +36 -0
- package/dist/builtin-pi-packages/pi-mode-switch/bin/mode +36 -0
- package/dist/builtin-pi-packages/pi-mode-switch/extensions/index.ts +449 -0
- package/dist/builtin-pi-packages/pi-mode-switch/package.json +14 -0
- package/dist/builtin-pi-packages/pi-mode-switch/tsconfig.json +9 -0
- package/dist/builtin-views/_lib/states.mjs +161 -0
- package/dist/builtin-views/canvas/core.mjs +657 -0
- package/dist/builtin-views/canvas/text.mjs +58 -0
- package/dist/builtin-views/canvas/tui.mjs +168 -0
- package/dist/builtin-views/canvas/web.jsx +121 -0
- package/dist/builtin-views/chat/core.mjs +684 -0
- package/dist/builtin-views/chat/text.mjs +101 -0
- package/dist/builtin-views/chat/tui.mjs +360 -0
- package/dist/builtin-views/chat/web.jsx +362 -0
- package/dist/builtin-views/git-pr/core.mjs +673 -0
- package/dist/builtin-views/git-pr/text.mjs +84 -0
- package/dist/builtin-views/git-pr/tui.mjs +301 -0
- package/dist/builtin-views/git-pr/web.jsx +216 -0
- package/dist/builtin-views/inbox/_lib/render.mjs +175 -0
- package/dist/builtin-views/inbox/core.mjs +1273 -0
- package/dist/builtin-views/inbox/text.mjs +73 -0
- package/dist/builtin-views/inbox/tui.mjs +314 -0
- package/dist/builtin-views/inbox/web.jsx +188 -0
- package/dist/builtin-views/linkedin/core.mjs +906 -0
- package/dist/builtin-views/linkedin/text.mjs +69 -0
- package/dist/builtin-views/linkedin/tui.mjs +413 -0
- package/dist/builtin-views/linkedin/web.jsx +206 -0
- package/dist/builtin-views/prompt-review/core.mjs +735 -0
- package/dist/builtin-views/prompt-review/text.mjs +15 -0
- package/dist/builtin-views/prompt-review/tui.mjs +196 -0
- package/dist/builtin-views/prompt-review/web.jsx +484 -0
- package/dist/builtin-views/workspace-sidebar/__tests__/core.test.d.ts +1 -0
- package/dist/builtin-views/workspace-sidebar/__tests__/core.test.js +50 -0
- package/dist/builtin-views/workspace-sidebar/__tests__/core.test.ts +53 -0
- package/dist/builtin-views/workspace-sidebar/core.mjs +670 -0
- package/dist/builtin-views/workspace-sidebar/text.mjs +53 -0
- package/dist/builtin-views/workspace-sidebar/tui.mjs +141 -0
- package/dist/builtin-views/workspace-sidebar/web.jsx +109 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +86 -0
- package/dist/clients/attach/__tests__/attach-chrome-remote.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/attach-chrome-remote.test.js +467 -0
- package/dist/clients/attach/__tests__/attach-keybindings.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/attach-keybindings.test.js +141 -0
- package/dist/clients/attach/__tests__/attach-remote-readonly.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/attach-remote-readonly.test.js +191 -0
- package/dist/clients/attach/__tests__/chat-view-snapshot-ordering.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/chat-view-snapshot-ordering.test.js +236 -0
- package/dist/clients/attach/__tests__/context-message.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/context-message.test.js +46 -0
- package/dist/clients/attach/__tests__/crtr-output-coverage.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/crtr-output-coverage.test.js +55 -0
- package/dist/clients/attach/__tests__/crtr-output.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/crtr-output.test.js +2103 -0
- package/dist/clients/attach/__tests__/diagram.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/diagram.test.js +42 -0
- package/dist/clients/attach/__tests__/markdown-headings.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/markdown-headings.test.js +27 -0
- package/dist/clients/attach/__tests__/oauth-dialog-lifecycle.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/oauth-dialog-lifecycle.test.js +133 -0
- package/dist/clients/attach/__tests__/prompt-preview.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/prompt-preview.test.js +87 -0
- package/dist/clients/attach/__tests__/ref-autocomplete.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/ref-autocomplete.test.js +176 -0
- package/dist/clients/attach/__tests__/titled-editor-preview.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/titled-editor-preview.test.js +271 -0
- package/dist/clients/attach/__tests__/visible-paths.test.d.ts +1 -0
- package/dist/clients/attach/__tests__/visible-paths.test.js +19 -0
- package/dist/clients/attach/chrome/bash-jobs.d.ts +9 -0
- package/dist/clients/attach/chrome/bash-jobs.js +43 -0
- package/dist/clients/attach/chrome/canvas-panels.d.ts +36 -0
- package/dist/clients/attach/chrome/canvas-panels.js +172 -0
- package/dist/clients/attach/chrome/completion-bell.d.ts +10 -0
- package/dist/clients/attach/chrome/completion-bell.js +89 -0
- package/dist/clients/attach/chrome/cron-wait.d.ts +3 -0
- package/dist/clients/attach/chrome/cron-wait.js +34 -0
- package/dist/clients/attach/chrome/git-info.d.ts +20 -0
- package/dist/clients/attach/chrome/git-info.js +44 -0
- package/dist/clients/attach/chrome/roster.d.ts +26 -0
- package/dist/clients/attach/chrome/roster.js +233 -0
- package/dist/clients/attach/chrome/status-line.d.ts +35 -0
- package/dist/clients/attach/chrome/status-line.js +133 -0
- package/dist/clients/attach/chrome/widgets.d.ts +9 -0
- package/dist/clients/attach/chrome/widgets.js +61 -0
- package/dist/clients/attach/command.d.ts +2 -0
- package/dist/clients/attach/command.js +96 -0
- package/dist/clients/attach/config.d.ts +91 -0
- package/dist/clients/attach/config.js +271 -0
- package/dist/clients/attach/input/clipboard-image.d.ts +55 -0
- package/dist/clients/attach/input/clipboard-image.js +237 -0
- package/dist/clients/attach/input/controller.d.ts +210 -0
- package/dist/clients/attach/input/controller.js +689 -0
- package/dist/clients/attach/input/ref-autocomplete.d.ts +75 -0
- package/dist/clients/attach/input/ref-autocomplete.js +135 -0
- package/dist/clients/attach/input/titled-editor.d.ts +209 -0
- package/dist/clients/attach/input/titled-editor.js +801 -0
- package/dist/clients/attach/overlays/auth.d.ts +13 -0
- package/dist/clients/attach/overlays/auth.js +245 -0
- package/dist/clients/attach/overlays/dialogs.d.ts +27 -0
- package/dist/clients/attach/overlays/dialogs.js +102 -0
- package/dist/clients/attach/overlays/file-review.d.ts +9 -0
- package/dist/clients/attach/overlays/file-review.js +181 -0
- package/dist/clients/attach/overlays/graph.d.ts +76 -0
- package/dist/clients/attach/overlays/graph.js +657 -0
- package/dist/clients/attach/overlays/mcp.d.ts +32 -0
- package/dist/clients/attach/overlays/mcp.js +310 -0
- package/dist/clients/attach/overlays/pickers.d.ts +59 -0
- package/dist/clients/attach/overlays/pickers.js +170 -0
- package/dist/clients/attach/render/chat-view.d.ts +185 -0
- package/dist/clients/attach/render/chat-view.js +946 -0
- package/dist/clients/attach/render/context-message.d.ts +14 -0
- package/dist/clients/attach/render/context-message.js +81 -0
- package/dist/clients/attach/render/crtr-output.d.ts +48 -0
- package/dist/clients/attach/render/crtr-output.js +694 -0
- package/dist/clients/attach/render/diagram.d.ts +14 -0
- package/dist/clients/attach/render/diagram.js +135 -0
- package/dist/clients/attach/render/edit-diff.d.ts +6 -0
- package/dist/clients/attach/render/edit-diff.js +263 -0
- package/dist/clients/attach/render/frozen-history.d.ts +38 -0
- package/dist/clients/attach/render/frozen-history.js +100 -0
- package/dist/clients/attach/render/markdown-headings.d.ts +11 -0
- package/dist/clients/attach/render/markdown-headings.js +82 -0
- package/dist/clients/attach/session/banner.d.ts +9 -0
- package/dist/clients/attach/session/banner.js +29 -0
- package/dist/clients/attach/session/bindings.d.ts +12 -0
- package/dist/clients/attach/session/bindings.js +52 -0
- package/dist/clients/attach/session/chrome-refresh.d.ts +34 -0
- package/dist/clients/attach/session/chrome-refresh.js +93 -0
- package/dist/clients/attach/session/connection.d.ts +44 -0
- package/dist/clients/attach/session/connection.js +178 -0
- package/dist/clients/attach/session/context.d.ts +54 -0
- package/dist/clients/attach/session/context.js +16 -0
- package/dist/clients/attach/session/editor-frame.d.ts +43 -0
- package/dist/clients/attach/session/editor-frame.js +136 -0
- package/dist/clients/attach/session/editor-inventory.d.ts +59 -0
- package/dist/clients/attach/session/editor-inventory.js +161 -0
- package/dist/clients/attach/session/focus-events.d.ts +4 -0
- package/dist/clients/attach/session/focus-events.js +12 -0
- package/dist/clients/attach/session/frames.d.ts +43 -0
- package/dist/clients/attach/session/frames.js +170 -0
- package/dist/clients/attach/session/identity.d.ts +16 -0
- package/dist/clients/attach/session/identity.js +25 -0
- package/dist/clients/attach/session/input-wiring.d.ts +31 -0
- package/dist/clients/attach/session/input-wiring.js +128 -0
- package/dist/clients/attach/session/keys.d.ts +22 -0
- package/dist/clients/attach/session/keys.js +60 -0
- package/dist/clients/attach/session/layout.d.ts +20 -0
- package/dist/clients/attach/session/layout.js +56 -0
- package/dist/clients/attach/session/mode.d.ts +25 -0
- package/dist/clients/attach/session/mode.js +97 -0
- package/dist/clients/attach/session/pane-tag.d.ts +15 -0
- package/dist/clients/attach/session/pane-tag.js +43 -0
- package/dist/clients/attach/session/pi-assets.d.ts +1 -0
- package/dist/clients/attach/session/pi-assets.js +24 -0
- package/dist/clients/attach/session/pi-oauth-flows.d.ts +1 -0
- package/dist/clients/attach/session/pi-oauth-flows.js +21 -0
- package/dist/clients/attach/session/reconnect.d.ts +37 -0
- package/dist/clients/attach/session/reconnect.js +127 -0
- package/dist/clients/attach/session/state-sync.d.ts +38 -0
- package/dist/clients/attach/session/state-sync.js +68 -0
- package/dist/clients/attach/session/teardown.d.ts +30 -0
- package/dist/clients/attach/session/teardown.js +96 -0
- package/dist/clients/attach/slash/dispatch.d.ts +124 -0
- package/dist/clients/attach/slash/dispatch.js +696 -0
- package/dist/clients/attach/slash/prompt-preview.d.ts +30 -0
- package/dist/clients/attach/slash/prompt-preview.js +121 -0
- package/dist/clients/attach/viewer.d.ts +8 -0
- package/dist/clients/attach/viewer.js +1559 -0
- package/dist/clients/attach/visible-paths.d.ts +9 -0
- package/dist/clients/attach/visible-paths.js +76 -0
- package/dist/clients/web/__tests__/push-engine.test.d.ts +1 -0
- package/dist/clients/web/__tests__/push-engine.test.js +302 -0
- package/dist/clients/web/__tests__/push-registry.test.d.ts +1 -0
- package/dist/clients/web/__tests__/push-registry.test.js +177 -0
- package/dist/clients/web/dev-server.d.ts +7 -0
- package/dist/clients/web/dev-server.js +60 -0
- package/dist/clients/web/events.d.ts +19 -0
- package/dist/clients/web/events.js +165 -0
- package/dist/clients/web/push-engine.d.ts +108 -0
- package/dist/clients/web/push-engine.js +256 -0
- package/dist/clients/web/push-registry.d.ts +89 -0
- package/dist/clients/web/push-registry.js +378 -0
- package/dist/clients/web/server.d.ts +19 -0
- package/dist/clients/web/server.js +693 -0
- package/dist/clients/web/web-client/shared/protocol.d.ts +322 -0
- package/dist/clients/web/web-client/shared/protocol.js +8 -0
- package/dist/clients/web/web-cmd.d.ts +2 -0
- package/dist/clients/web/web-cmd.js +141 -0
- package/dist/commands/__tests__/api-client-cold-start-diagnostic.test.d.ts +1 -0
- package/dist/commands/__tests__/api-client-cold-start-diagnostic.test.js +96 -0
- package/dist/commands/__tests__/canvas-config.test.d.ts +1 -0
- package/dist/commands/__tests__/canvas-config.test.js +107 -0
- package/dist/commands/__tests__/human.test.d.ts +1 -0
- package/dist/commands/__tests__/human.test.js +344 -0
- package/dist/commands/__tests__/node-no-kickoff-flag.test.d.ts +1 -0
- package/dist/commands/__tests__/node-no-kickoff-flag.test.js +73 -0
- package/dist/commands/__tests__/node-worktree-flag.test.d.ts +1 -0
- package/dist/commands/__tests__/node-worktree-flag.test.js +49 -0
- package/dist/commands/__tests__/revive-now-gate.test.d.ts +1 -0
- package/dist/commands/__tests__/revive-now-gate.test.js +60 -0
- package/dist/commands/api-client.d.ts +100 -0
- package/dist/commands/api-client.js +377 -0
- package/dist/commands/attention.d.ts +2 -0
- package/dist/commands/attention.js +223 -0
- package/dist/commands/canvas-browse.d.ts +2 -0
- package/dist/commands/canvas-browse.js +95 -0
- package/dist/commands/canvas-config.d.ts +2 -0
- package/dist/commands/canvas-config.js +210 -0
- package/dist/commands/canvas-history/grep.d.ts +1 -0
- package/dist/commands/canvas-history/grep.js +104 -0
- package/dist/commands/canvas-history/read.d.ts +1 -0
- package/dist/commands/canvas-history/read.js +48 -0
- package/dist/commands/canvas-history/search.d.ts +1 -0
- package/dist/commands/canvas-history/search.js +118 -0
- package/dist/commands/canvas-history/shared.d.ts +27 -0
- package/dist/commands/canvas-history/shared.js +76 -0
- package/dist/commands/canvas-history.d.ts +2 -0
- package/dist/commands/canvas-history.js +30 -0
- package/dist/commands/canvas-issue.d.ts +2 -0
- package/dist/commands/canvas-issue.js +149 -0
- package/dist/commands/canvas-prune.d.ts +2 -0
- package/dist/commands/canvas-prune.js +108 -0
- package/dist/commands/canvas-rebuild-index.d.ts +2 -0
- package/dist/commands/canvas-rebuild-index.js +46 -0
- package/dist/commands/canvas-roster.d.ts +2 -0
- package/dist/commands/canvas-roster.js +62 -0
- package/dist/commands/canvas-snapshot.d.ts +2 -0
- package/dist/commands/canvas-snapshot.js +34 -0
- package/dist/commands/canvas-use.d.ts +1 -0
- package/dist/commands/canvas-use.js +63 -0
- package/dist/commands/canvas.d.ts +3 -0
- package/dist/commands/canvas.js +50 -0
- package/dist/commands/chord.d.ts +2 -0
- package/dist/commands/chord.js +242 -0
- package/dist/commands/cron.d.ts +2 -0
- package/dist/commands/cron.js +524 -0
- package/dist/commands/dashboard.d.ts +2 -0
- package/dist/commands/dashboard.js +80 -0
- package/dist/commands/human/prompts.d.ts +8 -0
- package/dist/commands/human/prompts.js +427 -0
- package/dist/commands/human/queue.d.ts +12 -0
- package/dist/commands/human/queue.js +531 -0
- package/dist/commands/human/shared.d.ts +80 -0
- package/dist/commands/human/shared.js +194 -0
- package/dist/commands/human.d.ts +2 -0
- package/dist/commands/human.js +44 -0
- package/dist/commands/memory/delete.d.ts +1 -0
- package/dist/commands/memory/delete.js +77 -0
- package/dist/commands/memory/find.d.ts +1 -0
- package/dist/commands/memory/find.js +192 -0
- package/dist/commands/memory/lint.d.ts +9 -0
- package/dist/commands/memory/lint.js +217 -0
- package/dist/commands/memory/list.d.ts +1 -0
- package/dist/commands/memory/list.js +84 -0
- package/dist/commands/memory/origin.d.ts +1 -0
- package/dist/commands/memory/origin.js +100 -0
- package/dist/commands/memory/read.d.ts +1 -0
- package/dist/commands/memory/read.js +72 -0
- package/dist/commands/memory/shared.d.ts +54 -0
- package/dist/commands/memory/shared.js +225 -0
- package/dist/commands/memory/write.d.ts +1 -0
- package/dist/commands/memory/write.js +142 -0
- package/dist/commands/memory.d.ts +2 -0
- package/dist/commands/memory.js +26 -0
- package/dist/commands/node-context.d.ts +2 -0
- package/dist/commands/node-context.js +157 -0
- package/dist/commands/node-inspect-artifacts.d.ts +1 -0
- package/dist/commands/node-inspect-artifacts.js +109 -0
- package/dist/commands/node-lifecycle-revive.d.ts +12 -0
- package/dist/commands/node-lifecycle-revive.js +287 -0
- package/dist/commands/node-snapshot.d.ts +2 -0
- package/dist/commands/node-snapshot.js +37 -0
- package/dist/commands/node-transcript.d.ts +2 -0
- package/dist/commands/node-transcript.js +62 -0
- package/dist/commands/node-worktree.d.ts +2 -0
- package/dist/commands/node-worktree.js +102 -0
- package/dist/commands/node.d.ts +44 -0
- package/dist/commands/node.js +1943 -0
- package/dist/commands/pkg/cli-inspect.d.ts +17 -0
- package/dist/commands/pkg/cli-inspect.js +190 -0
- package/dist/commands/pkg/cli-manage.d.ts +3 -0
- package/dist/commands/pkg/cli-manage.js +206 -0
- package/dist/commands/pkg/cli.d.ts +1 -0
- package/dist/commands/pkg/cli.js +14 -0
- package/dist/commands/pkg/market-inspect.d.ts +2 -0
- package/dist/commands/pkg/market-inspect.js +141 -0
- package/dist/commands/pkg/market-manage.d.ts +3 -0
- package/dist/commands/pkg/market-manage.js +224 -0
- package/dist/commands/pkg/market.d.ts +1 -0
- package/dist/commands/pkg/market.js +14 -0
- package/dist/commands/pkg/plugin-inspect.d.ts +2 -0
- package/dist/commands/pkg/plugin-inspect.js +150 -0
- package/dist/commands/pkg/plugin-manage.d.ts +19 -0
- package/dist/commands/pkg/plugin-manage.js +398 -0
- package/dist/commands/pkg/plugin.d.ts +1 -0
- package/dist/commands/pkg/plugin.js +14 -0
- package/dist/commands/pkg/shared.d.ts +5 -0
- package/dist/commands/pkg/shared.js +61 -0
- package/dist/commands/pkg.d.ts +2 -0
- package/dist/commands/pkg.js +24 -0
- package/dist/commands/profile/default.d.ts +2 -0
- package/dist/commands/profile/default.js +143 -0
- package/dist/commands/profile/delete.d.ts +1 -0
- package/dist/commands/profile/delete.js +39 -0
- package/dist/commands/profile/env.d.ts +2 -0
- package/dist/commands/profile/env.js +194 -0
- package/dist/commands/profile/list.d.ts +1 -0
- package/dist/commands/profile/list.js +35 -0
- package/dist/commands/profile/new.d.ts +1 -0
- package/dist/commands/profile/new.js +75 -0
- package/dist/commands/profile/project.d.ts +2 -0
- package/dist/commands/profile/project.js +97 -0
- package/dist/commands/profile/rename.d.ts +1 -0
- package/dist/commands/profile/rename.js +42 -0
- package/dist/commands/profile/show.d.ts +1 -0
- package/dist/commands/profile/show.js +50 -0
- package/dist/commands/profile.d.ts +2 -0
- package/dist/commands/profile.js +37 -0
- package/dist/commands/push.d.ts +2 -0
- package/dist/commands/push.js +166 -0
- package/dist/commands/revive.d.ts +2 -0
- package/dist/commands/revive.js +174 -0
- package/dist/commands/search/answer.d.ts +1 -0
- package/dist/commands/search/answer.js +50 -0
- package/dist/commands/search/contents.d.ts +1 -0
- package/dist/commands/search/contents.js +96 -0
- package/dist/commands/search/exa.d.ts +53 -0
- package/dist/commands/search/exa.js +157 -0
- package/dist/commands/search/puremd.d.ts +11 -0
- package/dist/commands/search/puremd.js +53 -0
- package/dist/commands/search/web.d.ts +1 -0
- package/dist/commands/search/web.js +65 -0
- package/dist/commands/search.d.ts +2 -0
- package/dist/commands/search.js +24 -0
- package/dist/commands/surface-edit.d.ts +2 -0
- package/dist/commands/surface-edit.js +159 -0
- package/dist/commands/surface-inspect.d.ts +2 -0
- package/dist/commands/surface-inspect.js +38 -0
- package/dist/commands/surface-node.d.ts +2 -0
- package/dist/commands/surface-node.js +16 -0
- package/dist/commands/surface-reload.d.ts +2 -0
- package/dist/commands/surface-reload.js +127 -0
- package/dist/commands/surface-tmux-spread.d.ts +2 -0
- package/dist/commands/surface-tmux-spread.js +220 -0
- package/dist/commands/surface.d.ts +2 -0
- package/dist/commands/surface.js +48 -0
- package/dist/commands/sys/__tests__/config-broker-thresholds.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/config-broker-thresholds.test.js +95 -0
- package/dist/commands/sys/__tests__/config-keybindings.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/config-keybindings.test.js +55 -0
- package/dist/commands/sys/__tests__/config-model-ladders.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/config-model-ladders.test.js +121 -0
- package/dist/commands/sys/__tests__/helpers/setup-runtime.d.ts +5 -0
- package/dist/commands/sys/__tests__/helpers/setup-runtime.js +19 -0
- package/dist/commands/sys/__tests__/setup-core.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/setup-core.test.js +291 -0
- package/dist/commands/sys/__tests__/setup-front-door.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/setup-front-door.test.js +137 -0
- package/dist/commands/sys/__tests__/setup-models.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/setup-models.test.js +205 -0
- package/dist/commands/sys/__tests__/setup-providers-viewport.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/setup-providers-viewport.test.js +155 -0
- package/dist/commands/sys/__tests__/sync-deps.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/sync-deps.test.js +188 -0
- package/dist/commands/sys/__tests__/sync-import.test.d.ts +1 -0
- package/dist/commands/sys/__tests__/sync-import.test.js +314 -0
- package/dist/commands/sys/config.d.ts +1 -0
- package/dist/commands/sys/config.js +292 -0
- package/dist/commands/sys/daemon.d.ts +2 -0
- package/dist/commands/sys/daemon.js +188 -0
- package/dist/commands/sys/doctor.d.ts +1 -0
- package/dist/commands/sys/doctor.js +528 -0
- package/dist/commands/sys/feedback.d.ts +1 -0
- package/dist/commands/sys/feedback.js +174 -0
- package/dist/commands/sys/logs.d.ts +1 -0
- package/dist/commands/sys/logs.js +127 -0
- package/dist/commands/sys/prompt-review.d.ts +1 -0
- package/dist/commands/sys/prompt-review.js +291 -0
- package/dist/commands/sys/promptstudio.d.ts +2 -0
- package/dist/commands/sys/promptstudio.js +65 -0
- package/dist/commands/sys/setup-core.d.ts +138 -0
- package/dist/commands/sys/setup-core.js +582 -0
- package/dist/commands/sys/setup-wizard.d.ts +130 -0
- package/dist/commands/sys/setup-wizard.js +2310 -0
- package/dist/commands/sys/setup.d.ts +6 -0
- package/dist/commands/sys/setup.js +36 -0
- package/dist/commands/sys/shared.d.ts +51 -0
- package/dist/commands/sys/shared.js +81 -0
- package/dist/commands/sys/support/prepare.d.ts +13 -0
- package/dist/commands/sys/support/prepare.js +235 -0
- package/dist/commands/sys/support/submit.d.ts +19 -0
- package/dist/commands/sys/support/submit.js +525 -0
- package/dist/commands/sys/support.d.ts +2 -0
- package/dist/commands/sys/support.js +18 -0
- package/dist/commands/sys/sync-deps.d.ts +19 -0
- package/dist/commands/sys/sync-deps.js +508 -0
- package/dist/commands/sys/sync-project-guidance.d.ts +1 -0
- package/dist/commands/sys/sync-project-guidance.js +345 -0
- package/dist/commands/sys/sync-shared.d.ts +7 -0
- package/dist/commands/sys/sync-shared.js +49 -0
- package/dist/commands/sys/sync-skills.d.ts +1 -0
- package/dist/commands/sys/sync-skills.js +306 -0
- package/dist/commands/sys/sync.d.ts +2 -0
- package/dist/commands/sys/sync.js +18 -0
- package/dist/commands/sys/sysprompt.d.ts +1 -0
- package/dist/commands/sys/sysprompt.js +97 -0
- package/dist/commands/sys/update.d.ts +2 -0
- package/dist/commands/sys/update.js +139 -0
- package/dist/commands/sys.d.ts +2 -0
- package/dist/commands/sys.js +30 -0
- package/dist/commands/view-cycle.d.ts +2 -0
- package/dist/commands/view-cycle.js +130 -0
- package/dist/commands/view-list.d.ts +2 -0
- package/dist/commands/view-list.js +66 -0
- package/dist/commands/view-new.d.ts +2 -0
- package/dist/commands/view-new.js +74 -0
- package/dist/commands/view-pick.d.ts +6 -0
- package/dist/commands/view-pick.js +129 -0
- package/dist/commands/view-run.d.ts +2 -0
- package/dist/commands/view-run.js +214 -0
- package/dist/commands/view.d.ts +2 -0
- package/dist/commands/view.js +31 -0
- package/dist/commands/workspace.d.ts +2 -0
- package/dist/commands/workspace.js +165 -0
- package/dist/core/__tests__/base-worker-prompt.test.d.ts +1 -0
- package/dist/core/__tests__/base-worker-prompt.test.js +60 -0
- package/dist/core/__tests__/boot-fault-attempt.test.d.ts +1 -0
- package/dist/core/__tests__/boot-fault-attempt.test.js +83 -0
- package/dist/core/__tests__/boot.test.d.ts +1 -0
- package/dist/core/__tests__/boot.test.js +275 -0
- package/dist/core/__tests__/branded-host-concurrency.test.d.ts +1 -0
- package/dist/core/__tests__/branded-host-concurrency.test.js +72 -0
- package/dist/core/__tests__/broker-fork-seam.test.d.ts +1 -0
- package/dist/core/__tests__/broker-fork-seam.test.js +118 -0
- package/dist/core/__tests__/broker-launch-candidates.test.d.ts +1 -0
- package/dist/core/__tests__/broker-launch-candidates.test.js +241 -0
- package/dist/core/__tests__/broker-preflight.test.d.ts +1 -0
- package/dist/core/__tests__/broker-preflight.test.js +95 -0
- package/dist/core/__tests__/broker-sdk-wiring.test.d.ts +1 -0
- package/dist/core/__tests__/broker-sdk-wiring.test.js +732 -0
- package/dist/core/__tests__/broker-snapshot-history.test.d.ts +1 -0
- package/dist/core/__tests__/broker-snapshot-history.test.js +213 -0
- package/dist/core/__tests__/canvas-inbox-watcher-hold.test.d.ts +1 -0
- package/dist/core/__tests__/canvas-inbox-watcher-hold.test.js +502 -0
- package/dist/core/__tests__/canvas-inbox-watcher.test.d.ts +1 -0
- package/dist/core/__tests__/canvas-inbox-watcher.test.js +255 -0
- package/dist/core/__tests__/canvas.test.d.ts +1 -0
- package/dist/core/__tests__/canvas.test.js +201 -0
- package/dist/core/__tests__/chat-view-reconnect.test.d.ts +1 -0
- package/dist/core/__tests__/chat-view-reconnect.test.js +105 -0
- package/dist/core/__tests__/child-death-wake.test.d.ts +1 -0
- package/dist/core/__tests__/child-death-wake.test.js +161 -0
- package/dist/core/__tests__/close.test.d.ts +1 -0
- package/dist/core/__tests__/close.test.js +254 -0
- package/dist/core/__tests__/command-plugins-surfaces.test.d.ts +1 -0
- package/dist/core/__tests__/command-plugins-surfaces.test.js +325 -0
- package/dist/core/__tests__/command-plugins.test.d.ts +1 -0
- package/dist/core/__tests__/command-plugins.test.js +448 -0
- package/dist/core/__tests__/connection-reconnect-resume.test.d.ts +1 -0
- package/dist/core/__tests__/connection-reconnect-resume.test.js +36 -0
- package/dist/core/__tests__/context-intro.test.d.ts +1 -0
- package/dist/core/__tests__/context-intro.test.js +256 -0
- package/dist/core/__tests__/cron-broker-capacity.test.d.ts +1 -0
- package/dist/core/__tests__/cron-broker-capacity.test.js +100 -0
- package/dist/core/__tests__/daemon-boot.test.d.ts +1 -0
- package/dist/core/__tests__/daemon-boot.test.js +374 -0
- package/dist/core/__tests__/daemon-wedge.test.d.ts +1 -0
- package/dist/core/__tests__/daemon-wedge.test.js +104 -0
- package/dist/core/__tests__/dead-node-policy-table.test.d.ts +1 -0
- package/dist/core/__tests__/dead-node-policy-table.test.js +103 -0
- package/dist/core/__tests__/deferred-no-wake.test.d.ts +1 -0
- package/dist/core/__tests__/deferred-no-wake.test.js +514 -0
- package/dist/core/__tests__/events-contract.test.d.ts +1 -0
- package/dist/core/__tests__/events-contract.test.js +76 -0
- package/dist/core/__tests__/fault-classifier.test.d.ts +1 -0
- package/dist/core/__tests__/fault-classifier.test.js +71 -0
- package/dist/core/__tests__/finalization-migration.test.d.ts +1 -0
- package/dist/core/__tests__/finalization-migration.test.js +38 -0
- package/dist/core/__tests__/fixtures/api-server-host.d.ts +1 -0
- package/dist/core/__tests__/fixtures/api-server-host.js +47 -0
- package/dist/core/__tests__/fixtures/c3-custom-provider-ext.d.ts +2 -0
- package/dist/core/__tests__/fixtures/c3-custom-provider-ext.js +34 -0
- package/dist/core/__tests__/fixtures/c5-command-boundary-ext.d.ts +2 -0
- package/dist/core/__tests__/fixtures/c5-command-boundary-ext.js +8 -0
- package/dist/core/__tests__/fixtures/extra-extension.d.ts +1 -0
- package/dist/core/__tests__/fixtures/extra-extension.js +3 -0
- package/dist/core/__tests__/fixtures/fake-engine.d.ts +310 -0
- package/dist/core/__tests__/fixtures/fake-engine.js +1210 -0
- package/dist/core/__tests__/fixtures/fake-pi-host.d.ts +2 -0
- package/dist/core/__tests__/fixtures/fake-pi-host.js +311 -0
- package/dist/core/__tests__/fixtures/metadata-migration-race.d.ts +1 -0
- package/dist/core/__tests__/fixtures/metadata-migration-race.js +49 -0
- package/dist/core/__tests__/fixtures/spawn-proof-target.test.d.ts +1 -0
- package/dist/core/__tests__/fixtures/spawn-proof-target.test.js +15 -0
- package/dist/core/__tests__/flagship-lifecycle.test.d.ts +1 -0
- package/dist/core/__tests__/flagship-lifecycle.test.js +303 -0
- package/dist/core/__tests__/focuses.test.d.ts +1 -0
- package/dist/core/__tests__/focuses.test.js +208 -0
- package/dist/core/__tests__/fork.test.d.ts +1 -0
- package/dist/core/__tests__/fork.test.js +108 -0
- package/dist/core/__tests__/full/broker-attach-limits.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-attach-limits.test.js +147 -0
- package/dist/core/__tests__/full/broker-attach-stream.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-attach-stream.test.js +133 -0
- package/dist/core/__tests__/full/broker-crash-teardown.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-crash-teardown.test.js +122 -0
- package/dist/core/__tests__/full/broker-deliver-ack.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-deliver-ack.test.js +73 -0
- package/dist/core/__tests__/full/broker-dialogs.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-dialogs.test.js +180 -0
- package/dist/core/__tests__/full/broker-display-snapshot.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-display-snapshot.test.js +75 -0
- package/dist/core/__tests__/full/broker-dormant-wake.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-dormant-wake.test.js +130 -0
- package/dist/core/__tests__/full/broker-model-changed-broadcast.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-model-changed-broadcast.test.js +57 -0
- package/dist/core/__tests__/full/broker-navigate-tree-rewelcome.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-navigate-tree-rewelcome.test.js +80 -0
- package/dist/core/__tests__/full/broker-pane-resolution.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-pane-resolution.test.js +155 -0
- package/dist/core/__tests__/full/broker-provider-retry.test.d.ts +1 -0
- package/dist/core/__tests__/full/broker-provider-retry.test.js +387 -0
- package/dist/core/__tests__/full/cascade-close.test.d.ts +1 -0
- package/dist/core/__tests__/full/cascade-close.test.js +240 -0
- package/dist/core/__tests__/full/consult-startup-failure.test.d.ts +1 -0
- package/dist/core/__tests__/full/consult-startup-failure.test.js +124 -0
- package/dist/core/__tests__/full/detach-focus.test.d.ts +1 -0
- package/dist/core/__tests__/full/detach-focus.test.js +126 -0
- package/dist/core/__tests__/full/idle-release-settlement.test.d.ts +1 -0
- package/dist/core/__tests__/full/idle-release-settlement.test.js +108 -0
- package/dist/core/__tests__/full/issue-146-yield-spawn-focus.test.d.ts +1 -0
- package/dist/core/__tests__/full/issue-146-yield-spawn-focus.test.js +107 -0
- package/dist/core/__tests__/full/park-clock-release.test.d.ts +1 -0
- package/dist/core/__tests__/full/park-clock-release.test.js +56 -0
- package/dist/core/__tests__/full/yield-message-transaction.test.d.ts +1 -0
- package/dist/core/__tests__/full/yield-message-transaction.test.js +70 -0
- package/dist/core/__tests__/helpers/broker-clients.d.ts +43 -0
- package/dist/core/__tests__/helpers/broker-clients.js +182 -0
- package/dist/core/__tests__/helpers/fleet.d.ts +12 -0
- package/dist/core/__tests__/helpers/fleet.js +45 -0
- package/dist/core/__tests__/helpers/harness.d.ts +128 -0
- package/dist/core/__tests__/helpers/harness.js +867 -0
- package/dist/core/__tests__/helpers/viewer-panes.d.ts +12 -0
- package/dist/core/__tests__/helpers/viewer-panes.js +133 -0
- package/dist/core/__tests__/history-inbox.test.d.ts +1 -0
- package/dist/core/__tests__/history-inbox.test.js +105 -0
- package/dist/core/__tests__/host-teardown-process-group.test.d.ts +1 -0
- package/dist/core/__tests__/host-teardown-process-group.test.js +476 -0
- package/dist/core/__tests__/human-cancel-guard.test.d.ts +1 -0
- package/dist/core/__tests__/human-cancel-guard.test.js +71 -0
- package/dist/core/__tests__/human-deliver-e2e.test.d.ts +1 -0
- package/dist/core/__tests__/human-deliver-e2e.test.js +123 -0
- package/dist/core/__tests__/human-deliver.test.d.ts +1 -0
- package/dist/core/__tests__/human-deliver.test.js +399 -0
- package/dist/core/__tests__/human-node-not-supervised.test.d.ts +1 -0
- package/dist/core/__tests__/human-node-not-supervised.test.js +94 -0
- package/dist/core/__tests__/inline-memory-refs.test.d.ts +1 -0
- package/dist/core/__tests__/inline-memory-refs.test.js +320 -0
- package/dist/core/__tests__/kickoff.test.d.ts +1 -0
- package/dist/core/__tests__/kickoff.test.js +148 -0
- package/dist/core/__tests__/lifecycle.test.d.ts +1 -0
- package/dist/core/__tests__/lifecycle.test.js +165 -0
- package/dist/core/__tests__/live-lifecycle-prompt.test.d.ts +1 -0
- package/dist/core/__tests__/live-lifecycle-prompt.test.js +51 -0
- package/dist/core/__tests__/live-mutation-verbs.test.d.ts +1 -0
- package/dist/core/__tests__/live-mutation-verbs.test.js +195 -0
- package/dist/core/__tests__/live-mutation.test.d.ts +1 -0
- package/dist/core/__tests__/live-mutation.test.js +197 -0
- package/dist/core/__tests__/memory-index-render.test.d.ts +1 -0
- package/dist/core/__tests__/memory-index-render.test.js +60 -0
- package/dist/core/__tests__/memory-resolver-precedence.test.d.ts +1 -0
- package/dist/core/__tests__/memory-resolver-precedence.test.js +169 -0
- package/dist/core/__tests__/migration.test.d.ts +1 -0
- package/dist/core/__tests__/migration.test.js +717 -0
- package/dist/core/__tests__/model-pin-durability.test.d.ts +1 -0
- package/dist/core/__tests__/model-pin-durability.test.js +124 -0
- package/dist/core/__tests__/on-read-crouter-home-fence.test.d.ts +1 -0
- package/dist/core/__tests__/on-read-crouter-home-fence.test.js +67 -0
- package/dist/core/__tests__/on-read-dedup-resume.test.d.ts +1 -0
- package/dist/core/__tests__/on-read-dedup-resume.test.js +121 -0
- package/dist/core/__tests__/on-read-identity.test.d.ts +1 -0
- package/dist/core/__tests__/on-read-identity.test.js +68 -0
- package/dist/core/__tests__/parse-argv-stdin-secret.test.d.ts +1 -0
- package/dist/core/__tests__/parse-argv-stdin-secret.test.js +26 -0
- package/dist/core/__tests__/passive-subscription.test.d.ts +1 -0
- package/dist/core/__tests__/passive-subscription.test.js +212 -0
- package/dist/core/__tests__/pid-identity-match.test.d.ts +1 -0
- package/dist/core/__tests__/pid-identity-match.test.js +145 -0
- package/dist/core/__tests__/pid-zombie.test.d.ts +1 -0
- package/dist/core/__tests__/pid-zombie.test.js +42 -0
- package/dist/core/__tests__/preview-registry-sync.test.d.ts +1 -0
- package/dist/core/__tests__/preview-registry-sync.test.js +65 -0
- package/dist/core/__tests__/prune-to-limit.test.d.ts +1 -0
- package/dist/core/__tests__/prune-to-limit.test.js +126 -0
- package/dist/core/__tests__/prune.test.d.ts +1 -0
- package/dist/core/__tests__/prune.test.js +135 -0
- package/dist/core/__tests__/push-final-guard.test.d.ts +1 -0
- package/dist/core/__tests__/push-final-guard.test.js +184 -0
- package/dist/core/__tests__/refresh-stall-recycle.test.d.ts +1 -0
- package/dist/core/__tests__/refresh-stall-recycle.test.js +101 -0
- package/dist/core/__tests__/relaunch-root.test.d.ts +1 -0
- package/dist/core/__tests__/relaunch-root.test.js +114 -0
- package/dist/core/__tests__/remote-canvas-target.test.d.ts +1 -0
- package/dist/core/__tests__/remote-canvas-target.test.js +87 -0
- package/dist/core/__tests__/reset.test.d.ts +1 -0
- package/dist/core/__tests__/reset.test.js +69 -0
- package/dist/core/__tests__/respawn-throttle.test.d.ts +1 -0
- package/dist/core/__tests__/respawn-throttle.test.js +154 -0
- package/dist/core/__tests__/review-model-floor.test.d.ts +1 -0
- package/dist/core/__tests__/review-model-floor.test.js +104 -0
- package/dist/core/__tests__/revive-all.test.d.ts +1 -0
- package/dist/core/__tests__/revive-all.test.js +147 -0
- package/dist/core/__tests__/revive.test.d.ts +1 -0
- package/dist/core/__tests__/revive.test.js +575 -0
- package/dist/core/__tests__/scope-crouter-home-fence.test.d.ts +1 -0
- package/dist/core/__tests__/scope-crouter-home-fence.test.js +55 -0
- package/dist/core/__tests__/secrets.test.d.ts +1 -0
- package/dist/core/__tests__/secrets.test.js +55 -0
- package/dist/core/__tests__/session-branch.test.d.ts +1 -0
- package/dist/core/__tests__/session-branch.test.js +61 -0
- package/dist/core/__tests__/session-cycles.test.d.ts +1 -0
- package/dist/core/__tests__/session-cycles.test.js +77 -0
- package/dist/core/__tests__/session-model.test.d.ts +1 -0
- package/dist/core/__tests__/session-model.test.js +129 -0
- package/dist/core/__tests__/spawn-no-kickoff.test.d.ts +1 -0
- package/dist/core/__tests__/spawn-no-kickoff.test.js +119 -0
- package/dist/core/__tests__/spawn-root.test.d.ts +1 -0
- package/dist/core/__tests__/spawn-root.test.js +320 -0
- package/dist/core/__tests__/spawn-worktree-id-conflict.test.d.ts +1 -0
- package/dist/core/__tests__/spawn-worktree-id-conflict.test.js +59 -0
- package/dist/core/__tests__/stdin-body-no-discard.test.d.ts +1 -0
- package/dist/core/__tests__/stdin-body-no-discard.test.js +33 -0
- package/dist/core/__tests__/stdout-errors.test.d.ts +1 -0
- package/dist/core/__tests__/stdout-errors.test.js +16 -0
- package/dist/core/__tests__/steer-note.test.d.ts +1 -0
- package/dist/core/__tests__/steer-note.test.js +41 -0
- package/dist/core/__tests__/stop-guard.test.d.ts +1 -0
- package/dist/core/__tests__/stop-guard.test.js +157 -0
- package/dist/core/__tests__/stream-watchdog.test.d.ts +1 -0
- package/dist/core/__tests__/stream-watchdog.test.js +154 -0
- package/dist/core/__tests__/subcommand-tier.test.d.ts +1 -0
- package/dist/core/__tests__/subcommand-tier.test.js +99 -0
- package/dist/core/__tests__/subscription-delivery.test.d.ts +1 -0
- package/dist/core/__tests__/subscription-delivery.test.js +211 -0
- package/dist/core/__tests__/subscription-pool-credential-guard.test.d.ts +1 -0
- package/dist/core/__tests__/subscription-pool-credential-guard.test.js +94 -0
- package/dist/core/__tests__/test-runner-cheap-sharding.test.d.ts +1 -0
- package/dist/core/__tests__/test-runner-cheap-sharding.test.js +97 -0
- package/dist/core/__tests__/tmux-surface.test.d.ts +1 -0
- package/dist/core/__tests__/tmux-surface.test.js +470 -0
- package/dist/core/__tests__/wake-bearings.test.d.ts +1 -0
- package/dist/core/__tests__/wake-bearings.test.js +102 -0
- package/dist/core/__tests__/worktree.test.d.ts +1 -0
- package/dist/core/__tests__/worktree.test.js +876 -0
- package/dist/core/__tests__/yield-ensures-daemon.test.d.ts +1 -0
- package/dist/core/__tests__/yield-ensures-daemon.test.js +54 -0
- package/dist/core/auth-file.d.ts +40 -0
- package/dist/core/auth-file.js +177 -0
- package/dist/core/auth-interaction.d.ts +19 -0
- package/dist/core/auth-interaction.js +94 -0
- package/dist/core/auto-update.d.ts +1 -0
- package/dist/core/auto-update.js +93 -0
- package/dist/core/bash-jobs.d.ts +55 -0
- package/dist/core/bash-jobs.js +150 -0
- package/dist/core/bootstrap.d.ts +5 -0
- package/dist/core/bootstrap.js +98 -0
- package/dist/core/broker-client/__tests__/transport-relay.test.d.ts +1 -0
- package/dist/core/broker-client/__tests__/transport-relay.test.js +213 -0
- package/dist/core/broker-client/client.d.ts +97 -0
- package/dist/core/broker-client/client.js +189 -0
- package/dist/core/broker-client/index.d.ts +1 -0
- package/dist/core/broker-client/index.js +13 -0
- package/dist/core/broker-client/transport-relay.d.ts +51 -0
- package/dist/core/broker-client/transport-relay.js +169 -0
- package/dist/core/broker-client/transport-socket.d.ts +29 -0
- package/dist/core/broker-client/transport-socket.js +164 -0
- package/dist/core/broker-client/transport.d.ts +32 -0
- package/dist/core/broker-client/transport.js +26 -0
- package/dist/core/canvas/__tests__/attention.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/attention.test.js +97 -0
- package/dist/core/canvas/__tests__/human-work-outbox.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/human-work-outbox.test.js +123 -0
- package/dist/core/canvas/__tests__/remote-canvas-source.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/remote-canvas-source.test.js +372 -0
- package/dist/core/canvas/__tests__/remote-event-stream.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/remote-event-stream.test.js +146 -0
- package/dist/core/canvas/__tests__/render-remote.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/render-remote.test.js +241 -0
- package/dist/core/canvas/__tests__/source-resolve.test.d.ts +1 -0
- package/dist/core/canvas/__tests__/source-resolve.test.js +77 -0
- package/dist/core/canvas/attention.d.ts +19 -0
- package/dist/core/canvas/attention.js +87 -0
- package/dist/core/canvas/boot-id.d.ts +6 -0
- package/dist/core/canvas/boot-id.js +26 -0
- package/dist/core/canvas/boot.d.ts +93 -0
- package/dist/core/canvas/boot.js +190 -0
- package/dist/core/canvas/browse/__tests__/model.test.d.ts +1 -0
- package/dist/core/canvas/browse/__tests__/model.test.js +290 -0
- package/dist/core/canvas/browse/__tests__/rebuild-coalescer.test.d.ts +1 -0
- package/dist/core/canvas/browse/__tests__/rebuild-coalescer.test.js +134 -0
- package/dist/core/canvas/browse/__tests__/render.test.d.ts +1 -0
- package/dist/core/canvas/browse/__tests__/render.test.js +111 -0
- package/dist/core/canvas/browse/app.d.ts +41 -0
- package/dist/core/canvas/browse/app.js +916 -0
- package/dist/core/canvas/browse/model.d.ts +169 -0
- package/dist/core/canvas/browse/model.js +485 -0
- package/dist/core/canvas/browse/pins.d.ts +4 -0
- package/dist/core/canvas/browse/pins.js +29 -0
- package/dist/core/canvas/browse/rebuild-coalescer.d.ts +7 -0
- package/dist/core/canvas/browse/rebuild-coalescer.js +61 -0
- package/dist/core/canvas/browse/render.d.ts +59 -0
- package/dist/core/canvas/browse/render.js +550 -0
- package/dist/core/canvas/canvas.d.ts +358 -0
- package/dist/core/canvas/canvas.js +897 -0
- package/dist/core/canvas/crons.d.ts +222 -0
- package/dist/core/canvas/crons.js +367 -0
- package/dist/core/canvas/daemon-owner.d.ts +67 -0
- package/dist/core/canvas/daemon-owner.js +141 -0
- package/dist/core/canvas/db.d.ts +30 -0
- package/dist/core/canvas/db.js +1167 -0
- package/dist/core/canvas/extensions.d.ts +5 -0
- package/dist/core/canvas/extensions.js +39 -0
- package/dist/core/canvas/focuses.d.ts +22 -0
- package/dist/core/canvas/focuses.js +81 -0
- package/dist/core/canvas/history.d.ts +91 -0
- package/dist/core/canvas/history.js +490 -0
- package/dist/core/canvas/human-work-outbox.d.ts +73 -0
- package/dist/core/canvas/human-work-outbox.js +261 -0
- package/dist/core/canvas/index.d.ts +11 -0
- package/dist/core/canvas/index.js +13 -0
- package/dist/core/canvas/install-id.d.ts +9 -0
- package/dist/core/canvas/install-id.js +84 -0
- package/dist/core/canvas/labels.d.ts +28 -0
- package/dist/core/canvas/labels.js +38 -0
- package/dist/core/canvas/meta-file.d.ts +20 -0
- package/dist/core/canvas/meta-file.js +98 -0
- package/dist/core/canvas/nav-model.d.ts +55 -0
- package/dist/core/canvas/nav-model.js +284 -0
- package/dist/core/canvas/nav-render.d.ts +124 -0
- package/dist/core/canvas/nav-render.js +266 -0
- package/dist/core/canvas/paths.d.ts +81 -0
- package/dist/core/canvas/paths.js +164 -0
- package/dist/core/canvas/pid.d.ts +335 -0
- package/dist/core/canvas/pid.js +636 -0
- package/dist/core/canvas/remote-canvas-source.d.ts +62 -0
- package/dist/core/canvas/remote-canvas-source.js +231 -0
- package/dist/core/canvas/remote-event-stream.d.ts +24 -0
- package/dist/core/canvas/remote-event-stream.js +94 -0
- package/dist/core/canvas/render-source.d.ts +132 -0
- package/dist/core/canvas/render-source.js +457 -0
- package/dist/core/canvas/render.d.ts +47 -0
- package/dist/core/canvas/render.js +237 -0
- package/dist/core/canvas/source.d.ts +35 -0
- package/dist/core/canvas/source.js +44 -0
- package/dist/core/canvas/status-glyph.d.ts +42 -0
- package/dist/core/canvas/status-glyph.js +116 -0
- package/dist/core/canvas/telemetry.d.ts +14 -0
- package/dist/core/canvas/telemetry.js +35 -0
- package/dist/core/canvas/types.d.ts +302 -0
- package/dist/core/canvas/types.js +8 -0
- package/dist/core/clipboard-text.d.ts +3 -0
- package/dist/core/clipboard-text.js +39 -0
- package/dist/core/command-manifests/registry.d.ts +43 -0
- package/dist/core/command-manifests/registry.js +103 -0
- package/dist/core/command-manifests/schema.d.ts +87 -0
- package/dist/core/command-manifests/schema.js +849 -0
- package/dist/core/command-plugins/adapter.d.ts +22 -0
- package/dist/core/command-plugins/adapter.js +160 -0
- package/dist/core/command-plugins/compose.d.ts +11 -0
- package/dist/core/command-plugins/compose.js +88 -0
- package/dist/core/command-plugins/discovery.d.ts +74 -0
- package/dist/core/command-plugins/discovery.js +291 -0
- package/dist/core/command.d.ts +175 -0
- package/dist/core/command.js +636 -0
- package/dist/core/config.d.ts +125 -0
- package/dist/core/config.js +620 -0
- package/dist/core/configured-clis/cache.d.ts +16 -0
- package/dist/core/configured-clis/cache.js +57 -0
- package/dist/core/configured-clis/compose.d.ts +14 -0
- package/dist/core/configured-clis/compose.js +60 -0
- package/dist/core/configured-clis/discovery.d.ts +47 -0
- package/dist/core/configured-clis/discovery.js +173 -0
- package/dist/core/configured-clis/fetch.d.ts +51 -0
- package/dist/core/configured-clis/fetch.js +156 -0
- package/dist/core/configured-clis/invoker.d.ts +36 -0
- package/dist/core/configured-clis/invoker.js +547 -0
- package/dist/core/configured-clis/manifest.d.ts +24 -0
- package/dist/core/configured-clis/manifest.js +284 -0
- package/dist/core/configured-clis/registration.d.ts +40 -0
- package/dist/core/configured-clis/registration.js +201 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +48 -0
- package/dist/core/events/emit.d.ts +4 -0
- package/dist/core/events/emit.js +17 -0
- package/dist/core/events/envelope.d.ts +2 -0
- package/dist/core/events/envelope.js +84 -0
- package/dist/core/events/errors.d.ts +4 -0
- package/dist/core/events/errors.js +69 -0
- package/dist/core/events/index.d.ts +5 -0
- package/dist/core/events/index.js +4 -0
- package/dist/core/events/operation-id.d.ts +4 -0
- package/dist/core/events/operation-id.js +24 -0
- package/dist/core/events/read.d.ts +40 -0
- package/dist/core/events/read.js +639 -0
- package/dist/core/events/serialize.d.ts +4 -0
- package/dist/core/events/serialize.js +199 -0
- package/dist/core/events/source.d.ts +18 -0
- package/dist/core/events/source.js +47 -0
- package/dist/core/events/types.d.ts +68 -0
- package/dist/core/events/types.js +11 -0
- package/dist/core/fault-classifier.d.ts +43 -0
- package/dist/core/fault-classifier.js +143 -0
- package/dist/core/feed/__tests__/coalesce-human.test.d.ts +1 -0
- package/dist/core/feed/__tests__/coalesce-human.test.js +36 -0
- package/dist/core/feed/__tests__/empty-node-guard.test.d.ts +1 -0
- package/dist/core/feed/__tests__/empty-node-guard.test.js +45 -0
- package/dist/core/feed/__tests__/inbox-migrate.test.d.ts +1 -0
- package/dist/core/feed/__tests__/inbox-migrate.test.js +53 -0
- package/dist/core/feed/feed.d.ts +31 -0
- package/dist/core/feed/feed.js +159 -0
- package/dist/core/feed/inbox-migrate.d.ts +11 -0
- package/dist/core/feed/inbox-migrate.js +135 -0
- package/dist/core/feed/inbox.d.ts +84 -0
- package/dist/core/feed/inbox.js +407 -0
- package/dist/core/feed/passive.d.ts +14 -0
- package/dist/core/feed/passive.js +114 -0
- package/dist/core/frontmatter.d.ts +8 -0
- package/dist/core/frontmatter.js +35 -0
- package/dist/core/fs-utils.d.ts +21 -0
- package/dist/core/fs-utils.js +149 -0
- package/dist/core/git.d.ts +22 -0
- package/dist/core/git.js +72 -0
- package/dist/core/help.d.ts +223 -0
- package/dist/core/help.js +275 -0
- package/dist/core/host-exports/__tests__/export-prunes-boot-skill.test.d.ts +1 -0
- package/dist/core/host-exports/__tests__/export-prunes-boot-skill.test.js +84 -0
- package/dist/core/host-exports/builtins.d.ts +50 -0
- package/dist/core/host-exports/builtins.js +68 -0
- package/dist/core/host-exports/export.d.ts +32 -0
- package/dist/core/host-exports/export.js +128 -0
- package/dist/core/inspector/core.d.ts +23 -0
- package/dist/core/inspector/core.js +148 -0
- package/dist/core/inspector/model.d.ts +54 -0
- package/dist/core/inspector/model.js +182 -0
- package/dist/core/inspector/text.d.ts +5 -0
- package/dist/core/inspector/text.js +32 -0
- package/dist/core/inspector/tui.d.ts +3 -0
- package/dist/core/inspector/tui.js +220 -0
- package/dist/core/io.d.ts +73 -0
- package/dist/core/io.js +254 -0
- package/dist/core/keybindings/__tests__/bespoke-consumers.test.d.ts +1 -0
- package/dist/core/keybindings/__tests__/bespoke-consumers.test.js +40 -0
- package/dist/core/keybindings/__tests__/inbox-affordance.test.d.ts +1 -0
- package/dist/core/keybindings/__tests__/inbox-affordance.test.js +38 -0
- package/dist/core/keybindings/__tests__/resolve.test.d.ts +1 -0
- package/dist/core/keybindings/__tests__/resolve.test.js +233 -0
- package/dist/core/keybindings/background-bash.d.ts +13 -0
- package/dist/core/keybindings/background-bash.js +34 -0
- package/dist/core/keybindings/catalog.d.ts +15 -0
- package/dist/core/keybindings/catalog.js +285 -0
- package/dist/core/keybindings/inbox.d.ts +21 -0
- package/dist/core/keybindings/inbox.js +35 -0
- package/dist/core/keybindings/index.d.ts +7 -0
- package/dist/core/keybindings/index.js +6 -0
- package/dist/core/keybindings/match.d.ts +29 -0
- package/dist/core/keybindings/match.js +105 -0
- package/dist/core/keybindings/persistence.d.ts +14 -0
- package/dist/core/keybindings/persistence.js +31 -0
- package/dist/core/keybindings/resolve.d.ts +22 -0
- package/dist/core/keybindings/resolve.js +333 -0
- package/dist/core/keybindings/types.d.ts +37 -0
- package/dist/core/keybindings/types.js +1 -0
- package/dist/core/locked-file.d.ts +24 -0
- package/dist/core/locked-file.js +91 -0
- package/dist/core/log.d.ts +3 -0
- package/dist/core/log.js +27 -0
- package/dist/core/manifest.d.ts +5 -0
- package/dist/core/manifest.js +15 -0
- package/dist/core/memory/inline-ref-grammar.d.ts +53 -0
- package/dist/core/memory/inline-ref-grammar.js +99 -0
- package/dist/core/memory/inline-ref-guidance.d.ts +8 -0
- package/dist/core/memory/inline-ref-guidance.js +35 -0
- package/dist/core/memory/inline-ref-inventory.d.ts +13 -0
- package/dist/core/memory/inline-ref-inventory.js +79 -0
- package/dist/core/memory-resolver.d.ts +106 -0
- package/dist/core/memory-resolver.js +422 -0
- package/dist/core/output.d.ts +35 -0
- package/dist/core/output.js +99 -0
- package/dist/core/pagination.d.ts +33 -0
- package/dist/core/pagination.js +89 -0
- package/dist/core/pool-credential-store.d.ts +34 -0
- package/dist/core/pool-credential-store.js +116 -0
- package/dist/core/predicate.d.ts +65 -0
- package/dist/core/predicate.js +191 -0
- package/dist/core/preview-registry.d.ts +25 -0
- package/dist/core/preview-registry.js +2841 -0
- package/dist/core/profiles/__tests__/env-store.test.d.ts +1 -0
- package/dist/core/profiles/__tests__/env-store.test.js +97 -0
- package/dist/core/profiles/__tests__/root-profile.test.d.ts +1 -0
- package/dist/core/profiles/__tests__/root-profile.test.js +69 -0
- package/dist/core/profiles/default-binding.d.ts +6 -0
- package/dist/core/profiles/default-binding.js +46 -0
- package/dist/core/profiles/env-store.d.ts +22 -0
- package/dist/core/profiles/env-store.js +157 -0
- package/dist/core/profiles/manifest.d.ts +35 -0
- package/dist/core/profiles/manifest.js +371 -0
- package/dist/core/profiles/select.d.ts +42 -0
- package/dist/core/profiles/select.js +673 -0
- package/dist/core/profiles/state-block.d.ts +4 -0
- package/dist/core/profiles/state-block.js +16 -0
- package/dist/core/provider-management.d.ts +12 -0
- package/dist/core/provider-management.js +22 -0
- package/dist/core/render.d.ts +12 -0
- package/dist/core/render.js +127 -0
- package/dist/core/resolver.d.ts +14 -0
- package/dist/core/resolver.js +136 -0
- package/dist/core/runtime/__tests__/command-expansion.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/command-expansion.test.js +25 -0
- package/dist/core/runtime/__tests__/engine-route.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/engine-route.test.js +36 -0
- package/dist/core/runtime/__tests__/install-id-cache-scoping.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/install-id-cache-scoping.test.js +41 -0
- package/dist/core/runtime/__tests__/node-env.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/node-env.test.js +73 -0
- package/dist/core/runtime/__tests__/spawn-at-given-id.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/spawn-at-given-id.test.js +34 -0
- package/dist/core/runtime/__tests__/spawn-env.test.d.ts +1 -0
- package/dist/core/runtime/__tests__/spawn-env.test.js +268 -0
- package/dist/core/runtime/auth-reload.d.ts +7 -0
- package/dist/core/runtime/auth-reload.js +67 -0
- package/dist/core/runtime/banner.d.ts +13 -0
- package/dist/core/runtime/banner.js +51 -0
- package/dist/core/runtime/bearings.d.ts +99 -0
- package/dist/core/runtime/bearings.js +429 -0
- package/dist/core/runtime/boot-root.d.ts +24 -0
- package/dist/core/runtime/boot-root.js +102 -0
- package/dist/core/runtime/branded-host.d.ts +25 -0
- package/dist/core/runtime/branded-host.js +342 -0
- package/dist/core/runtime/broker-cli.d.ts +1 -0
- package/dist/core/runtime/broker-cli.js +81 -0
- package/dist/core/runtime/broker-protocol.d.ts +642 -0
- package/dist/core/runtime/broker-protocol.js +146 -0
- package/dist/core/runtime/broker-request.d.ts +37 -0
- package/dist/core/runtime/broker-request.js +85 -0
- package/dist/core/runtime/broker-sdk.d.ts +36 -0
- package/dist/core/runtime/broker-sdk.js +128 -0
- package/dist/core/runtime/broker.d.ts +245 -0
- package/dist/core/runtime/broker.js +3711 -0
- package/dist/core/runtime/busy.d.ts +32 -0
- package/dist/core/runtime/busy.js +107 -0
- package/dist/core/runtime/canvas-extensions.d.ts +20 -0
- package/dist/core/runtime/canvas-extensions.js +70 -0
- package/dist/core/runtime/close.d.ts +34 -0
- package/dist/core/runtime/close.js +223 -0
- package/dist/core/runtime/command-expansion.d.ts +19 -0
- package/dist/core/runtime/command-expansion.js +104 -0
- package/dist/core/runtime/connectivity.d.ts +12 -0
- package/dist/core/runtime/connectivity.js +73 -0
- package/dist/core/runtime/deliver-live.d.ts +26 -0
- package/dist/core/runtime/deliver-live.js +63 -0
- package/dist/core/runtime/fault-recovery-nudge.d.ts +3 -0
- package/dist/core/runtime/fault-recovery-nudge.js +3 -0
- package/dist/core/runtime/fault-recovery.d.ts +23 -0
- package/dist/core/runtime/fault-recovery.js +83 -0
- package/dist/core/runtime/fault.d.ts +64 -0
- package/dist/core/runtime/fault.js +260 -0
- package/dist/core/runtime/fleet.d.ts +57 -0
- package/dist/core/runtime/fleet.js +35 -0
- package/dist/core/runtime/front-door.d.ts +16 -0
- package/dist/core/runtime/front-door.js +186 -0
- package/dist/core/runtime/host.d.ts +43 -0
- package/dist/core/runtime/host.js +432 -0
- package/dist/core/runtime/interactive-deliver.d.ts +15 -0
- package/dist/core/runtime/interactive-deliver.js +41 -0
- package/dist/core/runtime/kickoff.d.ts +53 -0
- package/dist/core/runtime/kickoff.js +289 -0
- package/dist/core/runtime/launch-prompt.d.ts +8 -0
- package/dist/core/runtime/launch-prompt.js +13 -0
- package/dist/core/runtime/launch.d.ts +191 -0
- package/dist/core/runtime/launch.js +442 -0
- package/dist/core/runtime/lifecycle.d.ts +12 -0
- package/dist/core/runtime/lifecycle.js +121 -0
- package/dist/core/runtime/managed-provider-cooling.d.ts +38 -0
- package/dist/core/runtime/managed-provider-cooling.js +81 -0
- package/dist/core/runtime/memory.d.ts +3 -0
- package/dist/core/runtime/memory.js +18 -0
- package/dist/core/runtime/model-selection.d.ts +41 -0
- package/dist/core/runtime/model-selection.js +118 -0
- package/dist/core/runtime/model-swap.d.ts +27 -0
- package/dist/core/runtime/model-swap.js +70 -0
- package/dist/core/runtime/naming-persist.d.ts +11 -0
- package/dist/core/runtime/naming-persist.js +41 -0
- package/dist/core/runtime/naming.d.ts +26 -0
- package/dist/core/runtime/naming.js +174 -0
- package/dist/core/runtime/node-read.d.ts +36 -0
- package/dist/core/runtime/node-read.js +255 -0
- package/dist/core/runtime/nodes.d.ts +113 -0
- package/dist/core/runtime/nodes.js +330 -0
- package/dist/core/runtime/package-health.d.ts +49 -0
- package/dist/core/runtime/package-health.js +217 -0
- package/dist/core/runtime/persona.d.ts +25 -0
- package/dist/core/runtime/persona.js +132 -0
- package/dist/core/runtime/pi-cli.d.ts +8 -0
- package/dist/core/runtime/pi-cli.js +65 -0
- package/dist/core/runtime/pi-vendored.d.ts +26 -0
- package/dist/core/runtime/pi-vendored.js +77 -0
- package/dist/core/runtime/placement-tmux.d.ts +42 -0
- package/dist/core/runtime/placement-tmux.js +151 -0
- package/dist/core/runtime/placement.d.ts +97 -0
- package/dist/core/runtime/placement.js +394 -0
- package/dist/core/runtime/promote.d.ts +44 -0
- package/dist/core/runtime/promote.js +176 -0
- package/dist/core/runtime/recap.d.ts +8 -0
- package/dist/core/runtime/recap.js +136 -0
- package/dist/core/runtime/recycle.d.ts +14 -0
- package/dist/core/runtime/recycle.js +158 -0
- package/dist/core/runtime/reopen.d.ts +32 -0
- package/dist/core/runtime/reopen.js +119 -0
- package/dist/core/runtime/reset.d.ts +68 -0
- package/dist/core/runtime/reset.js +198 -0
- package/dist/core/runtime/resume-root.d.ts +6 -0
- package/dist/core/runtime/resume-root.js +292 -0
- package/dist/core/runtime/revive-all.d.ts +61 -0
- package/dist/core/runtime/revive-all.js +106 -0
- package/dist/core/runtime/revive.d.ts +58 -0
- package/dist/core/runtime/revive.js +357 -0
- package/dist/core/runtime/roadmap.d.ts +13 -0
- package/dist/core/runtime/roadmap.js +45 -0
- package/dist/core/runtime/session-branch.d.ts +13 -0
- package/dist/core/runtime/session-branch.js +46 -0
- package/dist/core/runtime/session-cycles.d.ts +30 -0
- package/dist/core/runtime/session-cycles.js +77 -0
- package/dist/core/runtime/session-list-cache.d.ts +53 -0
- package/dist/core/runtime/session-list-cache.js +406 -0
- package/dist/core/runtime/situational-context.d.ts +12 -0
- package/dist/core/runtime/situational-context.js +48 -0
- package/dist/core/runtime/situational-live.d.ts +9 -0
- package/dist/core/runtime/situational-live.js +40 -0
- package/dist/core/runtime/spawn-env.d.ts +31 -0
- package/dist/core/runtime/spawn-env.js +179 -0
- package/dist/core/runtime/spawn.d.ts +118 -0
- package/dist/core/runtime/spawn.js +473 -0
- package/dist/core/runtime/stop-guard.d.ts +18 -0
- package/dist/core/runtime/stop-guard.js +77 -0
- package/dist/core/runtime/stop-signals.d.ts +14 -0
- package/dist/core/runtime/stop-signals.js +46 -0
- package/dist/core/runtime/stream-watchdog.d.ts +55 -0
- package/dist/core/runtime/stream-watchdog.js +140 -0
- package/dist/core/runtime/structured-output.d.ts +12 -0
- package/dist/core/runtime/structured-output.js +90 -0
- package/dist/core/runtime/surface-bg.d.ts +11 -0
- package/dist/core/runtime/surface-bg.js +68 -0
- package/dist/core/runtime/tmux-chrome.d.ts +1 -0
- package/dist/core/runtime/tmux-chrome.js +4 -0
- package/dist/core/runtime/tmux.d.ts +247 -0
- package/dist/core/runtime/tmux.js +858 -0
- package/dist/core/runtime/warm-pool.d.ts +51 -0
- package/dist/core/runtime/warm-pool.js +373 -0
- package/dist/core/scope.d.ts +47 -0
- package/dist/core/scope.js +255 -0
- package/dist/core/secrets.d.ts +25 -0
- package/dist/core/secrets.js +55 -0
- package/dist/core/self-update.d.ts +21 -0
- package/dist/core/self-update.js +105 -0
- package/dist/core/session-model/session-state.d.ts +51 -0
- package/dist/core/session-model/session-state.js +170 -0
- package/dist/core/spawn.d.ts +16 -0
- package/dist/core/spawn.js +30 -0
- package/dist/core/stdout-errors.d.ts +3 -0
- package/dist/core/stdout-errors.js +14 -0
- package/dist/core/subscription-state.d.ts +138 -0
- package/dist/core/subscription-state.js +918 -0
- package/dist/core/substrate/ceiling.d.ts +20 -0
- package/dist/core/substrate/ceiling.js +69 -0
- package/dist/core/substrate/gate.d.ts +13 -0
- package/dist/core/substrate/gate.js +21 -0
- package/dist/core/substrate/index.d.ts +11 -0
- package/dist/core/substrate/index.js +25 -0
- package/dist/core/substrate/injected-store.d.ts +10 -0
- package/dist/core/substrate/injected-store.js +55 -0
- package/dist/core/substrate/on-read.d.ts +14 -0
- package/dist/core/substrate/on-read.js +404 -0
- package/dist/core/substrate/render-node.d.ts +11 -0
- package/dist/core/substrate/render-node.js +29 -0
- package/dist/core/substrate/render.d.ts +21 -0
- package/dist/core/substrate/render.js +547 -0
- package/dist/core/substrate/schema.d.ts +125 -0
- package/dist/core/substrate/schema.js +191 -0
- package/dist/core/substrate/session-cache.d.ts +25 -0
- package/dist/core/substrate/session-cache.js +101 -0
- package/dist/core/substrate/subject-fields.d.ts +45 -0
- package/dist/core/substrate/subject-fields.js +38 -0
- package/dist/core/substrate/subject.d.ts +12 -0
- package/dist/core/substrate/subject.js +47 -0
- package/dist/core/timing.d.ts +11 -0
- package/dist/core/timing.js +94 -0
- package/dist/core/tui/__tests__/host-keybindings.test.d.ts +1 -0
- package/dist/core/tui/__tests__/host-keybindings.test.js +113 -0
- package/dist/core/tui/draw.d.ts +100 -0
- package/dist/core/tui/draw.js +359 -0
- package/dist/core/tui/host.d.ts +66 -0
- package/dist/core/tui/host.js +689 -0
- package/dist/core/tui/terminal.d.ts +23 -0
- package/dist/core/tui/terminal.js +101 -0
- package/dist/core/view/__tests__/transport-cache.test.d.ts +1 -0
- package/dist/core/view/__tests__/transport-cache.test.js +62 -0
- package/dist/core/view/__tests__/transport-remote.test.d.ts +1 -0
- package/dist/core/view/__tests__/transport-remote.test.js +98 -0
- package/dist/core/view/bridge.d.ts +10 -0
- package/dist/core/view/bridge.js +31 -0
- package/dist/core/view/chrome.d.ts +9 -0
- package/dist/core/view/chrome.js +22 -0
- package/dist/core/view/contract.d.ts +205 -0
- package/dist/core/view/contract.js +23 -0
- package/dist/core/view/loader.d.ts +31 -0
- package/dist/core/view/loader.js +188 -0
- package/dist/core/view/remote-canvas-target.d.ts +4 -0
- package/dist/core/view/remote-canvas-target.js +30 -0
- package/dist/core/view/stream-local.d.ts +3 -0
- package/dist/core/view/stream-local.js +231 -0
- package/dist/core/view/transport-cache.d.ts +8 -0
- package/dist/core/view/transport-cache.js +38 -0
- package/dist/core/view/transport-local.d.ts +7 -0
- package/dist/core/view/transport-local.js +83 -0
- package/dist/core/view/transport-remote.d.ts +2 -0
- package/dist/core/view/transport-remote.js +58 -0
- package/dist/core/view/transport.d.ts +10 -0
- package/dist/core/view/transport.js +15 -0
- package/dist/core/wake.d.ts +86 -0
- package/dist/core/wake.js +307 -0
- package/dist/core/worktree.d.ts +111 -0
- package/dist/core/worktree.js +732 -0
- package/dist/daemon/__tests__/broker-ownership.test.d.ts +1 -0
- package/dist/daemon/__tests__/broker-ownership.test.js +25 -0
- package/dist/daemon/__tests__/daemon-ownership.test.d.ts +1 -0
- package/dist/daemon/__tests__/daemon-ownership.test.js +27 -0
- package/dist/daemon/api/__tests__/error-seam.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/error-seam.test.js +56 -0
- package/dist/daemon/api/__tests__/full/api-server.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/full/api-server.test.js +369 -0
- package/dist/daemon/api/__tests__/full/b10-attach-modelauth.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/full/b10-attach-modelauth.test.js +220 -0
- package/dist/daemon/api/__tests__/full/push-parity.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/full/push-parity.test.js +199 -0
- package/dist/daemon/api/__tests__/full/worktree-parity.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/full/worktree-parity.test.js +160 -0
- package/dist/daemon/api/__tests__/inbox.test.d.ts +1 -0
- package/dist/daemon/api/__tests__/inbox.test.js +578 -0
- package/dist/daemon/api/bridge.d.ts +21 -0
- package/dist/daemon/api/bridge.js +351 -0
- package/dist/daemon/api/handlers/attach.d.ts +2 -0
- package/dist/daemon/api/handlers/attach.js +56 -0
- package/dist/daemon/api/handlers/canvas.d.ts +2 -0
- package/dist/daemon/api/handlers/canvas.js +463 -0
- package/dist/daemon/api/handlers/crons.d.ts +2 -0
- package/dist/daemon/api/handlers/crons.js +354 -0
- package/dist/daemon/api/handlers/daemon.d.ts +2 -0
- package/dist/daemon/api/handlers/daemon.js +35 -0
- package/dist/daemon/api/handlers/files.d.ts +2 -0
- package/dist/daemon/api/handlers/files.js +64 -0
- package/dist/daemon/api/handlers/focus.d.ts +2 -0
- package/dist/daemon/api/handlers/focus.js +92 -0
- package/dist/daemon/api/handlers/health.d.ts +2 -0
- package/dist/daemon/api/handlers/health.js +65 -0
- package/dist/daemon/api/handlers/human.d.ts +12 -0
- package/dist/daemon/api/handlers/human.js +741 -0
- package/dist/daemon/api/handlers/inbox.d.ts +2 -0
- package/dist/daemon/api/handlers/inbox.js +423 -0
- package/dist/daemon/api/handlers/messages.d.ts +2 -0
- package/dist/daemon/api/handlers/messages.js +290 -0
- package/dist/daemon/api/handlers/modelauth.d.ts +2 -0
- package/dist/daemon/api/handlers/modelauth.js +116 -0
- package/dist/daemon/api/handlers/nodes.d.ts +2 -0
- package/dist/daemon/api/handlers/nodes.js +540 -0
- package/dist/daemon/api/handlers/profiles.d.ts +2 -0
- package/dist/daemon/api/handlers/profiles.js +69 -0
- package/dist/daemon/api/handlers/reports.d.ts +2 -0
- package/dist/daemon/api/handlers/reports.js +144 -0
- package/dist/daemon/api/handlers/subscriptions.d.ts +2 -0
- package/dist/daemon/api/handlers/subscriptions.js +53 -0
- package/dist/daemon/api/handlers/worktree.d.ts +2 -0
- package/dist/daemon/api/handlers/worktree.js +40 -0
- package/dist/daemon/api/map.d.ts +100 -0
- package/dist/daemon/api/map.js +360 -0
- package/dist/daemon/api/router.d.ts +56 -0
- package/dist/daemon/api/router.js +190 -0
- package/dist/daemon/api/server.d.ts +23 -0
- package/dist/daemon/api/server.js +258 -0
- package/dist/daemon/control.d.ts +21 -0
- package/dist/daemon/control.js +22 -0
- package/dist/daemon/cron-run.d.ts +64 -0
- package/dist/daemon/cron-run.js +944 -0
- package/dist/daemon/cron-sink.d.ts +26 -0
- package/dist/daemon/cron-sink.js +43 -0
- package/dist/daemon/crtrd-cli.d.ts +1 -0
- package/dist/daemon/crtrd-cli.js +18 -0
- package/dist/daemon/crtrd.d.ts +89 -0
- package/dist/daemon/crtrd.js +1953 -0
- package/dist/daemon/fleet.d.ts +81 -0
- package/dist/daemon/fleet.js +405 -0
- package/dist/daemon/manage.d.ts +103 -0
- package/dist/daemon/manage.js +389 -0
- package/dist/daemon/pidfile.d.ts +8 -0
- package/dist/daemon/pidfile.js +37 -0
- package/dist/daemon/supervise-cadence.d.ts +1 -0
- package/dist/daemon/supervise-cadence.js +6 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +44 -0
- package/dist/pi-extensions/__tests__/canvas-bash-valve.test.d.ts +1 -0
- package/dist/pi-extensions/__tests__/canvas-bash-valve.test.js +31 -0
- package/dist/pi-extensions/__tests__/canvas-context-intro.test.d.ts +1 -0
- package/dist/pi-extensions/__tests__/canvas-context-intro.test.js +182 -0
- package/dist/pi-extensions/__tests__/canvas-stophook-agentend.test.d.ts +1 -0
- package/dist/pi-extensions/__tests__/canvas-stophook-agentend.test.js +467 -0
- package/dist/pi-extensions/__tests__/canvas-stophook-context-nudge.test.d.ts +1 -0
- package/dist/pi-extensions/__tests__/canvas-stophook-context-nudge.test.js +121 -0
- package/dist/pi-extensions/canvas-bash-valve.d.ts +8 -0
- package/dist/pi-extensions/canvas-bash-valve.js +297 -0
- package/dist/pi-extensions/canvas-context-intro.d.ts +91 -0
- package/dist/pi-extensions/canvas-context-intro.js +230 -0
- package/dist/pi-extensions/canvas-doc-substrate.d.ts +44 -0
- package/dist/pi-extensions/canvas-doc-substrate.js +151 -0
- package/dist/pi-extensions/canvas-goal-capture.d.ts +21 -0
- package/dist/pi-extensions/canvas-goal-capture.js +83 -0
- package/dist/pi-extensions/canvas-inbox-watcher.d.ts +25 -0
- package/dist/pi-extensions/canvas-inbox-watcher.js +942 -0
- package/dist/pi-extensions/canvas-passive-context.d.ts +32 -0
- package/dist/pi-extensions/canvas-passive-context.js +134 -0
- package/dist/pi-extensions/canvas-recap.d.ts +41 -0
- package/dist/pi-extensions/canvas-recap.js +263 -0
- package/dist/pi-extensions/canvas-stophook.d.ts +53 -0
- package/dist/pi-extensions/canvas-stophook.js +985 -0
- package/dist/pi-extensions/canvas-structured-output.d.ts +9 -0
- package/dist/pi-extensions/canvas-structured-output.js +155 -0
- package/dist/prompts/review.d.ts +2 -0
- package/dist/prompts/review.js +130 -0
- package/dist/prompts/view.d.ts +7 -0
- package/dist/prompts/view.js +172 -0
- package/dist/suppress-experimental-warnings.d.ts +1 -0
- package/dist/suppress-experimental-warnings.js +15 -0
- package/dist/types.d.ts +297 -0
- package/dist/types.js +153 -0
- package/dist/web/ViewChrome.d.ts +7 -0
- package/dist/web/ViewChrome.js +28 -0
- package/dist/web/ViewPane.d.ts +39 -0
- package/dist/web/ViewPane.js +48 -0
- package/dist/web/index.d.ts +8 -0
- package/dist/web/index.js +22 -0
- package/dist/web/runtime.d.ts +39 -0
- package/dist/web/runtime.js +232 -0
- package/dist/web/states.d.ts +24 -0
- package/dist/web/states.js +24 -0
- package/dist/web/transport-http.d.ts +5 -0
- package/dist/web/transport-http.js +34 -0
- package/dist/web/transport-stream.d.ts +3 -0
- package/dist/web/transport-stream.js +204 -0
- package/dist/web-client/apple-touch-icon.png +0 -0
- package/dist/web-client/assets/fragment-mono-latin-400-normal-BYwT3kSJ.woff +0 -0
- package/dist/web-client/assets/fragment-mono-latin-400-normal-yxdJ5AmL.woff2 +0 -0
- package/dist/web-client/assets/fragment-mono-latin-ext-400-normal-BbKYyvR9.woff2 +0 -0
- package/dist/web-client/assets/fragment-mono-latin-ext-400-normal-CT4YFKeK.woff +0 -0
- package/dist/web-client/assets/index-BpyZGBhI.js +79 -0
- package/dist/web-client/assets/index-CpEl9LTS.css +2 -0
- package/dist/web-client/assets/martian-mono-cyrillic-wght-normal-B84CD5C_.woff2 +0 -0
- package/dist/web-client/assets/martian-mono-latin-ext-wght-normal-DlL6xMw5.woff2 +0 -0
- package/dist/web-client/assets/martian-mono-latin-wght-normal-5W32yIyr.woff2 +0 -0
- package/dist/web-client/assets/workbox-window.prod.es5-Bd17z0YL.js +2 -0
- package/dist/web-client/icon-192.png +0 -0
- package/dist/web-client/icon-512.png +0 -0
- package/dist/web-client/icon-maskable-512.png +0 -0
- package/dist/web-client/index.html +17 -0
- package/dist/web-client/manifest.webmanifest +1 -0
- package/dist/web-client/sw.js +1 -0
- package/docs/compat/hearth-crtr-v1.md +187 -0
- package/docs/compat/hearth-crtr-v2.md +185 -0
- package/docs/compat/hearth-crtr-v3.md +184 -0
- package/docs/compat/hearth-crtr-v4.md +188 -0
- package/docs/compat/hearth-crtr-v5.md +175 -0
- package/docs/public-api.md +77 -0
- package/package.json +156 -0
- package/runtime.lock.json +12919 -0
- package/scripts/install-runtime.mjs +308 -0
- package/scripts/patch-pi-tree-root-ordering.mjs +57 -0
- package/scripts/postinstall.mjs +33 -0
- package/scripts/runtime-lock.mjs +26 -0
package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/provider-rotation.test.ts
ADDED
|
@@ -0,0 +1,2632 @@
|
|
|
1
|
+
import { before, after, test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { LockedJsonFile } from "../../../../core/locked-file.ts";
|
|
6
|
+
import type { FallbackTarget, SubscriptionCredential } from "../../lib/subscription-state.ts";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
|
|
10
|
+
// Child processes reach crouter's locked-file primitive by absolute URL: they run under
|
|
11
|
+
// tsx with `--input-type=module`, so a bare relative specifier has no base to resolve from.
|
|
12
|
+
const lockedFileUrl = new URL("../../../../core/locked-file.ts", import.meta.url).href;
|
|
13
|
+
|
|
14
|
+
let home: string;
|
|
15
|
+
let helpers: typeof import("../../lib/subscription-state.ts");
|
|
16
|
+
let providerManagement: typeof import("../../../../core/provider-management.ts");
|
|
17
|
+
let rotationModule: typeof import("../provider-rotation.ts");
|
|
18
|
+
let providerRotationExtension: typeof import("../provider-rotation.ts").default;
|
|
19
|
+
const previousHome = process.env.HOME;
|
|
20
|
+
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
21
|
+
|
|
22
|
+
function writeLadderConfig() {
|
|
23
|
+
const configPath = join(home, ".crouter", "config.json");
|
|
24
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
25
|
+
writeFileSync(
|
|
26
|
+
configPath,
|
|
27
|
+
`${JSON.stringify(
|
|
28
|
+
{
|
|
29
|
+
modelLadders: {
|
|
30
|
+
anthropic: {
|
|
31
|
+
ultra: "anthropic/claude-fable-5:high",
|
|
32
|
+
strong: "anthropic/claude-opus-4-8:high",
|
|
33
|
+
medium: "anthropic/claude-sonnet-4-6:high",
|
|
34
|
+
light: "anthropic/custom-light-x",
|
|
35
|
+
},
|
|
36
|
+
openai: {
|
|
37
|
+
ultra: "openai-codex/gpt-5.6-sol:max",
|
|
38
|
+
strong: "openai-codex/gpt-5.6-sol:high",
|
|
39
|
+
medium: "openai-codex/gpt-5.6-terra:medium",
|
|
40
|
+
light: "openai-codex/gpt-5.6-luna:low",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
null,
|
|
45
|
+
2,
|
|
46
|
+
)}\n`,
|
|
47
|
+
"utf8",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function credential(label: string, overrides: Partial<SubscriptionCredential> = {}): SubscriptionCredential {
|
|
52
|
+
return {
|
|
53
|
+
label,
|
|
54
|
+
refresh: `refresh-${label}`,
|
|
55
|
+
access: `access-${label}`,
|
|
56
|
+
expires: Date.now() + 60_000,
|
|
57
|
+
rateLimitedUntil: 0,
|
|
58
|
+
lastAttemptAt: 0,
|
|
59
|
+
lastRateLimitedAt: 0,
|
|
60
|
+
...overrides,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function resetRotationState() {
|
|
65
|
+
rmSync(join(home, ".pi", "agent", "auth.json"), { force: true });
|
|
66
|
+
await helpers.writeSubscriptionPool("anthropic", []);
|
|
67
|
+
await helpers.writeSubscriptionPool("openai-codex", []);
|
|
68
|
+
helpers.clearPreferredModel();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function observeLines(stream: NodeJS.ReadableStream, onLine: (line: string) => void): void {
|
|
72
|
+
let buffer = "";
|
|
73
|
+
stream.setEncoding("utf8");
|
|
74
|
+
stream.on("data", (chunk: string) => {
|
|
75
|
+
buffer += chunk;
|
|
76
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
77
|
+
while (newlineIndex !== -1) {
|
|
78
|
+
const line = buffer.slice(0, newlineIndex);
|
|
79
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
80
|
+
onLine(line);
|
|
81
|
+
newlineIndex = buffer.indexOf("\n");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function within<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
|
|
87
|
+
return new Promise<T>((resolve, reject) => {
|
|
88
|
+
const timer = setTimeout(() => reject(new Error(message)), ms);
|
|
89
|
+
promise.then(
|
|
90
|
+
(value) => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
resolve(value);
|
|
93
|
+
},
|
|
94
|
+
(error: unknown) => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
reject(error);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
before(async () => {
|
|
103
|
+
home = mkdtempSync(join(tmpdir(), "pi-provider-rotation-"));
|
|
104
|
+
process.env.HOME = home;
|
|
105
|
+
process.env.PI_CODING_AGENT_DIR = join(home, ".pi", "agent");
|
|
106
|
+
helpers = await import("../../lib/subscription-state.ts");
|
|
107
|
+
providerManagement = await import("../../../../core/provider-management.ts");
|
|
108
|
+
rotationModule = await import("../provider-rotation.ts");
|
|
109
|
+
providerRotationExtension = rotationModule.default;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
after(() => {
|
|
113
|
+
if (previousHome === undefined) delete process.env.HOME;
|
|
114
|
+
else process.env.HOME = previousHome;
|
|
115
|
+
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
116
|
+
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
117
|
+
rmSync(home, { recursive: true, force: true });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("normalizes provider subscription pool files", async () => {
|
|
121
|
+
await resetRotationState();
|
|
122
|
+
await helpers.writeSubscriptionPool("anthropic", [
|
|
123
|
+
{
|
|
124
|
+
label: " personal ",
|
|
125
|
+
refresh: " refresh-token ",
|
|
126
|
+
access: " access-token ",
|
|
127
|
+
expires: 123,
|
|
128
|
+
rateLimitedUntil: Number.NaN,
|
|
129
|
+
lastAttemptAt: Number.NaN,
|
|
130
|
+
lastRateLimitedAt: Number.NaN,
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
assert.deepEqual(helpers.readSubscriptionPool("anthropic"), [
|
|
135
|
+
{
|
|
136
|
+
label: "personal",
|
|
137
|
+
refresh: "refresh-token",
|
|
138
|
+
access: "access-token",
|
|
139
|
+
expires: 123,
|
|
140
|
+
rateLimitedUntil: 0,
|
|
141
|
+
lastAttemptAt: 0,
|
|
142
|
+
lastRateLimitedAt: 0,
|
|
143
|
+
},
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Concurrent refreshes of the same expired pool credential serialize read, token exchange,
|
|
148
|
+
// and write under one lock. The injected refresh runs once; the second caller observes the
|
|
149
|
+
// winner's fresh token and does not make a second single-use refresh request.
|
|
150
|
+
test("brick-repro: concurrent refreshes of the same expired pool token serialize through the lock (exactly one network refresh)", async () => {
|
|
151
|
+
await resetRotationState();
|
|
152
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic", { refresh: "shared-refresh", access: "access-stale", expires: 1 })]);
|
|
153
|
+
const poolEntry = helpers.readSubscriptionPool("anthropic")[0];
|
|
154
|
+
assert.equal(poolEntry.label, "anthropic");
|
|
155
|
+
|
|
156
|
+
let refreshCalls = 0;
|
|
157
|
+
rotationModule.__setRefreshForProviderForTest(async (_providerId, refreshToken) => {
|
|
158
|
+
refreshCalls += 1;
|
|
159
|
+
if (refreshCalls === 1) {
|
|
160
|
+
return { refresh: "shared-refresh-rotated", access: "access-fresh", expires: Date.now() + 60_000 };
|
|
161
|
+
}
|
|
162
|
+
// Any refresh call after the first is simulating "this refresh token was already
|
|
163
|
+
// consumed by the winner" -- a genuine invalid_grant from the provider.
|
|
164
|
+
throw Object.assign(new Error(`HTTP request failed. status=400; body={"error":"invalid_grant"} for token ${refreshToken}`), { status: 400 });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const [a, b] = await Promise.all([
|
|
169
|
+
rotationModule.__refreshCredentialIfNeededForTest("anthropic", poolEntry),
|
|
170
|
+
rotationModule.__refreshCredentialIfNeededForTest("anthropic", poolEntry),
|
|
171
|
+
]);
|
|
172
|
+
|
|
173
|
+
assert.equal(refreshCalls, 1);
|
|
174
|
+
assert.equal(a.access, "access-fresh");
|
|
175
|
+
assert.equal(b.access, "access-fresh");
|
|
176
|
+
|
|
177
|
+
// The rotated value landed on the account it came from -- the pool is the only store now.
|
|
178
|
+
const [stored] = helpers.readSubscriptionPool("anthropic");
|
|
179
|
+
assert.equal(stored.label, "anthropic");
|
|
180
|
+
assert.equal(stored.access, "access-fresh");
|
|
181
|
+
assert.equal(stored.refresh, "shared-refresh-rotated");
|
|
182
|
+
} finally {
|
|
183
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("a fresh default credential bypasses the cross-process refresh lock", async () => {
|
|
188
|
+
await resetRotationState();
|
|
189
|
+
await helpers.writeSubscriptionPool("openai-codex", [
|
|
190
|
+
credential("openai-codex", { refresh: "refresh-codex", access: "access-codex-fresh", expires: Date.now() + 60_000 }),
|
|
191
|
+
]);
|
|
192
|
+
const poolEntry = helpers.readSubscriptionPool("openai-codex")[0];
|
|
193
|
+
const originalWithLockAsync = LockedJsonFile.prototype.withLockAsync;
|
|
194
|
+
LockedJsonFile.prototype.withLockAsync = async () => {
|
|
195
|
+
throw new Error("fresh credential unexpectedly joined the auth refresh lock");
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
const resolved = await rotationModule.__refreshCredentialIfNeededForTest("openai-codex", poolEntry);
|
|
200
|
+
assert.equal(resolved.access, "access-codex-fresh");
|
|
201
|
+
} finally {
|
|
202
|
+
LockedJsonFile.prototype.withLockAsync = originalWithLockAsync;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("subscription bookkeeping retries lock collisions and then degrades without failing the provider turn", async () => {
|
|
207
|
+
const waits: number[] = [];
|
|
208
|
+
rotationModule.__setSleepForTest(async (ms) => { waits.push(ms); });
|
|
209
|
+
try {
|
|
210
|
+
let eventualCalls = 0;
|
|
211
|
+
const eventual = await rotationModule.__recordSubscriptionMutationForTest("testing eventual acquisition", async () => {
|
|
212
|
+
eventualCalls++;
|
|
213
|
+
if (eventualCalls < 4) throw Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED" });
|
|
214
|
+
});
|
|
215
|
+
assert.equal(eventual, true);
|
|
216
|
+
assert.equal(eventualCalls, 4);
|
|
217
|
+
assert.deepEqual(waits, [25, 75, 150]);
|
|
218
|
+
|
|
219
|
+
waits.length = 0;
|
|
220
|
+
let exhaustedCalls = 0;
|
|
221
|
+
const exhausted = await rotationModule.__recordSubscriptionMutationForTest("testing exhaustion", async () => {
|
|
222
|
+
exhaustedCalls++;
|
|
223
|
+
throw Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED" });
|
|
224
|
+
});
|
|
225
|
+
assert.equal(exhausted, false);
|
|
226
|
+
assert.equal(exhaustedCalls, 4);
|
|
227
|
+
assert.deepEqual(waits, [25, 75, 150]);
|
|
228
|
+
} finally {
|
|
229
|
+
rotationModule.__setSleepForTest(undefined);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// A GENUINE invalid_grant (the refresh token is actually dead, not merely raced) must
|
|
234
|
+
// still reach the real cooldown -> reauth path through the new lock-delegated seam --
|
|
235
|
+
// the fix must not accidentally swallow or misclassify a real failure. Drives it through
|
|
236
|
+
// the actual provider stream (not the raw helper) so `isInvalidRefreshTokenError` +
|
|
237
|
+
// reauthentication + the credential-store persist all fire for real.
|
|
238
|
+
test("a genuine invalid_grant through the pool account's lock still reauthenticates and persists to the pool", async () => {
|
|
239
|
+
await resetRotationState();
|
|
240
|
+
writeLadderConfig();
|
|
241
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic", { refresh: "dead-refresh", access: "access-stale", expires: 1 })]);
|
|
242
|
+
|
|
243
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
244
|
+
ctx.hasUI = true;
|
|
245
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
246
|
+
ctx.ui.notify = () => {};
|
|
247
|
+
const loginCalls: string[] = [];
|
|
248
|
+
// Plain Error, no typed .status: real pi-ai refresh failures carry the HTTP status
|
|
249
|
+
// in the message text, so the refresh path still recognizes an invalid_grant from this
|
|
250
|
+
// shape.
|
|
251
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
252
|
+
if (providerId === "anthropic") {
|
|
253
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
254
|
+
}
|
|
255
|
+
throw new Error("unexpected refresh");
|
|
256
|
+
});
|
|
257
|
+
rotationModule.__setLoginForProviderForTest(async (providerId) => {
|
|
258
|
+
loginCalls.push(providerId);
|
|
259
|
+
return { refresh: "refresh-reauthed", access: "access-reauthed", expires: Date.now() + 60_000 };
|
|
260
|
+
});
|
|
261
|
+
rotationModule.__setStreamForProviderForTest((_model, _context, options) => {
|
|
262
|
+
return (async function* () {
|
|
263
|
+
yield { type: "text_delta", text: `hello with ${options?.apiKey}` };
|
|
264
|
+
})() as any;
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
await providerRotationExtension(pi);
|
|
269
|
+
await events.session_start?.({}, ctx);
|
|
270
|
+
const stream = providers["anthropic"].streamSimple({ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" }, ctx);
|
|
271
|
+
const emitted = [] as any[];
|
|
272
|
+
for await (const event of stream) emitted.push(event);
|
|
273
|
+
|
|
274
|
+
assert.deepEqual(loginCalls, ["anthropic"]);
|
|
275
|
+
assert.deepEqual(setModelCalls, []);
|
|
276
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
277
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
278
|
+
|
|
279
|
+
// Reauth persisted onto the pool account's own pool entry -- the single owner -- with the
|
|
280
|
+
// cooldown the failed refresh recorded cleared again.
|
|
281
|
+
const [entry] = helpers.readSubscriptionPool("anthropic");
|
|
282
|
+
assert.equal(entry.label, "anthropic");
|
|
283
|
+
assert.equal(entry.refresh, "refresh-reauthed");
|
|
284
|
+
assert.equal(entry.access, "access-reauthed");
|
|
285
|
+
assert.equal(entry.rateLimitedUntil, 0);
|
|
286
|
+
assert.equal(entry.authFailure, undefined);
|
|
287
|
+
} finally {
|
|
288
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
289
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
290
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// A genuine invalid_grant through the pool account's lock seam cools the credential down
|
|
295
|
+
// and falls back cross-provider when UI is unavailable: an expired default pool entry, an
|
|
296
|
+
// authenticated Codex fallback, and the real streamSimple path all participate.
|
|
297
|
+
test("a genuine invalid_grant through the pool account's lock with no UI reaches cooldown and falls back cross-provider", async () => {
|
|
298
|
+
await resetRotationState();
|
|
299
|
+
writeLadderConfig();
|
|
300
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic", { refresh: "dead-refresh", access: "access-stale", expires: 1 })]);
|
|
301
|
+
// Authenticated Codex fallback already sitting in its own pool.
|
|
302
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
303
|
+
|
|
304
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
305
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
306
|
+
// ctx.hasUI is deliberately left falsy: reauth must be impossible, so the only path
|
|
307
|
+
// forward is cooldown + cross-provider fallback.
|
|
308
|
+
const streamedModels: any[] = [];
|
|
309
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
310
|
+
if (providerId === "anthropic") {
|
|
311
|
+
// Plain Error, no typed .status: the refresh path reads the invalid_grant shape from
|
|
312
|
+
// the message text, matching production failures.
|
|
313
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
314
|
+
}
|
|
315
|
+
throw new Error("unexpected refresh");
|
|
316
|
+
});
|
|
317
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
318
|
+
streamedModels.push(model);
|
|
319
|
+
return (async function* () {
|
|
320
|
+
yield { type: "text_delta", text: "hello from codex fallback" };
|
|
321
|
+
})() as any;
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
await providerRotationExtension(pi);
|
|
326
|
+
await events.session_start?.({}, ctx);
|
|
327
|
+
const stream = providers["anthropic"].streamSimple(
|
|
328
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
329
|
+
ctx,
|
|
330
|
+
);
|
|
331
|
+
const emitted = [] as any[];
|
|
332
|
+
for await (const event of stream) emitted.push(event);
|
|
333
|
+
|
|
334
|
+
// Fell back cross-provider and actually served the turn on Codex.
|
|
335
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["openai-codex"]);
|
|
336
|
+
assert.equal(streamedModels.length, 1);
|
|
337
|
+
assert.equal(streamedModels[0].provider, "openai-codex");
|
|
338
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
339
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
340
|
+
|
|
341
|
+
// The pool account's entry got the ~30-day invalid-refresh exclusion, tagged with its auth
|
|
342
|
+
// cause through the real locked-refresh seam -- not a bypass.
|
|
343
|
+
const [entry] = helpers.readSubscriptionPool("anthropic");
|
|
344
|
+
assert.equal(entry.label, "anthropic");
|
|
345
|
+
assert.ok(entry.rateLimitedUntil > Date.now() + 29 * 24 * 60 * 60 * 1000);
|
|
346
|
+
assert.equal(entry.authFailure, "invalid_grant");
|
|
347
|
+
|
|
348
|
+
// No UI -- no reauth happened; the dead credential is still stored unchanged.
|
|
349
|
+
assert.equal(entry.refresh, "dead-refresh");
|
|
350
|
+
} finally {
|
|
351
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
352
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("/provider-sub add still adds an explicit additional subscription alongside the pool account", async () => {
|
|
357
|
+
await resetRotationState();
|
|
358
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic", { refresh: "refresh-first", access: "access-first" })]);
|
|
359
|
+
|
|
360
|
+
await helpers.upsertSubscription("anthropic", credential("work", { refresh: "refresh-work", access: "access-work" }));
|
|
361
|
+
|
|
362
|
+
assert.deepEqual(helpers.readSubscriptionPool("anthropic").map((entry) => entry.label), ["anthropic", "work"]);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// /provider-sub <provider> add accepts the default label as the login-backed slot: the
|
|
366
|
+
// registered command handler must store that login on the default pool entry rather than
|
|
367
|
+
// discard it, because the pool is the only credential store a managed provider has.
|
|
368
|
+
test("/provider-sub add with the default label persists the login credential to the default pool entry", async () => {
|
|
369
|
+
await resetRotationState();
|
|
370
|
+
|
|
371
|
+
const { ctx, commands, pi } = makeRotationCtx();
|
|
372
|
+
ctx.hasUI = true;
|
|
373
|
+
ctx.ui.notify = () => {};
|
|
374
|
+
ctx.ui.input = async () => "personal";
|
|
375
|
+
rotationModule.__setLoginForProviderForTest(async () => ({ refresh: "refresh-login", access: "access-login", expires: Date.now() + 60_000 }));
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
await providerRotationExtension(pi);
|
|
379
|
+
await commands["provider-sub"].handler("anthropic add", ctx);
|
|
380
|
+
|
|
381
|
+
// The default pool entry carries the login's value with the cooldown cleared -- not a
|
|
382
|
+
// broken "authenticated but valueless" slot.
|
|
383
|
+
const [entry] = helpers.readSubscriptionPool("anthropic");
|
|
384
|
+
assert.equal(entry.label, "personal");
|
|
385
|
+
assert.equal(entry.refresh, "refresh-login");
|
|
386
|
+
assert.equal(entry.access, "access-login");
|
|
387
|
+
assert.equal(entry.rateLimitedUntil, 0);
|
|
388
|
+
} finally {
|
|
389
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// The retained agent command must use the same coordinated removal as the Providers panel: the
|
|
394
|
+
// pool account leaves the pool exactly like any explicit account.
|
|
395
|
+
test("/provider-sub rm removes the pool account", async () => {
|
|
396
|
+
await resetRotationState();
|
|
397
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic")]);
|
|
398
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0]?.label, "anthropic");
|
|
399
|
+
|
|
400
|
+
const { ctx, commands, pi } = makeRotationCtx();
|
|
401
|
+
ctx.ui.notify = () => {};
|
|
402
|
+
await providerRotationExtension(pi);
|
|
403
|
+
await commands["provider-sub"].handler("anthropic rm anthropic", ctx);
|
|
404
|
+
|
|
405
|
+
assert.equal(helpers.readSubscriptionPool("anthropic").some((entry) => entry.label === "anthropic"), false);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// The manual-code-paste dialog races pi-ai's loopback callback server. These tests exercise
|
|
409
|
+
// the wrapper directly with a run function that can leave manual input pending. Aborting the
|
|
410
|
+
// dialog signal removes its broker entry and emits a request-scoped dismissal frame, so the
|
|
411
|
+
// assertions verify the signal rather than an unrelated notification.
|
|
412
|
+
|
|
413
|
+
test("loginWithManualInputCleanup aborts the still-open manual dialog's signal once the OAuth call settles without it (loopback-wins parity)", async () => {
|
|
414
|
+
let capturedSignal: AbortSignal | undefined;
|
|
415
|
+
const notifications: Array<{ message: string; type?: string }> = [];
|
|
416
|
+
const ctx = {
|
|
417
|
+
ui: {
|
|
418
|
+
notify: (message: string, type?: string) => notifications.push({ message, type }),
|
|
419
|
+
input: (_title: string, _placeholder: string, opts?: { signal?: AbortSignal }) => {
|
|
420
|
+
capturedSignal = opts?.signal;
|
|
421
|
+
// Never resolves on its own -- mirrors pi-ai abandoning the manual-input
|
|
422
|
+
// promise once the loopback callback server wins the race.
|
|
423
|
+
return new Promise<string | undefined>(() => {});
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
} as any;
|
|
427
|
+
|
|
428
|
+
const result = await rotationModule.loginWithManualInputCleanup(ctx, async (readCode: any) => {
|
|
429
|
+
// Start the manual-code prompt (as onManualCodeInput would) but -- like the real
|
|
430
|
+
// pi-ai race -- never await its outcome; the loopback callback "wins" instead.
|
|
431
|
+
void readCode("Open this URL...", "placeholder").catch(() => {});
|
|
432
|
+
return "loopback-code";
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
assert.equal(result, "loopback-code");
|
|
436
|
+
assert.equal(capturedSignal?.aborted, true, "the abandoned manual-input dialog's signal must be aborted once the OAuth call settles -- the broker turns that abort into a correlated extension_ui_dismiss");
|
|
437
|
+
assert.equal(notifications.length, 0, "no broad dismiss notify -- an unrelated notify must never be used as a dialog-dismissal signal");
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test("loginWithManualInputCleanup dismisses the manual dialog at callback-win (onProgress), NOT after a delayed token exchange", async () => {
|
|
441
|
+
// Once the loopback callback supplies a code, progress starts token exchange. The manual
|
|
442
|
+
// dialog is aborted at that boundary, before the exchange resolves, so a slow exchange does
|
|
443
|
+
// not leave its overlay open.
|
|
444
|
+
let order = 0;
|
|
445
|
+
let abortedAt: number | undefined;
|
|
446
|
+
let runResolvedAt: number | undefined;
|
|
447
|
+
const ctx = {
|
|
448
|
+
ui: {
|
|
449
|
+
notify: () => {},
|
|
450
|
+
input: (_title: string, _placeholder: string, opts?: { signal?: AbortSignal }) =>
|
|
451
|
+
// Mirror the broker: resolve to undefined on abort (which readCode turns
|
|
452
|
+
// into a throw, inert on the abandoned promise like pi-ai's own .catch).
|
|
453
|
+
new Promise<string | undefined>((resolve) => {
|
|
454
|
+
opts?.signal?.addEventListener("abort", () => { abortedAt = order++; resolve(undefined); }, { once: true });
|
|
455
|
+
}),
|
|
456
|
+
},
|
|
457
|
+
} as any;
|
|
458
|
+
|
|
459
|
+
const result = await rotationModule.loginWithManualInputCleanup(ctx, async (readCode: any, dismissManual: () => void) => {
|
|
460
|
+
void readCode("Open this URL...", "placeholder").catch(() => {});
|
|
461
|
+
dismissManual(); // pi-ai's onProgress fires here -- it already has the code
|
|
462
|
+
await new Promise((r) => setTimeout(r, 25)); // the (possibly slow) token exchange
|
|
463
|
+
runResolvedAt = order++;
|
|
464
|
+
return "exchanged-token";
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
assert.equal(result, "exchanged-token");
|
|
468
|
+
assert.notEqual(abortedAt, undefined, "the manual dialog's signal must have been aborted");
|
|
469
|
+
assert.notEqual(runResolvedAt, undefined);
|
|
470
|
+
assert.ok(abortedAt! < runResolvedAt!, "the manual dialog must be dismissed at callback-win (onProgress), BEFORE the delayed token exchange completes");
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test("loginWithManualInputCleanup's readCode rejects (rather than resolving to \"\") when the manual dialog is cancelled or times out", async () => {
|
|
474
|
+
const ctx = {
|
|
475
|
+
ui: {
|
|
476
|
+
notify: () => {},
|
|
477
|
+
// ctx.ui.input resolving to undefined is exactly what a Cancel button or the
|
|
478
|
+
// dialog's own timeout produces (dialogPromise's cancelled/timeout default).
|
|
479
|
+
input: async () => undefined,
|
|
480
|
+
},
|
|
481
|
+
} as any;
|
|
482
|
+
|
|
483
|
+
// pi-ai only calls its onPrompt paste-only fallback when onManualCodeInput
|
|
484
|
+
// RESOLVES (even to a falsy value) -- never when it rejects. Asserting
|
|
485
|
+
// loginWithManualInputCleanup itself rejects (instead of resolving to "", the
|
|
486
|
+
// pre-fix behavior) proves readCode ends the OAuth attempt directly and pi-ai
|
|
487
|
+
// never gets the chance to fall through to that second, URL-less dialog.
|
|
488
|
+
await assert.rejects(
|
|
489
|
+
() => rotationModule.loginWithManualInputCleanup(ctx, (readCode) => readCode("Open this URL...", "placeholder")),
|
|
490
|
+
/OAuth login cancelled/,
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
test("resolves Anthropic to strength-matched OpenAI Codex fallback", async () => {
|
|
495
|
+
await resetRotationState();
|
|
496
|
+
writeLadderConfig();
|
|
497
|
+
|
|
498
|
+
assert.deepEqual(helpers.resolveFallbackTarget("anthropic", "anthropic/claude-opus-4-8:high"), {
|
|
499
|
+
providerId: "openai-codex",
|
|
500
|
+
modelId: "gpt-5.6-sol",
|
|
501
|
+
label: "openai-codex/gpt-5.6-sol:high",
|
|
502
|
+
strength: "strong",
|
|
503
|
+
thinkingLevel: "high",
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
test("shared launch/general candidate policy preserves a viable request, skips a cooling request, and reports total exhaustion", async () => {
|
|
508
|
+
const requested = { providerId: "anthropic", modelId: "claude-opus", registered: true, authenticated: true };
|
|
509
|
+
const fallback = { providerId: "openai-codex", modelId: "gpt-5", registered: true, authenticated: true };
|
|
510
|
+
|
|
511
|
+
assert.deepEqual(helpers.resolveProviderCandidates([requested, fallback], 100).candidates, [requested, fallback]);
|
|
512
|
+
assert.deepEqual(
|
|
513
|
+
helpers.resolveProviderCandidates([{ ...requested, coolingUntil: 200 }, fallback], 100).candidates,
|
|
514
|
+
[fallback],
|
|
515
|
+
"a cooling requested provider must not prevent launch/general selection of a viable fallback",
|
|
516
|
+
);
|
|
517
|
+
assert.deepEqual(
|
|
518
|
+
helpers.resolveProviderCandidates([
|
|
519
|
+
{ ...requested, registered: false },
|
|
520
|
+
{ ...fallback, authenticated: false },
|
|
521
|
+
{ providerId: "anthropic", modelId: "claude-sonnet", registered: true, authenticated: true, coolingUntil: 200 },
|
|
522
|
+
], 100).rejected.map(({ reason }) => reason),
|
|
523
|
+
["unregistered", "unauthenticated", "cooling"],
|
|
524
|
+
"callers get one complete, actionable reason set when no candidate is viable",
|
|
525
|
+
);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test("resolves OpenAI Codex to strength-matched Anthropic fallback", async () => {
|
|
529
|
+
writeLadderConfig();
|
|
530
|
+
|
|
531
|
+
assert.deepEqual(helpers.resolveFallbackTarget("openai-codex", "openai-codex/gpt-5.6-terra:medium"), {
|
|
532
|
+
providerId: "anthropic",
|
|
533
|
+
modelId: "claude-sonnet-4-6",
|
|
534
|
+
label: "anthropic/claude-sonnet-4-6:high",
|
|
535
|
+
strength: "medium",
|
|
536
|
+
thinkingLevel: "high",
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
// Ultra and strong share the bare model id gpt-5.6-sol; the live thinking level selects
|
|
541
|
+
// the matching ladder rung.
|
|
542
|
+
test("disambiguates colliding ladder rungs by the live thinking level", async () => {
|
|
543
|
+
await resetRotationState();
|
|
544
|
+
writeLadderConfig();
|
|
545
|
+
const config = helpers.readRotationConfig();
|
|
546
|
+
|
|
547
|
+
// max -> ultra rung -> Anthropic ultra (claude-fable-5)
|
|
548
|
+
assert.deepEqual(helpers.resolveFallbackTarget("openai-codex", "gpt-5.6-sol", config, "max"), {
|
|
549
|
+
providerId: "anthropic",
|
|
550
|
+
modelId: "claude-fable-5",
|
|
551
|
+
label: "anthropic/claude-fable-5:high",
|
|
552
|
+
strength: "ultra",
|
|
553
|
+
thinkingLevel: "high",
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
// high -> strong rung -> Anthropic strong (claude-opus-4-8)
|
|
557
|
+
const highTarget = helpers.resolveFallbackTarget("openai-codex", "gpt-5.6-sol", config, "high");
|
|
558
|
+
assert.ok(highTarget);
|
|
559
|
+
assert.equal(highTarget.modelId, "claude-opus-4-8");
|
|
560
|
+
|
|
561
|
+
// No thinking level falls back to the default-strength tie-break (strong -> opus).
|
|
562
|
+
const defaultTarget = helpers.resolveFallbackTarget("openai-codex", "gpt-5.6-sol", config);
|
|
563
|
+
assert.ok(defaultTarget);
|
|
564
|
+
assert.equal(defaultTarget.modelId, "claude-opus-4-8");
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
test("parses Retry-After seconds and HTTP dates", async () => {
|
|
568
|
+
const now = Date.UTC(2026, 5, 16, 18, 30, 0);
|
|
569
|
+
assert.equal(helpers.parseRetryAfterHeader("1.5", now), 1500);
|
|
570
|
+
|
|
571
|
+
const retryAt = new Date(now + 15_000).toUTCString();
|
|
572
|
+
const parsed = helpers.parseRetryAfterHeader(retryAt, now);
|
|
573
|
+
assert.ok(parsed !== undefined && parsed >= 14_000 && parsed <= 15_000);
|
|
574
|
+
assert.equal(helpers.parseRetryAfterHeader("", now), undefined);
|
|
575
|
+
assert.equal(helpers.parseRetryAfterHeader("not-a-delay", now), undefined);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
test("restores preferred model when its provider pool frees up", async () => {
|
|
579
|
+
await resetRotationState();
|
|
580
|
+
writeLadderConfig();
|
|
581
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
582
|
+
helpers.writeRotationConfig({ preferredModel: { providerId: "openai-codex", modelId: "gpt-5.6-sol" } });
|
|
583
|
+
|
|
584
|
+
const setModelCalls: any[] = [];
|
|
585
|
+
const ctx = {
|
|
586
|
+
model: { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
587
|
+
modelRegistry: {
|
|
588
|
+
find(provider: string, id: string) {
|
|
589
|
+
return { provider, id, api: provider === "openai-codex" ? "openai-codex-responses" : "anthropic-messages" };
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
} as any;
|
|
593
|
+
const pi = {
|
|
594
|
+
async setModel(model: any) {
|
|
595
|
+
setModelCalls.push(model);
|
|
596
|
+
ctx.model = model;
|
|
597
|
+
return true;
|
|
598
|
+
},
|
|
599
|
+
} as any;
|
|
600
|
+
|
|
601
|
+
const restored = await helpers.restorePreferredModelIfPossible(pi, ctx);
|
|
602
|
+
|
|
603
|
+
assert.equal(restored, true);
|
|
604
|
+
assert.deepEqual(setModelCalls[0], {
|
|
605
|
+
provider: "openai-codex",
|
|
606
|
+
id: "gpt-5.6-sol",
|
|
607
|
+
api: "openai-codex-responses",
|
|
608
|
+
});
|
|
609
|
+
assert.equal(helpers.readRotationConfig().preferredModel, undefined);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test("pinned and exact launches retain their captured model during startup preferred-model restoration", async () => {
|
|
613
|
+
for (const reason of ["provider-pinned", "model-exact"] as const) {
|
|
614
|
+
await resetRotationState();
|
|
615
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
616
|
+
helpers.writeRotationConfig({ preferredModel: { providerId: "openai-codex", modelId: "gpt-5.6-sol" } });
|
|
617
|
+
|
|
618
|
+
const { ctx, events, pi, setModelCalls } = makeRotationCtx();
|
|
619
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
620
|
+
ctx.ui[Symbol.for("@crouton-kit/crtr:managed-provider-rotation-policy")] = () => ({
|
|
621
|
+
allowCrossProviderFallback: false,
|
|
622
|
+
reason,
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
await providerRotationExtension(pi);
|
|
626
|
+
await events.session_start?.({}, ctx);
|
|
627
|
+
await events.before_agent_start?.({}, ctx);
|
|
628
|
+
|
|
629
|
+
assert.deepEqual(setModelCalls, [], `${reason} launches must not restore the shared preferred model`);
|
|
630
|
+
assert.deepEqual(ctx.model, { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" });
|
|
631
|
+
assert.deepEqual(helpers.readRotationConfig().preferredModel, { providerId: "openai-codex", modelId: "gpt-5.6-sol" });
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
test("keeps newest Retry-After cooldown across overlapping attempts", async () => {
|
|
636
|
+
await resetRotationState();
|
|
637
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
638
|
+
|
|
639
|
+
await helpers.markSubscriptionAttempt("anthropic", "personal", 100);
|
|
640
|
+
await helpers.markSubscriptionAttempt("anthropic", "personal", 200);
|
|
641
|
+
await helpers.markSubscriptionRateLimited("anthropic", "personal", 60_000, 100, 150);
|
|
642
|
+
await helpers.markSubscriptionRateLimited("anthropic", "personal", 5_000, 200, 205);
|
|
643
|
+
await helpers.markSubscriptionRateLimited("anthropic", "personal", 10_000, 100, 300);
|
|
644
|
+
|
|
645
|
+
const [entry] = helpers.readSubscriptionPool("anthropic");
|
|
646
|
+
assert.deepEqual(
|
|
647
|
+
{ lastAttemptAt: entry.lastAttemptAt, lastRateLimitedAt: entry.lastRateLimitedAt, rateLimitedUntil: entry.rateLimitedUntil },
|
|
648
|
+
{ lastAttemptAt: 200, lastRateLimitedAt: 300, rateLimitedUntil: 10300 },
|
|
649
|
+
);
|
|
650
|
+
|
|
651
|
+
await helpers.markSubscriptionSuccess("anthropic", "personal", 250);
|
|
652
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 10300);
|
|
653
|
+
await helpers.markSubscriptionSuccess("anthropic", "personal", 400);
|
|
654
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 0);
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// Storage-hardening (design mrf6n12x): the locked read/modify/write primitive must preserve a
|
|
658
|
+
// causally newer cooldown across a stale credential upsert, while still letting an equal-timestamp
|
|
659
|
+
// reauth clear it.
|
|
660
|
+
test("a stale upsert refreshes tokens but cannot erase a newer cooldown; an equal-timestamp reauth clears it", async () => {
|
|
661
|
+
await resetRotationState();
|
|
662
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("work", { refresh: "r0", access: "a0", lastRateLimitedAt: 100 })]);
|
|
663
|
+
// What a node reads before doing a slow token refresh.
|
|
664
|
+
const snapshot = helpers.readSubscriptionPool("anthropic")[0];
|
|
665
|
+
|
|
666
|
+
// "Other node" 429s the slot with a strictly newer basis while the refresh is in flight.
|
|
667
|
+
await helpers.markSubscriptionRateLimited("anthropic", "work", 60_000, 500, 500);
|
|
668
|
+
const cooled = helpers.readSubscriptionPool("anthropic")[0];
|
|
669
|
+
assert.equal(cooled.lastRateLimitedAt, 500);
|
|
670
|
+
assert.equal(cooled.rateLimitedUntil, 60_500);
|
|
671
|
+
|
|
672
|
+
// Stale refresh upsert built from the pre-429 snapshot: fresh tokens, stale cooldown basis.
|
|
673
|
+
await helpers.upsertSubscription("anthropic", { ...snapshot, refresh: "r1", access: "a1", expires: snapshot.expires ?? 0 });
|
|
674
|
+
const merged = helpers.readSubscriptionPool("anthropic")[0];
|
|
675
|
+
assert.equal(merged.refresh, "r1", "token fields take the incoming value");
|
|
676
|
+
assert.equal(merged.access, "a1");
|
|
677
|
+
assert.equal(merged.rateLimitedUntil, 60_500, "the newer cooldown survives the stale upsert");
|
|
678
|
+
assert.equal(merged.lastRateLimitedAt, 500);
|
|
679
|
+
|
|
680
|
+
// Reauth clears the cooldown while preserving lastRateLimitedAt (equal timestamp -> incoming wins).
|
|
681
|
+
await helpers.upsertSubscription("anthropic", { ...merged, refresh: "r2", access: "a2", rateLimitedUntil: 0, lastRateLimitedAt: merged.lastRateLimitedAt });
|
|
682
|
+
const reauthed = helpers.readSubscriptionPool("anthropic")[0];
|
|
683
|
+
assert.equal(reauthed.rateLimitedUntil, 0, "an equal-timestamp reauth clears the cooldown");
|
|
684
|
+
assert.equal(reauthed.refresh, "r2");
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
test("a stale success cannot reopen a slot cooled down by a newer 429", async () => {
|
|
688
|
+
await resetRotationState();
|
|
689
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
690
|
+
await helpers.markSubscriptionRateLimited("anthropic", "personal", 30_000, 500, 500);
|
|
691
|
+
// A success whose attempt STARTED before the 429 must not clear the newer cooldown.
|
|
692
|
+
await helpers.markSubscriptionSuccess("anthropic", "personal", 200);
|
|
693
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 30_500);
|
|
694
|
+
// A success that started after the 429 legitimately clears it.
|
|
695
|
+
await helpers.markSubscriptionSuccess("anthropic", "personal", 600);
|
|
696
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 0);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// A mutation must genuinely go through the per-pool-file cross-process lock: while another
|
|
700
|
+
// process holds the pool file's lock (the SAME LockedJsonFile lock the backend uses),
|
|
701
|
+
// a mutator throws after exhausting its retry budget rather than writing unlocked; once the
|
|
702
|
+
// holder releases, the same call succeeds.
|
|
703
|
+
test("pool mutations take the cross-process pool-file lock", async () => {
|
|
704
|
+
await resetRotationState();
|
|
705
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("work")]);
|
|
706
|
+
const poolFile = join(home, ".pi", "agent", "openai-codex-subscriptions.json");
|
|
707
|
+
|
|
708
|
+
const lockHolder = spawn(
|
|
709
|
+
process.execPath,
|
|
710
|
+
[
|
|
711
|
+
"--import",
|
|
712
|
+
"tsx/esm",
|
|
713
|
+
"--input-type=module",
|
|
714
|
+
"-e",
|
|
715
|
+
String.raw`const { LockedJsonFile } = await import(${JSON.stringify(lockedFileUrl)});
|
|
716
|
+
const backend = new LockedJsonFile(${JSON.stringify(poolFile)});
|
|
717
|
+
await backend.withLockAsync(async () => {
|
|
718
|
+
process.stdout.write("locked\n");
|
|
719
|
+
await new Promise((resolve) => {
|
|
720
|
+
process.stdin.setEncoding("utf8");
|
|
721
|
+
process.stdin.once("data", resolve);
|
|
722
|
+
});
|
|
723
|
+
return { result: undefined };
|
|
724
|
+
});`,
|
|
725
|
+
],
|
|
726
|
+
{ env: { ...process.env, HOME: home }, stdio: ["pipe", "pipe", "pipe"] },
|
|
727
|
+
);
|
|
728
|
+
let lockStderr = "";
|
|
729
|
+
lockHolder.stderr!.setEncoding("utf8");
|
|
730
|
+
lockHolder.stderr!.on("data", (chunk: string) => {
|
|
731
|
+
lockStderr += chunk;
|
|
732
|
+
});
|
|
733
|
+
let sawLocked = false;
|
|
734
|
+
const lockReady = new Promise<void>((resolve, reject) => {
|
|
735
|
+
lockHolder.once("error", reject);
|
|
736
|
+
lockHolder.once("close", (code) => {
|
|
737
|
+
if (!sawLocked) reject(new Error(`lock-holder exited with ${code} before signalling readiness: ${lockStderr.trim()}`));
|
|
738
|
+
});
|
|
739
|
+
observeLines(lockHolder.stdout!, (line) => {
|
|
740
|
+
if (line === "locked") {
|
|
741
|
+
sawLocked = true;
|
|
742
|
+
resolve();
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
// Teardown releases the lock and proves the child completed its awaited unlock before the
|
|
747
|
+
// post-release mutation runs. A wedged child still gets bounded TERM/KILL cleanup.
|
|
748
|
+
const childClosed = new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve) =>
|
|
749
|
+
lockHolder.once("close", (code, signal) => resolve({ code, signal })),
|
|
750
|
+
);
|
|
751
|
+
let readyTimer: NodeJS.Timeout | undefined;
|
|
752
|
+
try {
|
|
753
|
+
await Promise.race([
|
|
754
|
+
lockReady,
|
|
755
|
+
new Promise<never>((_, reject) => {
|
|
756
|
+
// Boot budget, not a semantics guard: the child is a fresh `node --import tsx/esm`
|
|
757
|
+
// process that compiles the TS module graph before it can signal. Under the full
|
|
758
|
+
// tier's --test-concurrency=4 on a 4-vCPU CI runner that boot alone can exceed 10s,
|
|
759
|
+
// so give it real headroom -- a genuine lock bug shows up as a wrong outcome below,
|
|
760
|
+
// never as a slow boot.
|
|
761
|
+
readyTimer = setTimeout(() => reject(new Error("lock-holder did not signal readiness within 60s")), 60_000);
|
|
762
|
+
}),
|
|
763
|
+
]);
|
|
764
|
+
const mutation = helpers.markSubscriptionAttempt("openai-codex", "work", 123);
|
|
765
|
+
// Let the async acquirer observe the held cross-process lock before releasing it. The
|
|
766
|
+
// single asynchronous lock path waits without blocking the event loop, then commits once
|
|
767
|
+
// the holder releases.
|
|
768
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
769
|
+
lockHolder.stdin!.write("release\n");
|
|
770
|
+
lockHolder.stdin!.end();
|
|
771
|
+
const pool = await mutation;
|
|
772
|
+
assert.equal(pool[0].lastAttemptAt, 123);
|
|
773
|
+
} finally {
|
|
774
|
+
if (readyTimer) clearTimeout(readyTimer);
|
|
775
|
+
try {
|
|
776
|
+
lockHolder.stdin!.write("release\n");
|
|
777
|
+
lockHolder.stdin!.end();
|
|
778
|
+
} catch {
|
|
779
|
+
/* child already gone */
|
|
780
|
+
}
|
|
781
|
+
// Wait for clean exit first: code 0 proves the async unlock completed. A wedged child gets
|
|
782
|
+
// bounded SIGTERM/SIGKILL cleanup, and its test-owned lock is removed only on that fallback.
|
|
783
|
+
const closedWithin = (ms: number) =>
|
|
784
|
+
Promise.race([
|
|
785
|
+
childClosed,
|
|
786
|
+
new Promise<null>((resolve) => setTimeout(() => resolve(null), ms)),
|
|
787
|
+
]);
|
|
788
|
+
let closed = await closedWithin(2000);
|
|
789
|
+
let forced = false;
|
|
790
|
+
if (!closed || closed.code !== 0) {
|
|
791
|
+
forced = true;
|
|
792
|
+
lockHolder.kill("SIGTERM");
|
|
793
|
+
closed = await closedWithin(2000);
|
|
794
|
+
if (!closed) {
|
|
795
|
+
lockHolder.kill("SIGKILL");
|
|
796
|
+
closed = await closedWithin(2000);
|
|
797
|
+
}
|
|
798
|
+
if (!closed) throw new Error("lock-holder child did not exit after SIGKILL");
|
|
799
|
+
}
|
|
800
|
+
if (forced) {
|
|
801
|
+
rmSync(`${poolFile}.lock`, { recursive: true, force: true });
|
|
802
|
+
throw new Error(`lock-holder exited without clean unlock (code=${closed.code}, signal=${closed.signal})`);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const pool = await helpers.markSubscriptionAttempt("openai-codex", "work", 456);
|
|
807
|
+
assert.equal(pool[0].lastAttemptAt, 456);
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// Codex captures the login `accountId` and rejects the same account re-added under a different
|
|
811
|
+
// label (a sticky browser session otherwise fakes redundancy on one quota); a distinct account
|
|
812
|
+
// is stored with its own accountId.
|
|
813
|
+
test("rejects a duplicate Codex account under a new label and stores accountId for a distinct one", async () => {
|
|
814
|
+
await resetRotationState();
|
|
815
|
+
const { ctx, commands, pi } = makeRotationCtx();
|
|
816
|
+
ctx.hasUI = true;
|
|
817
|
+
const notes: Array<{ message: string; type?: string }> = [];
|
|
818
|
+
ctx.ui.notify = (message: string, type?: string) => notes.push({ message, type });
|
|
819
|
+
ctx.ui.input = async () => "";
|
|
820
|
+
let nextAccountId = "acct-1";
|
|
821
|
+
rotationModule.__setLoginForProviderForTest(async () => ({ refresh: "r", access: "a", expires: Date.now() + 60_000, accountId: nextAccountId }));
|
|
822
|
+
|
|
823
|
+
try {
|
|
824
|
+
await providerRotationExtension(pi);
|
|
825
|
+
|
|
826
|
+
await commands["provider-sub"].handler("openai-codex add codex-alt", ctx);
|
|
827
|
+
let pool = helpers.readSubscriptionPool("openai-codex");
|
|
828
|
+
assert.deepEqual(pool.map((e) => e.label), ["codex-alt"]);
|
|
829
|
+
assert.equal(pool[0].accountId, "acct-1");
|
|
830
|
+
|
|
831
|
+
// Same account, different label -> rejected, pool unchanged.
|
|
832
|
+
notes.length = 0;
|
|
833
|
+
await commands["provider-sub"].handler("openai-codex add codex-dup", ctx);
|
|
834
|
+
assert.ok(notes.some((n) => n.type === "error" && /already added/i.test(n.message)), "duplicate account is rejected with an error");
|
|
835
|
+
pool = helpers.readSubscriptionPool("openai-codex");
|
|
836
|
+
assert.deepEqual(pool.map((e) => e.label), ["codex-alt"]);
|
|
837
|
+
|
|
838
|
+
// Distinct account -> stored with its own accountId.
|
|
839
|
+
nextAccountId = "acct-2";
|
|
840
|
+
await commands["provider-sub"].handler("openai-codex add codex-other", ctx);
|
|
841
|
+
pool = helpers.readSubscriptionPool("openai-codex");
|
|
842
|
+
assert.deepEqual(pool.map((e) => e.label).sort(), ["codex-alt", "codex-other"]);
|
|
843
|
+
assert.equal(pool.find((e) => e.label === "codex-other")?.accountId, "acct-2");
|
|
844
|
+
} finally {
|
|
845
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// The default Codex slot carries its account identity, preventing a second label from claiming
|
|
850
|
+
// the same quota and making that identity visible in the list.
|
|
851
|
+
test("the default Codex slot carries its account identity: blocks re-adding the same account and renders it in list", async () => {
|
|
852
|
+
await resetRotationState();
|
|
853
|
+
await helpers.writeSubscriptionPool("openai-codex", [
|
|
854
|
+
credential("openai-codex", { refresh: "r-def", access: "a-def", accountId: "acct-default" }),
|
|
855
|
+
]);
|
|
856
|
+
|
|
857
|
+
let pool = helpers.readSubscriptionPool("openai-codex");
|
|
858
|
+
assert.deepEqual(pool.map((e) => e.label), ["openai-codex"]);
|
|
859
|
+
assert.equal(pool[0].accountId, "acct-default");
|
|
860
|
+
|
|
861
|
+
const { ctx, commands, pi } = makeRotationCtx();
|
|
862
|
+
ctx.hasUI = true;
|
|
863
|
+
const notes: Array<{ message: string; type?: string }> = [];
|
|
864
|
+
ctx.ui.notify = (message: string, type?: string) => notes.push({ message, type });
|
|
865
|
+
ctx.ui.input = async () => "";
|
|
866
|
+
// A sticky browser re-login yields the SAME ChatGPT account already backing the pool account.
|
|
867
|
+
rotationModule.__setLoginForProviderForTest(async () => ({ refresh: "r2", access: "a2", expires: Date.now() + 60_000, accountId: "acct-default" }));
|
|
868
|
+
try {
|
|
869
|
+
await providerRotationExtension(pi);
|
|
870
|
+
|
|
871
|
+
await commands["provider-sub"].handler("openai-codex add codex-dup", ctx);
|
|
872
|
+
assert.ok(notes.some((n) => n.type === "error" && /already added/i.test(n.message)), "re-adding the account under a new label is rejected");
|
|
873
|
+
pool = helpers.readSubscriptionPool("openai-codex");
|
|
874
|
+
assert.deepEqual(pool.map((e) => e.label), ["openai-codex"]);
|
|
875
|
+
|
|
876
|
+
notes.length = 0;
|
|
877
|
+
await commands["provider-sub"].handler("openai-codex list", ctx);
|
|
878
|
+
assert.match(notes.map((n) => n.message).join("\n"), /account=/);
|
|
879
|
+
} finally {
|
|
880
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// Drive the REAL login handler path: a collision with an explicit account must reject
|
|
885
|
+
// before commitManagedLogin writes anything, so the failed OAuth result never partially
|
|
886
|
+
// switches the default credential or creates a default pool entry with the duplicate identity.
|
|
887
|
+
test("login handler rejects a colliding Codex account before switching the pool account", async () => {
|
|
888
|
+
await resetRotationState();
|
|
889
|
+
await helpers.addSubscription("openai-codex", credential("work", { accountId: "acct-X" }));
|
|
890
|
+
const { ctx, commands, pi } = makeRotationCtx();
|
|
891
|
+
ctx.hasUI = true;
|
|
892
|
+
const notes: Array<{ message: string; type?: string }> = [];
|
|
893
|
+
ctx.ui.notify = (message: string, type?: string) => notes.push({ message, type });
|
|
894
|
+
ctx.ui.input = async () => "";
|
|
895
|
+
rotationModule.__setLoginForProviderForTest(async () => ({ refresh: "r-X", access: "a-X", expires: Date.now() + 60_000, accountId: "acct-X" }));
|
|
896
|
+
try {
|
|
897
|
+
await providerRotationExtension(pi);
|
|
898
|
+
await commands["provider-sub"].handler("openai-codex add openai-codex", ctx);
|
|
899
|
+
assert.ok(notes.some((note) => note.type === "error" && /already added/i.test(note.message)));
|
|
900
|
+
assert.equal(readAuthRecord("openai-codex"), undefined, "rejected login must not write auth.json");
|
|
901
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
902
|
+
assert.equal(pool.filter((entry) => entry.accountId === "acct-X").length, 1);
|
|
903
|
+
assert.equal(pool.some((entry) => entry.label === "openai-codex"), false);
|
|
904
|
+
} finally {
|
|
905
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
// The handler snapshots the pool account before OAuth. A 429 recorded while OAuth is open is
|
|
910
|
+
// causally newer, so completing a same-account login must not reopen that quota.
|
|
911
|
+
test("the uniqueness-aware reauth upsert refreshes its slot but rejects another slot's account", async () => {
|
|
912
|
+
await resetRotationState();
|
|
913
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("work", { accountId: "acct-old", rateLimitedUntil: 900, lastAttemptAt: 100, lastRateLimitedAt: 50 }), credential("other", { accountId: "acct-held" })]);
|
|
914
|
+
await helpers.upsertSubscriptionWithUniqueAccount("openai-codex", credential("work", { accountId: "acct-new", refresh: "r-new", access: "a-new" }));
|
|
915
|
+
let pool = helpers.readSubscriptionPool("openai-codex");
|
|
916
|
+
const refreshed = pool.find((entry) => entry.label === "work");
|
|
917
|
+
assert.equal(refreshed?.accountId, "acct-new");
|
|
918
|
+
assert.equal(refreshed?.rateLimitedUntil, 900);
|
|
919
|
+
assert.equal(refreshed?.lastAttemptAt, 100);
|
|
920
|
+
assert.equal(refreshed?.lastRateLimitedAt, 50);
|
|
921
|
+
await assert.rejects(
|
|
922
|
+
() => helpers.upsertSubscriptionWithUniqueAccount("openai-codex", credential("work", { accountId: "acct-held", refresh: "r-collision", access: "a-collision" })),
|
|
923
|
+
(err: unknown) => err instanceof helpers.DuplicateSubscriptionError && /already added/i.test((err as Error).message),
|
|
924
|
+
);
|
|
925
|
+
pool = helpers.readSubscriptionPool("openai-codex");
|
|
926
|
+
assert.equal(pool.find((entry) => entry.label === "work")?.accountId, "acct-new");
|
|
927
|
+
assert.equal(pool.filter((entry) => entry.accountId === "acct-held").length, 1);
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
// A rejected default identity move must leave the pool untouched — account uniqueness is decided
|
|
931
|
+
// inside the pool lock, before anything is written — and must not touch auth.json at all, which
|
|
932
|
+
// no managed path writes any more.
|
|
933
|
+
test("addSubscription normalizes labels and enforces Codex account uniqueness inside the locked transform", async () => {
|
|
934
|
+
await resetRotationState();
|
|
935
|
+
await helpers.addSubscription("openai-codex", credential("work", { accountId: "acct-1" }));
|
|
936
|
+
await assert.rejects(
|
|
937
|
+
() => helpers.addSubscription("openai-codex", credential(" work ", { accountId: "acct-2" })),
|
|
938
|
+
(err: unknown) => err instanceof helpers.DuplicateSubscriptionError && /already exists/i.test((err as Error).message),
|
|
939
|
+
);
|
|
940
|
+
await assert.rejects(
|
|
941
|
+
() => helpers.addSubscription("openai-codex", credential(" ", { accountId: "acct-3" })),
|
|
942
|
+
(err: unknown) => !(err instanceof helpers.DuplicateSubscriptionError) && /cannot be empty/i.test((err as Error).message),
|
|
943
|
+
);
|
|
944
|
+
await assert.rejects(
|
|
945
|
+
() => helpers.addSubscription("openai-codex", credential("work-2", { accountId: "acct-1" })),
|
|
946
|
+
(err: unknown) => err instanceof helpers.DuplicateSubscriptionError && /already added/i.test((err as Error).message),
|
|
947
|
+
);
|
|
948
|
+
await helpers.addSubscription("openai-codex", credential("work-3", { accountId: "acct-3" }));
|
|
949
|
+
assert.deepEqual(helpers.readSubscriptionPool("openai-codex").map((entry) => entry.label).sort(), ["work", "work-3"]);
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
// The first contender holds the real pool lock inside addSubscription's transform. The second
|
|
953
|
+
// contender cannot reach its own transform until it has first attempted that same real lock.
|
|
954
|
+
// This makes an outside-lock uniqueness check deterministic: both checks run while the pool is
|
|
955
|
+
// empty, then both appends succeed after the holder releases.
|
|
956
|
+
// Approved slow-test exception: two fresh TypeScript child processes can take over 10s to boot
|
|
957
|
+
// on a hosted runner; the test's bounded coordination budgets distinguish a genuine regression.
|
|
958
|
+
test("cross-process explicit adds admit exactly one duplicate Codex account", { timeout: 60_000 }, async () => {
|
|
959
|
+
await resetRotationState();
|
|
960
|
+
const poolPath = join(home, ".pi", "agent", "openai-codex-subscriptions.json");
|
|
961
|
+
const subscriptionStateUrl = new URL("../../lib/subscription-state.ts", import.meta.url).href;
|
|
962
|
+
const spawnContender = (label: string) => {
|
|
963
|
+
const child = spawn(
|
|
964
|
+
process.execPath,
|
|
965
|
+
[
|
|
966
|
+
"--import",
|
|
967
|
+
"tsx/esm",
|
|
968
|
+
"--input-type=module",
|
|
969
|
+
"-e",
|
|
970
|
+
String.raw`const { addSubscription, DuplicateSubscriptionError } = await import(${JSON.stringify(subscriptionStateUrl)});
|
|
971
|
+
try {
|
|
972
|
+
await addSubscription("openai-codex", {
|
|
973
|
+
label: ${JSON.stringify(label)}, refresh: "refresh-${label}", access: "access-${label}", expires: Date.now() + 60_000,
|
|
974
|
+
accountId: "acct-cross-process-race", rateLimitedUntil: 0, lastAttemptAt: 0, lastRateLimitedAt: 0,
|
|
975
|
+
});
|
|
976
|
+
process.stdout.write("outcome:success\n");
|
|
977
|
+
} catch (error) {
|
|
978
|
+
const outcome = error instanceof DuplicateSubscriptionError ? "duplicate" : "error";
|
|
979
|
+
process.stdout.write("outcome:" + outcome + "\n");
|
|
980
|
+
if (outcome === "error") process.stderr.write(String(error));
|
|
981
|
+
}`,
|
|
982
|
+
],
|
|
983
|
+
{ env: { ...process.env, HOME: home }, stdio: ["ignore", "pipe", "pipe"] },
|
|
984
|
+
);
|
|
985
|
+
return new Promise<{ outcome: string; stderr: string }>((resolve, reject) => {
|
|
986
|
+
let stdout = "";
|
|
987
|
+
let stderr = "";
|
|
988
|
+
child.stdout!.on("data", (chunk: string) => { stdout += chunk; });
|
|
989
|
+
child.stderr!.on("data", (chunk: string) => { stderr += chunk; });
|
|
990
|
+
child.once("error", reject);
|
|
991
|
+
child.once("close", (code) => {
|
|
992
|
+
const outcome = /outcome:([^\n]+)/.exec(stdout)?.[1];
|
|
993
|
+
if (code !== 0 || outcome === undefined) reject(new Error(`${label} exited with ${code}: ${stderr.trim()}`));
|
|
994
|
+
else resolve({ outcome, stderr });
|
|
995
|
+
});
|
|
996
|
+
});
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
const results = await Promise.all([spawnContender("race-left"), spawnContender("race-right")]);
|
|
1000
|
+
assert.deepEqual(results.map((result) => result.outcome).sort(), ["duplicate", "success"], results.map((result) => result.stderr).join("\n"));
|
|
1001
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
1002
|
+
assert.equal(pool.length, 1);
|
|
1003
|
+
assert.ok(["race-left", "race-right"].includes(pool[0].label));
|
|
1004
|
+
assert.equal(existsSync(`${poolPath}.lock`), false, "cross-process add race must release the pool lock directory");
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
test("renames explicit subscriptions without permitting pool or case-insensitive collisions", async () => {
|
|
1008
|
+
await resetRotationState();
|
|
1009
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("openai-codex"), credential("work"), credential("personal")]);
|
|
1010
|
+
assert.deepEqual((await helpers.renameSubscription("openai-codex", "work", "Lab")).map((entry) => entry.label), ["openai-codex", "Lab", "personal"]);
|
|
1011
|
+
await assert.rejects(() => helpers.renameSubscription("openai-codex", "Lab", " PERSONAL "), helpers.DuplicateSubscriptionError);
|
|
1012
|
+
await helpers.renameSubscription("openai-codex", "openai-codex", "anything");
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
test("treats numeric subscription refs as 1-based indexes", async () => {
|
|
1016
|
+
await resetRotationState();
|
|
1017
|
+
const pool = [credential("alpha"), credential("beta")];
|
|
1018
|
+
|
|
1019
|
+
await helpers.writeSubscriptionPool("openai-codex", pool);
|
|
1020
|
+
assert.deepEqual(
|
|
1021
|
+
(await helpers.removeSubscription("openai-codex", "1")).map((entry) => entry.label),
|
|
1022
|
+
["beta"],
|
|
1023
|
+
);
|
|
1024
|
+
|
|
1025
|
+
await helpers.writeSubscriptionPool("openai-codex", pool);
|
|
1026
|
+
assert.deepEqual(
|
|
1027
|
+
(await helpers.promoteSubscription("openai-codex", "2")).map((entry) => entry.label),
|
|
1028
|
+
["beta", "alpha"],
|
|
1029
|
+
);
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
test("switches exhausted Anthropic sessions to OpenAI Codex fallback", async () => {
|
|
1033
|
+
await resetRotationState();
|
|
1034
|
+
writeLadderConfig();
|
|
1035
|
+
|
|
1036
|
+
const ctx = {
|
|
1037
|
+
model: { provider: "anthropic", id: "claude-sonnet-4-6", api: "anthropic-messages" },
|
|
1038
|
+
modelRegistry: {
|
|
1039
|
+
find(provider: string, id: string) {
|
|
1040
|
+
return provider === "openai-codex" && id === "gpt-5.6-terra" ? { provider, id, api: "openai-codex-responses" } : undefined;
|
|
1041
|
+
},
|
|
1042
|
+
},
|
|
1043
|
+
} as any;
|
|
1044
|
+
let switchedTo: any;
|
|
1045
|
+
let thinkingLevel: string | undefined;
|
|
1046
|
+
const piApi = {
|
|
1047
|
+
async setModel(model: any) {
|
|
1048
|
+
switchedTo = model;
|
|
1049
|
+
ctx.model = model;
|
|
1050
|
+
return true;
|
|
1051
|
+
},
|
|
1052
|
+
setThinkingLevel(level: string) {
|
|
1053
|
+
thinkingLevel = level;
|
|
1054
|
+
},
|
|
1055
|
+
} as any;
|
|
1056
|
+
|
|
1057
|
+
const target = await helpers.switchToFallbackIfPossible(piApi, ctx);
|
|
1058
|
+
|
|
1059
|
+
assert.deepEqual(target, {
|
|
1060
|
+
providerId: "openai-codex",
|
|
1061
|
+
modelId: "gpt-5.6-terra",
|
|
1062
|
+
label: "openai-codex/gpt-5.6-terra:medium",
|
|
1063
|
+
strength: "medium",
|
|
1064
|
+
thinkingLevel: "medium",
|
|
1065
|
+
});
|
|
1066
|
+
assert.deepEqual(switchedTo, {
|
|
1067
|
+
provider: "openai-codex",
|
|
1068
|
+
id: "gpt-5.6-terra",
|
|
1069
|
+
api: "openai-codex-responses",
|
|
1070
|
+
});
|
|
1071
|
+
assert.equal(thinkingLevel, "medium");
|
|
1072
|
+
assert.deepEqual(helpers.readRotationConfig().preferredModel, {
|
|
1073
|
+
providerId: "anthropic",
|
|
1074
|
+
modelId: "claude-sonnet-4-6",
|
|
1075
|
+
});
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
test("switches exhausted OpenAI Codex sessions to Anthropic fallback", async () => {
|
|
1079
|
+
await resetRotationState();
|
|
1080
|
+
writeLadderConfig();
|
|
1081
|
+
|
|
1082
|
+
const ctx = {
|
|
1083
|
+
model: { provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" },
|
|
1084
|
+
modelRegistry: {
|
|
1085
|
+
find(provider: string, id: string) {
|
|
1086
|
+
return provider === "anthropic" && id === "claude-opus-4-8" ? { provider, id, api: "anthropic-messages" } : undefined;
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
} as any;
|
|
1090
|
+
let switchedTo: any;
|
|
1091
|
+
let thinkingLevel: string | undefined;
|
|
1092
|
+
const piApi = {
|
|
1093
|
+
async setModel(model: any) {
|
|
1094
|
+
switchedTo = model;
|
|
1095
|
+
ctx.model = model;
|
|
1096
|
+
return true;
|
|
1097
|
+
},
|
|
1098
|
+
setThinkingLevel(level: string) {
|
|
1099
|
+
thinkingLevel = level;
|
|
1100
|
+
},
|
|
1101
|
+
} as any;
|
|
1102
|
+
|
|
1103
|
+
const target = await helpers.switchToFallbackIfPossible(piApi, ctx);
|
|
1104
|
+
|
|
1105
|
+
assert.deepEqual(target, {
|
|
1106
|
+
providerId: "anthropic",
|
|
1107
|
+
modelId: "claude-opus-4-8",
|
|
1108
|
+
label: "anthropic/claude-opus-4-8:high",
|
|
1109
|
+
strength: "strong",
|
|
1110
|
+
thinkingLevel: "high",
|
|
1111
|
+
});
|
|
1112
|
+
assert.deepEqual(switchedTo, {
|
|
1113
|
+
provider: "anthropic",
|
|
1114
|
+
id: "claude-opus-4-8",
|
|
1115
|
+
api: "anthropic-messages",
|
|
1116
|
+
});
|
|
1117
|
+
assert.equal(thinkingLevel, "high");
|
|
1118
|
+
assert.deepEqual(helpers.readRotationConfig().preferredModel, {
|
|
1119
|
+
providerId: "openai-codex",
|
|
1120
|
+
modelId: "gpt-5.6-sol",
|
|
1121
|
+
});
|
|
1122
|
+
});
|
|
1123
|
+
|
|
1124
|
+
function makeRotationCtx() {
|
|
1125
|
+
const ctx = {
|
|
1126
|
+
model: { provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" },
|
|
1127
|
+
ui: { setStatus() {} },
|
|
1128
|
+
modelRegistry: {
|
|
1129
|
+
find(provider: string, id: string) {
|
|
1130
|
+
if (provider === "anthropic" && id === "claude-opus-4-8") return { provider, id, api: "anthropic-messages" };
|
|
1131
|
+
if (provider === "openai-codex" && id === "gpt-5.6-sol") return { provider, id, api: "openai-codex-responses" };
|
|
1132
|
+
return undefined;
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
} as any;
|
|
1136
|
+
const setModelCalls: any[] = [];
|
|
1137
|
+
const providers: Record<string, { streamSimple: (...args: any[]) => AsyncIterable<any> }> = {};
|
|
1138
|
+
const events: Record<string, (...args: any[]) => unknown> = {};
|
|
1139
|
+
const commands: Record<string, { handler: (args: string, ctx: any) => unknown }> = {};
|
|
1140
|
+
const pi = {
|
|
1141
|
+
registerProvider(name: string, provider: { streamSimple: (...args: any[]) => AsyncIterable<any> }) {
|
|
1142
|
+
providers[name] = provider;
|
|
1143
|
+
},
|
|
1144
|
+
registerCommand(name: string, command: { handler: (args: string, ctx: any) => unknown }) {
|
|
1145
|
+
commands[name] = command;
|
|
1146
|
+
},
|
|
1147
|
+
on(eventName: string, handler: (...args: any[]) => unknown) {
|
|
1148
|
+
events[eventName] = handler;
|
|
1149
|
+
},
|
|
1150
|
+
async setModel(model: any) {
|
|
1151
|
+
setModelCalls.push(model);
|
|
1152
|
+
ctx.model = model;
|
|
1153
|
+
return true;
|
|
1154
|
+
},
|
|
1155
|
+
setThinkingLevel() {},
|
|
1156
|
+
} as any;
|
|
1157
|
+
return { ctx, setModelCalls, providers, events, commands, pi };
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// Codex exhaustion switches the model and serves the same turn on the Anthropic fallback.
|
|
1161
|
+
test("falls back transparently and serves the turn on Anthropic when Codex is exhausted", async () => {
|
|
1162
|
+
await resetRotationState();
|
|
1163
|
+
writeLadderConfig();
|
|
1164
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
1165
|
+
|
|
1166
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1167
|
+
const streamedModels: any[] = [];
|
|
1168
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
1169
|
+
streamedModels.push(model);
|
|
1170
|
+
return (async function* () {
|
|
1171
|
+
yield { type: "text_delta", text: "hello from anthropic" };
|
|
1172
|
+
})() as any;
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
try {
|
|
1176
|
+
await providerRotationExtension(pi);
|
|
1177
|
+
await events.session_start?.({}, ctx);
|
|
1178
|
+
const stream = providers["openai-codex"].streamSimple(
|
|
1179
|
+
{ provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" },
|
|
1180
|
+
ctx,
|
|
1181
|
+
);
|
|
1182
|
+
const emitted = [] as any[];
|
|
1183
|
+
for await (const event of stream) emitted.push(event);
|
|
1184
|
+
|
|
1185
|
+
// Session model was switched to the Anthropic fallback...
|
|
1186
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["anthropic"]);
|
|
1187
|
+
// ...and the turn was actually STREAMED on the Anthropic model (not the codex one).
|
|
1188
|
+
assert.equal(streamedModels.length, 1);
|
|
1189
|
+
assert.equal(streamedModels[0].provider, "anthropic");
|
|
1190
|
+
// The turn was served with content, never failed with an error.
|
|
1191
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1192
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
1193
|
+
} finally {
|
|
1194
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
// Live incident: a viewer explicitly selected qualified Sol, which set the
|
|
1199
|
+
// broker's provider pin, but the extension ignored that broker state. The first
|
|
1200
|
+
// model call could request a tool; on the post-tool continuation a shared Codex
|
|
1201
|
+
// cooldown then rotated the supposedly-pinned session through every Anthropic
|
|
1202
|
+
// credential. The live broker policy must be consulted on every provider call.
|
|
1203
|
+
test("an explicit live Sol pin forbids Anthropic fallback on a post-tool provider continuation", async () => {
|
|
1204
|
+
await resetRotationState();
|
|
1205
|
+
writeLadderConfig();
|
|
1206
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1207
|
+
await helpers.markSubscriptionRateLimited("openai-codex", "codex", 30_000);
|
|
1208
|
+
const expectedDeadline = helpers.readSubscriptionPool("openai-codex")[0].rateLimitedUntil;
|
|
1209
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
1210
|
+
|
|
1211
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1212
|
+
ctx.ui[Symbol.for("@crouton-kit/crtr:managed-provider-rotation-policy")] = () => ({
|
|
1213
|
+
allowCrossProviderFallback: false,
|
|
1214
|
+
reason: "provider-pinned",
|
|
1215
|
+
});
|
|
1216
|
+
let streamCalls = 0;
|
|
1217
|
+
rotationModule.__setStreamForProviderForTest((_model) => {
|
|
1218
|
+
streamCalls += 1;
|
|
1219
|
+
return (async function* () {
|
|
1220
|
+
yield { type: "text_delta", text: "must not call a cooling or fallback provider" };
|
|
1221
|
+
})() as any;
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
try {
|
|
1225
|
+
await providerRotationExtension(pi);
|
|
1226
|
+
await events.session_start?.({}, ctx);
|
|
1227
|
+
const stream = providers["openai-codex"].streamSimple(
|
|
1228
|
+
{ provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" },
|
|
1229
|
+
ctx,
|
|
1230
|
+
);
|
|
1231
|
+
const emitted = [] as any[];
|
|
1232
|
+
for await (const event of stream) emitted.push(event);
|
|
1233
|
+
|
|
1234
|
+
assert.deepEqual(setModelCalls, [], "the pinned Sol session never switches to Anthropic");
|
|
1235
|
+
assert.equal(streamCalls, 0);
|
|
1236
|
+
assert.equal(emitted.length, 1);
|
|
1237
|
+
assert.match(emitted[0].error.errorMessage, /explicitly pinned/i);
|
|
1238
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, expectedDeadline);
|
|
1239
|
+
} finally {
|
|
1240
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1241
|
+
}
|
|
1242
|
+
});
|
|
1243
|
+
|
|
1244
|
+
// Request timeouts and other transient network/5xx blips retry the same provider in place
|
|
1245
|
+
// without cooling the credential down or rotating away.
|
|
1246
|
+
test("treats a request timeout as transient: retries the SAME provider in place, no cooldown or rotation", async () => {
|
|
1247
|
+
await resetRotationState();
|
|
1248
|
+
writeLadderConfig();
|
|
1249
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1250
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1251
|
+
|
|
1252
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1253
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1254
|
+
const streamedModels: any[] = [];
|
|
1255
|
+
const sleepCalls: number[] = [];
|
|
1256
|
+
let anthropicCalls = 0;
|
|
1257
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
1258
|
+
sleepCalls.push(ms);
|
|
1259
|
+
});
|
|
1260
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
1261
|
+
streamedModels.push(model);
|
|
1262
|
+
return (async function* () {
|
|
1263
|
+
if (model.provider === "anthropic") {
|
|
1264
|
+
anthropicCalls += 1;
|
|
1265
|
+
if (anthropicCalls === 1) {
|
|
1266
|
+
yield { type: "error", error: Object.assign(new Error("Request timed out."), { errorMessage: "Request timed out." }) };
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
yield { type: "text_delta", text: "hello from anthropic, second try" };
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
yield { type: "text_delta", text: "hello from codex" };
|
|
1273
|
+
})() as any;
|
|
1274
|
+
});
|
|
1275
|
+
|
|
1276
|
+
try {
|
|
1277
|
+
await providerRotationExtension(pi);
|
|
1278
|
+
await events.session_start?.({}, ctx);
|
|
1279
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1280
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1281
|
+
ctx,
|
|
1282
|
+
);
|
|
1283
|
+
const emitted = [] as any[];
|
|
1284
|
+
for await (const event of stream) emitted.push(event);
|
|
1285
|
+
|
|
1286
|
+
// Never switched providers or models -- both attempts stayed on anthropic.
|
|
1287
|
+
assert.deepEqual(setModelCalls, []);
|
|
1288
|
+
assert.deepEqual(streamedModels.map((m) => m.provider), ["anthropic", "anthropic"]);
|
|
1289
|
+
assert.deepEqual(sleepCalls, [250]);
|
|
1290
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1291
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
1292
|
+
// No cooldown -- a transient blip must never cool down a healthy subscription.
|
|
1293
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 0);
|
|
1294
|
+
} finally {
|
|
1295
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1296
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
// Once the in-place transient retry budget is exhausted, the failure is surfaced to the
|
|
1301
|
+
// user AND the credential is rotated away: the struggling credential cools down briefly and
|
|
1302
|
+
// the turn continues on the fallback provider, rather than hard-failing.
|
|
1303
|
+
test("surfaces the transient error and rotates to the fallback once the in-place retry budget is exhausted", async () => {
|
|
1304
|
+
await resetRotationState();
|
|
1305
|
+
writeLadderConfig();
|
|
1306
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1307
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1308
|
+
|
|
1309
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1310
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1311
|
+
const notifications: Array<{ message: string; level: string }> = [];
|
|
1312
|
+
ctx.ui.notify = (message: string, level: string) => {
|
|
1313
|
+
notifications.push({ message, level });
|
|
1314
|
+
};
|
|
1315
|
+
const streamedModels: any[] = [];
|
|
1316
|
+
const sleepCalls: number[] = [];
|
|
1317
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
1318
|
+
sleepCalls.push(ms);
|
|
1319
|
+
});
|
|
1320
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
1321
|
+
streamedModels.push(model);
|
|
1322
|
+
return (async function* () {
|
|
1323
|
+
if (model.provider === "anthropic") {
|
|
1324
|
+
// 503 with no retry-after header is transient by STATUS, not just by message.
|
|
1325
|
+
yield { type: "error", error: Object.assign(new Error("Service Unavailable"), { status: 503 }) };
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
yield { type: "text_delta", text: "hello from codex fallback" };
|
|
1329
|
+
})() as any;
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1332
|
+
try {
|
|
1333
|
+
await providerRotationExtension(pi);
|
|
1334
|
+
await events.session_start?.({}, ctx);
|
|
1335
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1336
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1337
|
+
ctx,
|
|
1338
|
+
);
|
|
1339
|
+
const emitted = [] as any[];
|
|
1340
|
+
for await (const event of stream) emitted.push(event);
|
|
1341
|
+
|
|
1342
|
+
// Retried the same anthropic credential in place (3 attempts) then rotated to codex.
|
|
1343
|
+
assert.equal(streamedModels.filter((m) => m.provider === "anthropic").length, 3);
|
|
1344
|
+
assert.deepEqual(sleepCalls, [250, 750]);
|
|
1345
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["openai-codex"]);
|
|
1346
|
+
// The turn was served on the fallback, never failed with a terminal error.
|
|
1347
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1348
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
1349
|
+
// The user was told about the transient failure AND that it rotated.
|
|
1350
|
+
assert.ok(notifications.some((n) => /transient error after 3 attempts/.test(n.message) && /rotating/i.test(n.message)));
|
|
1351
|
+
// The struggling anthropic credential was cooled down so rotation moved on.
|
|
1352
|
+
assert.ok(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil > Date.now());
|
|
1353
|
+
} finally {
|
|
1354
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1355
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
// Regression: a genuine rate limit (HTTP 429) must never get the transient in-place
|
|
1360
|
+
// retry treatment -- it cools the credential down and rotates on the FIRST failure. The
|
|
1361
|
+
// cooldown duration must reflect a real Retry-After header (5s here) rather than always
|
|
1362
|
+
// falling back to the 5-minute default, so a misclassification is obvious from the numbers.
|
|
1363
|
+
test("treats HTTP 429 as a genuine rate limit: rotates immediately using the Retry-After header, no in-place retry", async () => {
|
|
1364
|
+
await resetRotationState();
|
|
1365
|
+
writeLadderConfig();
|
|
1366
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1367
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1368
|
+
|
|
1369
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1370
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1371
|
+
const streamedModels: any[] = [];
|
|
1372
|
+
const sleepCalls: number[] = [];
|
|
1373
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
1374
|
+
sleepCalls.push(ms);
|
|
1375
|
+
});
|
|
1376
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
1377
|
+
streamedModels.push(model);
|
|
1378
|
+
return (async function* () {
|
|
1379
|
+
if (model.provider === "anthropic") {
|
|
1380
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "5" } }, model);
|
|
1381
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
yield { type: "text_delta", text: "hello from codex" };
|
|
1385
|
+
})() as any;
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
try {
|
|
1389
|
+
await providerRotationExtension(pi);
|
|
1390
|
+
await events.session_start?.({}, ctx);
|
|
1391
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1392
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1393
|
+
ctx,
|
|
1394
|
+
);
|
|
1395
|
+
const emitted = [] as any[];
|
|
1396
|
+
for await (const event of stream) emitted.push(event);
|
|
1397
|
+
|
|
1398
|
+
assert.equal(streamedModels.filter((m) => m.provider === "anthropic").length, 1);
|
|
1399
|
+
assert.deepEqual(sleepCalls, []); // a genuine rate limit rotates immediately, it never sleeps in place
|
|
1400
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["openai-codex"]);
|
|
1401
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1402
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
1403
|
+
const [entry] = helpers.readSubscriptionPool("anthropic");
|
|
1404
|
+
// Retry-After: 5 -> ~5s cooldown, not the 5-minute default backoff.
|
|
1405
|
+
assert.ok(entry.rateLimitedUntil > Date.now() + 4_000 && entry.rateLimitedUntil <= Date.now() + 5_000);
|
|
1406
|
+
} finally {
|
|
1407
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1408
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
test("re-enters an already-attempted provider when a concurrent success makes it ready again", async () => {
|
|
1413
|
+
await resetRotationState();
|
|
1414
|
+
writeLadderConfig();
|
|
1415
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1416
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1417
|
+
|
|
1418
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1419
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1420
|
+
const streamedProviders: string[] = [];
|
|
1421
|
+
let anthropicAttempts = 0;
|
|
1422
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
1423
|
+
streamedProviders.push(model.provider);
|
|
1424
|
+
return (async function* () {
|
|
1425
|
+
if (model.provider === "anthropic" && anthropicAttempts++ > 0) {
|
|
1426
|
+
yield { type: "text_delta", text: "recovered on Anthropic" };
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
if (model.provider === "openai-codex") {
|
|
1430
|
+
// A concurrent turn began after this turn's 429, so its causal success
|
|
1431
|
+
// may legitimately clear Anthropic's cooldown before Codex exhausts.
|
|
1432
|
+
await helpers.markSubscriptionSuccess("anthropic", "primary", Date.now() + 1);
|
|
1433
|
+
}
|
|
1434
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "0" } }, model);
|
|
1435
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
1436
|
+
})() as any;
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
try {
|
|
1440
|
+
await providerRotationExtension(pi);
|
|
1441
|
+
await events.session_start?.({}, ctx);
|
|
1442
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1443
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1444
|
+
ctx,
|
|
1445
|
+
);
|
|
1446
|
+
const emitted = [] as any[];
|
|
1447
|
+
for await (const event of stream) emitted.push(event);
|
|
1448
|
+
|
|
1449
|
+
assert.deepEqual(streamedProviders, ["anthropic", "openai-codex", "anthropic"]);
|
|
1450
|
+
assert.deepEqual(setModelCalls.map((entry) => entry.provider), ["openai-codex", "anthropic"]);
|
|
1451
|
+
assert.ok(emitted.some((event) => event.type === "text_delta"));
|
|
1452
|
+
assert.ok(!emitted.some((event) => event.type === "error"), "the ready-again provider must not fall into fatal exhaustion");
|
|
1453
|
+
} finally {
|
|
1454
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
test("does not cool down credentials or switch providers when the user aborts", async () => {
|
|
1459
|
+
await resetRotationState();
|
|
1460
|
+
writeLadderConfig();
|
|
1461
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1462
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1463
|
+
|
|
1464
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1465
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1466
|
+
const streamedModels: any[] = [];
|
|
1467
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
1468
|
+
streamedModels.push(model);
|
|
1469
|
+
return (async function* () {
|
|
1470
|
+
yield {
|
|
1471
|
+
type: "error",
|
|
1472
|
+
reason: "aborted",
|
|
1473
|
+
error: {
|
|
1474
|
+
role: "assistant",
|
|
1475
|
+
content: [],
|
|
1476
|
+
api: model.api,
|
|
1477
|
+
provider: model.provider,
|
|
1478
|
+
model: model.id,
|
|
1479
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
|
|
1480
|
+
stopReason: "aborted",
|
|
1481
|
+
errorMessage: "Request was aborted",
|
|
1482
|
+
timestamp: Date.now(),
|
|
1483
|
+
},
|
|
1484
|
+
};
|
|
1485
|
+
})() as any;
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
try {
|
|
1489
|
+
await providerRotationExtension(pi);
|
|
1490
|
+
await events.session_start?.({}, ctx);
|
|
1491
|
+
// No AbortSignal is threaded through options here on purpose: the abort must be recognized
|
|
1492
|
+
// from the event's own `reason: "aborted"` marker alone. Requiring the signal is exactly the
|
|
1493
|
+
// regression that let an ESC cool down every credential and drain both provider pools.
|
|
1494
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1495
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1496
|
+
ctx,
|
|
1497
|
+
);
|
|
1498
|
+
const emitted = [] as any[];
|
|
1499
|
+
for await (const event of stream) emitted.push(event);
|
|
1500
|
+
|
|
1501
|
+
assert.deepEqual(setModelCalls, []);
|
|
1502
|
+
assert.deepEqual(streamedModels.map((m) => m.provider), ["anthropic"]);
|
|
1503
|
+
assert.equal(emitted.length, 1);
|
|
1504
|
+
assert.equal(emitted[0].type, "error");
|
|
1505
|
+
assert.equal(emitted[0].reason, "aborted");
|
|
1506
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil, 0);
|
|
1507
|
+
assert.equal(helpers.readSubscriptionPool("openai-codex")[0].rateLimitedUntil, 0);
|
|
1508
|
+
} finally {
|
|
1509
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
test("skips invalid refresh tokens and serves the turn on the fallback provider", async () => {
|
|
1514
|
+
await resetRotationState();
|
|
1515
|
+
writeLadderConfig();
|
|
1516
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("stale", { expires: 1 })]);
|
|
1517
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1518
|
+
|
|
1519
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1520
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1521
|
+
const streamedModels: any[] = [];
|
|
1522
|
+
// Plain Error, no typed .status: the pool path still recognizes invalid_grant
|
|
1523
|
+
// from the message text.
|
|
1524
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
1525
|
+
if (providerId === "anthropic") {
|
|
1526
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
1527
|
+
}
|
|
1528
|
+
throw new Error("unexpected refresh");
|
|
1529
|
+
});
|
|
1530
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
1531
|
+
streamedModels.push(model);
|
|
1532
|
+
return (async function* () {
|
|
1533
|
+
yield { type: "text_delta", text: "hello from codex" };
|
|
1534
|
+
})() as any;
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
try {
|
|
1538
|
+
await providerRotationExtension(pi);
|
|
1539
|
+
await events.session_start?.({}, ctx);
|
|
1540
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1541
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1542
|
+
ctx,
|
|
1543
|
+
);
|
|
1544
|
+
const emitted = [] as any[];
|
|
1545
|
+
for await (const event of stream) emitted.push(event);
|
|
1546
|
+
|
|
1547
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["openai-codex"]);
|
|
1548
|
+
assert.equal(streamedModels.length, 1);
|
|
1549
|
+
assert.equal(streamedModels[0].provider, "openai-codex");
|
|
1550
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1551
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
1552
|
+
assert.ok(helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil > Date.now() + 29 * 24 * 60 * 60 * 1000);
|
|
1553
|
+
} finally {
|
|
1554
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
1555
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1559
|
+
test("all invalid refresh credentials surface an auth terminal instead of a typed cooldown", async () => {
|
|
1560
|
+
await resetRotationState();
|
|
1561
|
+
writeLadderConfig();
|
|
1562
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("anthropic-stale", { expires: 1 })]);
|
|
1563
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex-stale", { expires: 1 })]);
|
|
1564
|
+
|
|
1565
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
1566
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1567
|
+
rotationModule.__setRefreshForProviderForTest(async () => {
|
|
1568
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant"}');
|
|
1569
|
+
});
|
|
1570
|
+
|
|
1571
|
+
try {
|
|
1572
|
+
await providerRotationExtension(pi);
|
|
1573
|
+
await events.session_start?.({}, ctx);
|
|
1574
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1575
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1576
|
+
ctx,
|
|
1577
|
+
);
|
|
1578
|
+
const emitted = [] as any[];
|
|
1579
|
+
for await (const event of stream) emitted.push(event);
|
|
1580
|
+
|
|
1581
|
+
const terminal = emitted.find((event) => event.type === "error");
|
|
1582
|
+
assert.ok(terminal, "all invalid credentials must terminate the turn");
|
|
1583
|
+
assert.match(terminal.error.errorMessage, /authentication failed.*invalid_grant/i);
|
|
1584
|
+
assert.equal(terminal.error.diagnostics, undefined, "an auth failure must not carry the auto-cooling diagnostic");
|
|
1585
|
+
assert.equal(helpers.readSubscriptionPool("anthropic")[0].authFailure, "invalid_grant");
|
|
1586
|
+
assert.equal(helpers.readSubscriptionPool("openai-codex")[0].authFailure, "invalid_grant");
|
|
1587
|
+
} finally {
|
|
1588
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
test("automatically reauthenticates invalid refresh tokens when UI is available", async () => {
|
|
1593
|
+
await resetRotationState();
|
|
1594
|
+
writeLadderConfig();
|
|
1595
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("stale", { expires: 1 })]);
|
|
1596
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1597
|
+
|
|
1598
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1599
|
+
ctx.hasUI = true;
|
|
1600
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1601
|
+
ctx.ui.notify = () => {};
|
|
1602
|
+
const loginCalls: string[] = [];
|
|
1603
|
+
const streamedOptions: any[] = [];
|
|
1604
|
+
// Plain Error, no typed .status: the pool path still recognizes invalid_grant
|
|
1605
|
+
// from the message text.
|
|
1606
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
1607
|
+
if (providerId === "anthropic") {
|
|
1608
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
1609
|
+
}
|
|
1610
|
+
throw new Error("unexpected refresh");
|
|
1611
|
+
});
|
|
1612
|
+
rotationModule.__setLoginForProviderForTest(async (providerId) => {
|
|
1613
|
+
loginCalls.push(providerId);
|
|
1614
|
+
return { refresh: "refresh-fresh", access: "access-fresh", expires: Date.now() + 60_000 };
|
|
1615
|
+
});
|
|
1616
|
+
rotationModule.__setStreamForProviderForTest((_model, _context, options) => {
|
|
1617
|
+
streamedOptions.push(options);
|
|
1618
|
+
return (async function* () {
|
|
1619
|
+
yield { type: "text_delta", text: "hello after reauth" };
|
|
1620
|
+
})() as any;
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
try {
|
|
1624
|
+
await providerRotationExtension(pi);
|
|
1625
|
+
await events.session_start?.({}, ctx);
|
|
1626
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1627
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1628
|
+
ctx,
|
|
1629
|
+
);
|
|
1630
|
+
const emitted = [] as any[];
|
|
1631
|
+
for await (const event of stream) emitted.push(event);
|
|
1632
|
+
|
|
1633
|
+
assert.deepEqual(loginCalls, ["anthropic"]);
|
|
1634
|
+
assert.deepEqual(setModelCalls, []);
|
|
1635
|
+
assert.equal(streamedOptions[0].apiKey, "access-fresh");
|
|
1636
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
1637
|
+
const [stored] = helpers.readSubscriptionPool("anthropic");
|
|
1638
|
+
assert.equal(stored.label, "stale");
|
|
1639
|
+
assert.equal(stored.refresh, "refresh-fresh");
|
|
1640
|
+
assert.equal(stored.access, "access-fresh");
|
|
1641
|
+
assert.equal(stored.rateLimitedUntil, 0);
|
|
1642
|
+
} finally {
|
|
1643
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
1644
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
1645
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1646
|
+
}
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
// The real invalid-refresh path must route an explicit Codex reauth through the locked identity
|
|
1650
|
+
// gate. A colliding OAuth result is rejected, the old credential remains intact, and the slot is
|
|
1651
|
+
// cooled instead of being duplicated or streamed with another slot's quota.
|
|
1652
|
+
test("real explicit Codex reauth rejects an account held by another slot", async () => {
|
|
1653
|
+
await resetRotationState();
|
|
1654
|
+
writeLadderConfig();
|
|
1655
|
+
await helpers.writeSubscriptionPool("openai-codex", [
|
|
1656
|
+
credential("stale", { expires: 1, accountId: "acct-old" }),
|
|
1657
|
+
credential("held", { accountId: "acct-held", rateLimitedUntil: Date.now() + 10 * 60_000 }),
|
|
1658
|
+
]);
|
|
1659
|
+
|
|
1660
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
1661
|
+
ctx.hasUI = true;
|
|
1662
|
+
const notes: Array<{ message: string; type?: string }> = [];
|
|
1663
|
+
ctx.ui.notify = (message: string, type?: string) => notes.push({ message, type });
|
|
1664
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
1665
|
+
if (providerId === "openai-codex") {
|
|
1666
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
1667
|
+
}
|
|
1668
|
+
throw new Error("unexpected refresh");
|
|
1669
|
+
});
|
|
1670
|
+
rotationModule.__setLoginForProviderForTest(async () => ({
|
|
1671
|
+
refresh: "r-collision",
|
|
1672
|
+
access: "a-collision",
|
|
1673
|
+
expires: Date.now() + 60_000,
|
|
1674
|
+
accountId: "acct-held",
|
|
1675
|
+
}));
|
|
1676
|
+
try {
|
|
1677
|
+
await providerRotationExtension(pi);
|
|
1678
|
+
await events.session_start?.({}, ctx);
|
|
1679
|
+
const stream = providers["openai-codex"].streamSimple(ctx.model, ctx);
|
|
1680
|
+
for await (const _event of stream) {
|
|
1681
|
+
// Drain the real managed-provider stream to completion.
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
1685
|
+
const stale = pool.find((entry) => entry.label === "stale");
|
|
1686
|
+
assert.equal(stale?.accountId, "acct-old");
|
|
1687
|
+
assert.equal(stale?.refresh, "refresh-stale");
|
|
1688
|
+
assert.ok((stale?.rateLimitedUntil ?? 0) > Date.now() + 29 * 24 * 60 * 60 * 1000);
|
|
1689
|
+
assert.equal(pool.filter((entry) => entry.accountId === "acct-held").length, 1);
|
|
1690
|
+
assert.ok(notes.some((note) => note.type === "error" && /re-authentication failed.*already added/i.test(note.message)));
|
|
1691
|
+
} finally {
|
|
1692
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
1693
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
|
|
1697
|
+
// The default Codex reauth branch uses the same gate before it commits. A colliding login leaves
|
|
1698
|
+
// the default pool entry on the original account and keeps both pool identities unique.
|
|
1699
|
+
test("real default Codex reauth rejects an explicit slot's account before switching the default entry", async () => {
|
|
1700
|
+
await resetRotationState();
|
|
1701
|
+
writeLadderConfig();
|
|
1702
|
+
await helpers.writeSubscriptionPool("openai-codex", [
|
|
1703
|
+
credential("openai-codex", { refresh: "dead-refresh", access: "stale-access", expires: 1, accountId: "acct-old" }),
|
|
1704
|
+
]);
|
|
1705
|
+
await helpers.addSubscription("openai-codex", credential("held", { accountId: "acct-held", rateLimitedUntil: Date.now() + 10 * 60_000 }));
|
|
1706
|
+
|
|
1707
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
1708
|
+
ctx.hasUI = true;
|
|
1709
|
+
const notes: Array<{ message: string; type?: string }> = [];
|
|
1710
|
+
ctx.ui.notify = (message: string, type?: string) => notes.push({ message, type });
|
|
1711
|
+
rotationModule.__setRefreshForProviderForTest(async (providerId) => {
|
|
1712
|
+
if (providerId === "openai-codex") {
|
|
1713
|
+
throw new Error('HTTP request failed. status=400; body={"error":"invalid_grant","error_description":"Refresh token not found or invalid"}');
|
|
1714
|
+
}
|
|
1715
|
+
throw new Error("unexpected refresh");
|
|
1716
|
+
});
|
|
1717
|
+
rotationModule.__setLoginForProviderForTest(async () => ({
|
|
1718
|
+
refresh: "r-collision",
|
|
1719
|
+
access: "a-collision",
|
|
1720
|
+
expires: Date.now() + 60_000,
|
|
1721
|
+
accountId: "acct-held",
|
|
1722
|
+
}));
|
|
1723
|
+
try {
|
|
1724
|
+
await providerRotationExtension(pi);
|
|
1725
|
+
await events.session_start?.({}, ctx);
|
|
1726
|
+
const stream = providers["openai-codex"].streamSimple(ctx.model, ctx);
|
|
1727
|
+
for await (const _event of stream) {
|
|
1728
|
+
// Drain the real managed-provider stream to completion.
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
1732
|
+
const slot = pool.find((entry) => entry.label === "openai-codex");
|
|
1733
|
+
assert.equal(slot?.accountId, "acct-old");
|
|
1734
|
+
assert.equal(slot?.refresh, "dead-refresh");
|
|
1735
|
+
assert.equal(pool.filter((entry) => entry.accountId === "acct-held").length, 1);
|
|
1736
|
+
assert.ok(notes.some((note) => note.type === "error" && /re-authentication failed.*already added/i.test(note.message)));
|
|
1737
|
+
} finally {
|
|
1738
|
+
rotationModule.__setRefreshForProviderForTest(undefined);
|
|
1739
|
+
rotationModule.__setLoginForProviderForTest(undefined);
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
|
|
1743
|
+
// A resolved-but-unauthenticated fallback stays on the current model and returns an
|
|
1744
|
+
// actionable "not authenticated" error when no provider is logged in.
|
|
1745
|
+
test("emits an actionable 'not authenticated' error without switching models when neither provider has ever logged in", async () => {
|
|
1746
|
+
await resetRotationState();
|
|
1747
|
+
writeLadderConfig();
|
|
1748
|
+
|
|
1749
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1750
|
+
|
|
1751
|
+
await providerRotationExtension(pi);
|
|
1752
|
+
await events.session_start?.({}, ctx);
|
|
1753
|
+
const stream = providers["openai-codex"].streamSimple(ctx.model, ctx);
|
|
1754
|
+
const emitted = [] as any[];
|
|
1755
|
+
for await (const event of stream) emitted.push(event);
|
|
1756
|
+
|
|
1757
|
+
// Never switches to the unauthenticated fallback -- nothing to try it with.
|
|
1758
|
+
assert.deepEqual(setModelCalls, []);
|
|
1759
|
+
assert.equal(emitted.length, 1);
|
|
1760
|
+
assert.equal(emitted[0].type, "error");
|
|
1761
|
+
assert.match(emitted[0].error.errorMessage, /OpenAI Codex not authenticated.*crtr sys setup/);
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// The builtin ladder is available even with no ~/.crouter/config.json, so a config-less
|
|
1765
|
+
// user can still resolve cross-provider fallbacks.
|
|
1766
|
+
test("degrades gracefully via the builtin ladder when a config-less user has no cross-provider credentials", async () => {
|
|
1767
|
+
await resetRotationState();
|
|
1768
|
+
rmSync(join(home, ".crouter", "config.json"), { force: true });
|
|
1769
|
+
|
|
1770
|
+
const ctx = {
|
|
1771
|
+
model: { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1772
|
+
ui: { setStatus() {} },
|
|
1773
|
+
modelRegistry: {
|
|
1774
|
+
find(provider: string, id: string) {
|
|
1775
|
+
if (provider === "anthropic" && id === "claude-opus-4-8") return { provider, id, api: "anthropic-messages" };
|
|
1776
|
+
if (provider === "openai-codex" && id === "gpt-5.6-sol") return { provider, id, api: "openai-codex-responses" };
|
|
1777
|
+
return undefined;
|
|
1778
|
+
},
|
|
1779
|
+
},
|
|
1780
|
+
} as any;
|
|
1781
|
+
const setModelCalls: any[] = [];
|
|
1782
|
+
const providers: Record<string, { streamSimple: (...args: any[]) => AsyncIterable<any> }> = {};
|
|
1783
|
+
const events: Record<string, (...args: any[]) => unknown> = {};
|
|
1784
|
+
const pi = {
|
|
1785
|
+
registerProvider(name: string, provider: { streamSimple: (...args: any[]) => AsyncIterable<any> }) {
|
|
1786
|
+
providers[name] = provider;
|
|
1787
|
+
},
|
|
1788
|
+
registerCommand() {},
|
|
1789
|
+
on(eventName: string, handler: (...args: any[]) => unknown) {
|
|
1790
|
+
events[eventName] = handler;
|
|
1791
|
+
},
|
|
1792
|
+
async setModel(model: any) {
|
|
1793
|
+
setModelCalls.push(model);
|
|
1794
|
+
ctx.model = model;
|
|
1795
|
+
return true;
|
|
1796
|
+
},
|
|
1797
|
+
setThinkingLevel() {},
|
|
1798
|
+
} as any;
|
|
1799
|
+
|
|
1800
|
+
await providerRotationExtension(pi);
|
|
1801
|
+
await events.session_start?.({}, ctx);
|
|
1802
|
+
// Anthropic's pool is empty, so the credential loop never runs. The builtin ladder resolves
|
|
1803
|
+
// a cross-provider target (openai-codex/gpt-5.6-sol), but that provider is also
|
|
1804
|
+
// unauthenticated; the session model stays unchanged and the turn returns actionable advice.
|
|
1805
|
+
const stream = providers["anthropic"].streamSimple(ctx.model, ctx);
|
|
1806
|
+
const emitted = [] as any[];
|
|
1807
|
+
for await (const event of stream) emitted.push(event);
|
|
1808
|
+
|
|
1809
|
+
assert.deepEqual(setModelCalls, []);
|
|
1810
|
+
assert.equal(emitted.length, 1);
|
|
1811
|
+
assert.equal(emitted[0].type, "error");
|
|
1812
|
+
assert.match(emitted[0].error.errorMessage, /Claude not authenticated.*crtr sys setup/);
|
|
1813
|
+
assert.ok(!emitted[0].error.errorMessage.includes("configure a openai ladder"));
|
|
1814
|
+
});
|
|
1815
|
+
|
|
1816
|
+
// readModelLadders() reads the builtin anthropic/openai ladder when config.json is absent.
|
|
1817
|
+
test("resolves the builtin anthropic ladder (medium = sonnet-5) with no ~/.crouter/config.json present", async () => {
|
|
1818
|
+
await resetRotationState();
|
|
1819
|
+
rmSync(join(home, ".crouter", "config.json"), { force: true });
|
|
1820
|
+
|
|
1821
|
+
const target = helpers.resolveFallbackTarget("anthropic", "anthropic/claude-sonnet-5:xhigh");
|
|
1822
|
+
|
|
1823
|
+
assert.deepEqual(target, {
|
|
1824
|
+
providerId: "openai-codex",
|
|
1825
|
+
modelId: "gpt-5.6-terra",
|
|
1826
|
+
label: "openai-codex/gpt-5.6-terra:medium",
|
|
1827
|
+
strength: "medium",
|
|
1828
|
+
thinkingLevel: "medium",
|
|
1829
|
+
});
|
|
1830
|
+
});
|
|
1831
|
+
|
|
1832
|
+
// A cooling provider must settle the turn with a typed retry deadline. Holding
|
|
1833
|
+
// the stream open here rendered the node as generic `Working...` for five silent
|
|
1834
|
+
// minutes and prevented the broker's existing scheduled retry path from owning
|
|
1835
|
+
// recovery.
|
|
1836
|
+
test("settles a sole provider cooldown with a typed retry deadline instead of sleeping in-stream", async () => {
|
|
1837
|
+
await resetRotationState();
|
|
1838
|
+
writeLadderConfig();
|
|
1839
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1840
|
+
await helpers.markSubscriptionRateLimited("anthropic", "primary", 30_000);
|
|
1841
|
+
const expectedDeadline = helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil;
|
|
1842
|
+
|
|
1843
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1844
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1845
|
+
const sleepCalls: number[] = [];
|
|
1846
|
+
rotationModule.__setSleepForTest(async (ms) => { sleepCalls.push(ms); });
|
|
1847
|
+
let streamCalls = 0;
|
|
1848
|
+
rotationModule.__setStreamForProviderForTest((_model) => {
|
|
1849
|
+
streamCalls += 1;
|
|
1850
|
+
return (async function* () {
|
|
1851
|
+
yield { type: "text_delta", text: "must not stream while cooling" };
|
|
1852
|
+
})() as any;
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1855
|
+
try {
|
|
1856
|
+
await providerRotationExtension(pi);
|
|
1857
|
+
await events.session_start?.({}, ctx);
|
|
1858
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1859
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1860
|
+
ctx,
|
|
1861
|
+
);
|
|
1862
|
+
const emitted = [] as any[];
|
|
1863
|
+
for await (const event of stream) emitted.push(event);
|
|
1864
|
+
|
|
1865
|
+
assert.deepEqual(setModelCalls, []);
|
|
1866
|
+
assert.deepEqual(sleepCalls, []);
|
|
1867
|
+
assert.equal(streamCalls, 0);
|
|
1868
|
+
assert.equal(emitted.length, 1);
|
|
1869
|
+
assert.equal(emitted[0].type, "error");
|
|
1870
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
1871
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, expectedDeadline);
|
|
1872
|
+
} finally {
|
|
1873
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1874
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1875
|
+
}
|
|
1876
|
+
});
|
|
1877
|
+
|
|
1878
|
+
// A fallback that is itself cooling must contribute its earlier deadline without
|
|
1879
|
+
// churning the live session model to a provider that cannot serve the turn.
|
|
1880
|
+
test("does not switch to a cooling fallback and schedules the earliest provider deadline", async () => {
|
|
1881
|
+
await resetRotationState();
|
|
1882
|
+
writeLadderConfig();
|
|
1883
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1884
|
+
await helpers.markSubscriptionRateLimited("anthropic", "primary", 60_000);
|
|
1885
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
1886
|
+
await helpers.markSubscriptionRateLimited("openai-codex", "codex", 30_000);
|
|
1887
|
+
const expectedDeadline = helpers.readSubscriptionPool("openai-codex")[0].rateLimitedUntil;
|
|
1888
|
+
|
|
1889
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1890
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1891
|
+
const sleepCalls: number[] = [];
|
|
1892
|
+
let streamCalls = 0;
|
|
1893
|
+
rotationModule.__setSleepForTest(async (ms) => { sleepCalls.push(ms); });
|
|
1894
|
+
rotationModule.__setStreamForProviderForTest((_model) => {
|
|
1895
|
+
streamCalls += 1;
|
|
1896
|
+
return (async function* () {
|
|
1897
|
+
yield { type: "text_delta", text: "must not stream while cooling" };
|
|
1898
|
+
})() as any;
|
|
1899
|
+
});
|
|
1900
|
+
|
|
1901
|
+
try {
|
|
1902
|
+
await providerRotationExtension(pi);
|
|
1903
|
+
await events.session_start?.({}, ctx);
|
|
1904
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1905
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1906
|
+
ctx,
|
|
1907
|
+
);
|
|
1908
|
+
const emitted = [] as any[];
|
|
1909
|
+
for await (const event of stream) emitted.push(event);
|
|
1910
|
+
|
|
1911
|
+
assert.deepEqual(setModelCalls, [], "a cooling fallback does not churn the session model");
|
|
1912
|
+
assert.deepEqual(sleepCalls, []);
|
|
1913
|
+
assert.equal(streamCalls, 0);
|
|
1914
|
+
assert.equal(emitted.length, 1);
|
|
1915
|
+
assert.equal(emitted[0].type, "error");
|
|
1916
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, expectedDeadline);
|
|
1917
|
+
} finally {
|
|
1918
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
1919
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1920
|
+
}
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
// Even an unusually long provider deadline uses the same typed scheduled-retry
|
|
1924
|
+
// path; invalid-grant remains separately classified before this branch.
|
|
1925
|
+
test("emits a typed rate-limit cooling error for a long provider deadline", async () => {
|
|
1926
|
+
await resetRotationState();
|
|
1927
|
+
writeLadderConfig();
|
|
1928
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1929
|
+
await helpers.markSubscriptionRateLimited("anthropic", "primary", 30 * 24 * 60 * 60 * 1000);
|
|
1930
|
+
const expectedDeadline = helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil;
|
|
1931
|
+
|
|
1932
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
1933
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1934
|
+
const sleepCalls: number[] = [];
|
|
1935
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
1936
|
+
sleepCalls.push(ms);
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
try {
|
|
1940
|
+
await providerRotationExtension(pi);
|
|
1941
|
+
await events.session_start?.({}, ctx);
|
|
1942
|
+
const stream = providers["anthropic"].streamSimple(
|
|
1943
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
1944
|
+
ctx,
|
|
1945
|
+
);
|
|
1946
|
+
const emitted = [] as any[];
|
|
1947
|
+
for await (const event of stream) emitted.push(event);
|
|
1948
|
+
|
|
1949
|
+
assert.deepEqual(setModelCalls, []);
|
|
1950
|
+
assert.deepEqual(sleepCalls, [], "a cooldown past the cap must not sleep in-process");
|
|
1951
|
+
assert.equal(emitted.length, 1);
|
|
1952
|
+
assert.equal(emitted[0].type, "error");
|
|
1953
|
+
// Rate-limit-classifiable so classify('pi→provider', msg) → rate-limit/auto (not fatal other).
|
|
1954
|
+
assert.match(emitted[0].error.errorMessage, /rate limit/i);
|
|
1955
|
+
// Still carries the actionable fallback hint.
|
|
1956
|
+
assert.match(emitted[0].error.errorMessage, /authenticate a fallback provider/);
|
|
1957
|
+
// And the typed cooling diagnostic carrying the exact pool deadline for the stophook.
|
|
1958
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
1959
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, expectedDeadline);
|
|
1960
|
+
} finally {
|
|
1961
|
+
rotationModule.__setSleepForTest(undefined);
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
test("an excluded invalid_grant credential does not mask a cooling credential", async () => {
|
|
1966
|
+
await resetRotationState();
|
|
1967
|
+
writeLadderConfig();
|
|
1968
|
+
await helpers.writeSubscriptionPool("anthropic", [
|
|
1969
|
+
credential("dead", { authFailure: "invalid_grant", rateLimitedUntil: Date.now() + 30 * 24 * 60 * 60 * 1000 }),
|
|
1970
|
+
credential("cooling", { rateLimitedUntil: Date.now() + 60_000 }),
|
|
1971
|
+
]);
|
|
1972
|
+
const expectedDeadline = helpers.readSubscriptionPool("anthropic").find((entry) => entry.label === "cooling")!.rateLimitedUntil;
|
|
1973
|
+
|
|
1974
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
1975
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
1976
|
+
|
|
1977
|
+
await providerRotationExtension(pi);
|
|
1978
|
+
await events.session_start?.({}, ctx);
|
|
1979
|
+
const stream = providers["anthropic"].streamSimple(ctx.model, ctx);
|
|
1980
|
+
const emitted = [] as any[];
|
|
1981
|
+
for await (const event of stream) emitted.push(event);
|
|
1982
|
+
|
|
1983
|
+
assert.equal(emitted.length, 1);
|
|
1984
|
+
assert.equal(emitted[0].type, "error");
|
|
1985
|
+
assert.match(emitted[0].error.errorMessage, /rate limited/i);
|
|
1986
|
+
assert.doesNotMatch(emitted[0].error.errorMessage, /invalid_grant/);
|
|
1987
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
1988
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, expectedDeadline);
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1991
|
+
// Fix 1 (switchToFallbackIfPossible): pi's `setModel` returns false when the target lacks
|
|
1992
|
+
// configured auth and leaves the model unchanged. A concurrent transition can still land on
|
|
1993
|
+
// the target while that call is in flight; accept only that observed live result and reject
|
|
1994
|
+
// every other false return.
|
|
1995
|
+
test("a same-turn 429 settles immediately instead of starting cooldown continuations", async () => {
|
|
1996
|
+
await resetRotationState();
|
|
1997
|
+
writeLadderConfig();
|
|
1998
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
1999
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
2000
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2001
|
+
let attempts = 0;
|
|
2002
|
+
let waits = 0;
|
|
2003
|
+
rotationModule.__setSleepForTest(async () => { waits++; });
|
|
2004
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
2005
|
+
attempts++;
|
|
2006
|
+
return (async function* () {
|
|
2007
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "1" } }, model);
|
|
2008
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
2009
|
+
})() as any;
|
|
2010
|
+
});
|
|
2011
|
+
|
|
2012
|
+
try {
|
|
2013
|
+
await providerRotationExtension(pi);
|
|
2014
|
+
await events.session_start?.({}, ctx);
|
|
2015
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2016
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2017
|
+
ctx,
|
|
2018
|
+
);
|
|
2019
|
+
const emitted = [] as any[];
|
|
2020
|
+
for await (const event of stream) emitted.push(event);
|
|
2021
|
+
|
|
2022
|
+
assert.equal(attempts, 1, "the mocked clock keeps the credential cooling after its first 429");
|
|
2023
|
+
assert.equal(waits, 0, "cooldown recovery never sleeps inside the active turn");
|
|
2024
|
+
assert.equal(emitted.length, 1);
|
|
2025
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
2026
|
+
} finally {
|
|
2027
|
+
rotationModule.__setSleepForTest(undefined);
|
|
2028
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
|
|
2032
|
+
test("does not requeue a zero Retry-After credential without a later success", async () => {
|
|
2033
|
+
await resetRotationState();
|
|
2034
|
+
writeLadderConfig();
|
|
2035
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
2036
|
+
const { ctx, providers, events, pi } = makeRotationCtx();
|
|
2037
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2038
|
+
let attempts = 0;
|
|
2039
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
2040
|
+
attempts++;
|
|
2041
|
+
return (async function* () {
|
|
2042
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "0" } }, model);
|
|
2043
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
2044
|
+
})() as any;
|
|
2045
|
+
});
|
|
2046
|
+
|
|
2047
|
+
try {
|
|
2048
|
+
await providerRotationExtension(pi);
|
|
2049
|
+
await events.session_start?.({}, ctx);
|
|
2050
|
+
const stream = providers["anthropic"].streamSimple(ctx.model, ctx);
|
|
2051
|
+
const emitted = [] as any[];
|
|
2052
|
+
for await (const event of stream) emitted.push(event);
|
|
2053
|
+
|
|
2054
|
+
assert.equal(attempts, 1, "a zero deadline must not manufacture a fresh candidate");
|
|
2055
|
+
assert.equal(emitted.length, 1);
|
|
2056
|
+
assert.equal(emitted[0].type, "error");
|
|
2057
|
+
} finally {
|
|
2058
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
test("switchToFallbackIfPossible accepts a false setModel only when the live model already equals the target", async () => {
|
|
2063
|
+
await resetRotationState();
|
|
2064
|
+
writeLadderConfig();
|
|
2065
|
+
|
|
2066
|
+
const target = helpers.resolveFallbackTarget("anthropic", "anthropic/claude-opus-4-8:high");
|
|
2067
|
+
assert.ok(target && target.providerId === "openai-codex" && target.modelId === "gpt-5.6-sol", "anthropic opus falls back to codex sol");
|
|
2068
|
+
|
|
2069
|
+
// Benign: setModel returns false without changing the model, while an independent
|
|
2070
|
+
// concurrent transition lands on the exact target before the required live re-read.
|
|
2071
|
+
{
|
|
2072
|
+
let modelReads = 0;
|
|
2073
|
+
const ctx = {
|
|
2074
|
+
get model() {
|
|
2075
|
+
modelReads++;
|
|
2076
|
+
return modelReads === 1
|
|
2077
|
+
? { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" }
|
|
2078
|
+
: { provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" };
|
|
2079
|
+
},
|
|
2080
|
+
modelRegistry: { find: (provider: string, id: string) => ({ provider, id, api: "x" }) },
|
|
2081
|
+
} as any;
|
|
2082
|
+
const pi = {
|
|
2083
|
+
async setModel(_m: any) { return false; },
|
|
2084
|
+
setThinkingLevel() {},
|
|
2085
|
+
getThinkingLevel() { return undefined; },
|
|
2086
|
+
} as any;
|
|
2087
|
+
const result = await helpers.switchToFallbackIfPossible(pi, ctx);
|
|
2088
|
+
assert.ok(result, "a false setModel with the target already current must be accepted");
|
|
2089
|
+
assert.equal(result!.providerId, "openai-codex");
|
|
2090
|
+
assert.equal(result!.modelId, "gpt-5.6-sol");
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
// Real failure: setModel returns false and the live model stays DIFFERENT from the target
|
|
2094
|
+
// → the switch is a genuine failure and must be rejected (undefined).
|
|
2095
|
+
{
|
|
2096
|
+
const ctx = {
|
|
2097
|
+
model: { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2098
|
+
modelRegistry: { find: (provider: string, id: string) => ({ provider, id, api: "x" }) },
|
|
2099
|
+
} as any;
|
|
2100
|
+
const pi = {
|
|
2101
|
+
async setModel(_m: any) { return false; }, // leaves ctx.model on anthropic
|
|
2102
|
+
setThinkingLevel() {},
|
|
2103
|
+
getThinkingLevel() { return undefined; },
|
|
2104
|
+
} as any;
|
|
2105
|
+
const result = await helpers.switchToFallbackIfPossible(pi, ctx);
|
|
2106
|
+
assert.equal(result, undefined, "a false setModel that did not land on the target is a real failure");
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
|
|
2110
|
+
// Fresh-availability re-entry (Fix 3a): a credential that becomes ready AFTER the initial
|
|
2111
|
+
// `available` snapshot (a concurrent turn's cooldown expiring, or a causally valid success)
|
|
2112
|
+
// must be consumed by re-entering the SAME provider, not lost to a stale snapshot that would
|
|
2113
|
+
// wrongly declare exhaustion. Start on an unauthenticated Anthropic (empty pool) so the
|
|
2114
|
+
// fallback to Codex is already attempted; Codex has A ready + B cooling; A's 429 frees B
|
|
2115
|
+
// mid-attempt, so the re-entry must attempt B and stream the turn with no terminal error.
|
|
2116
|
+
test("re-enters the same provider to consume a credential that became ready after the initial snapshot", async () => {
|
|
2117
|
+
await resetRotationState();
|
|
2118
|
+
writeLadderConfig();
|
|
2119
|
+
// Anthropic unauthenticated (empty) so the turn falls back to Codex immediately.
|
|
2120
|
+
await helpers.writeSubscriptionPool("anthropic", []);
|
|
2121
|
+
// Codex: A ready now, B cooling (absent from the initial ready snapshot).
|
|
2122
|
+
await helpers.writeSubscriptionPool("openai-codex", [
|
|
2123
|
+
credential("A"),
|
|
2124
|
+
credential("B", { rateLimitedUntil: Date.now() + 60_000 }),
|
|
2125
|
+
]);
|
|
2126
|
+
|
|
2127
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2128
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2129
|
+
const streamedModels: any[] = [];
|
|
2130
|
+
let codexAttempt = 0;
|
|
2131
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
2132
|
+
streamedModels.push(model.provider);
|
|
2133
|
+
return (async function* () {
|
|
2134
|
+
if (model.provider === "openai-codex") {
|
|
2135
|
+
codexAttempt += 1;
|
|
2136
|
+
if (codexAttempt === 1) {
|
|
2137
|
+
// Attempt A: 429 (cools A). Free B mid-attempt so it becomes ready AFTER the
|
|
2138
|
+
// snapshot that only saw A — the fresh-availability condition under test.
|
|
2139
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "5" } }, model);
|
|
2140
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
2141
|
+
await helpers.writeSubscriptionPool(
|
|
2142
|
+
"openai-codex",
|
|
2143
|
+
pool.map((entry) => (entry.label === "B" ? { ...entry, rateLimitedUntil: 0 } : entry)),
|
|
2144
|
+
);
|
|
2145
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
// Re-entry attempt: B is now ready — serve the turn.
|
|
2149
|
+
yield { type: "text_delta", text: "hello from codex B after re-entry" };
|
|
2150
|
+
return;
|
|
2151
|
+
}
|
|
2152
|
+
yield { type: "text_delta", text: "unexpected" };
|
|
2153
|
+
})() as any;
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
try {
|
|
2157
|
+
await providerRotationExtension(pi);
|
|
2158
|
+
await events.session_start?.({}, ctx);
|
|
2159
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2160
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2161
|
+
ctx,
|
|
2162
|
+
);
|
|
2163
|
+
const emitted = [] as any[];
|
|
2164
|
+
for await (const event of stream) emitted.push(event);
|
|
2165
|
+
|
|
2166
|
+
// Fell back to codex, attempted A (429), then re-entered and attempted B to success.
|
|
2167
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["openai-codex"]);
|
|
2168
|
+
assert.equal(codexAttempt, 2, "re-entered the same provider once to consume the freshly-ready credential");
|
|
2169
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"), "the turn was served, not terminally failed");
|
|
2170
|
+
assert.ok(!emitted.some((e) => e.type === "error"), "no terminal all-pools error despite the stale initial snapshot");
|
|
2171
|
+
} finally {
|
|
2172
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
|
|
2176
|
+
// Both-pools-cooling typed diagnostic (Fix 3b): when EVERY managed pool tried this turn is
|
|
2177
|
+
// cooling with a finite future deadline, the terminal error must be rate-limit-classifiable
|
|
2178
|
+
// AND carry the typed cooling diagnostic whose deadline is the exact MINIMUM across the tried
|
|
2179
|
+
// pools (so the stophook stamps retry.nextAt at the soonest pool free-up).
|
|
2180
|
+
test("both pools cooling: emits a rate-limit-classifiable terminal carrying the exact earliest deadline as a typed diagnostic", async () => {
|
|
2181
|
+
await resetRotationState();
|
|
2182
|
+
writeLadderConfig();
|
|
2183
|
+
const now = Date.now();
|
|
2184
|
+
const anthropicDeadline = now + 10 * 60_000; // earliest
|
|
2185
|
+
const codexDeadline = now + 20 * 60_000;
|
|
2186
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("a", { rateLimitedUntil: anthropicDeadline })]);
|
|
2187
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("c", { rateLimitedUntil: codexDeadline })]);
|
|
2188
|
+
const expectedMin = helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil;
|
|
2189
|
+
|
|
2190
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2191
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2192
|
+
const sleepCalls: number[] = [];
|
|
2193
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
2194
|
+
sleepCalls.push(ms);
|
|
2195
|
+
});
|
|
2196
|
+
|
|
2197
|
+
try {
|
|
2198
|
+
await providerRotationExtension(pi);
|
|
2199
|
+
await events.session_start?.({}, ctx);
|
|
2200
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2201
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2202
|
+
ctx,
|
|
2203
|
+
);
|
|
2204
|
+
const emitted = [] as any[];
|
|
2205
|
+
for await (const event of stream) emitted.push(event);
|
|
2206
|
+
|
|
2207
|
+
// A cooling fallback contributes its deadline without churning the live model.
|
|
2208
|
+
assert.deepEqual(setModelCalls, []);
|
|
2209
|
+
assert.deepEqual(sleepCalls, [], "cooldowns are never waited out in-process");
|
|
2210
|
+
assert.equal(emitted.length, 1);
|
|
2211
|
+
assert.equal(emitted[0].type, "error");
|
|
2212
|
+
assert.match(emitted[0].error.errorMessage, /rate limit/i, "classifiable as rate-limit (auto), not fatal other");
|
|
2213
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
2214
|
+
assert.equal(
|
|
2215
|
+
emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil,
|
|
2216
|
+
expectedMin,
|
|
2217
|
+
"the diagnostic carries the exact MINIMUM deadline across both tried pools",
|
|
2218
|
+
);
|
|
2219
|
+
} finally {
|
|
2220
|
+
rotationModule.__setSleepForTest(undefined);
|
|
2221
|
+
}
|
|
2222
|
+
});
|
|
2223
|
+
|
|
2224
|
+
// Live-incident regression (Hearth: a home's config.json had `gpt-5.6-*` ladder rungs baked
|
|
2225
|
+
// in while the installed guest's model registry only had `gpt-5.5`): when the ONLY viable
|
|
2226
|
+
// fallback target is authenticated (its pool has a credential) but its resolved model isn't
|
|
2227
|
+
// in this build's registry, the terminal error must name that specific reason -- not the old
|
|
2228
|
+
// generic "authenticate a fallback provider" text, which is actively wrong when the real
|
|
2229
|
+
// blocker is a stale/out-of-sync ladder, not a missing login.
|
|
2230
|
+
test("surfaces a specific 'not in model registry' reason instead of misleadingly telling the user to authenticate", async () => {
|
|
2231
|
+
await resetRotationState();
|
|
2232
|
+
writeLadderConfig();
|
|
2233
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
2234
|
+
await helpers.markSubscriptionRateLimited("anthropic", "primary", 30 * 24 * 60 * 60 * 1000);
|
|
2235
|
+
// OpenAI Codex IS authenticated -- the fallback rejection must NOT be "no credentials".
|
|
2236
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
2237
|
+
|
|
2238
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2239
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2240
|
+
// Registry recognizes anthropic's own model but NOT the configured openai-codex fallback
|
|
2241
|
+
// rung (`gpt-5.6-sol`, from writeLadderConfig) -- simulating an installed guest whose
|
|
2242
|
+
// catalog hasn't caught up with the configured ladder.
|
|
2243
|
+
ctx.modelRegistry = {
|
|
2244
|
+
find(provider: string, id: string) {
|
|
2245
|
+
return provider === "anthropic" && id === "claude-opus-4-8" ? { provider, id, api: "anthropic-messages" } : undefined;
|
|
2246
|
+
},
|
|
2247
|
+
};
|
|
2248
|
+
const sleepCalls: number[] = [];
|
|
2249
|
+
rotationModule.__setSleepForTest(async (ms) => {
|
|
2250
|
+
sleepCalls.push(ms);
|
|
2251
|
+
});
|
|
2252
|
+
|
|
2253
|
+
try {
|
|
2254
|
+
await providerRotationExtension(pi);
|
|
2255
|
+
await events.session_start?.({}, ctx);
|
|
2256
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2257
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2258
|
+
ctx,
|
|
2259
|
+
);
|
|
2260
|
+
const emitted = [] as any[];
|
|
2261
|
+
for await (const event of stream) emitted.push(event);
|
|
2262
|
+
|
|
2263
|
+
assert.deepEqual(setModelCalls, []);
|
|
2264
|
+
assert.deepEqual(sleepCalls, []);
|
|
2265
|
+
assert.equal(emitted.length, 1);
|
|
2266
|
+
assert.equal(emitted[0].type, "error");
|
|
2267
|
+
assert.match(emitted[0].error.errorMessage, /openai-codex\/gpt-5\.6-sol:high is not in this build's model registry/);
|
|
2268
|
+
assert.match(emitted[0].error.errorMessage, /modelLadders config is out of sync with the installed model catalog/);
|
|
2269
|
+
assert.doesNotMatch(emitted[0].error.errorMessage, /authenticate a fallback provider/);
|
|
2270
|
+
// The repair command must be EXECUTABLE as printed: `--value`, the CONFIG ladder
|
|
2271
|
+
// provider key (`openai`, not the runtime `openai-codex`), and the target's strength.
|
|
2272
|
+
assert.match(
|
|
2273
|
+
emitted[0].error.errorMessage,
|
|
2274
|
+
/crtr sys config set modelLadders\.openai\.strong --value <installed-model-id>/,
|
|
2275
|
+
);
|
|
2276
|
+
} finally {
|
|
2277
|
+
rotationModule.__setSleepForTest(undefined);
|
|
2278
|
+
}
|
|
2279
|
+
});
|
|
2280
|
+
|
|
2281
|
+
// Every fallback-rejection discriminant maps to actionable advice. Only `no_credentials`
|
|
2282
|
+
// advises authentication because the other rejection states require a different remedy.
|
|
2283
|
+
test("fallback rejection hints: only no_credentials advises authentication; every other discriminant gets accurate advice", async () => {
|
|
2284
|
+
const codex = {
|
|
2285
|
+
providerId: "openai-codex",
|
|
2286
|
+
modelId: "gpt-5.6-sol",
|
|
2287
|
+
label: "openai-codex/gpt-5.6-sol:high",
|
|
2288
|
+
strength: "strong",
|
|
2289
|
+
} as FallbackTarget;
|
|
2290
|
+
|
|
2291
|
+
const noCreds = rotationModule.__fallbackRejectionHintForTest("no_credentials", codex);
|
|
2292
|
+
assert.match(noCreds, /authenticate a fallback provider/);
|
|
2293
|
+
assert.match(noCreds, /OpenAI Codex/);
|
|
2294
|
+
assert.match(noCreds, /\/provider-sub openai-codex add/);
|
|
2295
|
+
|
|
2296
|
+
const unregistered = rotationModule.__fallbackRejectionHintForTest("model_unregistered", codex);
|
|
2297
|
+
assert.doesNotMatch(unregistered, /authenticate a fallback provider/);
|
|
2298
|
+
assert.match(unregistered, /not in this build's model registry/);
|
|
2299
|
+
// Executable repair command: --value, CONFIG ladder key (openai), target strength.
|
|
2300
|
+
assert.match(unregistered, /crtr sys config set modelLadders\.openai\.strong --value <installed-model-id>/);
|
|
2301
|
+
|
|
2302
|
+
const alreadyTried = rotationModule.__fallbackRejectionHintForTest("already_attempted", codex);
|
|
2303
|
+
assert.doesNotMatch(alreadyTried, /authenticate a fallback provider/);
|
|
2304
|
+
assert.match(alreadyTried, /already tried this turn/);
|
|
2305
|
+
assert.match(alreadyTried, /try again later/);
|
|
2306
|
+
|
|
2307
|
+
const cooling = rotationModule.__fallbackRejectionHintForTest("cooling", codex);
|
|
2308
|
+
assert.doesNotMatch(cooling, /authenticate a fallback provider/);
|
|
2309
|
+
assert.match(cooling, /also cooling down/);
|
|
2310
|
+
|
|
2311
|
+
const pinned = rotationModule.__fallbackRejectionHintForTest("provider_pinned");
|
|
2312
|
+
assert.doesNotMatch(pinned, /authenticate a fallback provider/);
|
|
2313
|
+
assert.match(pinned, /explicitly pinned/);
|
|
2314
|
+
|
|
2315
|
+
const noLadder = rotationModule.__fallbackRejectionHintForTest("no_ladder_entry");
|
|
2316
|
+
assert.doesNotMatch(noLadder, /authenticate a fallback provider/);
|
|
2317
|
+
assert.match(noLadder, /no cross-provider fallback is configured/);
|
|
2318
|
+
assert.match(noLadder, /modelLadders/);
|
|
2319
|
+
});
|
|
2320
|
+
|
|
2321
|
+
// A 429 observed during this provider call must author the deadline from the
|
|
2322
|
+
// freshly-mutated pool, without retrying or sleeping inside the active turn.
|
|
2323
|
+
test("schedules a sole credential cooldown observed in this turn from fresh pool state", async () => {
|
|
2324
|
+
await resetRotationState();
|
|
2325
|
+
writeLadderConfig();
|
|
2326
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
2327
|
+
// openai-codex pool stays empty -- no authenticated fallback to switch to.
|
|
2328
|
+
|
|
2329
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2330
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2331
|
+
const sleepCalls: number[] = [];
|
|
2332
|
+
let anthropicCalls = 0;
|
|
2333
|
+
rotationModule.__setSleepForTest(async (ms) => { sleepCalls.push(ms); });
|
|
2334
|
+
rotationModule.__setStreamForProviderForTest((model, _context, options) => {
|
|
2335
|
+
return (async function* () {
|
|
2336
|
+
anthropicCalls += 1;
|
|
2337
|
+
if (anthropicCalls === 1) {
|
|
2338
|
+
await options?.onResponse?.({ status: 429, headers: { "retry-after": "1" } }, model);
|
|
2339
|
+
yield { type: "error", error: Object.assign(new Error("Too Many Requests"), { status: 429 }) };
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
yield { type: "text_delta", text: "must not retry inside this turn" };
|
|
2343
|
+
})() as any;
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
try {
|
|
2347
|
+
await providerRotationExtension(pi);
|
|
2348
|
+
await events.session_start?.({}, ctx);
|
|
2349
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2350
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2351
|
+
ctx,
|
|
2352
|
+
);
|
|
2353
|
+
const emitted = [] as any[];
|
|
2354
|
+
for await (const event of stream) emitted.push(event);
|
|
2355
|
+
|
|
2356
|
+
assert.deepEqual(setModelCalls, []);
|
|
2357
|
+
assert.deepEqual(sleepCalls, []);
|
|
2358
|
+
assert.equal(anthropicCalls, 1);
|
|
2359
|
+
assert.equal(emitted.length, 1);
|
|
2360
|
+
assert.equal(emitted[0].type, "error");
|
|
2361
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil, helpers.readSubscriptionPool("anthropic")[0].rateLimitedUntil);
|
|
2362
|
+
} finally {
|
|
2363
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2364
|
+
rotationModule.__setSleepForTest(undefined);
|
|
2365
|
+
}
|
|
2366
|
+
});
|
|
2367
|
+
|
|
2368
|
+
// pi-ai's Codex adapter can surface a genuine usage-limit exhaustion on a non-429
|
|
2369
|
+
// status. Without Retry-After it is local to this turn (never a global gate),
|
|
2370
|
+
// while the authenticated fallback still serves the same turn.
|
|
2371
|
+
test("treats a headerless Codex usage-limit message as turn-local and falls back", async () => {
|
|
2372
|
+
await resetRotationState();
|
|
2373
|
+
writeLadderConfig();
|
|
2374
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
2375
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
2376
|
+
|
|
2377
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2378
|
+
ctx.model = { provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" };
|
|
2379
|
+
const streamedModels: any[] = [];
|
|
2380
|
+
rotationModule.__setStreamForProviderForTest((model) => {
|
|
2381
|
+
streamedModels.push(model);
|
|
2382
|
+
return (async function* () {
|
|
2383
|
+
if (model.provider === "openai-codex") {
|
|
2384
|
+
yield {
|
|
2385
|
+
type: "error",
|
|
2386
|
+
error: Object.assign(new Error("You have hit your ChatGPT usage limit. Please try again later."), {
|
|
2387
|
+
status: 403,
|
|
2388
|
+
errorMessage: "You have hit your ChatGPT usage limit. usage_limit_reached",
|
|
2389
|
+
}),
|
|
2390
|
+
};
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
yield { type: "text_delta", text: "hello from anthropic fallback" };
|
|
2394
|
+
})() as any;
|
|
2395
|
+
});
|
|
2396
|
+
|
|
2397
|
+
try {
|
|
2398
|
+
await providerRotationExtension(pi);
|
|
2399
|
+
await events.session_start?.({}, ctx);
|
|
2400
|
+
const stream = providers["openai-codex"].streamSimple(
|
|
2401
|
+
{ provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" },
|
|
2402
|
+
ctx,
|
|
2403
|
+
);
|
|
2404
|
+
const emitted = [] as any[];
|
|
2405
|
+
for await (const event of stream) emitted.push(event);
|
|
2406
|
+
|
|
2407
|
+
// A headerless usage-limit signal is turn-local: it proves this request
|
|
2408
|
+
// failed, not that unrelated brokers sharing the credential are cooling.
|
|
2409
|
+
assert.equal(helpers.readSubscriptionPool("openai-codex")[0].rateLimitedUntil, 0);
|
|
2410
|
+
// Fell back to the authenticated Anthropic subscription and served the turn on it.
|
|
2411
|
+
assert.deepEqual(setModelCalls.map((m) => m.provider), ["anthropic"]);
|
|
2412
|
+
assert.equal(streamedModels.filter((m) => m.provider === "anthropic").length, 1);
|
|
2413
|
+
assert.ok(emitted.some((e) => e.type === "text_delta"));
|
|
2414
|
+
assert.ok(!emitted.some((e) => e.type === "error"));
|
|
2415
|
+
} finally {
|
|
2416
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
|
|
2420
|
+
test("a pinned provider's headerless usage-limit stays turn-local and carries its retry deadline", async () => {
|
|
2421
|
+
await resetRotationState();
|
|
2422
|
+
writeLadderConfig();
|
|
2423
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("codex")]);
|
|
2424
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("personal")]);
|
|
2425
|
+
|
|
2426
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2427
|
+
ctx.model = { provider: "openai-codex", id: "gpt-5.6-sol", api: "openai-codex-responses" };
|
|
2428
|
+
ctx.ui[Symbol.for("@crouton-kit/crtr:managed-provider-rotation-policy")] = () => ({
|
|
2429
|
+
allowCrossProviderFallback: false,
|
|
2430
|
+
reason: "provider-pinned",
|
|
2431
|
+
});
|
|
2432
|
+
rotationModule.__setStreamForProviderForTest(() => {
|
|
2433
|
+
return (async function* () {
|
|
2434
|
+
yield {
|
|
2435
|
+
type: "error",
|
|
2436
|
+
error: Object.assign(new Error("You have hit your ChatGPT usage limit."), {
|
|
2437
|
+
status: 403,
|
|
2438
|
+
errorMessage: "usage_limit_reached",
|
|
2439
|
+
}),
|
|
2440
|
+
};
|
|
2441
|
+
})() as any;
|
|
2442
|
+
});
|
|
2443
|
+
|
|
2444
|
+
try {
|
|
2445
|
+
await providerRotationExtension(pi);
|
|
2446
|
+
await events.session_start?.({}, ctx);
|
|
2447
|
+
const before = Date.now();
|
|
2448
|
+
const emitted = [] as any[];
|
|
2449
|
+
for await (const event of providers["openai-codex"].streamSimple(ctx.model, ctx)) emitted.push(event);
|
|
2450
|
+
|
|
2451
|
+
assert.deepEqual(setModelCalls, []);
|
|
2452
|
+
assert.equal(helpers.readSubscriptionPool("openai-codex")[0].rateLimitedUntil, 0);
|
|
2453
|
+
assert.equal(emitted.length, 1);
|
|
2454
|
+
assert.equal(emitted[0].error.diagnostics?.[0]?.type, "crtr:managed-provider-cooling");
|
|
2455
|
+
const deadline = emitted[0].error.diagnostics?.[0]?.details?.rateLimitedUntil;
|
|
2456
|
+
assert.ok(deadline >= before + 14_000 && deadline <= Date.now() + 15_000);
|
|
2457
|
+
} finally {
|
|
2458
|
+
rotationModule.__setStreamForProviderForTest(undefined);
|
|
2459
|
+
}
|
|
2460
|
+
});
|
|
2461
|
+
|
|
2462
|
+
// --- Provider-management removal routing and login coordination ---
|
|
2463
|
+
|
|
2464
|
+
function readAuthRecord(providerId: string): unknown {
|
|
2465
|
+
const authPath = join(home, ".pi", "agent", "auth.json");
|
|
2466
|
+
if (!existsSync(authPath)) return undefined;
|
|
2467
|
+
return (JSON.parse(readFileSync(authPath, "utf8")) as Record<string, unknown>)[providerId];
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
// Removing a managed provider from its HEADER row (no label -- the default cursor position) tears
|
|
2471
|
+
// down the WHOLE pool, not just the account: a surviving explicit account would stay
|
|
2472
|
+
// configured and keep serving turns while the panel said "Removed".
|
|
2473
|
+
test("removeProviderRow on a managed HEADER row clears the whole pool", async () => {
|
|
2474
|
+
await resetRotationState();
|
|
2475
|
+
await helpers.upsertSubscription("anthropic", credential("anthropic"));
|
|
2476
|
+
await helpers.upsertSubscription("anthropic", credential("work"));
|
|
2477
|
+
assert.ok(helpers.readSubscriptionPool("anthropic").some((e) => e.label === "anthropic"), "pool account present");
|
|
2478
|
+
assert.ok(helpers.readSubscriptionPool("anthropic").some((e) => e.label === "work"), "explicit account present");
|
|
2479
|
+
|
|
2480
|
+
const notice = await providerManagement.removeProviderRow(join(home, ".pi", "agent"), {
|
|
2481
|
+
providerId: "anthropic",
|
|
2482
|
+
name: "Claude",
|
|
2483
|
+
managed: true,
|
|
2484
|
+
configured: true,
|
|
2485
|
+
// no label -> the provider header row
|
|
2486
|
+
});
|
|
2487
|
+
|
|
2488
|
+
assert.equal(notice, "Removed Claude");
|
|
2489
|
+
assert.deepEqual(helpers.readSubscriptionPool("anthropic"), [], "pool fully torn down");
|
|
2490
|
+
});
|
|
2491
|
+
|
|
2492
|
+
// An account ROW (has a label) removes just that account and leaves the rest of the pool intact.
|
|
2493
|
+
test("removeProviderRow on a managed account row removes only that account", async () => {
|
|
2494
|
+
await resetRotationState();
|
|
2495
|
+
await helpers.upsertSubscription("anthropic", credential("anthropic"));
|
|
2496
|
+
await helpers.upsertSubscription("anthropic", credential("work"));
|
|
2497
|
+
|
|
2498
|
+
const notice = await providerManagement.removeProviderRow(join(home, ".pi", "agent"), {
|
|
2499
|
+
providerId: "anthropic",
|
|
2500
|
+
name: "Claude",
|
|
2501
|
+
managed: true,
|
|
2502
|
+
label: "work",
|
|
2503
|
+
});
|
|
2504
|
+
|
|
2505
|
+
assert.equal(notice, "Removed Claude account");
|
|
2506
|
+
const remaining = helpers.readSubscriptionPool("anthropic");
|
|
2507
|
+
assert.deepEqual(
|
|
2508
|
+
remaining.map((e) => e.label),
|
|
2509
|
+
["anthropic"],
|
|
2510
|
+
"only the pool account remains",
|
|
2511
|
+
);
|
|
2512
|
+
assert.equal(remaining[0].refresh, "refresh-anthropic", "the pool account keeps its own token");
|
|
2513
|
+
});
|
|
2514
|
+
|
|
2515
|
+
// Managed login commits the pool account through commitManagedLogin; the default pool entry
|
|
2516
|
+
// carries its tokens and auth.json has no managed OAuth record.
|
|
2517
|
+
test("commitManagedLogin pool account writes tokens into the default pool entry, not auth.json", async () => {
|
|
2518
|
+
await resetRotationState();
|
|
2519
|
+
await helpers.commitManagedLogin("anthropic", "anthropic", { refresh: "r1", access: "a1", expires: Date.now() + 60_000, accountId: "acct-1", lastRateLimitedAt: 0 });
|
|
2520
|
+
|
|
2521
|
+
const slot = helpers.readSubscriptionPool("anthropic").find((e) => e.label === "anthropic");
|
|
2522
|
+
assert.ok(slot, "pool account present");
|
|
2523
|
+
assert.equal(slot?.accountId, "acct-1", "pool pool account carries the identity");
|
|
2524
|
+
assert.equal(slot?.refresh, "r1", "pool pool account carries its own token");
|
|
2525
|
+
assert.equal(readAuthRecord("anthropic"), undefined, "no auth.json record written for a managed login");
|
|
2526
|
+
});
|
|
2527
|
+
|
|
2528
|
+
// A managed login that identifies an existing account refreshes that row rather than creating a
|
|
2529
|
+
// second quota slot under the requested label.
|
|
2530
|
+
test("commitManagedLogin updates an existing account identity", async () => {
|
|
2531
|
+
await resetRotationState();
|
|
2532
|
+
await helpers.commitManagedLogin("openai-codex", "first", { refresh: "r", access: "a", expires: Date.now() + 60_000, accountId: "dup", lastRateLimitedAt: 0 });
|
|
2533
|
+
await helpers.commitManagedLogin("openai-codex", "second", { refresh: "r2", access: "a2", expires: Date.now() + 60_000, accountId: "dup", lastRateLimitedAt: 0 });
|
|
2534
|
+
const pool = helpers.readSubscriptionPool("openai-codex");
|
|
2535
|
+
assert.equal(pool.length, 1);
|
|
2536
|
+
assert.equal(pool[0].label, "first");
|
|
2537
|
+
assert.equal(pool[0].refresh, "r2");
|
|
2538
|
+
});
|
|
2539
|
+
|
|
2540
|
+
// A provider with NO account must never be switched onto: rotation would move the session model
|
|
2541
|
+
// onto a provider pi cannot serve, and the next turn dies with the non-retryable
|
|
2542
|
+
// `Provider is not configured: openai-codex`, which no agent can clear from inside a turn that
|
|
2543
|
+
// fails before it starts.
|
|
2544
|
+
test("a provider with no account: rotation never switches onto it", async () => {
|
|
2545
|
+
await resetRotationState();
|
|
2546
|
+
writeLadderConfig();
|
|
2547
|
+
await helpers.writeSubscriptionPool("anthropic", [credential("primary")]);
|
|
2548
|
+
await helpers.markSubscriptionRateLimited("anthropic", "primary", 30 * 24 * 60 * 60 * 1000);
|
|
2549
|
+
await helpers.writeSubscriptionPool("openai-codex", []);
|
|
2550
|
+
assert.equal(helpers.readSubscriptionPool("openai-codex").length, 0, "no account stored");
|
|
2551
|
+
|
|
2552
|
+
const { ctx, setModelCalls, providers, events, pi } = makeRotationCtx();
|
|
2553
|
+
ctx.model = { provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" };
|
|
2554
|
+
|
|
2555
|
+
await providerRotationExtension(pi);
|
|
2556
|
+
await events.session_start?.({}, ctx);
|
|
2557
|
+
const stream = providers["anthropic"].streamSimple(
|
|
2558
|
+
{ provider: "anthropic", id: "claude-opus-4-8", api: "anthropic-messages" },
|
|
2559
|
+
ctx,
|
|
2560
|
+
);
|
|
2561
|
+
const emitted = [] as any[];
|
|
2562
|
+
for await (const event of stream) emitted.push(event);
|
|
2563
|
+
|
|
2564
|
+
assert.deepEqual(setModelCalls, [], "never switches the session model onto an unconfigured provider");
|
|
2565
|
+
assert.equal(emitted.length, 1);
|
|
2566
|
+
assert.equal(emitted[0].type, "error");
|
|
2567
|
+
// The blocker is a missing login, and the error says exactly that instead of wedging a node.
|
|
2568
|
+
assert.match(emitted[0].error.errorMessage, /authenticate a fallback provider/);
|
|
2569
|
+
assert.match(emitted[0].error.errorMessage, /\/provider-sub openai-codex add/);
|
|
2570
|
+
});
|
|
2571
|
+
|
|
2572
|
+
|
|
2573
|
+
test("Anthropic profile enrichment reads the real account identity", async () => {
|
|
2574
|
+
const originalFetch = globalThis.fetch;
|
|
2575
|
+
globalThis.fetch = async () => new Response(JSON.stringify({ account: { uuid: "account-a", email: "a@example.test" } }), { status: 200 });
|
|
2576
|
+
try {
|
|
2577
|
+
assert.deepEqual(
|
|
2578
|
+
await helpers.enrichManagedLoginIdentity("anthropic", { access: "test-access" }),
|
|
2579
|
+
{ accountId: "account-a", email: "a@example.test" },
|
|
2580
|
+
);
|
|
2581
|
+
} finally {
|
|
2582
|
+
globalThis.fetch = originalFetch;
|
|
2583
|
+
}
|
|
2584
|
+
});
|
|
2585
|
+
|
|
2586
|
+
test("a failed Anthropic profile lookup leaves identity unknown", async () => {
|
|
2587
|
+
const originalFetch = globalThis.fetch;
|
|
2588
|
+
globalThis.fetch = async () => { throw new Error("profile unavailable"); };
|
|
2589
|
+
try {
|
|
2590
|
+
assert.deepEqual(await helpers.enrichManagedLoginIdentity("anthropic", { access: "test-access" }), {});
|
|
2591
|
+
} finally {
|
|
2592
|
+
globalThis.fetch = originalFetch;
|
|
2593
|
+
}
|
|
2594
|
+
});
|
|
2595
|
+
|
|
2596
|
+
test("Anthropic managed login auto-labels new accounts and updates the matching account", async () => {
|
|
2597
|
+
await resetRotationState();
|
|
2598
|
+
const originalFetch = globalThis.fetch;
|
|
2599
|
+
globalThis.fetch = async (_url, options) => {
|
|
2600
|
+
const access = (options as RequestInit).headers as Record<string, string>;
|
|
2601
|
+
const account = access.Authorization === "Bearer a1" || access.Authorization === "Bearer a2"
|
|
2602
|
+
? { uuid: "account-a", email: "a@example.test" }
|
|
2603
|
+
: { uuid: "account-b", email: "b@example.test" };
|
|
2604
|
+
return new Response(JSON.stringify({ account }), { status: 200 });
|
|
2605
|
+
};
|
|
2606
|
+
try {
|
|
2607
|
+
const expires = Date.now() + 60_000;
|
|
2608
|
+
await helpers.commitManagedLogin("anthropic", "anthropic", { refresh: "refresh-a1", access: "a1", expires, lastRateLimitedAt: 0, autoLabel: true });
|
|
2609
|
+
await helpers.commitManagedLogin("anthropic", "anthropic", { refresh: "refresh-a2", access: "a2", expires, lastRateLimitedAt: 0, autoLabel: true });
|
|
2610
|
+
await helpers.commitManagedLogin("anthropic", "anthropic", { refresh: "refresh-b", access: "b", expires, lastRateLimitedAt: 0, autoLabel: true });
|
|
2611
|
+
const pool = helpers.readSubscriptionPool("anthropic");
|
|
2612
|
+
assert.deepEqual(pool.map((entry) => entry.label), ["a@example.test", "b@example.test"]);
|
|
2613
|
+
assert.equal(pool[0]?.refresh, "refresh-a2");
|
|
2614
|
+
} finally {
|
|
2615
|
+
globalThis.fetch = originalFetch;
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
|
|
2619
|
+
test("managed login preserves a cooldown newer than its login snapshot", async () => {
|
|
2620
|
+
await resetRotationState();
|
|
2621
|
+
await helpers.writeSubscriptionPool("openai-codex", [credential("personal", { accountId: "account-a", lastRateLimitedAt: 100, rateLimitedUntil: 60_100 })]);
|
|
2622
|
+
await helpers.commitManagedLogin("openai-codex", "personal", {
|
|
2623
|
+
refresh: "refresh-new",
|
|
2624
|
+
access: "access-new",
|
|
2625
|
+
expires: Date.now() + 60_000,
|
|
2626
|
+
accountId: "account-a",
|
|
2627
|
+
lastRateLimitedAt: 0,
|
|
2628
|
+
});
|
|
2629
|
+
const [entry] = helpers.readSubscriptionPool("openai-codex");
|
|
2630
|
+
assert.equal(entry.rateLimitedUntil, 60_100);
|
|
2631
|
+
assert.equal(entry.lastRateLimitedAt, 100);
|
|
2632
|
+
});
|