@caupulican/pi-adaptative 0.86.17 → 0.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -15
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -16
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +4 -4
- package/dist/core/agent-session.d.ts +23 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +76 -109
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +16 -0
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +2 -1
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +2 -18
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-tool-task-controller.js +5 -5
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +22 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +75 -39
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/context/brain-curator.d.ts +2 -3
- package/dist/core/context/brain-curator.d.ts.map +1 -1
- package/dist/core/context/brain-curator.js +3 -20
- package/dist/core/context/brain-curator.js.map +1 -1
- package/dist/core/context/context-composition.d.ts +2 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js +6 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/memory-prompt-block.js +1 -1
- package/dist/core/context/memory-prompt-block.js.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.js +10 -10
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +4 -4
- package/dist/core/context-pipeline.js +4 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts +2 -2
- package/dist/core/delegation/session-worker-claim.js +2 -2
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.js +3 -3
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +2 -13
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +5 -67
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/extensions/builtin.js +4 -4
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +21 -9
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +2 -2
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +13 -9
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +1 -1
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/human-input-controller.js +1 -1
- package/dist/core/human-input-controller.js.map +1 -1
- package/dist/core/improvement-loop.js +13 -13
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +2 -1
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +4 -24
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -1
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-router/route-judge.d.ts +2 -1
- package/dist/core/model-router/route-judge.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.js +4 -12
- package/dist/core/model-router/route-judge.js.map +1 -1
- package/dist/core/models/perf-profile.d.ts +1 -1
- package/dist/core/models/perf-profile.d.ts.map +1 -1
- package/dist/core/models/perf-profile.js +2 -8
- package/dist/core/models/perf-profile.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +1 -6
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.js +3 -3
- package/dist/core/process-matrix/resume-launcher.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +2 -0
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +23 -19
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +34 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -0
- package/dist/core/provider-prompt-contracts.js +133 -0
- package/dist/core/provider-prompt-contracts.js.map +1 -0
- package/dist/core/provider-request-context-controller.d.ts +40 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -0
- package/dist/core/provider-request-context-controller.js +68 -0
- package/dist/core/provider-request-context-controller.js.map +1 -0
- package/dist/core/provider-request-runtime-controller.d.ts +22 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -0
- package/dist/core/provider-request-runtime-controller.js +87 -0
- package/dist/core/provider-request-runtime-controller.js.map +1 -0
- package/dist/core/provider-tool-text.d.ts +7 -0
- package/dist/core/provider-tool-text.d.ts.map +1 -0
- package/dist/core/provider-tool-text.js +42 -0
- package/dist/core/provider-tool-text.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +2 -5
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +2 -20
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -1
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +6 -21
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +9 -1
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +3 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +20 -25
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +2 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +2 -16
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +6 -6
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +11 -1
- package/dist/core/secrets/credential-manager.d.ts.map +1 -1
- package/dist/core/secrets/credential-manager.js +28 -7
- package/dist/core/secrets/credential-manager.js.map +1 -1
- package/dist/core/secrets/credential-migration-source.d.ts +20 -0
- package/dist/core/secrets/credential-migration-source.d.ts.map +1 -0
- package/dist/core/secrets/credential-migration-source.js +113 -0
- package/dist/core/secrets/credential-migration-source.js.map +1 -0
- package/dist/core/secrets/credential-session-connection.d.ts +9 -0
- package/dist/core/secrets/credential-session-connection.d.ts.map +1 -0
- package/dist/core/secrets/credential-session-connection.js +39 -0
- package/dist/core/secrets/credential-session-connection.js.map +1 -0
- package/dist/core/security/untrusted-boundary.d.ts +2 -2
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +3 -10
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -2
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/skill-vault.d.ts +98 -0
- package/dist/core/skill-vault.d.ts.map +1 -0
- package/dist/core/skill-vault.js +270 -0
- package/dist/core/skill-vault.js.map +1 -0
- package/dist/core/skills.d.ts +10 -9
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +42 -50
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +1 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +20 -60
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts +4 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +87 -121
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +6 -7
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js +4 -7
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-selection/promotion.d.ts.map +1 -1
- package/dist/core/tool-selection/promotion.js +2 -6
- package/dist/core/tool-selection/promotion.js.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts +2 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.js +2 -14
- package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
- package/dist/core/tools/ask-question.js +6 -6
- package/dist/core/tools/ask-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +17 -13
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +111 -226
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -2
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +149 -48
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.js +4 -4
- package/dist/core/tools/extensionify-runtime.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.js +3 -3
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.js +2 -2
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.js +4 -4
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +30 -16
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +98 -59
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/python.js +6 -6
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/run-process.js +4 -4
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +4 -4
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +32 -3
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +141 -34
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/skill.d.ts +29 -0
- package/dist/core/tools/skill.d.ts.map +1 -0
- package/dist/core/tools/skill.js +79 -0
- package/dist/core/tools/skill.js.map +1 -0
- package/dist/core/tools/task-steps.js +4 -4
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/worktree-sync.js +6 -6
- package/dist/core/tools/worktree-sync.js.map +1 -1
- package/dist/core/tools/write.js +3 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.js +2 -18
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +1 -1
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/compaction.md +45 -25
- package/docs/extensions.md +23 -7
- package/docs/settings.md +3 -3
- package/docs/skills.md +14 -10
- package/docs/task-steps.md +2 -2
- package/docs/tmux-agent-manager.md +1 -1
- package/docs/tool-repair.md +18 -1
- package/docs/usage.md +4 -2
- package/docs/worker-profiles.md +3 -3
- package/docs/worktree-sync.md +2 -2
- package/examples/extensions/custom-compaction.ts +5 -17
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -5
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/util/json-size.d.ts +0 -3
- package/dist/core/util/json-size.d.ts.map +0 -1
- package/dist/core/util/json-size.js +0 -95
- package/dist/core/util/json-size.js.map +0 -1
package/docs/skills.md
CHANGED
|
@@ -50,7 +50,7 @@ Unload specific skills with settings filters. Put user-wide filters in `~/.pi/ag
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
The existing `skills` array also accepts resource patterns: plain entries include local files/directories, `!pattern` excludes matching auto-discovered resources, `+path` force-includes an exact path, and `-path` force-excludes an exact path. `disabledResources.skills` is the explicit reversible unload form. It removes matching skills from
|
|
53
|
+
The existing `skills` array also accepts resource patterns: plain entries include local files/directories, `!pattern` excludes matching auto-discovered resources, `+path` force-includes an exact path, and `-path` force-excludes an exact path. `disabledResources.skills` is the explicit reversible unload form. It removes matching skills from vault search and skill commands after reload; an active skill is invalidated before another request can use it.
|
|
54
54
|
|
|
55
55
|
### Using Skills from Other Harnesses
|
|
56
56
|
|
|
@@ -75,14 +75,18 @@ For project-level Claude Code skills, add to `.pi/settings.json`:
|
|
|
75
75
|
|
|
76
76
|
## How Skills Work
|
|
77
77
|
|
|
78
|
-
1. At startup,
|
|
79
|
-
2.
|
|
80
|
-
3.
|
|
81
|
-
4. The
|
|
78
|
+
1. At startup, Pi reads a bounded frontmatter prefix from each skill. It retains routing metadata, not the body.
|
|
79
|
+
2. When the `skill` tool is active, the stable system prompt carries one brief rule: search the vault if, and only if, specialist focus would help. It contains no skill catalog, paths, bodies, or XML wrappers.
|
|
80
|
+
3. The agent searches metadata with `skill { action: "search", query: "..." }`, then loads an exact name. `/skill:name` performs the same load when the user selects a skill explicitly.
|
|
81
|
+
4. The host keeps one loaded skill. It appends that body as a hidden, request-local message after normal context processing; it never writes the body into session history or concatenates it into the system prompt.
|
|
82
|
+
5. The host moves the skill from `loaded_pending` to `active` on the first provider request. It records monotonic time on provider projections, completed model turns, tool execution; invalidates changed or profile-blocked resources; expires ten minutes of observed inactivity before the next host event. No polling timer runs.
|
|
83
|
+
6. Loading another skill replaces the current one. Explicit unload is optional; host expiry and invalidation do not depend on model cooperation.
|
|
82
84
|
|
|
83
|
-
This is progressive disclosure:
|
|
85
|
+
This is progressive disclosure: the reminder and compact tool schema are stable, searches return at most a bounded name/description list, only one selected body enters a request.
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
Descriptions are the routing contract. Write narrow descriptions so metadata search can select the most task-specific skill. The `/context` dashboard includes the active request-local body in its estimate without refreshing the skill's activity clock.
|
|
88
|
+
|
|
89
|
+
Compaction never serializes an active skill body into history or a summary. Provider admission treats it as mandatory request-local context, compacts durable history around it, then re-injects it from the host vault on the replanned request. If the fixed envelope still cannot fit, Pi reports an explicit overflow instead of truncating or dropping the skill. Skill-vault state is in memory: `/new`, `/resume`, `/fork`, or a process restart starts a new unloaded vault. `/reload` retains an unchanged eligible skill and invalidates it if the resource changed or became unavailable.
|
|
86
90
|
|
|
87
91
|
Skills may carry optional resource profile blocks:
|
|
88
92
|
|
|
@@ -92,7 +96,7 @@ Skills may carry optional resource profile blocks:
|
|
|
92
96
|
</resource-profile>
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
These blocks are JSON config, not instructions. Pi parses only matching profile blocks and strips them from
|
|
99
|
+
These blocks are JSON config, not instructions. Pi parses only matching profile blocks and strips them from every vault activation.
|
|
96
100
|
|
|
97
101
|
## Skill Commands
|
|
98
102
|
|
|
@@ -103,7 +107,7 @@ Skills register as `/skill:name` commands:
|
|
|
103
107
|
/skill:pdf-tools extract # Load skill with arguments
|
|
104
108
|
```
|
|
105
109
|
|
|
106
|
-
Arguments after the command
|
|
110
|
+
Arguments after the command remain the user request. The selected body is injected separately and request-locally.
|
|
107
111
|
|
|
108
112
|
Toggle skill commands via `/settings` in interactive mode or in `settings.json`:
|
|
109
113
|
|
|
@@ -170,7 +174,7 @@ Per the [Agent Skills specification](https://agentskills.io/specification#frontm
|
|
|
170
174
|
| `compatibility` | No | Max 500 chars. Environment requirements. |
|
|
171
175
|
| `metadata` | No | Arbitrary key-value mapping. |
|
|
172
176
|
| `allowed-tools` | No | Space-delimited list of pre-approved tools (experimental). |
|
|
173
|
-
| `disable-model-invocation` | No | When `true`, skill is hidden from
|
|
177
|
+
| `disable-model-invocation` | No | When `true`, skill is hidden from model search and cannot be model-loaded. Users may still use `/skill:name`. For full project/user unload, prefer `disabledResources.skills` in settings. |
|
|
174
178
|
|
|
175
179
|
### Name Rules
|
|
176
180
|
|
package/docs/task-steps.md
CHANGED
|
@@ -6,7 +6,7 @@ Task steps complement the native goal and delegation systems:
|
|
|
6
6
|
|
|
7
7
|
- `task_steps` tracks the current execution checklist.
|
|
8
8
|
- `goal` records durable outcome requirements and evidence.
|
|
9
|
-
- `delegate` starts
|
|
9
|
+
- `delegate` starts worker lanes, retrieves status, reviews claims, and coordinates them.
|
|
10
10
|
|
|
11
11
|
## Statuses
|
|
12
12
|
|
|
@@ -79,7 +79,7 @@ Use `/task` or its `/steps` alias:
|
|
|
79
79
|
|
|
80
80
|
## Background work migration
|
|
81
81
|
|
|
82
|
-
The old user-level task-steps extension also implemented detached jobs, teams, and polling. Those duplicate execution commands are not part of the native checklist. `/task run`, `/task route`, `/task bg`, and `/task team` now point to Pi's session-owned `delegate`
|
|
82
|
+
The old user-level task-steps extension also implemented detached jobs, teams, and polling. Those duplicate execution commands are not part of the native checklist. `/task run`, `/task route`, `/task bg`, and `/task team` now point to Pi's session-owned `delegate` tool instead.
|
|
83
83
|
|
|
84
84
|
Native worker lanes emit terminal handoff notifications and retain bounded results for explicit retrieval; task steps do not poll worker processes or inspect logs to detect completion.
|
|
85
85
|
|
|
@@ -97,7 +97,7 @@ self-reported worker usage are **advisory** — a claim to review, never a hard
|
|
|
97
97
|
boundary (the child bills under its own authentication).
|
|
98
98
|
|
|
99
99
|
Dispatched tmux workers appear as `tmux-worker` lanes alongside in-process worker lanes in `/autonomy`
|
|
100
|
-
and `
|
|
100
|
+
and `delegate { action: "status" }`; a worker's self-reported changed files are re-checked against the session's active
|
|
101
101
|
write scope and flagged for parent review when out of scope, exactly like an in-process worker's.
|
|
102
102
|
|
|
103
103
|
## Goal-bound dispatch (`goal dispatch_worker dispatchTarget:"tmux"`)
|
package/docs/tool-repair.md
CHANGED
|
@@ -2,12 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Pi validates every model-emitted tool call against its TypeBox schema before execution. Valid calls run unchanged. Invalid calls either pass through a named deterministic repair and then execute with the repaired arguments, or they bounce with schema feedback when no safe repair applies.
|
|
4
4
|
|
|
5
|
-
Execution failures are not argument repairs. Pi removes their potentially large failed protocol turns from provider context and normally retains one bounded failure record: constant-size operation fingerprint, bounded operation preview, occurrence count, failure code, a cause-bearing diagnostic when available, and `next_action`. A matching successful retry clears the record. Change-approach classes such as non-UTF-8 text edits are different: Pi discards the complete attempted operation, exposes one bounded reason/directive for the next assistant response, then expires it. Pi uses `repair` only for argument/protocol rejections with a concrete call correction; policy, preflight, abort, and execution failures use `next_action`. It never invents a deterministic repair from an unknown nonzero exit.
|
|
5
|
+
Execution failures are not argument repairs. Pi removes their potentially large failed protocol turns from provider context and normally retains one bounded failure record: constant-size operation fingerprint, bounded operation preview, occurrence count, failure code, a cause-bearing diagnostic when available, and `next_action`. Every retained record carries `"MUST":true`; the provider receives one canonical `mandatory_tool_failure_recovery_protocol` template explaining that `repair` or `next_action` is an execution constraint, unchanged retries are gated, and unrelated argument changes are not recovery. A matching successful retry clears the record. Change-approach classes such as non-UTF-8 text edits are different: Pi discards the complete attempted operation, exposes one bounded reason/directive for the next assistant response, then expires it. Pi uses `repair` only for argument/protocol rejections with a concrete call correction; policy, preflight, abort, and execution failures use `next_action`. It never invents a deterministic repair from an unknown nonzero exit.
|
|
6
|
+
|
|
7
|
+
Canonical execution-failure template:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"MUST": true,
|
|
12
|
+
"failure_key": "<bounded operation identity>",
|
|
13
|
+
"state": "failed",
|
|
14
|
+
"phase": "execution",
|
|
15
|
+
"tool": "<tool name>",
|
|
16
|
+
"failure_code": "<classified cause>",
|
|
17
|
+
"diagnostic": "<bounded cause-bearing detail>",
|
|
18
|
+
"next_action": "<mandatory capability-backed recovery or blocker delivery>"
|
|
19
|
+
}
|
|
20
|
+
```
|
|
6
21
|
|
|
7
22
|
## Runtime behavior
|
|
8
23
|
|
|
9
24
|
- The shared validation choke point is `validateToolArguments` in `packages/ai/src/utils/validation.ts`.
|
|
10
25
|
- Repair is validate-then-repair: schema-valid arguments are returned unchanged; only invalid arguments enter the repair layer.
|
|
26
|
+
- Recovery exhaustion opens the run-scoped circuit, disables tools, and permits exactly one provider delivery turn. A tool call emitted despite that empty tool surface is paired with a rejected result without running hooks or tool code, followed by a deterministic blocker delivery.
|
|
11
27
|
- Repair is built-in and has no settings toggle. `PI_TOOL_REPAIR_DISABLED=1` is only an emergency diagnostic kill switch; normal configuration should leave repair on.
|
|
12
28
|
- Teaching can be disabled independently with `toolRepair.teach: false` or `PI_TOOL_REPAIR_TEACH_DISABLED=1`. Repairs can still execute; the in-band "Tool argument repair note" is suppressed.
|
|
13
29
|
- Tool-recovery logging can be disabled with `toolRepair.logging: false`. Repairs still run, but Pi does not enqueue recovery records or spawn the background recovery-log worker.
|
|
@@ -83,6 +99,7 @@ Confirmed against current source:
|
|
|
83
99
|
- Repair mode names and standing-rule text: `packages/ai/src/utils/tool-repair/registry.ts`.
|
|
84
100
|
- Agent repair event metadata and teach-note gate: `packages/agent/src/types.ts`, `packages/agent/src/agent-loop.ts`.
|
|
85
101
|
- Bounded execution-failure assessment and retry memory: `packages/agent/src/tool-failure-memory.ts`.
|
|
102
|
+
- Mandatory recovery template and terminal-delivery prompt: `packages/agent/src/tool-failure-recovery-protocol.ts`.
|
|
86
103
|
- Interactive marker: `packages/coding-agent/src/modes/interactive/components/tool-execution.ts`.
|
|
87
104
|
- Settings/env kill switches: `packages/coding-agent/src/core/settings-manager.ts`, `packages/coding-agent/src/core/tool-repair-settings.ts`.
|
|
88
105
|
- Health, tool probing, rule removal, and protocol reset: `packages/coding-agent/src/core/tool-repair-health.ts`, `packages/coding-agent/src/core/models/adaptation-store.ts`, `packages/coding-agent/src/core/slash-commands.ts`, `packages/coding-agent/src/modes/interactive/interactive-mode.ts`, `packages/coding-agent/src/modes/rpc/rpc-mode.ts`.
|
package/docs/usage.md
CHANGED
|
@@ -47,11 +47,13 @@ Native task steps and worker agents share the same compact work panel. Steps and
|
|
|
47
47
|
|
|
48
48
|
### Secret Store
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
The only Pi-side Bitwarden setup input is a `BW_SESSION` key. When a TUI credential action needs it, Pi opens one masked prompt; paste the key there and the agent continues the activation or migration itself. `/secrets` uses the same prompt for manual profile management. Pi provisions its pinned [Bitwarden Password Manager CLI](https://bitwarden.com/help/cli/) (`bw`) automatically when no system installation is available. Generate the key with `bw unlock --raw` after signing in to Bitwarden. Pi keeps it in memory for the current session; it is never placed in model context or passed to model-controlled processes.
|
|
51
51
|
|
|
52
52
|
The private menu accepts username/password pairs, a pasted token or private key, a dropped absolute key-file path, or multiple variables in dotenv syntax. Pi stores the profile as an encrypted Bitwarden item and writes no local vault or project dotenv. A normalized Git-origin identity binds the profile to the project, so another clone on a synced machine detects the same binding. Repositories without a portable origin use a machine-local opaque project identity. An existing profile can be explicitly bound to additional projects on the same machine.
|
|
53
53
|
|
|
54
|
-
The model-facing `secret_store` tool can
|
|
54
|
+
The model-facing `secret_store` tool can inspect non-secret profile metadata, activate a profile already authorized for the current project, and migrate model-blind credential sources. Activation works without a live TUI in interactive, print, and RPC modes when that Pi process has a valid `BW_SESSION`. Values are injected in memory into Bash, Python, and allowlisted `run_process` variables; exact values are redacted from tool results and owner-shell transcripts. Locking or exiting clears the active environment and session key. This is a model-facing boundary, not an OS sandbox: code intentionally given process or network authority can use an activated credential through its consuming application.
|
|
55
|
+
|
|
56
|
+
In a user-plane session with credential capability, the agent can also migrate credentials it can already access by naming an environment variable, dotenv file, or credential/key file through `secret_store migrate`. The host reads those sources and writes the encrypted profile directly; values never enter tool arguments, model context, or tool results. Migration activates the profile for the current project and retains source files so existing consumers are not silently broken. Replacing an existing profile requires an explicit `overwrite` flag. If the Bitwarden session is missing or stale, the only owner input Pi requests is a fresh `BW_SESSION` key through the masked prompt; filesystem/process authority cannot manufacture vault authority.
|
|
55
57
|
|
|
56
58
|
## Slash Commands
|
|
57
59
|
|
package/docs/worker-profiles.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Native delegation does not require a profile. `delegate.authority` can choose a child model, reasoning level, role label, classified tools, capabilities, paths, and budget directly. Omitted fields inherit from the caller, and Pi persists the resulting immutable execution grant.
|
|
4
4
|
|
|
5
|
-
`
|
|
5
|
+
`delegate` profile actions remain useful when the foreground orchestrator wants a reusable session-scoped preset. They do not edit user or project profile files. Task presets are:
|
|
6
6
|
|
|
7
7
|
- Derived only from an owner-authorized base profile.
|
|
8
8
|
- Immutable and assigned a `task-...` ID by Pi.
|
|
@@ -11,9 +11,9 @@ Native delegation does not require a profile. `delegate.authority` can choose a
|
|
|
11
11
|
- Unable to add tools, resources, or budget beyond the base profile.
|
|
12
12
|
- Limited to configured, authenticated, non-exhausted models and a reasoning level that model supports.
|
|
13
13
|
|
|
14
|
-
Use `
|
|
14
|
+
Use `delegate { action: "profile_inspect" }` when the reusable bases or model combinations are unknown. Then call `profile_create` with a concise task and only the defaults worth preserving. Pass the returned profile ID unchanged to `delegate start`; never invent one.
|
|
15
15
|
|
|
16
|
-
Worker agents do not
|
|
16
|
+
Worker agents do not receive the root-only profile/status actions. They receive `delegate` only when their admitted tool set and capability ceiling both retain delegation; a caller can create a non-delegating leaf by narrowing either field. Delegating workers may recursively create descendants within the fixed depth, direct-child, session-agent, and queue bounds. They can discover safe session-peer metadata, exchange non-waking threaded messages and bounded broadcasts, and use event-driven `wait`/`wait_many`, but bounded transcript reads and waking controls remain limited to the caller's own control subtree. Transcript cursors address raw session entries, so a continuation page may be empty after non-message entries; an individually oversized message is omitted with a count instead of being truncated. A descendant may vary model or role through another preset, but it cannot acquire new resources: pointers must fully match the ancestor's admitted pointer metadata, soul text must match exactly, and verifier resources and authority stay within the ancestral verifier or worker boundary.
|
|
17
17
|
|
|
18
18
|
New agents may receive immutable sanitized birth context with `forkTurns: "none"`, `"all"`, or a positive user-turn count such as `"3"`. Omission inherits all bounded complete turns only for the exact same provider and model. Crossing either provider or model defaults to no inherited turns, and an explicit non-`none` cross-boundary fork is rejected. Tool calls/results, reasoning/commentary, system/developer/custom messages, mailbox controls, non-text content, and incomplete assistant output never enter the snapshot. Dispatching another task with an existing `agentId` reuses that agent's durable transcript and cannot replace its birth context.
|
|
19
19
|
|
package/docs/worktree-sync.md
CHANGED
|
@@ -164,12 +164,12 @@ environment value a lane-bound process can set to shed the worker ceiling below.
|
|
|
164
164
|
|
|
165
165
|
### Forbidden-tool ceiling
|
|
166
166
|
|
|
167
|
-
A worker session can never activate: `goal`, `delegate`, `
|
|
167
|
+
A worker session can never activate: `goal`, `delegate`, `improvement_loop`,
|
|
168
168
|
`extensionify`, `skillify`, `run_toolkit_script`, `model_fitness`, `tmux_agent_manager`,
|
|
169
169
|
`context_scout`, `python`. This is enforced as the FIRST line of the tool registry's allow
|
|
170
170
|
predicate (`RuntimeBuilder.refreshToolRegistry`'s `isAllowedTool`) -- it wins over an allow-list,
|
|
171
171
|
an exclude-list, or an active resource profile that names the tool explicitly. `goal`/`delegate`/
|
|
172
|
-
`
|
|
172
|
+
`tmux_agent_manager` are sub-orchestration (a worker dispatching its own workers
|
|
173
173
|
defeats single-owner lane accountability); `improvement_loop`/`extensionify`/`skillify` are
|
|
174
174
|
self-adaptation surface a worker should never mutate; `run_toolkit_script`/`model_fitness` spend
|
|
175
175
|
budget a worker's dispatcher does not control. **`python`** is included because it is a bounded but
|
|
@@ -53,9 +53,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
53
53
|
// Convert messages to readable text format
|
|
54
54
|
const conversationText = serializeConversation(convertToLlm(allMessages));
|
|
55
55
|
|
|
56
|
-
// Include previous summary context if available
|
|
57
|
-
const previousContext = previousSummary ? `\n\nPrevious session summary for context:\n${previousSummary}` : "";
|
|
58
|
-
|
|
59
56
|
// Build messages that ask for a comprehensive summary
|
|
60
57
|
const summaryMessages = [
|
|
61
58
|
{
|
|
@@ -63,22 +60,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
63
60
|
content: [
|
|
64
61
|
{
|
|
65
62
|
type: "text" as const,
|
|
66
|
-
text: `
|
|
67
|
-
|
|
68
|
-
1. The main goals and objectives discussed
|
|
69
|
-
2. Key decisions made and their rationale
|
|
70
|
-
3. Important code changes, file modifications, or technical details
|
|
71
|
-
4. Current state of any ongoing work
|
|
72
|
-
5. Any blockers, issues, or open questions
|
|
73
|
-
6. Next steps that were planned or suggested
|
|
74
|
-
|
|
75
|
-
Be thorough but concise. The summary will replace the ENTIRE conversation history, so include all information needed to continue the work effectively.
|
|
63
|
+
text: `Create complete replacement checkpoint. Preserve goals, mandatory rules, decisions/rationale, code/file details, current state, blockers/open questions, next steps. Omit resolved/transient noise. Structured Markdown, concise but sufficient to resume.
|
|
76
64
|
|
|
77
|
-
|
|
65
|
+
OLD CHECKPOINT
|
|
66
|
+
${previousSummary ?? "(none)"}
|
|
78
67
|
|
|
79
|
-
|
|
80
|
-
${conversationText}
|
|
81
|
-
</conversation>`,
|
|
68
|
+
CHAT
|
|
69
|
+
${conversationText}`,
|
|
82
70
|
},
|
|
83
71
|
],
|
|
84
72
|
timestamp: Date.now(),
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-custom-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-custom-provider",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.90.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-sandbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-sandbox",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.90.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sandbox-runtime": "^0.0.26"
|
|
12
12
|
}
|
|
@@ -105,13 +105,11 @@ const buildConversationText = (entries: SessionEntry[]): string => {
|
|
|
105
105
|
|
|
106
106
|
const buildSummaryPrompt = (conversationText: string): string =>
|
|
107
107
|
[
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"Keep it concise and structured with headings.",
|
|
108
|
+
"Create concise structured checkpoint for later resume.",
|
|
109
|
+
"Keep goals, mandatory rules, decisions, progress, open questions, next steps.",
|
|
111
110
|
"",
|
|
112
|
-
"
|
|
111
|
+
"CHAT",
|
|
113
112
|
conversationText,
|
|
114
|
-
"</conversation>",
|
|
115
113
|
].join("\n");
|
|
116
114
|
|
|
117
115
|
const showSummaryUi = async (summary: string, ctx: ExtensionCommandContext) => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.90.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-adaptative",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@caupulican/pi-adaptative",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.90.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@caupulican/pi-agent-core": "^0.
|
|
13
|
-
"@caupulican/pi-ai": "^0.
|
|
14
|
-
"@caupulican/pi-tui": "^0.
|
|
12
|
+
"@caupulican/pi-agent-core": "^0.90.0",
|
|
13
|
+
"@caupulican/pi-ai": "^0.90.0",
|
|
14
|
+
"@caupulican/pi-tui": "^0.90.0",
|
|
15
15
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
16
16
|
"chalk": "5.6.2",
|
|
17
17
|
"cross-spawn": "7.0.6",
|
|
@@ -547,11 +547,11 @@
|
|
|
547
547
|
}
|
|
548
548
|
},
|
|
549
549
|
"node_modules/@caupulican/pi-agent-core": {
|
|
550
|
-
"version": "0.
|
|
551
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.
|
|
550
|
+
"version": "0.90.0",
|
|
551
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-agent-core/-/pi-agent-core-0.90.0.tgz",
|
|
552
552
|
"license": "MIT",
|
|
553
553
|
"dependencies": {
|
|
554
|
-
"@caupulican/pi-ai": "^0.
|
|
554
|
+
"@caupulican/pi-ai": "^0.90.0",
|
|
555
555
|
"ignore": "7.0.5",
|
|
556
556
|
"typebox": "1.1.38",
|
|
557
557
|
"yaml": "2.9.0"
|
|
@@ -561,8 +561,8 @@
|
|
|
561
561
|
}
|
|
562
562
|
},
|
|
563
563
|
"node_modules/@caupulican/pi-ai": {
|
|
564
|
-
"version": "0.
|
|
565
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.
|
|
564
|
+
"version": "0.90.0",
|
|
565
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-ai/-/pi-ai-0.90.0.tgz",
|
|
566
566
|
"license": "MIT",
|
|
567
567
|
"dependencies": {
|
|
568
568
|
"@anthropic-ai/sdk": "0.91.1",
|
|
@@ -616,8 +616,8 @@
|
|
|
616
616
|
}
|
|
617
617
|
},
|
|
618
618
|
"node_modules/@caupulican/pi-tui": {
|
|
619
|
-
"version": "0.
|
|
620
|
-
"resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.
|
|
619
|
+
"version": "0.90.0",
|
|
620
|
+
"resolved": "https://registry.npmjs.org/@caupulican/pi-tui/-/pi-tui-0.90.0.tgz",
|
|
621
621
|
"license": "MIT",
|
|
622
622
|
"dependencies": {
|
|
623
623
|
"get-east-asian-width": "1.6.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-adaptative",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.0",
|
|
4
4
|
"description": "Adaptive fork of Pi coding agent for self-evolving agent harness experiments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"postinstall": "node scripts/postinstall-python-runtime.mjs"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@caupulican/pi-agent-core": "^0.
|
|
88
|
-
"@caupulican/pi-ai": "^0.
|
|
89
|
-
"@caupulican/pi-tui": "^0.
|
|
87
|
+
"@caupulican/pi-agent-core": "^0.90.0",
|
|
88
|
+
"@caupulican/pi-ai": "^0.90.0",
|
|
89
|
+
"@caupulican/pi-tui": "^0.90.0",
|
|
90
90
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
91
91
|
"chalk": "5.6.2",
|
|
92
92
|
"cross-spawn": "7.0.6",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-size.d.ts","sourceRoot":"","sources":["../../../src/core/util/json-size.ts"],"names":[],"mappings":"AAsFA,wGAAwG;AACxG,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEpE"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
function jsonStringLength(value) {
|
|
2
|
-
let length = 2;
|
|
3
|
-
for (let index = 0; index < value.length; index++) {
|
|
4
|
-
const code = value.charCodeAt(index);
|
|
5
|
-
if (code === 0x22 ||
|
|
6
|
-
code === 0x5c ||
|
|
7
|
-
code === 0x08 ||
|
|
8
|
-
code === 0x09 ||
|
|
9
|
-
code === 0x0a ||
|
|
10
|
-
code === 0x0c ||
|
|
11
|
-
code === 0x0d) {
|
|
12
|
-
length += 2;
|
|
13
|
-
}
|
|
14
|
-
else if (code < 0x20) {
|
|
15
|
-
length += 6;
|
|
16
|
-
}
|
|
17
|
-
else if (code >= 0xd800 && code <= 0xdbff) {
|
|
18
|
-
const next = value.charCodeAt(index + 1);
|
|
19
|
-
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
20
|
-
length += 2;
|
|
21
|
-
index++;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
length += 6;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
28
|
-
length += 6;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
length++;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return length;
|
|
35
|
-
}
|
|
36
|
-
function measuredJsonValue(value, key, active) {
|
|
37
|
-
if (typeof value === "object" && value !== null) {
|
|
38
|
-
const toJSON = Reflect.get(value, "toJSON");
|
|
39
|
-
if (typeof toJSON === "function")
|
|
40
|
-
value = Reflect.apply(toJSON, value, [key]);
|
|
41
|
-
}
|
|
42
|
-
switch (typeof value) {
|
|
43
|
-
case "string":
|
|
44
|
-
return jsonStringLength(value);
|
|
45
|
-
case "number":
|
|
46
|
-
return Number.isFinite(value) ? (Object.is(value, -0) ? 1 : String(value).length) : 4;
|
|
47
|
-
case "boolean":
|
|
48
|
-
return value ? 4 : 5;
|
|
49
|
-
case "bigint":
|
|
50
|
-
throw new TypeError("Do not know how to serialize a BigInt");
|
|
51
|
-
case "undefined":
|
|
52
|
-
case "function":
|
|
53
|
-
case "symbol":
|
|
54
|
-
return undefined;
|
|
55
|
-
case "object":
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
if (value === null)
|
|
59
|
-
return 4;
|
|
60
|
-
if (value instanceof String || value instanceof Number || value instanceof Boolean) {
|
|
61
|
-
return measuredJsonValue(value.valueOf(), key, active);
|
|
62
|
-
}
|
|
63
|
-
if (active.has(value))
|
|
64
|
-
throw new TypeError("Converting circular structure to JSON");
|
|
65
|
-
active.add(value);
|
|
66
|
-
try {
|
|
67
|
-
if (Array.isArray(value)) {
|
|
68
|
-
let length = 2 + Math.max(0, value.length - 1);
|
|
69
|
-
for (let index = 0; index < value.length; index++) {
|
|
70
|
-
length += measuredJsonValue(value[index], String(index), active) ?? 4;
|
|
71
|
-
}
|
|
72
|
-
return length;
|
|
73
|
-
}
|
|
74
|
-
let length = 2;
|
|
75
|
-
let fields = 0;
|
|
76
|
-
for (const field of Object.keys(value)) {
|
|
77
|
-
const fieldLength = measuredJsonValue(Reflect.get(value, field), field, active);
|
|
78
|
-
if (fieldLength === undefined)
|
|
79
|
-
continue;
|
|
80
|
-
if (fields > 0)
|
|
81
|
-
length++;
|
|
82
|
-
length += jsonStringLength(field) + 1 + fieldLength;
|
|
83
|
-
fields++;
|
|
84
|
-
}
|
|
85
|
-
return length;
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
active.delete(value);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/** Exact UTF-16 length of standard JSON-compatible data without constructing the serialized payload. */
|
|
92
|
-
export function measureJsonLength(value) {
|
|
93
|
-
return measuredJsonValue(value, "", new Set());
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=json-size.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json-size.js","sourceRoot":"","sources":["../../../src/core/util/json-size.ts"],"names":[],"mappings":"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","sourcesContent":["function jsonStringLength(value: string): number {\n\tlet length = 2;\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst code = value.charCodeAt(index);\n\t\tif (\n\t\t\tcode === 0x22 ||\n\t\t\tcode === 0x5c ||\n\t\t\tcode === 0x08 ||\n\t\t\tcode === 0x09 ||\n\t\t\tcode === 0x0a ||\n\t\t\tcode === 0x0c ||\n\t\t\tcode === 0x0d\n\t\t) {\n\t\t\tlength += 2;\n\t\t} else if (code < 0x20) {\n\t\t\tlength += 6;\n\t\t} else if (code >= 0xd800 && code <= 0xdbff) {\n\t\t\tconst next = value.charCodeAt(index + 1);\n\t\t\tif (next >= 0xdc00 && next <= 0xdfff) {\n\t\t\t\tlength += 2;\n\t\t\t\tindex++;\n\t\t\t} else {\n\t\t\t\tlength += 6;\n\t\t\t}\n\t\t} else if (code >= 0xdc00 && code <= 0xdfff) {\n\t\t\tlength += 6;\n\t\t} else {\n\t\t\tlength++;\n\t\t}\n\t}\n\treturn length;\n}\n\nfunction measuredJsonValue(value: unknown, key: string, active: Set<object>): number | undefined {\n\tif (typeof value === \"object\" && value !== null) {\n\t\tconst toJSON = Reflect.get(value, \"toJSON\");\n\t\tif (typeof toJSON === \"function\") value = Reflect.apply(toJSON, value, [key]) as unknown;\n\t}\n\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\treturn jsonStringLength(value);\n\t\tcase \"number\":\n\t\t\treturn Number.isFinite(value) ? (Object.is(value, -0) ? 1 : String(value).length) : 4;\n\t\tcase \"boolean\":\n\t\t\treturn value ? 4 : 5;\n\t\tcase \"bigint\":\n\t\t\tthrow new TypeError(\"Do not know how to serialize a BigInt\");\n\t\tcase \"undefined\":\n\t\tcase \"function\":\n\t\tcase \"symbol\":\n\t\t\treturn undefined;\n\t\tcase \"object\":\n\t\t\tbreak;\n\t}\n\n\tif (value === null) return 4;\n\tif (value instanceof String || value instanceof Number || value instanceof Boolean) {\n\t\treturn measuredJsonValue(value.valueOf(), key, active);\n\t}\n\tif (active.has(value)) throw new TypeError(\"Converting circular structure to JSON\");\n\tactive.add(value);\n\ttry {\n\t\tif (Array.isArray(value)) {\n\t\t\tlet length = 2 + Math.max(0, value.length - 1);\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tlength += measuredJsonValue(value[index], String(index), active) ?? 4;\n\t\t\t}\n\t\t\treturn length;\n\t\t}\n\n\t\tlet length = 2;\n\t\tlet fields = 0;\n\t\tfor (const field of Object.keys(value)) {\n\t\t\tconst fieldLength = measuredJsonValue(Reflect.get(value, field), field, active);\n\t\t\tif (fieldLength === undefined) continue;\n\t\t\tif (fields > 0) length++;\n\t\t\tlength += jsonStringLength(field) + 1 + fieldLength;\n\t\t\tfields++;\n\t\t}\n\t\treturn length;\n\t} finally {\n\t\tactive.delete(value);\n\t}\n}\n\n/** Exact UTF-16 length of standard JSON-compatible data without constructing the serialized payload. */\nexport function measureJsonLength(value: unknown): number | undefined {\n\treturn measuredJsonValue(value, \"\", new Set());\n}\n"]}
|