@unbrained/pm-cli 2026.8.13 → 2026.8.15
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/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +165 -113
- package/dist/cli/commander-usage.js +17 -4
- package/dist/cli/error-guidance.d.ts +2 -0
- package/dist/cli/error-guidance.js +52 -25
- package/dist/cli/main.js +40 -3
- package/dist/cli/register-mutation.js +4 -2
- package/dist/cli/register-operations.js +5 -5
- package/dist/cli-bundle/bundle-manifest.json +146 -178
- package/dist/cli-bundle/chunks/{chunk-F7FJYGK3.js → chunk-24GAV7XL.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-AIM6VT2N.js +13 -0
- package/dist/cli-bundle/chunks/chunk-DSWDLTDR.js +197 -0
- package/dist/cli-bundle/chunks/{chunk-Q47C67TQ.js → chunk-J42EGKDK.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-KIEGUBYQ.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-3ZMOWAFM.js → chunk-KLKYLSDX.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-QGTUPEU5.js → chunk-LJHOAVGI.js} +59 -59
- package/dist/cli-bundle/chunks/chunk-MEM2ZS3O.js +5 -0
- package/dist/cli-bundle/chunks/chunk-QHPCJWEJ.js +35 -0
- package/dist/cli-bundle/chunks/{chunk-YLBAPY22.js → chunk-WLPDLNEZ.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-4HIZ7EA3.js → register-list-query-CT3LFDDN.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-W64FZ5HN.js → register-mutation-NWEVA5YS.js} +3 -3
- package/dist/cli-bundle/chunks/register-operations-AHIAG5KM.js +2 -0
- package/dist/cli-bundle/chunks/{register-setup-634MFRXU.js → register-setup-ZJZFVAKE.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-4X57RE4U.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-6XKF3PGV.js +18 -0
- package/dist/cli-bundle/focused-chunks/chunk-7NJ4QYQ2.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-I75MANL7.js → chunk-EXZA4257.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-ITAUHSO6.js +50 -0
- package/dist/cli-bundle/focused-chunks/{chunk-OOYYKQWX.js → chunk-KLVUMNXJ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-2RI2FESN.js → chunk-KT5XMYSX.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-E3AVJ655.js → chunk-KTKH4IMG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-M67F5AIN.js +8 -0
- package/dist/cli-bundle/focused-chunks/{chunk-3DJSGWVB.js → chunk-NSPYTG6G.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-OKA6ELTL.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-PUISBOPP.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-QLNMCESQ.js +155 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IIS2FRKL.js → chunk-SLKC6QLJ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-U65UC4G3.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-WTSER4WJ.js +16 -0
- package/dist/cli-bundle/focused-chunks/{chunk-2JP7W7GO.js → chunk-ZMFXQ7VF.js} +2 -2
- package/dist/cli-bundle/main.js +13 -13
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +1 -1
- package/dist/cli-bundle/sdk-core.js +41 -41
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +110 -1
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +2 -2
- package/dist/core/diagnostics/remediation.js +7 -2
- package/dist/core/extensions/reserved-host-flags.js +3 -2
- package/dist/core/history/drift-scan.d.ts +6 -0
- package/dist/core/history/drift-scan.js +74 -50
- package/dist/core/history/replay.d.ts +14 -1
- package/dist/core/history/replay.js +45 -8
- package/dist/core/history/workspace-history.d.ts +59 -0
- package/dist/core/history/workspace-history.js +197 -10
- package/dist/core/output/output.d.ts +2 -0
- package/dist/core/output/output.js +13 -4
- package/dist/core/shared/command-types.d.ts +2 -0
- package/dist/core/shared/command-types.js +2 -2
- package/dist/core/shared/errors.d.ts +12 -0
- package/dist/core/shared/errors.js +2 -2
- package/dist/mcp/tool-definitions.js +9 -5
- package/dist/sdk/agent/refusal-reachability.d.ts +61 -0
- package/dist/sdk/agent/refusal-reachability.js +91 -3
- package/dist/sdk/cli-bootstrap.d.ts +2 -0
- package/dist/sdk/cli-bootstrap.js +7 -2
- package/dist/sdk/cli-contracts/completeness.js +3 -2
- package/dist/sdk/cli-contracts/flag-contracts.js +3 -2
- package/dist/sdk/cli-contracts/registration-helpers.js +3 -2
- package/dist/sdk/cli-contracts/runtime-contracts.d.ts +11 -1
- package/dist/sdk/cli-contracts/runtime-contracts.js +176 -65
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +15 -5
- package/dist/sdk/cli-contracts/tool-schema.js +10 -3
- package/dist/sdk/cli-program.js +4 -3
- package/dist/sdk/context-relevance.js +12 -4
- package/dist/sdk/core.d.ts +2 -2
- package/dist/sdk/core.js +3 -3
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +26 -2
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +50 -26
- package/dist/sdk/governance/assurance-action.d.ts +7 -1
- package/dist/sdk/governance/assurance-action.js +7 -6
- package/dist/sdk/governance/assurance-mutation-error.d.ts +42 -1
- package/dist/sdk/governance/assurance-mutation-error.js +27 -3
- package/dist/sdk/governance/assurance-runtime.js +12 -11
- package/dist/sdk/governance/assurance.d.ts +9 -0
- package/dist/sdk/governance/assurance.js +82 -16
- package/dist/sdk/governance/extension-host-version.d.ts +25 -0
- package/dist/sdk/governance/extension-host-version.js +105 -0
- package/dist/sdk/governance/health.d.ts +32 -1
- package/dist/sdk/governance/health.js +132 -28
- package/dist/sdk/governance/provenance-health.d.ts +27 -0
- package/dist/sdk/governance/provenance-health.js +95 -3
- package/dist/sdk/governance/validate-history-drift.d.ts +7 -0
- package/dist/sdk/governance/validate-history-drift.js +68 -0
- package/dist/sdk/governance/validate.js +9 -52
- package/dist/sdk/governance.d.ts +6 -0
- package/dist/sdk/governance.js +8 -2
- package/dist/sdk/graph/assembly.d.ts +23 -0
- package/dist/sdk/graph/assembly.js +54 -2
- package/dist/sdk/graph/durable-cache.js +50 -20
- package/dist/sdk/graph/governance-contracts.d.ts +1 -1
- package/dist/sdk/graph/governance-contracts.js +4 -2
- package/dist/sdk/graph/governance.d.ts +21 -1
- package/dist/sdk/graph/governance.js +94 -32
- package/dist/sdk/graph/index.d.ts +2 -2
- package/dist/sdk/graph/index.js +4 -4
- package/dist/sdk/graph/mutation-advisory.js +15 -7
- package/dist/sdk/graph/remediation.js +12 -2
- package/dist/sdk/history-read.d.ts +8 -0
- package/dist/sdk/history-read.js +2 -2
- package/dist/sdk/history-repair.d.ts +13 -1
- package/dist/sdk/history-repair.js +62 -18
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +3 -3
- package/dist/sdk/linked-artifacts.js +16 -5
- package/dist/sdk/pagination.d.ts +15 -0
- package/dist/sdk/pagination.js +9 -5
- package/dist/sdk/query/context.d.ts +5 -1
- package/dist/sdk/query/context.js +14 -5
- package/dist/sdk/query/history.js +20 -3
- package/dist/sdk/read-output/continuation.d.ts +11 -0
- package/dist/sdk/read-output/continuation.js +132 -0
- package/dist/sdk/read-output-budget.d.ts +3 -1
- package/dist/sdk/read-output-budget.js +24 -13
- package/dist/sdk/read-output-contracts.d.ts +127 -7
- package/dist/sdk/read-output-contracts.js +381 -35
- package/dist/sdk/read-output-rows.d.ts +13 -0
- package/dist/sdk/read-output-rows.js +60 -2
- package/dist/sdk/runtime-input.js +4 -2
- package/dist/sdk/runtime-primitives.d.ts +1 -1
- package/dist/sdk/runtime-primitives.js +3 -3
- package/dist/sdk/runtime.js +5 -3
- package/docs/ASSURANCE.md +68 -2
- package/docs/COMMANDS.md +39 -4
- package/docs/READ_OUTPUT_CONTRACTS.md +85 -8
- package/docs/RELATIONSHIP_GRAPH.md +20 -5
- package/docs/RELEASING.md +42 -5
- package/docs/SDK.md +12 -5
- package/docs/SDK_CONTEXT_INTEGRITY.md +94 -1
- package/docs/TESTING.md +23 -1
- package/docs/performance/sdk-entrypoint-import-costs.md +20 -13
- package/marketplace.json +2 -2
- package/package.json +7 -7
- package/packages/pm-beads/extensions/beads/index.ts +1 -0
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/extensions/calendar/index.ts +1 -0
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/extensions/digital-twin/index.ts +7 -0
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/extensions/governance-audit/index.ts +4 -0
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/extensions/guide-shell/index.ts +5 -0
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/index.ts +6 -0
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/extensions/search-advanced/index.ts +2 -0
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/extensions/templates/index.ts +4 -0
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/extensions/todos/index.ts +2 -0
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/extensions/vcs/index.ts +7 -0
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/scripts/bundle-cli.mjs +17 -4
- package/sdk/public-surface.json +1283 -157
- package/dist/cli-bundle/chunks/chunk-DEDU3DG7.js +0 -196
- package/dist/cli-bundle/chunks/chunk-DL5M5J3V.js +0 -13
- package/dist/cli-bundle/chunks/chunk-HIUZVCMN.js +0 -5
- package/dist/cli-bundle/chunks/chunk-IMGIN7R6.js +0 -2
- package/dist/cli-bundle/chunks/chunk-TF3TPKPR.js +0 -34
- package/dist/cli-bundle/chunks/register-operations-C44ET7R5.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-27N23W6M.js +0 -31
- package/dist/cli-bundle/focused-chunks/chunk-3BNVU6LC.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-6MLIRBLV.js +0 -5
- package/dist/cli-bundle/focused-chunks/chunk-6XYLENDV.js +0 -155
- package/dist/cli-bundle/focused-chunks/chunk-CP4K4WFS.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-EBTNSFYE.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-HC2OL2H2.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-NFHFZH2Z.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-OGC4XSBC.js +0 -17
- package/dist/cli-bundle/focused-chunks/chunk-PKPOZXLL.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QDZUABWL.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QQX5TDFT.js +0 -16
- package/dist/cli-bundle/focused-chunks/chunk-TEZIXMTH.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-WEH6NSL6.js +0 -18
package/dist/sdk/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Defines public SDK APIs and package-author helpers for Index.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
7
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a05170b2-a48d-5275-ac04-aafc9f8315b2")}catch(e){}}();
|
|
8
8
|
export { PM_COMMAND_VISIBILITY_CONTRACTS, PM_MCP_PROMPT_CONTRACTS, PM_MCP_RESOURCE_CONTRACTS, PM_MCP_TOOL_COMMAND_CONTRACTS, listPmCommandsForTier, listPmMcpToolsForProfile, renderPmCommandVisibilityMarkdown, resolvePmCommandVisibilityTier, } from "./agent-capability-contracts.js";
|
|
9
9
|
export * from "./agent-session-context.js";
|
|
10
10
|
export { isErrnoError, limitAnnotationEntries, parseAnnotationTextInput, readAnnotationEntries, normalizeAnnotationTransportOptions, resolveAnnotationInput, resolveAnnotationIndex, runAnnotationCommand, wrapOwnershipConflict, } from "./annotations.js";
|
|
@@ -82,7 +82,7 @@ export * from "./history-compact.js";
|
|
|
82
82
|
export * from "./history-read.js";
|
|
83
83
|
export * from "./history-provenance.js";
|
|
84
84
|
export * from "./mutation-events.js";
|
|
85
|
-
export { appendWorkspaceAuditEvent, appendWorkspaceHistoryChange, getWorkspaceHistoryPath, mutateWorkspaceJsonWithHistory, WORKSPACE_HISTORY_ID, writeWorkspaceJsonWithHistory, } from "../core/history/workspace-history.js";
|
|
85
|
+
export { appendWorkspaceAuditEvent, appendWorkspaceHistoryChange, getWorkspaceHistoryPath, inspectWorkspaceHistoryState, mutateWorkspaceJsonWithHistory, reconcileWorkspaceJsonHistory, restoreWorkspaceJsonFromHistory, WORKSPACE_HISTORY_ID, writeWorkspaceJsonWithHistory, } from "../core/history/workspace-history.js";
|
|
86
86
|
export * from "./history-redact.js";
|
|
87
87
|
export { _testOnly } from "./history-redact.js";
|
|
88
88
|
export * from "./history-repair.js";
|
|
@@ -151,4 +151,4 @@ export * from "./governance.js";
|
|
|
151
151
|
export * from "./query.js";
|
|
152
152
|
export * from "./testing.js";
|
|
153
153
|
//# sourceMappingURL=index.js.map
|
|
154
|
-
//# debugId=
|
|
154
|
+
//# debugId=a05170b2-a48d-5275-ac04-aafc9f8315b2
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Implements the pm linked artifacts command surface and its agent-facing runtime behavior.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
7
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="256b39b7-882e-553c-9dea-813bfd363dd7")}catch(e){}}();
|
|
8
8
|
import fs from "node:fs/promises";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import fg from "fast-glob";
|
|
@@ -57,9 +57,20 @@ export function looksLikeStructuredPathEntry(raw) {
|
|
|
57
57
|
if (/^(?:[-*+]\s+)?(?:path|scope|note)\s*[:=]/i.test(raw)) {
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
60
|
+
// An equals sign is valid inside filesystem paths and URL query strings.
|
|
61
|
+
// Preserve unmistakable whitespace-free path/URL shapes while routing
|
|
62
|
+
// leading assignment syntax through the structured-key allowlist so typos
|
|
63
|
+
// and malformed URL-plus-note input remain atomic failures (GH-258,
|
|
64
|
+
// GH-1000).
|
|
65
|
+
const equalsIndex = raw.indexOf("=");
|
|
66
|
+
if (equalsIndex >= 0 &&
|
|
67
|
+
!/\s/u.test(raw) &&
|
|
68
|
+
(/^[A-Za-z][A-Za-z0-9+.-]*:\/\//u.test(raw) ||
|
|
69
|
+
/^(?:[A-Za-z]:[\\/]|[\\/]{1,2}|\.\.?(?:[\\/]))/u.test(raw) ||
|
|
70
|
+
[raw.indexOf("/"), raw.indexOf("\\")].some((separatorIndex) => separatorIndex >= 0 && separatorIndex < equalsIndex))) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return raw.includes("=") || looksLikeGenericKeyValueEntry(raw);
|
|
63
74
|
}
|
|
64
75
|
function expandBareCommaSeparatedAddEntries(raw) {
|
|
65
76
|
return raw.flatMap((entry) => {
|
|
@@ -479,4 +490,4 @@ export function renameArtifactsResultKey(result, key) {
|
|
|
479
490
|
return out;
|
|
480
491
|
}
|
|
481
492
|
//# sourceMappingURL=linked-artifacts.js.map
|
|
482
|
-
//# debugId=
|
|
493
|
+
//# debugId=256b39b7-882e-553c-9dea-813bfd363dd7
|
package/dist/sdk/pagination.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { CliFlagContract } from "./cli-contracts/flag-contracts.js";
|
|
2
|
+
/** Validated transport envelope carried by an opaque query cursor. */
|
|
3
|
+
export interface QueryCursorEnvelope {
|
|
4
|
+
/** Serialized cursor contract version. */
|
|
5
|
+
version: number;
|
|
6
|
+
/** Stable fingerprint of the query semantics that produced the cursor. */
|
|
7
|
+
fingerprint: string;
|
|
8
|
+
/** Stable id of the last row emitted by the producer. */
|
|
9
|
+
after_id: string;
|
|
10
|
+
/** Zero-based position of the last emitted row when available. */
|
|
11
|
+
after_index?: number;
|
|
12
|
+
/** Opaque producer-defined snapshot token for stable continuation. */
|
|
13
|
+
snapshot?: string;
|
|
14
|
+
}
|
|
2
15
|
/** Decoded cursor state for advanced package and retrieval-window integrations. */
|
|
3
16
|
export interface QueryCursorState {
|
|
4
17
|
/** Stable id of the last row emitted by the previous page. */
|
|
@@ -27,6 +40,8 @@ export declare function selectCursorSemanticOptions(options: Readonly<Record<str
|
|
|
27
40
|
export declare function createQueryFingerprint(command: string, contract: unknown): string;
|
|
28
41
|
/** Encode the last emitted item id into a versioned opaque base64url cursor. */
|
|
29
42
|
export declare function encodeQueryCursor(fingerprint: string, afterId: string, afterIndex?: number, snapshot?: string): string;
|
|
43
|
+
/** Decode and validate an opaque cursor without imposing caller query identity. */
|
|
44
|
+
export declare function decodeQueryCursorEnvelope(cursor: unknown): QueryCursorEnvelope;
|
|
30
45
|
/** Decode and validate complete cursor state against a query fingerprint. */
|
|
31
46
|
export declare function decodeQueryCursorState(cursor: unknown, expectedFingerprint: string): QueryCursorState;
|
|
32
47
|
/** Decode and validate a cursor against the normalized query fingerprint. */
|
package/dist/sdk/pagination.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* package-authored query surfaces.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
8
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d3329fac-693d-566c-a30a-43f8fb37938f")}catch(e){}}();
|
|
9
9
|
import { createHash } from "node:crypto";
|
|
10
10
|
import { PmCliError } from "../core/shared/errors.js";
|
|
11
11
|
import { EXIT_CODE } from "../core/shared/constants.js";
|
|
@@ -78,8 +78,8 @@ function isQueryCursorEnvelope(value) {
|
|
|
78
78
|
(envelope.snapshot === undefined ||
|
|
79
79
|
(typeof envelope.snapshot === "string" && envelope.snapshot.length > 0)));
|
|
80
80
|
}
|
|
81
|
-
/** Decode and validate
|
|
82
|
-
export function
|
|
81
|
+
/** Decode and validate an opaque cursor without imposing caller query identity. */
|
|
82
|
+
export function decodeQueryCursorEnvelope(cursor) {
|
|
83
83
|
if (typeof cursor !== "string") {
|
|
84
84
|
throw invalidCursor("Query cursor is malformed.");
|
|
85
85
|
}
|
|
@@ -99,7 +99,11 @@ export function decodeQueryCursorState(cursor, expectedFingerprint) {
|
|
|
99
99
|
if (!isQueryCursorEnvelope(parsed)) {
|
|
100
100
|
throw invalidCursor("Query cursor version or payload is unsupported.");
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
return parsed;
|
|
103
|
+
}
|
|
104
|
+
/** Decode and validate complete cursor state against a query fingerprint. */
|
|
105
|
+
export function decodeQueryCursorState(cursor, expectedFingerprint) {
|
|
106
|
+
const envelope = decodeQueryCursorEnvelope(cursor);
|
|
103
107
|
if (envelope.fingerprint !== expectedFingerprint) {
|
|
104
108
|
throw invalidCursor(`Query cursor does not match the current filters, sort, or query (${envelope.fingerprint} != ${expectedFingerprint}).`);
|
|
105
109
|
}
|
|
@@ -156,4 +160,4 @@ export const QUERY_CURSOR_CONTRACT = Object.freeze({
|
|
|
156
160
|
max_length: MAX_CURSOR_LENGTH,
|
|
157
161
|
});
|
|
158
162
|
//# sourceMappingURL=pagination.js.map
|
|
159
|
-
//# debugId=
|
|
163
|
+
//# debugId=d3329fac-693d-566c-a30a-43f8fb37938f
|
|
@@ -399,6 +399,10 @@ export interface ContextRankingSummary {
|
|
|
399
399
|
score: number;
|
|
400
400
|
contributions: ContextRelevanceContributions;
|
|
401
401
|
}>;
|
|
402
|
+
/** Number of candidates considered before answer-sized projection. */
|
|
403
|
+
candidate_count: number;
|
|
404
|
+
/** Number of candidate explanations omitted because their rows were not served. */
|
|
405
|
+
omitted_count: number;
|
|
402
406
|
/** Rebuildable feature-store freshness and provenance. */
|
|
403
407
|
feature_store?: {
|
|
404
408
|
source: "derived_index" | "scan_fallback";
|
|
@@ -462,7 +466,7 @@ export declare function packRankedContextItems(report: ContextRelevanceReport<It
|
|
|
462
466
|
/** Projects the SDK packer report onto the stable low-token command envelope. */
|
|
463
467
|
export declare function toContextPackingSummary(report: ContextPackingReport<ItemMetadata>): ContextPackingSummary;
|
|
464
468
|
/** Project a full scorer report onto the low-token command explanation shape. */
|
|
465
|
-
export declare function toContextRankingSummary<TItem>(report: ContextRelevanceReport<TItem>, featureStore?: ContextSignalStoreReadResult): ContextRankingSummary;
|
|
469
|
+
export declare function toContextRankingSummary<TItem>(report: ContextRelevanceReport<TItem>, featureStore?: ContextSignalStoreReadResult, servedItemIds?: ReadonlySet<string>): ContextRankingSummary;
|
|
466
470
|
declare function completionPct(closed: number, total: number): number;
|
|
467
471
|
/** Indexes items by their parent id, yielding a parent→direct-children map used by the hierarchy/progress rollups and by focus-row child completion. Items without a parent are skipped. Exported so sibling read commands reuse the same index. */
|
|
468
472
|
export declare function buildChildrenByParent(allItems: ItemMetadata[]): Map<string, ItemMetadata[]>;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Implements the pm context command surface and its agent-facing runtime behavior.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
7
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ee5279f2-7489-59fb-8f96-f2e035434cce")}catch(e){}}();
|
|
8
8
|
import { SETTINGS_DEFAULTS, EXIT_CODE, PmCliError, compareTimestampStrings, nowIso, isTerminalStatus, normalizeStatusForRegistry, normalizeStatusInput, resolveRuntimeStatusRegistry, resolvePmRoot, readSettings, resolveAuthor, discoverExtensions, } from "../runtime-primitives.js";
|
|
9
9
|
import { collectDependencyBlockedIds, resolveItemBlockers, } from "../actionability.js";
|
|
10
10
|
import { CONTEXT_DEPTH_VALUES, CONTEXT_SECTION_VALUES, } from "../../types/index.js";
|
|
@@ -455,17 +455,22 @@ export function toContextPackingSummary(report) {
|
|
|
455
455
|
};
|
|
456
456
|
}
|
|
457
457
|
/** Project a full scorer report onto the low-token command explanation shape. */
|
|
458
|
-
export function toContextRankingSummary(report, featureStore) {
|
|
458
|
+
export function toContextRankingSummary(report, featureStore, servedItemIds) {
|
|
459
|
+
const ranked = servedItemIds === undefined
|
|
460
|
+
? report.ranked
|
|
461
|
+
: report.ranked.filter((entry) => servedItemIds.has(entry.id));
|
|
459
462
|
return {
|
|
460
463
|
model: report.model,
|
|
461
464
|
available_signals: report.available_signals,
|
|
462
|
-
items:
|
|
465
|
+
items: ranked.map((entry) => ({
|
|
463
466
|
id: entry.id,
|
|
464
467
|
rank: entry.rank,
|
|
465
468
|
baseline_rank: entry.baseline_rank,
|
|
466
469
|
score: entry.score,
|
|
467
470
|
contributions: entry.contributions,
|
|
468
471
|
})),
|
|
472
|
+
candidate_count: report.ranked.length,
|
|
473
|
+
omitted_count: report.ranked.length - ranked.length,
|
|
469
474
|
...(featureStore
|
|
470
475
|
? {
|
|
471
476
|
feature_store: {
|
|
@@ -1659,7 +1664,11 @@ export async function runContext(options, global) {
|
|
|
1659
1664
|
attachOptionalContextSections(result, sections, focusGroups.featureStore.warning_details);
|
|
1660
1665
|
applyContextTagProjection(result, options.noTags === true);
|
|
1661
1666
|
if (options.explainRanking === true) {
|
|
1662
|
-
result.ranking = toContextRankingSummary(focusGroups.ranking, focusGroups.featureStore
|
|
1667
|
+
result.ranking = toContextRankingSummary(focusGroups.ranking, focusGroups.featureStore, new Set([
|
|
1668
|
+
...focusGroups.highLevel,
|
|
1669
|
+
...focusGroups.lowLevel,
|
|
1670
|
+
...focusGroups.blockedFallback,
|
|
1671
|
+
].map((entry) => entry.id)));
|
|
1663
1672
|
result.packing = toContextPackingSummary(focusGroups.packing);
|
|
1664
1673
|
}
|
|
1665
1674
|
applyContextFocusProjection(result, runtime.focusFields);
|
|
@@ -1670,4 +1679,4 @@ export async function runContext(options, global) {
|
|
|
1670
1679
|
return result;
|
|
1671
1680
|
}
|
|
1672
1681
|
//# sourceMappingURL=context.js.map
|
|
1673
|
-
//# debugId=
|
|
1682
|
+
//# debugId=ee5279f2-7489-59fb-8f96-f2e035434cce
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Implements the pm history command surface and its agent-facing runtime behavior.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
8
|
-
import { pathExists, computeHistoryDiff, patchPathToChangedField, normalizeReplayPatchOps, verifyHistoryChain, enforceHistoryStreamPolicyForItem, EXIT_CODE, PmCliError, getActiveExtensionRegistrations, normalizeItemId, resolveItemTypeRegistry, locateItem, readLocatedItem, getHistoryPath, getWorkspaceHistoryPath, getSettingsPath, resolvePmRoot, readSettings, WORKSPACE_HISTORY_ID, } from "../runtime-primitives.js";
|
|
7
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f18d7526-01eb-593b-bf50-788c08a35e5d")}catch(e){}}();
|
|
8
|
+
import { pathExists, computeHistoryDiff, patchPathToChangedField, normalizeReplayPatchOps, verifyHistoryChain, enforceHistoryStreamPolicyForItem, EXIT_CODE, PmCliError, getActiveExtensionRegistrations, normalizeItemId, resolveItemTypeRegistry, locateItem, readLocatedItem, getHistoryPath, getWorkspaceHistoryPath, inspectWorkspaceHistoryState, getSettingsPath, resolvePmRoot, readSettings, WORKSPACE_HISTORY_ID, } from "../runtime-primitives.js";
|
|
9
9
|
import { readHistoryEntries, verifyHistoryEntries, } from "../history-read.js";
|
|
10
10
|
export { readHistoryEntries } from "../history-read.js";
|
|
11
11
|
import { parseLimit } from "./parsers.js";
|
|
@@ -140,8 +140,25 @@ export async function runHistory(id, options, global) {
|
|
|
140
140
|
})).document
|
|
141
141
|
: undefined;
|
|
142
142
|
result.verification = verifyHistoryEntries(fullHistory, currentDocument);
|
|
143
|
+
if (resolvedId === WORKSPACE_HISTORY_ID && result.verification.ok) {
|
|
144
|
+
const agreement = await inspectWorkspaceHistoryState(resolvePmRoot(process.cwd(), global.path));
|
|
145
|
+
result.verification = {
|
|
146
|
+
...result.verification,
|
|
147
|
+
ok: agreement.ok,
|
|
148
|
+
errors: agreement.ok
|
|
149
|
+
? result.verification.errors
|
|
150
|
+
: [
|
|
151
|
+
...result.verification.errors,
|
|
152
|
+
"verify_failed:workspace_state_mismatch",
|
|
153
|
+
],
|
|
154
|
+
workspace_state_matches_latest: agreement.ok,
|
|
155
|
+
workspace_state_mismatches: agreement.mismatched_documents,
|
|
156
|
+
workspace_state_missing: agreement.missing_documents,
|
|
157
|
+
workspace_state_unreadable: agreement.unreadable_documents,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
143
160
|
}
|
|
144
161
|
return result;
|
|
145
162
|
}
|
|
146
163
|
//# sourceMappingURL=history.js.map
|
|
147
|
-
//# debugId=
|
|
164
|
+
//# debugId=f18d7526-01eb-593b-bf50-788c08a35e5d
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PmReadOutputCursorEnvelope, PmReadOutputSurface } from "../read-output-contracts.js";
|
|
2
|
+
/** Fingerprint stable row identities without including volatile observation fields. */
|
|
3
|
+
export declare function readOutputCollectionFingerprint(path: string, value: unknown[] | Record<string, unknown>): string;
|
|
4
|
+
/** Encode one stable declared-row continuation for CLI, SDK, and MCP callers. */
|
|
5
|
+
export declare function encodeReadOutputContinuationCursor(cursor: Omit<PmReadOutputCursorEnvelope, "version">): string;
|
|
6
|
+
/** Decode and validate one universal declared-row continuation cursor. */
|
|
7
|
+
export declare function decodeReadOutputContinuationCursor(raw: string): PmReadOutputCursorEnvelope;
|
|
8
|
+
/** Place every non-passing assurance assertion before passing evidence. */
|
|
9
|
+
export declare function prioritizeAssuranceAssertions(result: Record<string, unknown>): Record<string, unknown>;
|
|
10
|
+
/** Validate and apply a continuation suffix to its declared row collection. */
|
|
11
|
+
export declare function applyReadOutputContinuation(result: Record<string, unknown>, command: PmReadOutputSurface, cursor: PmReadOutputCursorEnvelope | undefined): Record<string, unknown>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sdk/read-output/continuation
|
|
3
|
+
*
|
|
4
|
+
* Encodes, validates, and applies stable continuations for declared read-output
|
|
5
|
+
* row collections while keeping cursor mechanics separate from dimension
|
|
6
|
+
* resolution and budget policy.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8e523bbc-5745-514e-a1d8-a6ad6ece001a")}catch(e){}}();
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { EXIT_CODE } from "../../core/shared/constants.js";
|
|
12
|
+
import { PmCliError } from "../../core/shared/errors.js";
|
|
13
|
+
import { resolveReadOutputSurface } from "../read-output-contracts.js";
|
|
14
|
+
import { readOutputRowCollections, sliceReadOutputRowCollection, } from "../read-output-rows.js";
|
|
15
|
+
const MAX_READ_OUTPUT_CURSOR_LENGTH = 4096;
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
/** Fingerprint stable row identities without including volatile observation fields. */
|
|
20
|
+
export function readOutputCollectionFingerprint(path, value) {
|
|
21
|
+
const identities = Array.isArray(value)
|
|
22
|
+
? value.map((row, index) => {
|
|
23
|
+
if (!isRecord(row))
|
|
24
|
+
return `index:${String(index)}`;
|
|
25
|
+
for (const key of [
|
|
26
|
+
"id",
|
|
27
|
+
"assertion_id",
|
|
28
|
+
"measurement_id",
|
|
29
|
+
"event_id",
|
|
30
|
+
]) {
|
|
31
|
+
const candidate = row[key];
|
|
32
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
33
|
+
return `${key}:${candidate}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return `index:${String(index)}`;
|
|
37
|
+
})
|
|
38
|
+
: Object.keys(value);
|
|
39
|
+
return createHash("sha256")
|
|
40
|
+
.update(JSON.stringify({ path, identities }))
|
|
41
|
+
.digest("base64url")
|
|
42
|
+
.slice(0, 16);
|
|
43
|
+
}
|
|
44
|
+
/** Encode one stable declared-row continuation for CLI, SDK, and MCP callers. */
|
|
45
|
+
export function encodeReadOutputContinuationCursor(cursor) {
|
|
46
|
+
return Buffer.from(JSON.stringify({
|
|
47
|
+
v: 1,
|
|
48
|
+
c: cursor.command,
|
|
49
|
+
p: cursor.path,
|
|
50
|
+
o: cursor.offset,
|
|
51
|
+
n: cursor.total_rows,
|
|
52
|
+
f: cursor.fingerprint,
|
|
53
|
+
}), "utf8").toString("base64url");
|
|
54
|
+
}
|
|
55
|
+
/** Decode and validate one universal declared-row continuation cursor. */
|
|
56
|
+
export function decodeReadOutputContinuationCursor(raw) {
|
|
57
|
+
if (raw.length > MAX_READ_OUTPUT_CURSOR_LENGTH) {
|
|
58
|
+
throw new PmCliError("The read-output continuation cursor is malformed or unsupported.", EXIT_CODE.USAGE, { code: "read_output_cursor_invalid" });
|
|
59
|
+
}
|
|
60
|
+
let candidate;
|
|
61
|
+
try {
|
|
62
|
+
candidate = JSON.parse(Buffer.from(raw, "base64url").toString("utf8"));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
candidate = null;
|
|
66
|
+
}
|
|
67
|
+
if (!isRecord(candidate) ||
|
|
68
|
+
candidate.v !== 1 ||
|
|
69
|
+
resolveReadOutputSurface(String(candidate.c ?? "")) !== candidate.c ||
|
|
70
|
+
typeof candidate.p !== "string" ||
|
|
71
|
+
candidate.p.length === 0 ||
|
|
72
|
+
!Number.isSafeInteger(candidate.o) ||
|
|
73
|
+
candidate.o < 0 ||
|
|
74
|
+
!Number.isSafeInteger(candidate.n) ||
|
|
75
|
+
candidate.n < 1 ||
|
|
76
|
+
typeof candidate.f !== "string" ||
|
|
77
|
+
candidate.f.length === 0) {
|
|
78
|
+
throw new PmCliError("The read-output continuation cursor is malformed or unsupported.", EXIT_CODE.USAGE, { code: "read_output_cursor_invalid" });
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
version: 1,
|
|
82
|
+
command: candidate.c,
|
|
83
|
+
path: candidate.p,
|
|
84
|
+
offset: candidate.o,
|
|
85
|
+
total_rows: candidate.n,
|
|
86
|
+
fingerprint: candidate.f,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Place every non-passing assurance assertion before passing evidence. */
|
|
90
|
+
export function prioritizeAssuranceAssertions(result) {
|
|
91
|
+
if (!Array.isArray(result.assertions))
|
|
92
|
+
return result;
|
|
93
|
+
const priority = (row) => {
|
|
94
|
+
if (!isRecord(row) || row.verdict === "pass")
|
|
95
|
+
return 4;
|
|
96
|
+
if (row.verdict === "retired")
|
|
97
|
+
return 3;
|
|
98
|
+
return row.enforcement === "block" ? 0 : row.enforcement === "warn" ? 1 : 2;
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
...result,
|
|
102
|
+
assertions: result.assertions
|
|
103
|
+
.map((row, index) => ({ row, index }))
|
|
104
|
+
.sort((left, right) => priority(left.row) - priority(right.row) || left.index - right.index)
|
|
105
|
+
.map(({ row }) => row),
|
|
106
|
+
budget_retention_policy: "verdict_priority",
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Validate and apply a continuation suffix to its declared row collection. */
|
|
110
|
+
export function applyReadOutputContinuation(result, command, cursor) {
|
|
111
|
+
if (!cursor)
|
|
112
|
+
return result;
|
|
113
|
+
if (cursor.command !== command) {
|
|
114
|
+
throw new PmCliError(`The read-output cursor belongs to ${cursor.command}, not ${command}.`, EXIT_CODE.USAGE, { code: "read_output_cursor_command_mismatch" });
|
|
115
|
+
}
|
|
116
|
+
const collection = readOutputRowCollections(result).find((entry) => entry.path === cursor.path);
|
|
117
|
+
const totalRows = collection
|
|
118
|
+
? Array.isArray(collection.value)
|
|
119
|
+
? collection.value.length
|
|
120
|
+
: Object.keys(collection.value).length
|
|
121
|
+
: 0;
|
|
122
|
+
if (!collection ||
|
|
123
|
+
totalRows !== cursor.total_rows ||
|
|
124
|
+
cursor.offset > totalRows ||
|
|
125
|
+
readOutputCollectionFingerprint(cursor.path, collection.value) !==
|
|
126
|
+
cursor.fingerprint) {
|
|
127
|
+
throw new PmCliError("The read-output continuation no longer matches the declared row collection; restart the bounded read.", EXIT_CODE.USAGE, { code: "read_output_cursor_stale" });
|
|
128
|
+
}
|
|
129
|
+
return sliceReadOutputRowCollection(result, cursor.path, cursor.offset);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=continuation.js.map
|
|
132
|
+
//# debugId=8e523bbc-5745-514e-a1d8-a6ad6ece001a
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* read-output contract without expanding its public declaration module.
|
|
6
6
|
*/
|
|
7
7
|
import type { PmReadOutputReceipt } from "./read-output-contracts.js";
|
|
8
|
+
/** Estimate the conservative token cost of a JSON-shaped result. */
|
|
9
|
+
export declare function estimateReadOutputTokens(result: unknown): number;
|
|
8
10
|
/** Update a receipt to the fixed-point estimate of the result containing it. */
|
|
9
11
|
export declare function updateReadOutputReceiptEstimate(result: Record<string, unknown>, receipt: PmReadOutputReceipt): void;
|
|
10
12
|
/** Compact strings and rows in place, then return the final exact estimate. */
|
|
11
|
-
export declare function compactReadOutputToBudget(result: Record<string, unknown>, receipt: PmReadOutputReceipt, budget: number): Record<string, unknown>;
|
|
13
|
+
export declare function compactReadOutputToBudget(result: Record<string, unknown>, receipt: PmReadOutputReceipt, budget: number, minimumRowsByPath?: ReadonlyMap<string, number>): Record<string, unknown>;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
-
import { countReadOutputRows,
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="737ac274-c165-5d1a-8b8e-cb5d57a81c46")}catch(e){}}();
|
|
3
|
+
import { countReadOutputRows, readOutputBudgetCollections, } from "./read-output-rows.js";
|
|
4
4
|
const MAX_ESTIMATE_ITERATIONS = 8;
|
|
5
5
|
const MAX_COMPACTION_ITERATIONS = 64;
|
|
6
|
+
/** Estimate the conservative token cost of a JSON-shaped result. */
|
|
7
|
+
export function estimateReadOutputTokens(result) {
|
|
8
|
+
return Math.ceil(Buffer.byteLength(JSON.stringify(result), "utf8") / 4);
|
|
9
|
+
}
|
|
6
10
|
/** Return whether a value is a non-array object record. */
|
|
7
11
|
function isRecord(value) {
|
|
8
12
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -30,7 +34,7 @@ export function updateReadOutputReceiptEstimate(result, receipt) {
|
|
|
30
34
|
let estimate = receipt.estimated_tokens;
|
|
31
35
|
for (let iteration = 0; iteration < MAX_ESTIMATE_ITERATIONS; iteration += 1) {
|
|
32
36
|
receipt.estimated_tokens = estimate;
|
|
33
|
-
const measured =
|
|
37
|
+
const measured = estimateReadOutputTokens(result);
|
|
34
38
|
if (measured === estimate)
|
|
35
39
|
return;
|
|
36
40
|
estimate = measured;
|
|
@@ -38,15 +42,18 @@ export function updateReadOutputReceiptEstimate(result, receipt) {
|
|
|
38
42
|
receipt.estimated_tokens = estimate;
|
|
39
43
|
}
|
|
40
44
|
/** Reduce the largest row collection until the budget fits or no rows can move. */
|
|
41
|
-
function compactRowsToBudget(result, receipt, budget) {
|
|
45
|
+
function compactRowsToBudget(result, receipt, budget, minimumRowsByPath) {
|
|
42
46
|
for (let iteration = 0; iteration < MAX_COMPACTION_ITERATIONS; iteration += 1) {
|
|
43
47
|
updateReadOutputReceiptEstimate(result, receipt);
|
|
44
48
|
if (receipt.estimated_tokens <= budget)
|
|
45
49
|
return;
|
|
46
|
-
const candidate =
|
|
47
|
-
.filter((collection) =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const candidate = readOutputBudgetCollections(result)
|
|
51
|
+
.filter((collection) => {
|
|
52
|
+
const length = Array.isArray(collection.value)
|
|
53
|
+
? collection.value.length
|
|
54
|
+
: Object.keys(collection.value).length;
|
|
55
|
+
return (length > Math.max(1, minimumRowsByPath.get(collection.path) ?? 0));
|
|
56
|
+
})
|
|
50
57
|
.map((collection) => ({
|
|
51
58
|
collection,
|
|
52
59
|
length: Array.isArray(collection.value)
|
|
@@ -57,16 +64,20 @@ function compactRowsToBudget(result, receipt, budget) {
|
|
|
57
64
|
left.collection.path.localeCompare(right.collection.path))[0]?.collection;
|
|
58
65
|
if (!candidate)
|
|
59
66
|
return;
|
|
67
|
+
const minimumRows = Math.max(1, minimumRowsByPath.get(candidate.path) ?? 0);
|
|
60
68
|
if (Array.isArray(candidate.value)) {
|
|
61
|
-
candidate.value.splice(-Math.max(1, Math.ceil(candidate.value.length / 2)));
|
|
69
|
+
candidate.value.splice(-Math.min(candidate.value.length - minimumRows, Math.max(1, Math.ceil(candidate.value.length / 2))));
|
|
62
70
|
}
|
|
63
71
|
else {
|
|
64
72
|
const keys = Object.keys(candidate.value);
|
|
65
|
-
for (const key of keys.slice(-Math.max(1, Math.ceil(keys.length / 2)))) {
|
|
73
|
+
for (const key of keys.slice(-Math.min(keys.length - minimumRows, Math.max(1, Math.ceil(keys.length / 2))))) {
|
|
66
74
|
delete candidate.value[key];
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
receipt.rows_compacted = true;
|
|
78
|
+
receipt.compacted_row_paths = [
|
|
79
|
+
...new Set([...(receipt.compacted_row_paths ?? []), candidate.path]),
|
|
80
|
+
].sort((left, right) => left.localeCompare(right));
|
|
70
81
|
result.has_more = true;
|
|
71
82
|
result.truncated = true;
|
|
72
83
|
if (typeof result.count === "number") {
|
|
@@ -75,14 +86,14 @@ function compactRowsToBudget(result, receipt, budget) {
|
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
/** Compact strings and rows in place, then return the final exact estimate. */
|
|
78
|
-
export function compactReadOutputToBudget(result, receipt, budget) {
|
|
89
|
+
export function compactReadOutputToBudget(result, receipt, budget, minimumRowsByPath = new Map()) {
|
|
79
90
|
const stringCompactionState = { compacted: false };
|
|
80
91
|
const compacted = compactStrings(result, stringCompactionState);
|
|
81
92
|
receipt.strings_compacted = stringCompactionState.compacted;
|
|
82
93
|
compacted.read_output = receipt;
|
|
83
|
-
compactRowsToBudget(compacted, receipt, budget);
|
|
94
|
+
compactRowsToBudget(compacted, receipt, budget, minimumRowsByPath);
|
|
84
95
|
updateReadOutputReceiptEstimate(compacted, receipt);
|
|
85
96
|
return compacted;
|
|
86
97
|
}
|
|
87
98
|
//# sourceMappingURL=read-output-budget.js.map
|
|
88
|
-
//# debugId=
|
|
99
|
+
//# debugId=737ac274-c165-5d1a-8b8e-cb5d57a81c46
|