@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38
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/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -2
- package/dist/admin/admin.module.js +9 -5
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +41 -0
- package/dist/admin/org-network.service.js +101 -0
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +54 -47
- package/dist/config/schema.js +198 -42
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/event-log.js +4 -1
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.d.ts +8 -1
- package/dist/ctx/create-ctx.js +13 -3
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +27 -6
- package/dist/devices/devices.service.js +2 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +10 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -4
- package/dist/extensions/host.js +14 -8
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +4 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/database/transaction-host.d.ts +32 -1
- package/dist/infra/database/transaction-host.js +30 -4
- package/dist/infra/database/xact-lock.d.ts +16 -0
- package/dist/infra/database/xact-lock.js +28 -1
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/net/public-address.d.ts +21 -1
- package/dist/net/public-address.js +56 -10
- package/dist/net/safe-fetch.d.ts +4 -1
- package/dist/net/safe-fetch.js +15 -4
- package/dist/orgs/directory-sync.js +2 -0
- package/dist/orgs/members.service.js +5 -0
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +9 -2
- package/dist/orgs/org-lock.d.ts +28 -2
- package/dist/orgs/org-lock.js +59 -4
- package/dist/orgs/orgs.controller.d.ts +11 -2
- package/dist/orgs/orgs.controller.js +19 -3
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +6 -2
- package/dist/orgs/orgs.schemas.d.ts +12 -0
- package/dist/orgs/orgs.schemas.js +5 -0
- package/dist/orgs/orgs.service.js +6 -1
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +7 -7
- package/dist/overrides.js +4 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +11 -3
- package/dist/platform/ops/orgs.ops.js +139 -5
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +7 -4
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +9 -3
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.d.ts +56 -3
- package/dist/runtime/run-execution.js +81 -11
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/step-log.d.ts +5 -0
- package/dist/runtime/step-log.js +9 -4
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/runtime/waits.js +3 -1
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connector-content.js +1 -0
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +65 -6
- package/dist/tools/drift.d.ts +6 -2
- package/dist/tools/drift.js +10 -5
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +17 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/src/migrations/0145_org_network_allowances.sql +12 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -5,8 +5,6 @@ import { planningBounds } from "./fit.js";
|
|
|
5
5
|
import { scheduleHeader, senderTranscriptLabel } from "./run-context.js";
|
|
6
6
|
import { estimateTokens } from "./tokens.js";
|
|
7
7
|
import { toolsChangedText } from "./tool-changes.js";
|
|
8
|
-
/** 压缩请求的标记:放在 system 中,便于识别(model-fake 据此返回摘要)。 */
|
|
9
|
-
export const COMPACTION_MARKER = "CAPYBARA_COMPACTION";
|
|
10
8
|
/**
|
|
11
9
|
* The summary request's output cap when the caller gives none: the built-in default of the
|
|
12
10
|
* `compaction.maxOutputTokens` setting (context compaction spec §4.8). The effective setting is
|
|
@@ -22,7 +20,6 @@ const MIN_SUMMARY_RATIO = 0.05;
|
|
|
22
20
|
* with nine sections; only the `<summary>` is stored and sent again in later requests.
|
|
23
21
|
*/
|
|
24
22
|
const COMPACTION_INSTRUCTION = [
|
|
25
|
-
COMPACTION_MARKER,
|
|
26
23
|
"You are summarizing the earlier part of a conversation between people and an AI agent, so the agent can continue without the full history.",
|
|
27
24
|
"If the transcript starts with an earlier summary, merge it into your summary.",
|
|
28
25
|
"Write in the same language as the conversation.",
|
|
@@ -201,7 +198,7 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
|
|
|
201
198
|
return [];
|
|
202
199
|
const first = sorted.find((e) => e.type === "model_call" && e.runId === runId && e.seq > start.seq);
|
|
203
200
|
const upTo = first?.type === "model_call"
|
|
204
|
-
? Math.min(first.payload.request.absorbedUpToSeq
|
|
201
|
+
? Math.min(first.payload.request.absorbedUpToSeq, first.seq)
|
|
205
202
|
: absorbedUpToSeq;
|
|
206
203
|
let floor = Number.NEGATIVE_INFINITY;
|
|
207
204
|
for (const e of sorted) {
|
|
@@ -210,7 +207,7 @@ export function openingSeqs(events, runId, coversUpToSeq, absorbedUpToSeq = Numb
|
|
|
210
207
|
if (e.type === "assistant_message")
|
|
211
208
|
floor = Math.max(floor, e.seq);
|
|
212
209
|
else if (e.type === "model_call") {
|
|
213
|
-
floor = Math.max(floor, e.payload.request.absorbedUpToSeq
|
|
210
|
+
floor = Math.max(floor, e.payload.request.absorbedUpToSeq);
|
|
214
211
|
}
|
|
215
212
|
}
|
|
216
213
|
return sorted
|
|
@@ -297,7 +294,7 @@ function transcriptLine(e) {
|
|
|
297
294
|
// scheduled tasks spec §12: the header the request shows, so the summary keeps the origin
|
|
298
295
|
const schedule = e.payload.schedule;
|
|
299
296
|
const text = schedule === undefined ? body : `${scheduleHeader(schedule)} ${body}`;
|
|
300
|
-
// run context spec §5: the sender as logged (
|
|
297
|
+
// run context spec §5: the sender as logged (a sub-agent task has none: unchanged)
|
|
301
298
|
const sender = e.payload.sender;
|
|
302
299
|
return sender !== undefined
|
|
303
300
|
? `User (${senderTranscriptLabel(sender)}): ${text}`
|
|
@@ -329,8 +326,44 @@ function transcriptLine(e) {
|
|
|
329
326
|
// stale names should not be summarised as current
|
|
330
327
|
case "tool_result":
|
|
331
328
|
return `Tool result ${e.payload.toolKey}${e.payload.isError ? " (error)" : ""}: ${e.payload.content}`;
|
|
332
|
-
|
|
329
|
+
// Every other event type is left out of the transcript: not model-visible, or re-rendered
|
|
330
|
+
// after the summary (build.ts). Adding an event type fails typecheck until it is listed.
|
|
331
|
+
case "model_call":
|
|
332
|
+
case "run_started":
|
|
333
|
+
case "usage":
|
|
334
|
+
case "device_paths":
|
|
335
|
+
case "project_root":
|
|
336
|
+
case "run_context":
|
|
337
|
+
case "plugin_context":
|
|
338
|
+
case "tool_call_started":
|
|
339
|
+
case "connection_required":
|
|
340
|
+
case "approval_requested":
|
|
341
|
+
case "approval_decided":
|
|
342
|
+
case "approval_updated":
|
|
343
|
+
case "question_asked":
|
|
344
|
+
case "question_answered":
|
|
345
|
+
case "media_excluded":
|
|
346
|
+
case "artifact_created":
|
|
347
|
+
case "skills_catalog":
|
|
348
|
+
case "hook_denied":
|
|
349
|
+
case "network_blocked":
|
|
350
|
+
case "device_code":
|
|
351
|
+
case "model_switched":
|
|
352
|
+
case "subagent_started":
|
|
353
|
+
case "subagent_dispatched":
|
|
354
|
+
case "subagent_waiting":
|
|
355
|
+
case "subagent_finished":
|
|
356
|
+
case "compaction_summary":
|
|
357
|
+
case "compaction_failed":
|
|
358
|
+
case "run_finished":
|
|
359
|
+
case "run_aborted":
|
|
360
|
+
case "run_failed":
|
|
333
361
|
return null;
|
|
362
|
+
default: {
|
|
363
|
+
const unrendered = e;
|
|
364
|
+
void unrendered;
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
334
367
|
}
|
|
335
368
|
}
|
|
336
369
|
/**
|
|
@@ -470,7 +503,7 @@ function splitLine(line, max) {
|
|
|
470
503
|
return pieces;
|
|
471
504
|
}
|
|
472
505
|
/**
|
|
473
|
-
* The summary request: the
|
|
506
|
+
* The summary request: the English instruction (request `purpose: "compaction"`) as the system prompt and the transcript as
|
|
474
507
|
* the only user message. `maxOutputTokens` is the effective `compaction.maxOutputTokens` setting,
|
|
475
508
|
* which the caller narrows to the model's own cap (context compaction spec §4.8); omitted, it is
|
|
476
509
|
* the built-in default.
|
|
@@ -488,6 +521,7 @@ export function buildCompactionRequest(transcript, model, maxOutputTokens = COMP
|
|
|
488
521
|
tools: [],
|
|
489
522
|
maxOutputTokens,
|
|
490
523
|
params: {},
|
|
524
|
+
purpose: "compaction",
|
|
491
525
|
};
|
|
492
526
|
}
|
|
493
527
|
/** Estimated input tokens of a plain text (a user message carries nothing else). */
|
|
@@ -104,8 +104,7 @@ export function runContextChange(prev, next) {
|
|
|
104
104
|
}
|
|
105
105
|
if (next.attribution !== undefined &&
|
|
106
106
|
!sameAttribution(prev.attribution, next.attribution) &&
|
|
107
|
-
// an all-empty value writes nothing when there was nothing to turn off (absence means "none"
|
|
108
|
-
// so a conversation that never has an attribution stays as old logs are)
|
|
107
|
+
// an all-empty value writes nothing when there was nothing to turn off (absence means "none")
|
|
109
108
|
(hasAttribution(next.attribution) || hasAttribution(prev.attribution))) {
|
|
110
109
|
out.attribution = next.attribution;
|
|
111
110
|
}
|
|
@@ -7,32 +7,26 @@ import type { ConversationEvent, EventPayload } from "../../conversations/events
|
|
|
7
7
|
export type CatalogSkill = EventPayload<"skills_catalog">["skills"][number];
|
|
8
8
|
/** The whole `skills_catalog` payload. */
|
|
9
9
|
export type SkillsSnapshot = EventPayload<"skills_catalog">;
|
|
10
|
-
/** A pinned skill in a snapshot (phase B, spec §9.1). */
|
|
11
|
-
export type PinnedSkill = NonNullable<SkillsSnapshot["pinned"]>[number];
|
|
12
10
|
/** 日志里的 `skills_catalog` 事件。 */
|
|
13
11
|
export type SkillsCatalogEvent = Extract<ConversationEvent, {
|
|
14
12
|
type: "skills_catalog";
|
|
15
13
|
}>;
|
|
16
14
|
/**
|
|
17
|
-
* The model-visible skills texts that name the skill-loading builtin
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* The model-visible skills texts that name the skill-loading builtin:
|
|
16
|
+
* - `skillsCatalogHeader`: the header of the first catalog (in the system cache segment);
|
|
17
|
+
* - `newSkills` / `updatedSkills`: the headings of the added and updated skills in a change notice;
|
|
18
|
+
* - `currentSkills`: the heading of the current catalog after a compaction summary;
|
|
19
|
+
* - `invokedSkills`: the line restored after a compaction summary for the skills invoked in its
|
|
20
|
+
* range (`names` non-empty): a person's invocations and the template skills the kernel wrote as
|
|
21
|
+
* invocations at a child's start (`user_message.skill.template`), so it names no invoker.
|
|
20
22
|
*/
|
|
21
|
-
export
|
|
22
|
-
/** The header of the first catalog (in the system cache segment). */
|
|
23
|
+
export declare const SKILL_TEXTS: Readonly<{
|
|
23
24
|
skillsCatalogHeader: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/** The heading of the updated skills in a change notice. */
|
|
27
|
-
updatedSkills: string;
|
|
28
|
-
/** The heading of the current catalog after a compaction summary. */
|
|
25
|
+
newSkills: "New skills (call Skill with the name to use one):";
|
|
26
|
+
updatedSkills: "Updated skills (call Skill again before relying on earlier instructions):";
|
|
29
27
|
currentSkills: string;
|
|
30
|
-
/** The line restored after a compaction summary for the invoked skills (`names` non-empty). */
|
|
31
28
|
invokedSkills: (names: readonly string[]) => string;
|
|
32
|
-
|
|
33
|
-
pinnedSkillsHeader: string;
|
|
34
|
-
}
|
|
35
|
-
export declare const SKILL_TEXTS: SkillTexts;
|
|
29
|
+
}>;
|
|
36
30
|
/** 目录开头的说明(system 缓存段里的第一份目录)。 */
|
|
37
31
|
export declare const SKILLS_CATALOG_HEADER: string;
|
|
38
32
|
/** 目录里每个技能描述最多的码点数(超出确定地截断;`Skill` 仍返回完整正文)。 */
|
|
@@ -43,28 +37,19 @@ export declare const catalogLine: (s: Pick<CatalogSkill, "name" | "description">
|
|
|
43
37
|
* The heading of the name-only entries of a listing (skills default-on spec §7): the entries a
|
|
44
38
|
* snapshot recorded past the catalog budget (`nameOnly`). Every listing (the system catalog, a
|
|
45
39
|
* change notice's new or updated skills, the current catalog after a compaction) puts them after
|
|
46
|
-
* its described lines under this heading, names in code point order joined by ", ".
|
|
47
|
-
* with phase 2: no request before it has a name-only entry, so the legacy texts need no copy.
|
|
40
|
+
* its described lines under this heading, names in code point order joined by ", ".
|
|
48
41
|
*/
|
|
49
42
|
export declare const MORE_SKILLS_HEADER: string;
|
|
50
43
|
/** 第一份目录(进 system 缓存段),按名字排序。 */
|
|
51
|
-
export declare function skillsCatalogText(skills: readonly CatalogSkill[]
|
|
44
|
+
export declare function skillsCatalogText(skills: readonly CatalogSkill[]): string;
|
|
52
45
|
/**
|
|
53
46
|
* 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 Also by `nameOnly` (absent = false):
|
|
54
47
|
* an entry crossing the catalog budget writes a new snapshot and reads as updated.
|
|
55
48
|
*/
|
|
56
49
|
export declare function sameSkills(a: readonly CatalogSkill[], b: readonly CatalogSkill[]): boolean;
|
|
57
50
|
/**
|
|
58
|
-
* Two
|
|
59
|
-
*
|
|
60
|
-
* renders no message ({@link pinnedChangeText} is "" and the catalog part is skipped), and only the
|
|
61
|
-
* system segment of a new conversation or a compaction restore shows the new order. This is
|
|
62
|
-
* deliberate and consistent from the log: do not "fix" the missing message.
|
|
63
|
-
*/
|
|
64
|
-
export declare function samePinned(a: readonly PinnedSkill[] | undefined, b: readonly PinnedSkill[] | undefined): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared, so a snapshot written
|
|
67
|
-
* before phase B stays current), {@link samePinned} and the same `toolMap` (absent = undefined).
|
|
51
|
+
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared) and the same `toolMap`
|
|
52
|
+
* (absent = undefined).
|
|
68
53
|
*/
|
|
69
54
|
export declare function sameSnapshot(a: SkillsSnapshot, b: SkillsSnapshot): boolean;
|
|
70
55
|
/**
|
|
@@ -72,14 +57,15 @@ export declare function sameSnapshot(a: SkillsSnapshot, b: SkillsSnapshot): bool
|
|
|
72
57
|
* 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
|
|
73
58
|
* `prev` 为上一份快照(没有为空)。
|
|
74
59
|
*/
|
|
75
|
-
export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[]
|
|
60
|
+
export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[]): string;
|
|
76
61
|
/** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
|
|
77
|
-
export declare function skillsCurrentText(skills: readonly CatalogSkill[]
|
|
62
|
+
export declare function skillsCurrentText(skills: readonly CatalogSkill[]): string;
|
|
78
63
|
/**
|
|
79
64
|
* The line restored after a compaction summary whose range holds inline skill invocations
|
|
80
|
-
* (`names`: distinct, code point order
|
|
65
|
+
* (`names`: distinct, code point order; a person's and the template skills the kernel wrote as
|
|
66
|
+
* invocations); empty for none. Bodies are not re-injected.
|
|
81
67
|
*/
|
|
82
|
-
export declare function invokedSkillsText(names: readonly string[]
|
|
68
|
+
export declare function invokedSkillsText(names: readonly string[]): string;
|
|
83
69
|
/** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
|
|
84
70
|
export declare function invokedSkillNames(events: readonly ConversationEvent[], upToSeq: number): string[];
|
|
85
71
|
/** A skill a person invoked: the version recorded in their message. */
|
|
@@ -104,33 +90,18 @@ export declare function latestSkillsCatalog(events: readonly ConversationEvent[]
|
|
|
104
90
|
* 改为在所在位置追加提醒,已发送的前缀不变)。没有为 null。
|
|
105
91
|
*/
|
|
106
92
|
export declare function systemSkillsCatalog(events: readonly ConversationEvent[]): SkillsCatalogEvent | null;
|
|
107
|
-
/** The header of the pinned skills in the system cache segment. */
|
|
108
|
-
export declare const PINNED_SKILLS_HEADER: string;
|
|
109
|
-
/** One pinned skill with its body. */
|
|
110
|
-
export declare function pinnedBlock(p: PinnedSkill): string;
|
|
111
|
-
/** The pinned skills of the system snapshot (non-empty), after the catalog. */
|
|
112
|
-
export declare function pinnedSystemText(pinned: readonly PinnedSkill[], texts?: SkillTexts): string;
|
|
113
|
-
/**
|
|
114
|
-
* The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
|
|
115
|
-
* or has another version or source, with its whole body; then the names of the removed ones.
|
|
116
|
-
* Empty when nothing changed.
|
|
117
|
-
*/
|
|
118
|
-
export declare function pinnedChangeText(prev: readonly PinnedSkill[] | undefined, next: readonly PinnedSkill[] | undefined): string;
|
|
119
|
-
/** The pinned skills after a compaction summary, when they differ from the system snapshot's. */
|
|
120
|
-
export declare function pinnedCurrentText(pinned: readonly PinnedSkill[] | undefined): string;
|
|
121
93
|
/** The tool-name map change notice (the map differs from the previous one). */
|
|
122
94
|
export declare function toolMapChangeText(next: string | undefined): string;
|
|
123
95
|
/**
|
|
124
96
|
* The one system message of a later snapshot: the catalog change (when the skills differ, or when
|
|
125
|
-
*
|
|
126
|
-
* tool-name map change; joined by blank lines.
|
|
97
|
+
* the map does not), the tool-name map change; joined by blank lines.
|
|
127
98
|
*/
|
|
128
|
-
export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot
|
|
99
|
+
export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot): string;
|
|
129
100
|
/**
|
|
130
101
|
* What follows a compaction summary when the covered snapshot is not the system one: today's
|
|
131
|
-
* current catalog (when the skills differ from the system snapshot's)
|
|
132
|
-
*
|
|
102
|
+
* current catalog (when the skills differ from the system snapshot's) and the tool-name map (when
|
|
103
|
+
* it differs); joined by blank lines, "" for nothing.
|
|
133
104
|
*/
|
|
134
|
-
export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot
|
|
135
|
-
/** The system snapshot's text after the agent's instructions: catalog,
|
|
136
|
-
export declare function snapshotSystemText(s: SkillsSnapshot
|
|
105
|
+
export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot): string;
|
|
106
|
+
/** The system snapshot's text after the agent's instructions: the catalog, then the tool map. */
|
|
107
|
+
export declare function snapshotSystemText(s: SkillsSnapshot): string;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { SKILL_LOAD } from "../../tools/builtin-names.js";
|
|
2
|
+
/**
|
|
3
|
+
* The model-visible skills texts that name the skill-loading builtin:
|
|
4
|
+
* - `skillsCatalogHeader`: the header of the first catalog (in the system cache segment);
|
|
5
|
+
* - `newSkills` / `updatedSkills`: the headings of the added and updated skills in a change notice;
|
|
6
|
+
* - `currentSkills`: the heading of the current catalog after a compaction summary;
|
|
7
|
+
* - `invokedSkills`: the line restored after a compaction summary for the skills invoked in its
|
|
8
|
+
* range (`names` non-empty): a person's invocations and the template skills the kernel wrote as
|
|
9
|
+
* invocations at a child's start (`user_message.skill.template`), so it names no invoker.
|
|
10
|
+
*/
|
|
2
11
|
export const SKILL_TEXTS = Object.freeze({
|
|
3
12
|
skillsCatalogHeader: "Skills are available in this conversation. A skill is a set of instructions, sometimes with " +
|
|
4
13
|
"scripts or other files, for a specific kind of task. When a task matches a skill's description, " +
|
|
@@ -8,10 +17,7 @@ export const SKILL_TEXTS = Object.freeze({
|
|
|
8
17
|
updatedSkills: `Updated skills (call ${SKILL_LOAD} again before relying on earlier instructions):`,
|
|
9
18
|
currentSkills: "Skills available in this conversation now (this replaces any earlier list of skills; call " +
|
|
10
19
|
`${SKILL_LOAD} with a name to read a skill's instructions):`,
|
|
11
|
-
invokedSkills: (names) => `Skills
|
|
12
|
-
pinnedSkillsHeader: "Pinned skills: the owner of this agent pinned these skills, so their instructions apply " +
|
|
13
|
-
`throughout this conversation. Follow them without calling ${SKILL_LOAD}; call ${SKILL_LOAD} ` +
|
|
14
|
-
"only to copy a pinned skill's files into the sandbox.",
|
|
20
|
+
invokedSkills: (names) => `Skills invoked earlier in this conversation: ${names.join(", ")}. Call ${SKILL_LOAD} with a name to read its instructions again.`,
|
|
15
21
|
});
|
|
16
22
|
/** 目录开头的说明(system 缓存段里的第一份目录)。 */
|
|
17
23
|
export const SKILLS_CATALOG_HEADER = SKILL_TEXTS.skillsCatalogHeader;
|
|
@@ -33,8 +39,7 @@ export const catalogLine = (s) => `- ${s.name}: ${shortDescription(s.description
|
|
|
33
39
|
* The heading of the name-only entries of a listing (skills default-on spec §7): the entries a
|
|
34
40
|
* snapshot recorded past the catalog budget (`nameOnly`). Every listing (the system catalog, a
|
|
35
41
|
* change notice's new or updated skills, the current catalog after a compaction) puts them after
|
|
36
|
-
* its described lines under this heading, names in code point order joined by ", ".
|
|
37
|
-
* with phase 2: no request before it has a name-only entry, so the legacy texts need no copy.
|
|
42
|
+
* its described lines under this heading, names in code point order joined by ", ".
|
|
38
43
|
*/
|
|
39
44
|
export const MORE_SKILLS_HEADER = `More skills (names only; call ${SKILL_LOAD} with the name to read one):`;
|
|
40
45
|
/**
|
|
@@ -55,8 +60,8 @@ function lines(skills) {
|
|
|
55
60
|
return head === "" ? more : `${head}\n${more}`;
|
|
56
61
|
}
|
|
57
62
|
/** 第一份目录(进 system 缓存段),按名字排序。 */
|
|
58
|
-
export function skillsCatalogText(skills
|
|
59
|
-
return `${
|
|
63
|
+
export function skillsCatalogText(skills) {
|
|
64
|
+
return `${SKILL_TEXTS.skillsCatalogHeader}\n${lines(skills)}`;
|
|
60
65
|
}
|
|
61
66
|
/**
|
|
62
67
|
* 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 Also by `nameOnly` (absent = false):
|
|
@@ -79,34 +84,14 @@ export function sameSkills(a, b) {
|
|
|
79
84
|
});
|
|
80
85
|
}
|
|
81
86
|
/**
|
|
82
|
-
* Two
|
|
83
|
-
*
|
|
84
|
-
* renders no message ({@link pinnedChangeText} is "" and the catalog part is skipped), and only the
|
|
85
|
-
* system segment of a new conversation or a compaction restore shows the new order. This is
|
|
86
|
-
* deliberate and consistent from the log: do not "fix" the missing message.
|
|
87
|
-
*/
|
|
88
|
-
export function samePinned(a, b) {
|
|
89
|
-
const x = a ?? [];
|
|
90
|
-
const y = b ?? [];
|
|
91
|
-
return (x.length === y.length &&
|
|
92
|
-
x.every((p, i) => {
|
|
93
|
-
const q = y[i];
|
|
94
|
-
return q !== undefined && p.id === q.id && p.version === q.version && p.source === q.source;
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared, so a snapshot written
|
|
99
|
-
* before phase B stays current), {@link samePinned} and the same `toolMap` (absent = undefined).
|
|
87
|
+
* Two snapshots are the same: {@link sameSkills} (`plugin` is not compared) and the same `toolMap`
|
|
88
|
+
* (absent = undefined).
|
|
100
89
|
*/
|
|
101
90
|
export function sameSnapshot(a, b) {
|
|
102
|
-
return
|
|
91
|
+
return sameSkills(a.skills, b.skills) && a.toolMap === b.toolMap;
|
|
103
92
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
* B) are left out of `updated`: a pinned skill's new body is rendered by {@link pinnedChangeText},
|
|
107
|
-
* and the pinned header says not to call `Skill` for it.
|
|
108
|
-
*/
|
|
109
|
-
function catalogChanges(prev, next, pinnedIds) {
|
|
93
|
+
/** The catalog differences between two snapshots. */
|
|
94
|
+
function catalogChanges(prev, next) {
|
|
110
95
|
const before = new Map(prev.map((s) => [s.id, s]));
|
|
111
96
|
const after = new Map(next.map((s) => [s.id, s]));
|
|
112
97
|
// A skill renamed under its id (the platform components migration renames a clashing org skill)
|
|
@@ -121,7 +106,6 @@ function catalogChanges(prev, next, pinnedIds) {
|
|
|
121
106
|
const p = before.get(s.id);
|
|
122
107
|
return (p !== undefined &&
|
|
123
108
|
p.name === s.name &&
|
|
124
|
-
!pinnedIds?.has(s.id) &&
|
|
125
109
|
(p.version !== s.version ||
|
|
126
110
|
p.description !== s.description ||
|
|
127
111
|
p.source !== s.source ||
|
|
@@ -134,14 +118,14 @@ function catalogChanges(prev, next, pinnedIds) {
|
|
|
134
118
|
* 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
|
|
135
119
|
* `prev` 为上一份快照(没有为空)。
|
|
136
120
|
*/
|
|
137
|
-
export function skillsChangeText(prev, next
|
|
138
|
-
const { added, updated, removed } = catalogChanges(prev, next
|
|
121
|
+
export function skillsChangeText(prev, next) {
|
|
122
|
+
const { added, updated, removed } = catalogChanges(prev, next);
|
|
139
123
|
const parts = ["The skills available in this conversation have changed."];
|
|
140
124
|
if (added.length > 0) {
|
|
141
|
-
parts.push(`${
|
|
125
|
+
parts.push(`${SKILL_TEXTS.newSkills}\n${lines(added)}`);
|
|
142
126
|
}
|
|
143
127
|
if (updated.length > 0) {
|
|
144
|
-
parts.push(`${
|
|
128
|
+
parts.push(`${SKILL_TEXTS.updatedSkills}\n${lines(updated)}`);
|
|
145
129
|
}
|
|
146
130
|
if (removed.length > 0) {
|
|
147
131
|
parts.push(`Removed skills (no longer available; do not use them): ${[...removed]
|
|
@@ -154,21 +138,22 @@ export function skillsChangeText(prev, next, pinnedIds, texts = SKILL_TEXTS) {
|
|
|
154
138
|
return parts.join("\n\n");
|
|
155
139
|
}
|
|
156
140
|
/** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
|
|
157
|
-
export function skillsCurrentText(skills
|
|
141
|
+
export function skillsCurrentText(skills) {
|
|
158
142
|
if (skills.length === 0) {
|
|
159
143
|
return "No skills are available in this conversation now (this replaces any earlier list of skills).";
|
|
160
144
|
}
|
|
161
|
-
return `${
|
|
145
|
+
return `${SKILL_TEXTS.currentSkills}\n${lines(skills)}`;
|
|
162
146
|
}
|
|
163
|
-
// ----
|
|
147
|
+
// ---- Invoked skills (phase D spec §4.4; model-visible, English) ----
|
|
164
148
|
/**
|
|
165
149
|
* The line restored after a compaction summary whose range holds inline skill invocations
|
|
166
|
-
* (`names`: distinct, code point order
|
|
150
|
+
* (`names`: distinct, code point order; a person's and the template skills the kernel wrote as
|
|
151
|
+
* invocations); empty for none. Bodies are not re-injected.
|
|
167
152
|
*/
|
|
168
|
-
export function invokedSkillsText(names
|
|
153
|
+
export function invokedSkillsText(names) {
|
|
169
154
|
if (names.length === 0)
|
|
170
155
|
return "";
|
|
171
|
-
return
|
|
156
|
+
return SKILL_TEXTS.invokedSkills(names);
|
|
172
157
|
}
|
|
173
158
|
/** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
|
|
174
159
|
export function invokedSkillNames(events, upToSeq) {
|
|
@@ -225,48 +210,7 @@ export function systemSkillsCatalog(events) {
|
|
|
225
210
|
const earlierCall = events.some((e) => e.type === "model_call" && e.seq < first.seq);
|
|
226
211
|
return earlierCall ? null : first;
|
|
227
212
|
}
|
|
228
|
-
// ----
|
|
229
|
-
/** The header of the pinned skills in the system cache segment. */
|
|
230
|
-
export const PINNED_SKILLS_HEADER = SKILL_TEXTS.pinnedSkillsHeader;
|
|
231
|
-
/** One pinned skill with its body. */
|
|
232
|
-
export function pinnedBlock(p) {
|
|
233
|
-
return `<pinned_skill name="${p.name}" version="${p.version}">\n${p.body.trim()}\n</pinned_skill>`;
|
|
234
|
-
}
|
|
235
|
-
/** The pinned skills of the system snapshot (non-empty), after the catalog. */
|
|
236
|
-
export function pinnedSystemText(pinned, texts = SKILL_TEXTS) {
|
|
237
|
-
return `${texts.pinnedSkillsHeader}\n\n${pinned.map(pinnedBlock).join("\n\n")}`;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
|
|
241
|
-
* or has another version or source, with its whole body; then the names of the removed ones.
|
|
242
|
-
* Empty when nothing changed.
|
|
243
|
-
*/
|
|
244
|
-
export function pinnedChangeText(prev, next) {
|
|
245
|
-
const before = new Map((prev ?? []).map((p) => [p.id, p]));
|
|
246
|
-
const after = new Set((next ?? []).map((p) => p.id));
|
|
247
|
-
const parts = [];
|
|
248
|
-
for (const p of next ?? []) {
|
|
249
|
-
const was = before.get(p.id);
|
|
250
|
-
if (was && was.version === p.version && was.source === p.source)
|
|
251
|
-
continue;
|
|
252
|
-
parts.push(`Pinned skill "${p.name}" (version ${p.version}) now applies to this conversation and ` +
|
|
253
|
-
`replaces any previous version of it:\n\n${pinnedBlock(p)}`);
|
|
254
|
-
}
|
|
255
|
-
const removed = (prev ?? []).filter((p) => !after.has(p.id)).map((p) => p.name);
|
|
256
|
-
if (removed.length > 0) {
|
|
257
|
-
parts.push(`Pinned skills removed (their pinned instructions no longer apply): ${removed.join(", ")}`);
|
|
258
|
-
}
|
|
259
|
-
return parts.join("\n\n");
|
|
260
|
-
}
|
|
261
|
-
/** The pinned skills after a compaction summary, when they differ from the system snapshot's. */
|
|
262
|
-
export function pinnedCurrentText(pinned) {
|
|
263
|
-
if (!pinned || pinned.length === 0) {
|
|
264
|
-
return "No skills are pinned now (this replaces any earlier pinned skills).";
|
|
265
|
-
}
|
|
266
|
-
return `Pinned skills now (this replaces any earlier pinned skills):\n\n${pinned
|
|
267
|
-
.map(pinnedBlock)
|
|
268
|
-
.join("\n\n")}`;
|
|
269
|
-
}
|
|
213
|
+
// ---- The tool-name map (phase B, spec §9.4; model-visible, English) ----
|
|
270
214
|
/** The tool-name map change notice (the map differs from the previous one). */
|
|
271
215
|
export function toolMapChangeText(next) {
|
|
272
216
|
return next === undefined
|
|
@@ -275,53 +219,37 @@ export function toolMapChangeText(next) {
|
|
|
275
219
|
}
|
|
276
220
|
/**
|
|
277
221
|
* The one system message of a later snapshot: the catalog change (when the skills differ, or when
|
|
278
|
-
*
|
|
279
|
-
* tool-name map change; joined by blank lines.
|
|
222
|
+
* the map does not), the tool-name map change; joined by blank lines.
|
|
280
223
|
*/
|
|
281
|
-
export function snapshotChangeText(prev, next
|
|
224
|
+
export function snapshotChangeText(prev, next) {
|
|
282
225
|
const prevSkills = prev?.skills ?? [];
|
|
283
|
-
const pinnedDiff = !samePinned(prev?.pinned, next.pinned);
|
|
284
226
|
const mapDiff = prev?.toolMap !== next.toolMap;
|
|
285
|
-
// a snapshot with pinned skills leaves them out of the "Updated skills" list; when that leaves no
|
|
286
|
-
// catalog change, the catalog text is skipped (the pinned change carries the message). Logs
|
|
287
|
-
// without `pinned` render exactly as before.
|
|
288
|
-
const pinnedIds = next.pinned && next.pinned.length > 0 ? new Set(next.pinned.map((p) => p.id)) : undefined;
|
|
289
|
-
const c = catalogChanges(prevSkills, next.skills, pinnedIds);
|
|
290
|
-
const catalogDiff = pinnedIds
|
|
291
|
-
? c.added.length + c.updated.length + c.removed.length > 0
|
|
292
|
-
: !sameSkills(prevSkills, next.skills);
|
|
293
227
|
const parts = [];
|
|
294
|
-
if (
|
|
295
|
-
parts.push(skillsChangeText(prevSkills, next.skills
|
|
228
|
+
if (!sameSkills(prevSkills, next.skills) || !mapDiff) {
|
|
229
|
+
parts.push(skillsChangeText(prevSkills, next.skills));
|
|
296
230
|
}
|
|
297
|
-
if (pinnedDiff)
|
|
298
|
-
parts.push(pinnedChangeText(prev?.pinned, next.pinned));
|
|
299
231
|
if (mapDiff)
|
|
300
232
|
parts.push(toolMapChangeText(next.toolMap));
|
|
301
|
-
return parts.
|
|
233
|
+
return parts.join("\n\n");
|
|
302
234
|
}
|
|
303
235
|
/**
|
|
304
236
|
* What follows a compaction summary when the covered snapshot is not the system one: today's
|
|
305
|
-
* current catalog (when the skills differ from the system snapshot's)
|
|
306
|
-
*
|
|
237
|
+
* current catalog (when the skills differ from the system snapshot's) and the tool-name map (when
|
|
238
|
+
* it differs); joined by blank lines, "" for nothing.
|
|
307
239
|
*/
|
|
308
|
-
export function snapshotCurrentText(system, covered
|
|
240
|
+
export function snapshotCurrentText(system, covered) {
|
|
309
241
|
const parts = [];
|
|
310
242
|
if (!sameSkills(system?.skills ?? [], covered.skills)) {
|
|
311
|
-
parts.push(skillsCurrentText(covered.skills
|
|
243
|
+
parts.push(skillsCurrentText(covered.skills));
|
|
312
244
|
}
|
|
313
|
-
if (!samePinned(system?.pinned, covered.pinned))
|
|
314
|
-
parts.push(pinnedCurrentText(covered.pinned));
|
|
315
245
|
if (system?.toolMap !== covered.toolMap) {
|
|
316
246
|
parts.push(toolMapChangeText(covered.toolMap));
|
|
317
247
|
}
|
|
318
248
|
return parts.join("\n\n");
|
|
319
249
|
}
|
|
320
|
-
/** The system snapshot's text after the agent's instructions: catalog,
|
|
321
|
-
export function snapshotSystemText(s
|
|
322
|
-
let text = skillsCatalogText(s.skills
|
|
323
|
-
if (s.pinned && s.pinned.length > 0)
|
|
324
|
-
text += `\n\n${pinnedSystemText(s.pinned, texts)}`;
|
|
250
|
+
/** The system snapshot's text after the agent's instructions: the catalog, then the tool map. */
|
|
251
|
+
export function snapshotSystemText(s) {
|
|
252
|
+
let text = skillsCatalogText(s.skills);
|
|
325
253
|
if (s.toolMap !== undefined)
|
|
326
254
|
text += `\n\n${s.toolMap}`;
|
|
327
255
|
return text;
|
|
@@ -13,9 +13,9 @@ export type ToolsChange = Pick<EventPayload<"tools_changed">, "added" | "removed
|
|
|
13
13
|
* `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
|
|
14
14
|
* tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
|
|
15
15
|
* step that logged its change and crashed before its request: the change is not logged twice).
|
|
16
|
-
* Skipped: a
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Skipped: a call whose tools the kernel left out because its model has no tool support
|
|
17
|
+
* (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
|
|
18
|
+
* set yet.
|
|
19
19
|
*/
|
|
20
20
|
export declare function previousToolSet(events: readonly ConversationEvent[]): Set<string> | null;
|
|
21
21
|
/**
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import { TOOLS_UNSUPPORTED_REMINDER } from "./reminders.js";
|
|
2
1
|
/**
|
|
3
2
|
* The tool set the conversation's previous model request offered, from the log alone: the last
|
|
4
3
|
* `model_call`'s `tools` and `catalog` keys (with `ToolSearch` the catalog holds the deferred
|
|
5
4
|
* tools, so the union is the whole resolved set), then any `tools_changed` logged after it (a
|
|
6
5
|
* step that logged its change and crashed before its request: the change is not logged twice).
|
|
7
|
-
* Skipped: a
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Skipped: a call whose tools the kernel left out because its model has no tool support
|
|
7
|
+
* (`toolsOmitted`): it says nothing about the resolved set. Null when no request offered a known
|
|
8
|
+
* set yet.
|
|
10
9
|
*/
|
|
11
10
|
export function previousToolSet(events) {
|
|
12
|
-
const unsupported = new Set();
|
|
13
|
-
for (const e of events) {
|
|
14
|
-
if (e.type === "reminder" && e.payload.text === TOOLS_UNSUPPORTED_REMINDER) {
|
|
15
|
-
unsupported.add(`${e.runId ?? ""}\u0000${e.payload.step}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
11
|
let known = null;
|
|
19
12
|
for (const e of events) {
|
|
20
13
|
if (e.type === "model_call") {
|
|
21
|
-
const { tools, catalog } = e.payload.request;
|
|
22
|
-
if (
|
|
23
|
-
continue;
|
|
24
|
-
const keys = [...tools, ...(catalog ?? [])].map((t) => t.key);
|
|
25
|
-
if (keys.length === 0 && unsupported.has(`${e.runId ?? ""}\u0000${e.payload.step}`))
|
|
14
|
+
const { tools, catalog, toolsOmitted } = e.payload.request;
|
|
15
|
+
if (toolsOmitted === true)
|
|
26
16
|
continue;
|
|
27
|
-
known = new Set(
|
|
17
|
+
known = new Set([...tools, ...(catalog ?? [])].map((t) => t.key));
|
|
28
18
|
}
|
|
29
19
|
else if (e.type === "tools_changed" && known !== null) {
|
|
30
20
|
for (const k of e.payload.removed)
|
|
@@ -36,12 +36,12 @@ export declare function hookScope(hooks: HookRunner | undefined, s: {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function fireObserve<K extends "model.response" | "tool.postExecute">(hooks: HookRunner, mount: K, payload: HookPayloads[K], signal: AbortSignal, log: Pick<Logger, "warn">): void;
|
|
38
38
|
/**
|
|
39
|
-
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
|
|
40
|
-
* and
|
|
41
|
-
* so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
42
|
-
* messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
43
|
-
* and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
44
|
-
* before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
39
|
+
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
|
|
40
|
+
* document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
|
|
41
|
+
* `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
42
|
+
* user messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
43
|
+
* clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
44
|
+
* refs before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
45
45
|
*/
|
|
46
46
|
export declare function hookRequestOf(request: ModelRequest, log?: Pick<Logger, "warn">): HookModelRequest;
|
|
47
47
|
/** Where a denial is recorded (conversation, run, actor and the idem key of its `hook_denied`). */
|
|
@@ -43,17 +43,17 @@ const base64Bytes = (data) => {
|
|
|
43
43
|
return Math.max(0, Math.floor(data.length / 4) * 3 - pad);
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image
|
|
47
|
-
* and
|
|
48
|
-
* so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
49
|
-
* messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
50
|
-
* and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
51
|
-
* before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
46
|
+
* The `model.request` payload's request (F10, I-3): the request sent to the provider with every image,
|
|
47
|
+
* document and file block replaced by a {@link HookMediaPlaceholder} (`kind`, `mediaType`, decoded
|
|
48
|
+
* `size`), so hook payloads carry neither media bytes nor attachment ids. Media never sits outside
|
|
49
|
+
* user messages, but every message is projected anyway. Building the copy also keeps the per-call
|
|
50
|
+
* clone and freeze of the payload small. A `ref` source should never reach here (the kernel resolves
|
|
51
|
+
* refs before sending); it becomes a placeholder of size 0 and logs a warning.
|
|
52
52
|
*/
|
|
53
53
|
export function hookRequestOf(request, log) {
|
|
54
54
|
let refs = 0;
|
|
55
55
|
const project = (b) => {
|
|
56
|
-
if (b.type !== "image" && b.type !== "document")
|
|
56
|
+
if (b.type !== "image" && b.type !== "document" && b.type !== "file")
|
|
57
57
|
return b;
|
|
58
58
|
if (b.source.kind === "ref")
|
|
59
59
|
refs++;
|