@kontextmind/kxm 0.7.39 → 0.7.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +41 -7
- package/docs/README.md +5 -3
- package/docs/agent-skills.md +1 -1
- package/docs/architecture.md +1 -1
- package/docs/configuration.md +28 -5
- package/docs/{vnext → contracts}/README.md +7 -7
- package/docs/{vnext → contracts}/architecture.md +2 -2
- package/docs/{vnext → contracts}/migration.md +25 -25
- package/docs/{vnext → contracts}/routing.md +2 -2
- package/docs/{vnext → contracts}/synchronization.md +1 -1
- package/docs/{vnext → contracts}/validation.md +7 -7
- package/docs/getting-started.md +1 -1
- package/docs/kb/qa-authentik-authentication.md +47 -0
- package/docs/kb/qa-extension-install-and-hub-bootstrap.md +68 -0
- package/docs/kb/qa-hub-on-a-public-host.md +31 -0
- package/docs/kb/qa-sqlite-vs-duckdb.md +18 -0
- package/docs/kb/qa-what-the-hub-stores.md +47 -0
- package/docs/packages.md +91 -0
- package/docs/templates/architecture.md +1 -1
- package/docs/test-matrix.md +6 -6
- package/docs/tui-components.md +131 -0
- package/examples/README.md +2 -2
- package/examples/{vnext → project}/.kxm/agents/critic-3.yaml +1 -1
- package/examples/{vnext → project}/README.md +4 -4
- package/package.json +18 -8
- package/packages/core/tui/CHANGELOG.md +19 -0
- package/packages/core/tui/LICENSE +21 -0
- package/packages/core/tui/README.md +45 -0
- package/packages/core/tui/dist/index.js +1439 -0
- package/packages/core/tui/src/adapters/pi.ts +73 -0
- package/packages/core/tui/src/adapters/terminal.ts +106 -0
- package/packages/core/tui/src/exports/index.ts +30 -0
- package/packages/core/tui/src/services/registry.ts +274 -0
- package/packages/core/tui/src/tui/keys.ts +130 -0
- package/packages/core/tui/src/tui/layout.ts +117 -0
- package/packages/core/tui/src/tui/panel.ts +435 -0
- package/packages/core/tui/src/tui/panelComponent.ts +208 -0
- package/packages/core/tui/src/tui/render.ts +309 -0
- package/packages/core/tui/src/tui/theme.ts +145 -0
- package/packages/core/tui/src/types/surface.ts +407 -0
- package/plugins/kxm/.claude-plugin/plugin.json +1 -1
- package/plugins/kxm/dist/cli.js +681 -553
- package/plugins/kxm/dist/extension.js +18 -18
- package/plugins/kxm/dist/mcp-server.js +1 -1
- package/plugins/kxm/dist/{vnext-runtime-supervisor.js → runtime-supervisor.js} +553 -553
- package/plugins/kxm/dist/runtime.js +608 -608
- package/plugins/kxm/dist/server.js +13 -13
- package/plugins/kxm/package.json +2 -2
- package/plugins/kxm/skills/kxm-project-setup/SKILL.md +2 -2
- package/plugins/kxm/skills/kxm-runs/SKILL.md +3 -3
- package/plugins/kxm/skills/kxm-session/SKILL.md +1 -1
- package/plugins/kxm/skills/kxm-workflow/SKILL.md +1 -1
- package/plugins/kxm/src/autocomplete.ts +4 -4
- package/plugins/kxm/src/{vnext-bindings.ts → bindings.ts} +48 -48
- package/plugins/kxm/src/cli/hub.ts +3 -3
- package/plugins/kxm/src/cli/{vnext.ts → project.ts} +106 -106
- package/plugins/kxm/src/cli/roles.ts +9 -9
- package/plugins/kxm/src/cli/system.ts +2 -2
- package/plugins/kxm/src/cli/tasks.ts +8 -8
- package/plugins/kxm/src/cli/workflows.ts +8 -8
- package/plugins/kxm/src/cli.ts +47 -47
- package/plugins/kxm/src/config.ts +69 -14
- package/plugins/kxm/src/database.ts +4 -4
- package/plugins/kxm/src/{vnext-engine-artifacts.ts → engine-artifacts.ts} +7 -7
- package/plugins/kxm/src/{vnext-engine-command.ts → engine-command.ts} +40 -40
- package/plugins/kxm/src/{vnext-engine-compile.ts → engine-compile.ts} +64 -64
- package/plugins/kxm/src/{vnext-engine-evidence.ts → engine-evidence.ts} +26 -26
- package/plugins/kxm/src/{vnext-engine-fold.ts → engine-fold.ts} +99 -99
- package/plugins/kxm/src/{vnext-engine-gate-records.ts → engine-gate-records.ts} +105 -105
- package/plugins/kxm/src/{vnext-engine-plan.ts → engine-plan.ts} +69 -69
- package/plugins/kxm/src/{vnext-engine.ts → engine.ts} +502 -502
- package/plugins/kxm/src/gate-hash.ts +10 -0
- package/plugins/kxm/src/{vnext-harness.ts → harness.ts} +1 -1
- package/plugins/kxm/src/hub.ts +1 -1
- package/plugins/kxm/src/init-guide-setup.ts +3 -3
- package/plugins/kxm/src/{vnext-init.ts → init.ts} +93 -93
- package/plugins/kxm/src/kxm-install-kind.ts +1 -1
- package/plugins/kxm/src/kxm-update-config.ts +2 -2
- package/plugins/kxm/src/local-snapshot.ts +23 -23
- package/plugins/kxm/src/mcp-server.ts +1 -1
- package/plugins/kxm/src/{vnext-migrate.ts → migrate.ts} +123 -123
- package/plugins/kxm/src/model-inventory.ts +1 -1
- package/plugins/kxm/src/{vnext-oneshot-evidence.ts → oneshot-evidence.ts} +2 -2
- package/plugins/kxm/src/{vnext-oneshot-process.ts → oneshot-process.ts} +4 -4
- package/plugins/kxm/src/{vnext-oneshot-producer.ts → oneshot-producer.ts} +24 -24
- package/plugins/kxm/src/{vnext-permission.ts → permission.ts} +86 -86
- package/plugins/kxm/src/{vnext-pi-producer.ts → pi-producer.ts} +13 -13
- package/plugins/kxm/src/{vnext-config.ts → project-config.ts} +177 -177
- package/plugins/kxm/src/{vnext-repair.ts → repair.ts} +159 -159
- package/plugins/kxm/src/restricted-yaml.d.mts +3 -3
- package/plugins/kxm/src/restricted-yaml.mjs +4 -4
- package/plugins/kxm/src/{vnext-runtime-owner.ts → runtime-owner.ts} +35 -35
- package/plugins/kxm/src/{vnext-runtime.ts → runtime-service.ts} +136 -136
- package/plugins/kxm/src/{vnext-runtime-store.ts → runtime-store.ts} +145 -145
- package/plugins/kxm/src/{vnext-runtime-supervisor.ts → runtime-supervisor.ts} +80 -80
- package/plugins/kxm/src/runtime.ts +6 -6
- package/plugins/kxm/src/session-work.ts +3 -3
- package/plugins/kxm/src/studio-layout.ts +6 -6
- package/plugins/kxm/src/{vnext-template.ts → template.ts} +33 -33
- package/plugins/kxm/src/tui.ts +10 -24
- package/schemas/{vnext/README.md → README.md} +3 -3
- package/schemas/{vnext/agent.schema.json → agent.schema.json} +1 -1
- package/schemas/{vnext/assignment-result.schema.json → assignment-result.schema.json} +1 -1
- package/schemas/{vnext/backup-manifest.schema.json → backup-manifest.schema.json} +1 -1
- package/schemas/{vnext/candidate.schema.json → candidate.schema.json} +1 -1
- package/schemas/{vnext/common.schema.json → common.schema.json} +2 -2
- package/schemas/{vnext/context-candidate.schema.json → context-candidate.schema.json} +1 -1
- package/schemas/{vnext/context-packet.schema.json → context-packet.schema.json} +1 -1
- package/schemas/{vnext/delivery-manifest.schema.json → delivery-manifest.schema.json} +1 -1
- package/schemas/{vnext/drive-receipt.schema.json → drive-receipt.schema.json} +2 -2
- package/schemas/{vnext/environment.schema.json → environment.schema.json} +1 -1
- package/schemas/{vnext/gate-registry.schema.json → gate-registry.schema.json} +1 -1
- package/schemas/{vnext/handoff-manifest.schema.json → handoff-manifest.schema.json} +1 -1
- package/schemas/{vnext/init-operation.schema.json → init-operation.schema.json} +1 -1
- package/schemas/{vnext/local-repository-bindings.schema.json → local-repository-bindings.schema.json} +1 -1
- package/schemas/{vnext/memory-record.schema.json → memory-record.schema.json} +1 -1
- package/schemas/{vnext/migration-decision.schema.json → migration-decision.schema.json} +1 -1
- package/schemas/{vnext/migration-plan.schema.json → migration-plan.schema.json} +1 -1
- package/schemas/{vnext/migration-receipt.schema.json → migration-receipt.schema.json} +1 -1
- package/schemas/{vnext/model.schema.json → model.schema.json} +1 -1
- package/schemas/{vnext/modes.schema.json → modes.schema.json} +1 -1
- package/schemas/{vnext/permission-diff.schema.json → permission-diff.schema.json} +1 -1
- package/schemas/policy-draft/README.md +2 -2
- package/schemas/{vnext/prices.schema.json → prices.schema.json} +1 -1
- package/schemas/{vnext/project.schema.json → project.schema.json} +1 -1
- package/schemas/{vnext/repository.schema.json → repository.schema.json} +1 -1
- package/schemas/{vnext/role.schema.json → role.schema.json} +1 -1
- package/schemas/{vnext/run-event.schema.json → run-event.schema.json} +1 -1
- package/schemas/{vnext/session-brief.schema.json → session-brief.schema.json} +2 -2
- package/schemas/{vnext/sync-event.schema.json → sync-event.schema.json} +1 -1
- package/schemas/{vnext/template-provenance.schema.json → template-provenance.schema.json} +1 -1
- package/schemas/{vnext/workflow.schema.json → workflow.schema.json} +1 -1
- package/scripts/build-package.mjs +59 -0
- package/scripts/build-runtime.mjs +3 -2
- package/scripts/check-generated.mjs +2 -1
- package/scripts/check-versions.mjs +12 -1
- package/scripts/docker-install-smoke.mjs +268 -0
- package/scripts/emit-codex-artifacts.mjs +1 -1
- package/scripts/kxm-bump-version.mjs +53 -3
- package/scripts/kxm-runtime-supervisor.mjs +3 -3
- package/scripts/package-surfaces.mjs +39 -0
- package/scripts/roster-policy.mjs +1 -1
- package/plugins/kxm/src/vnext-gate-hash.ts +0 -10
- /package/docs/{vnext → contracts}/effects-and-recovery.md +0 -0
- /package/docs/{vnext → contracts}/lifecycles.md +0 -0
- /package/docs/{vnext → contracts}/terminology.md +0 -0
- /package/examples/{vnext → project}/.kxm/agents/coordinator.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/critic-1.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/critic-2.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/implementer.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/planner.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/reproducer.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/agents/reviewer.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/gates.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/models/critic-claude.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/models/critic-gemini.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/models/critic-grok.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/models/implementation.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/models/primary.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/prices.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/project/env.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/project.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/repo/repo.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/workflows/default.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/workflows/fix.yaml +0 -0
- /package/examples/{vnext → project}/.kxm/workflows/improve.yaml +0 -0
- /package/examples/{vnext → project}/records/assignment-result-recorded.json +0 -0
- /package/examples/{vnext → project}/records/assignment-result.json +0 -0
- /package/examples/{vnext → project}/records/context-candidate.json +0 -0
- /package/examples/{vnext → project}/records/delivery-manifest.json +0 -0
- /package/examples/{vnext → project}/records/effect-uncertainty-resolved-sync.json +0 -0
- /package/examples/{vnext → project}/records/effect-uncertainty-resolved.json +0 -0
- /package/examples/{vnext → project}/records/run-created.json +0 -0
- /package/examples/{vnext → project}/records/sync-event.json +0 -0
- /package/examples/{vnext → project}/repositories/api/.kxm/repo/env.yaml +0 -0
- /package/examples/{vnext → project}/repositories/api/.kxm/repo/repo.yaml +0 -0
- /package/examples/{vnext → project}/repositories/web/.kxm/repo/repo.yaml +0 -0
|
@@ -14778,7 +14778,7 @@ var require_dist = __commonJS({
|
|
|
14778
14778
|
}
|
|
14779
14779
|
});
|
|
14780
14780
|
|
|
14781
|
-
// plugins/kxm/src/
|
|
14781
|
+
// plugins/kxm/src/runtime-supervisor.ts
|
|
14782
14782
|
import { spawn as spawn3 } from "node:child_process";
|
|
14783
14783
|
import { createHash as createHash11, createHmac, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
14784
14784
|
import { chmodSync as chmodSync2, existsSync as existsSync10, lstatSync as lstatSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync8, renameSync, rmSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
@@ -14804,7 +14804,7 @@ function findKxmRepoRoot(fromUrl = import.meta.url) {
|
|
|
14804
14804
|
);
|
|
14805
14805
|
}
|
|
14806
14806
|
|
|
14807
|
-
// plugins/kxm/src/
|
|
14807
|
+
// plugins/kxm/src/project-config.ts
|
|
14808
14808
|
var import__ = __toESM(require__(), 1);
|
|
14809
14809
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
14810
14810
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -14813,7 +14813,7 @@ import { basename, dirname as dirname2, extname, isAbsolute, join as join2, rela
|
|
|
14813
14813
|
|
|
14814
14814
|
// plugins/kxm/src/restricted-yaml.mjs
|
|
14815
14815
|
var import_yaml = __toESM(require_dist(), 1);
|
|
14816
|
-
var
|
|
14816
|
+
var KXM_YAML_LIMITS = Object.freeze({
|
|
14817
14817
|
maxDocumentBytes: 256 * 1024,
|
|
14818
14818
|
maxDepth: 32,
|
|
14819
14819
|
maxScalarBytes: 64 * 1024,
|
|
@@ -14884,7 +14884,7 @@ function assertJsonValue(value, label, path = "$", seen = /* @__PURE__ */ new Se
|
|
|
14884
14884
|
}
|
|
14885
14885
|
seen.delete(value);
|
|
14886
14886
|
}
|
|
14887
|
-
function parseRestrictedYaml(input, label = "<yaml>", limits =
|
|
14887
|
+
function parseRestrictedYaml(input, label = "<yaml>", limits = KXM_YAML_LIMITS) {
|
|
14888
14888
|
const byteLength = typeof input === "string" ? Buffer.byteLength(input, "utf8") : input.byteLength;
|
|
14889
14889
|
if (byteLength > limits.maxDocumentBytes) {
|
|
14890
14890
|
fail("parse", "document_too_large", label, `document exceeds ${limits.maxDocumentBytes} bytes`);
|
|
@@ -14936,13 +14936,13 @@ function parseRestrictedYaml(input, label = "<yaml>", limits = VNEXT_YAML_LIMITS
|
|
|
14936
14936
|
return value;
|
|
14937
14937
|
}
|
|
14938
14938
|
|
|
14939
|
-
// plugins/kxm/src/
|
|
14939
|
+
// plugins/kxm/src/template.ts
|
|
14940
14940
|
var import_yaml2 = __toESM(require_dist(), 1);
|
|
14941
14941
|
import { createHash } from "node:crypto";
|
|
14942
|
-
var
|
|
14943
|
-
var
|
|
14944
|
-
var
|
|
14945
|
-
var
|
|
14942
|
+
var KXM_TEMPLATE_ID = "builtin-minimal";
|
|
14943
|
+
var KXM_TEMPLATE_PROVENANCE_PATH = ".kxm/template-provenance.yaml";
|
|
14944
|
+
var CURRENT_KXM_TEMPLATE_VARIANT = "v4-registry";
|
|
14945
|
+
var SUPPORTED_KXM_TEMPLATE_VARIANTS = ["v1", "v2", "v3-policy", "v4-registry"];
|
|
14946
14946
|
function compareCodeUnits2(left, right) {
|
|
14947
14947
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
14948
14948
|
}
|
|
@@ -14953,7 +14953,7 @@ function canonicalJson(value) {
|
|
|
14953
14953
|
if (Array.isArray(value)) return `[${value.map((candidate) => canonicalJson(candidate)).join(",")}]`;
|
|
14954
14954
|
return `{${Object.keys(value).sort(compareCodeUnits2).map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
14955
14955
|
}
|
|
14956
|
-
function
|
|
14956
|
+
function kxmContentSha256(input) {
|
|
14957
14957
|
return `sha256:${createHash("sha256").update(input).digest("hex")}`;
|
|
14958
14958
|
}
|
|
14959
14959
|
function authorityProjection(value) {
|
|
@@ -14964,8 +14964,8 @@ function authorityProjection(value) {
|
|
|
14964
14964
|
if (projected.schema === "kxm.workflow.v1") delete projected.description;
|
|
14965
14965
|
return projected;
|
|
14966
14966
|
}
|
|
14967
|
-
function
|
|
14968
|
-
return
|
|
14967
|
+
function kxmAuthoritySha256(value) {
|
|
14968
|
+
return kxmContentSha256(canonicalJson(authorityProjection(value)));
|
|
14969
14969
|
}
|
|
14970
14970
|
function coreTemplate(projectId, projectName, variant) {
|
|
14971
14971
|
const files = /* @__PURE__ */ new Map([
|
|
@@ -15081,14 +15081,14 @@ function coreTemplate(projectId, projectName, variant) {
|
|
|
15081
15081
|
return files;
|
|
15082
15082
|
}
|
|
15083
15083
|
function provenanceRevision(files) {
|
|
15084
|
-
return
|
|
15084
|
+
return kxmContentSha256(canonicalJson(files.map((file) => ({
|
|
15085
15085
|
path: file.path,
|
|
15086
15086
|
sha256: file.sha256,
|
|
15087
15087
|
authoritySha256: file.authoritySha256,
|
|
15088
15088
|
bytes: file.bytes
|
|
15089
15089
|
}))));
|
|
15090
15090
|
}
|
|
15091
|
-
function
|
|
15091
|
+
function renderKxmTemplate(projectId, projectName, variant = CURRENT_KXM_TEMPLATE_VARIANT) {
|
|
15092
15092
|
const values = coreTemplate(projectId, projectName, variant);
|
|
15093
15093
|
const coreFiles = /* @__PURE__ */ new Map();
|
|
15094
15094
|
const records = [...values.entries()].map(([path, value]) => {
|
|
@@ -15096,22 +15096,22 @@ function renderVnextTemplate(projectId, projectName, variant = CURRENT_VNEXT_TEM
|
|
|
15096
15096
|
coreFiles.set(path, bytes);
|
|
15097
15097
|
return {
|
|
15098
15098
|
path,
|
|
15099
|
-
sha256:
|
|
15100
|
-
authoritySha256:
|
|
15099
|
+
sha256: kxmContentSha256(bytes),
|
|
15100
|
+
authoritySha256: kxmAuthoritySha256(value),
|
|
15101
15101
|
bytes: bytes.byteLength
|
|
15102
15102
|
};
|
|
15103
15103
|
}).sort((left, right) => compareCodeUnits2(left.path, right.path));
|
|
15104
15104
|
const templateRevision = provenanceRevision(records);
|
|
15105
15105
|
const provenance = {
|
|
15106
15106
|
schema: "kxm.template-provenance.v1",
|
|
15107
|
-
templateId:
|
|
15107
|
+
templateId: KXM_TEMPLATE_ID,
|
|
15108
15108
|
templateRevision,
|
|
15109
15109
|
inputs: { projectId, projectName },
|
|
15110
15110
|
files: records
|
|
15111
15111
|
};
|
|
15112
15112
|
const fileEntries = [...coreFiles.entries()];
|
|
15113
15113
|
fileEntries.push([
|
|
15114
|
-
|
|
15114
|
+
KXM_TEMPLATE_PROVENANCE_PATH,
|
|
15115
15115
|
Buffer.from((0, import_yaml2.stringify)(provenance, { lineWidth: 0 }), "utf8")
|
|
15116
15116
|
]);
|
|
15117
15117
|
fileEntries.sort(([left], [right]) => compareCodeUnits2(left, right));
|
|
@@ -15119,15 +15119,15 @@ function renderVnextTemplate(projectId, projectName, variant = CURRENT_VNEXT_TEM
|
|
|
15119
15119
|
return { projectId, projectName, templateRevision, provenance, files, values };
|
|
15120
15120
|
}
|
|
15121
15121
|
function validatedTemplateProvenance(value) {
|
|
15122
|
-
if (value.schema !== "kxm.template-provenance.v1" || value.templateId !==
|
|
15122
|
+
if (value.schema !== "kxm.template-provenance.v1" || value.templateId !== KXM_TEMPLATE_ID) return void 0;
|
|
15123
15123
|
const candidate = value;
|
|
15124
15124
|
return provenanceRevision(candidate.files) === candidate.templateRevision ? candidate : void 0;
|
|
15125
15125
|
}
|
|
15126
|
-
function
|
|
15126
|
+
function resolveKxmTemplateBaseline(value) {
|
|
15127
15127
|
const candidate = validatedTemplateProvenance(value);
|
|
15128
15128
|
if (!candidate) return void 0;
|
|
15129
|
-
for (const variant of
|
|
15130
|
-
const known =
|
|
15129
|
+
for (const variant of SUPPORTED_KXM_TEMPLATE_VARIANTS) {
|
|
15130
|
+
const known = renderKxmTemplate(candidate.inputs.projectId, candidate.inputs.projectName, variant).provenance;
|
|
15131
15131
|
if (known.templateRevision === candidate.templateRevision && canonicalJson(known) === canonicalJson(candidate)) {
|
|
15132
15132
|
return candidate;
|
|
15133
15133
|
}
|
|
@@ -15135,12 +15135,12 @@ function resolveVnextTemplateBaseline(value) {
|
|
|
15135
15135
|
return void 0;
|
|
15136
15136
|
}
|
|
15137
15137
|
|
|
15138
|
-
// plugins/kxm/src/
|
|
15138
|
+
// plugins/kxm/src/harness.ts
|
|
15139
15139
|
import { spawnSync } from "node:child_process";
|
|
15140
15140
|
import { existsSync as existsSync2 } from "node:fs";
|
|
15141
15141
|
import { win32 as win32Path } from "node:path";
|
|
15142
15142
|
|
|
15143
|
-
// plugins/kxm/src/
|
|
15143
|
+
// plugins/kxm/src/oneshot-process.ts
|
|
15144
15144
|
import { spawn } from "node:child_process";
|
|
15145
15145
|
var OUTPUT_LIMIT = 8 * 1024 * 1024;
|
|
15146
15146
|
var KILL_GRACE_MS = 250;
|
|
@@ -15293,7 +15293,7 @@ function defaultSpawn(command, args, options) {
|
|
|
15293
15293
|
});
|
|
15294
15294
|
}
|
|
15295
15295
|
|
|
15296
|
-
// plugins/kxm/src/
|
|
15296
|
+
// plugins/kxm/src/harness.ts
|
|
15297
15297
|
var DEFAULT_HARNESS = "pi";
|
|
15298
15298
|
var UNKNOWN_AUTH_HARNESSES = /* @__PURE__ */ new Set(["deepseek"]);
|
|
15299
15299
|
var GROK_LOGIN_LINE = "You are logged in with grok.com.";
|
|
@@ -16186,20 +16186,20 @@ async function probeHarnessAssignmentAsync(options) {
|
|
|
16186
16186
|
);
|
|
16187
16187
|
}
|
|
16188
16188
|
|
|
16189
|
-
// plugins/kxm/src/
|
|
16190
|
-
var
|
|
16189
|
+
// plugins/kxm/src/project-config.ts
|
|
16190
|
+
var KxmConfigError = class extends Error {
|
|
16191
16191
|
issues;
|
|
16192
16192
|
constructor(issues) {
|
|
16193
16193
|
const sorted = sortIssues2(issues);
|
|
16194
16194
|
super(sorted.map((issue3) => `${issue3.file}: ${issue3.code}: ${issue3.message}`).join("\n"));
|
|
16195
|
-
this.name = "
|
|
16195
|
+
this.name = "KxmConfigError";
|
|
16196
16196
|
this.issues = sorted;
|
|
16197
16197
|
}
|
|
16198
16198
|
};
|
|
16199
|
-
function
|
|
16200
|
-
return join2(findKxmRepoRoot(import.meta.url), "schemas"
|
|
16199
|
+
function defaultKxmSchemaDir() {
|
|
16200
|
+
return join2(findKxmRepoRoot(import.meta.url), "schemas");
|
|
16201
16201
|
}
|
|
16202
|
-
var DEFAULT_SCHEMA_DIR =
|
|
16202
|
+
var DEFAULT_SCHEMA_DIR = defaultKxmSchemaDir();
|
|
16203
16203
|
var RESOURCE_SCHEMA = Object.freeze({
|
|
16204
16204
|
project: { identity: "kxm.project.v1", file: "project.schema.json" },
|
|
16205
16205
|
repository: { identity: "kxm.repository.v1", file: "repository.schema.json" },
|
|
@@ -16231,16 +16231,16 @@ function issue2(phase, code, file, message) {
|
|
|
16231
16231
|
return { phase, code, file, message };
|
|
16232
16232
|
}
|
|
16233
16233
|
function fail2(phase, code, file, message) {
|
|
16234
|
-
throw new
|
|
16234
|
+
throw new KxmConfigError([issue2(phase, code, file, message)]);
|
|
16235
16235
|
}
|
|
16236
16236
|
function isJsonObject2(value) {
|
|
16237
16237
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
16238
16238
|
}
|
|
16239
|
-
function parseRestrictedYaml2(input, label = "<yaml>", limits =
|
|
16239
|
+
function parseRestrictedYaml2(input, label = "<yaml>", limits = KXM_YAML_LIMITS) {
|
|
16240
16240
|
try {
|
|
16241
16241
|
return parseRestrictedYaml(input, label, limits);
|
|
16242
16242
|
} catch (error) {
|
|
16243
|
-
if (error instanceof RestrictedYamlError) throw new
|
|
16243
|
+
if (error instanceof RestrictedYamlError) throw new KxmConfigError(error.issues);
|
|
16244
16244
|
throw error;
|
|
16245
16245
|
}
|
|
16246
16246
|
}
|
|
@@ -16249,7 +16249,7 @@ function readJsonObject(file) {
|
|
|
16249
16249
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${file} is not a JSON object`);
|
|
16250
16250
|
return parsed;
|
|
16251
16251
|
}
|
|
16252
|
-
var
|
|
16252
|
+
var KxmSchemaRegistry = class {
|
|
16253
16253
|
schemasDir;
|
|
16254
16254
|
ajv;
|
|
16255
16255
|
validators = /* @__PURE__ */ new Map();
|
|
@@ -16289,19 +16289,19 @@ var VnextSchemaRegistry = class {
|
|
|
16289
16289
|
this.ajv.addSchema(readJsonObject(join2(this.schemasDir, runEventFile)));
|
|
16290
16290
|
this.ajv.addSchema(readJsonObject(join2(this.schemasDir, driveReceiptFile)));
|
|
16291
16291
|
for (const [kind, definition] of Object.entries(RESOURCE_SCHEMA)) {
|
|
16292
|
-
const validator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16292
|
+
const validator = this.ajv.getSchema(`https://schemas.kxm.dev/${definition.file}`);
|
|
16293
16293
|
if (!validator) throw new Error(`schema did not compile: ${definition.file}`);
|
|
16294
16294
|
this.validators.set(kind, validator);
|
|
16295
16295
|
}
|
|
16296
|
-
const localBindingsValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16297
|
-
const templateProvenanceValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16298
|
-
const initOperationValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16299
|
-
const migrationPlanValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16300
|
-
const migrationDecisionValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16301
|
-
const migrationReceiptValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16302
|
-
const permissionDiffValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16303
|
-
const runEventValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16304
|
-
const driveReceiptValidator = this.ajv.getSchema(`https://schemas.kxm.dev
|
|
16296
|
+
const localBindingsValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${localBindingsFile}`);
|
|
16297
|
+
const templateProvenanceValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${templateProvenanceFile}`);
|
|
16298
|
+
const initOperationValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${initOperationFile}`);
|
|
16299
|
+
const migrationPlanValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${migrationPlanFile}`);
|
|
16300
|
+
const migrationDecisionValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${migrationDecisionFile}`);
|
|
16301
|
+
const migrationReceiptValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${migrationReceiptFile}`);
|
|
16302
|
+
const permissionDiffValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${permissionDiffFile}`);
|
|
16303
|
+
const runEventValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${runEventFile}`);
|
|
16304
|
+
const driveReceiptValidator = this.ajv.getSchema(`https://schemas.kxm.dev/${driveReceiptFile}`);
|
|
16305
16305
|
if (!localBindingsValidator) throw new Error(`schema did not compile: ${localBindingsFile}`);
|
|
16306
16306
|
if (!templateProvenanceValidator) throw new Error(`schema did not compile: ${templateProvenanceFile}`);
|
|
16307
16307
|
if (!initOperationValidator) throw new Error(`schema did not compile: ${initOperationFile}`);
|
|
@@ -16327,7 +16327,7 @@ var VnextSchemaRegistry = class {
|
|
|
16327
16327
|
return [issue2("schema", "schema_identity_mismatch", file, `expected ${definition.identity}, received ${String(value.schema)}`)];
|
|
16328
16328
|
}
|
|
16329
16329
|
const validator = this.validators.get(kind);
|
|
16330
|
-
if (!validator) throw new Error(`missing
|
|
16330
|
+
if (!validator) throw new Error(`missing KXM validator for ${kind}`);
|
|
16331
16331
|
if (validator(value)) return [];
|
|
16332
16332
|
return (validator.errors ?? []).map((error) => schemaIssue(file, error));
|
|
16333
16333
|
}
|
|
@@ -16365,9 +16365,9 @@ var VnextSchemaRegistry = class {
|
|
|
16365
16365
|
};
|
|
16366
16366
|
var cachedRunEventRegistry;
|
|
16367
16367
|
function validateRunEvent(value, file) {
|
|
16368
|
-
const registry = cachedRunEventRegistry ??= new
|
|
16368
|
+
const registry = cachedRunEventRegistry ??= new KxmSchemaRegistry();
|
|
16369
16369
|
if (!registry.runEventValidator(value)) {
|
|
16370
|
-
throw new
|
|
16370
|
+
throw new KxmConfigError([issue2(
|
|
16371
16371
|
"schema",
|
|
16372
16372
|
"run_event_invalid",
|
|
16373
16373
|
file,
|
|
@@ -16376,9 +16376,9 @@ function validateRunEvent(value, file) {
|
|
|
16376
16376
|
}
|
|
16377
16377
|
}
|
|
16378
16378
|
function validateDriveReceipt(value, file) {
|
|
16379
|
-
const registry = cachedRunEventRegistry ??= new
|
|
16379
|
+
const registry = cachedRunEventRegistry ??= new KxmSchemaRegistry();
|
|
16380
16380
|
if (!value || typeof value !== "object" || Array.isArray(value) || value.schema !== "kxm.drive-receipt.v1") {
|
|
16381
|
-
throw new
|
|
16381
|
+
throw new KxmConfigError([issue2(
|
|
16382
16382
|
"schema",
|
|
16383
16383
|
"drive_receipt_invalid",
|
|
16384
16384
|
file,
|
|
@@ -16386,7 +16386,7 @@ function validateDriveReceipt(value, file) {
|
|
|
16386
16386
|
)]);
|
|
16387
16387
|
}
|
|
16388
16388
|
if (!registry.driveReceiptValidator(value)) {
|
|
16389
|
-
throw new
|
|
16389
|
+
throw new KxmConfigError([issue2(
|
|
16390
16390
|
"schema",
|
|
16391
16391
|
"drive_receipt_invalid",
|
|
16392
16392
|
file,
|
|
@@ -16436,7 +16436,7 @@ function portableBindingIssue(root, pathHint, repositoryId) {
|
|
|
16436
16436
|
}
|
|
16437
16437
|
return void 0;
|
|
16438
16438
|
}
|
|
16439
|
-
function
|
|
16439
|
+
function kxmPortablePath(path) {
|
|
16440
16440
|
return portablePath(path);
|
|
16441
16441
|
}
|
|
16442
16442
|
function portablePath(path) {
|
|
@@ -16445,11 +16445,11 @@ function portablePath(path) {
|
|
|
16445
16445
|
const segments = path.split("/");
|
|
16446
16446
|
return segments.every((segment) => segment.length > 0 && segment !== "." && segment !== ".." && !WINDOWS_RESERVED.test((segment.split(".")[0] ?? segment).replace(/[ .]+$/g, "")) && !segment.endsWith(".") && !segment.endsWith(" ") && !segment.includes(":"));
|
|
16447
16447
|
}
|
|
16448
|
-
function
|
|
16448
|
+
function kxmResourceIdentifier(id) {
|
|
16449
16449
|
return id.length <= 64 && IDENTIFIER.test(id) && !WINDOWS_RESERVED.test(id);
|
|
16450
16450
|
}
|
|
16451
16451
|
function resourceIdentifier(id) {
|
|
16452
|
-
return
|
|
16452
|
+
return kxmResourceIdentifier(id);
|
|
16453
16453
|
}
|
|
16454
16454
|
function displayPath(root, file) {
|
|
16455
16455
|
const candidate = relative(root, file).replaceAll("\\", "/");
|
|
@@ -16480,7 +16480,7 @@ function readResource(registry, root, file, logicalPath, kind, id, containmentRo
|
|
|
16480
16480
|
if (!stat.isFile()) fail2("path", "resource_not_file", label, "configuration resource must be a regular file");
|
|
16481
16481
|
const value = parseRestrictedYaml2(readFileSync(file), label);
|
|
16482
16482
|
const issues = registry.validate(kind, value, label);
|
|
16483
|
-
if (issues.length > 0) throw new
|
|
16483
|
+
if (issues.length > 0) throw new KxmConfigError(issues);
|
|
16484
16484
|
return { kind, ...id === void 0 ? {} : { id }, file, logicalPath, value };
|
|
16485
16485
|
}
|
|
16486
16486
|
function readTemplateProvenance(registry, root) {
|
|
@@ -16503,8 +16503,8 @@ function readTemplateProvenance(registry, root) {
|
|
|
16503
16503
|
}
|
|
16504
16504
|
const value = parseRestrictedYaml2(readFileSync(file), label);
|
|
16505
16505
|
const issues = registry.validateTemplateProvenance(value, label);
|
|
16506
|
-
if (issues.length > 0) throw new
|
|
16507
|
-
if (!
|
|
16506
|
+
if (issues.length > 0) throw new KxmConfigError(issues);
|
|
16507
|
+
if (!resolveKxmTemplateBaseline(value)) {
|
|
16508
16508
|
fail2("semantic", "template_provenance_revision_invalid", label, "template provenance does not exactly match a supported built-in baseline");
|
|
16509
16509
|
}
|
|
16510
16510
|
const files = Array.isArray(value.files) ? value.files : [];
|
|
@@ -16564,11 +16564,11 @@ function listNamedResources(registry, root, directory, logicalDirectory, kind) {
|
|
|
16564
16564
|
const resource = readResource(registry, root, join2(directory, entry.name), `${logicalDirectory}/${id}.yaml`, kind, id);
|
|
16565
16565
|
resources.set(id, resource);
|
|
16566
16566
|
} catch (error) {
|
|
16567
|
-
if (error instanceof
|
|
16567
|
+
if (error instanceof KxmConfigError) issues.push(...error.issues);
|
|
16568
16568
|
else throw error;
|
|
16569
16569
|
}
|
|
16570
16570
|
}
|
|
16571
|
-
if (issues.length > 0) throw new
|
|
16571
|
+
if (issues.length > 0) throw new KxmConfigError(issues);
|
|
16572
16572
|
return resources;
|
|
16573
16573
|
}
|
|
16574
16574
|
function valuesOf(object, field) {
|
|
@@ -17088,7 +17088,7 @@ function validateBundle(project, repositories, agents, models, workflows, enviro
|
|
|
17088
17088
|
}
|
|
17089
17089
|
}
|
|
17090
17090
|
} catch (error) {
|
|
17091
|
-
if (error instanceof
|
|
17091
|
+
if (error instanceof KxmConfigError) {
|
|
17092
17092
|
issues.push(...error.issues);
|
|
17093
17093
|
}
|
|
17094
17094
|
}
|
|
@@ -17096,13 +17096,13 @@ function validateBundle(project, repositories, agents, models, workflows, enviro
|
|
|
17096
17096
|
}
|
|
17097
17097
|
return sortIssues2(issues);
|
|
17098
17098
|
}
|
|
17099
|
-
function
|
|
17099
|
+
function kxmCanonicalJson(value) {
|
|
17100
17100
|
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
17101
|
-
if (Array.isArray(value)) return `[${value.map((candidate) =>
|
|
17102
|
-
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${
|
|
17101
|
+
if (Array.isArray(value)) return `[${value.map((candidate) => kxmCanonicalJson(candidate)).join(",")}]`;
|
|
17102
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${kxmCanonicalJson(value[key])}`).join(",")}}`;
|
|
17103
17103
|
}
|
|
17104
17104
|
function canonicalize(value) {
|
|
17105
|
-
return
|
|
17105
|
+
return kxmCanonicalJson(value);
|
|
17106
17106
|
}
|
|
17107
17107
|
function bundleRevision(resources) {
|
|
17108
17108
|
const hash = createHash2("sha256");
|
|
@@ -17132,19 +17132,19 @@ function discoverGitRoot(start = process.cwd()) {
|
|
|
17132
17132
|
}
|
|
17133
17133
|
function assertNoRegisteredGates(options) {
|
|
17134
17134
|
if ("registeredGates" in options) {
|
|
17135
|
-
throw new
|
|
17135
|
+
throw new KxmConfigError([issue2("semantic", "registered_gates_removed", ".kxm/gates.yaml", "registeredGates was removed; declare gates in .kxm/gates.yaml")]);
|
|
17136
17136
|
}
|
|
17137
17137
|
}
|
|
17138
|
-
function
|
|
17138
|
+
function loadKxmProject(projectRoot, options = {}) {
|
|
17139
17139
|
assertNoRegisteredGates(options);
|
|
17140
17140
|
const root = resolve(projectRoot);
|
|
17141
17141
|
let migrationReceipt;
|
|
17142
17142
|
if (legacyConfigFilesAt(root).length > 0 && options.allowUnreceiptedLegacyConfig !== true) {
|
|
17143
|
-
const receiptCheck =
|
|
17144
|
-
if (receiptCheck.issues.length > 0) throw new
|
|
17143
|
+
const receiptCheck = readKxmMigrationReceipt(root, options);
|
|
17144
|
+
if (receiptCheck.issues.length > 0) throw new KxmConfigError(receiptCheck.issues);
|
|
17145
17145
|
migrationReceipt = receiptCheck.receipt;
|
|
17146
17146
|
}
|
|
17147
|
-
const registry = new
|
|
17147
|
+
const registry = new KxmSchemaRegistry(options.schemasDir);
|
|
17148
17148
|
const project = readResource(registry, root, join2(root, ".kxm", "project.yaml"), ".kxm/project.yaml", "project");
|
|
17149
17149
|
const earlyIssues = [];
|
|
17150
17150
|
validatePortablePaths(project, earlyIssues);
|
|
@@ -17156,7 +17156,7 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17156
17156
|
}
|
|
17157
17157
|
}
|
|
17158
17158
|
if (migrationReceipt && stringValue(migrationReceipt.projectId) !== stringValue(project.value.id)) {
|
|
17159
|
-
earlyIssues.push(issue2("semantic", "migration_project_mismatch",
|
|
17159
|
+
earlyIssues.push(issue2("semantic", "migration_project_mismatch", KXM_MIGRATION_RECEIPT_PATH, "migration receipt belongs to a different project identity"));
|
|
17160
17160
|
}
|
|
17161
17161
|
const declaredRepositoryIds = new Set(valuesOf(project.value, "repositories").map((candidate) => stringValue(objectValue(candidate)?.id)).filter((candidate) => candidate !== void 0));
|
|
17162
17162
|
for (const repositoryId of Object.keys(options.repositoryBindings ?? {}).sort(compareCodeUnits3)) {
|
|
@@ -17166,7 +17166,7 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17166
17166
|
earlyIssues.push(issue2("reference", "repository_binding_unknown", ".kxm/project.yaml", `host-local binding references unknown repository ${repositoryId}`));
|
|
17167
17167
|
}
|
|
17168
17168
|
}
|
|
17169
|
-
if (earlyIssues.length > 0) throw new
|
|
17169
|
+
if (earlyIssues.length > 0) throw new KxmConfigError(earlyIssues);
|
|
17170
17170
|
const agents = listNamedResources(registry, root, join2(root, ".kxm", "agents"), ".kxm/agents", "agent");
|
|
17171
17171
|
const models = listNamedResources(registry, root, join2(root, ".kxm", "models"), ".kxm/models", "model");
|
|
17172
17172
|
const workflows = listNamedResources(registry, root, join2(root, ".kxm", "workflows"), ".kxm/workflows", "workflow");
|
|
@@ -17180,7 +17180,7 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17180
17180
|
try {
|
|
17181
17181
|
environments.push(readResource(registry, root, projectEnvironment, ".kxm/project/env.yaml", "environment"));
|
|
17182
17182
|
} catch (error) {
|
|
17183
|
-
if (error instanceof
|
|
17183
|
+
if (error instanceof KxmConfigError) loadIssues.push(...error.issues);
|
|
17184
17184
|
else throw error;
|
|
17185
17185
|
}
|
|
17186
17186
|
}
|
|
@@ -17253,7 +17253,7 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17253
17253
|
definitionValidated = repositories.get(repositoryId) === resource;
|
|
17254
17254
|
}
|
|
17255
17255
|
} catch (error) {
|
|
17256
|
-
if (error instanceof
|
|
17256
|
+
if (error instanceof KxmConfigError) loadIssues.push(...error.issues);
|
|
17257
17257
|
else throw error;
|
|
17258
17258
|
}
|
|
17259
17259
|
} else if (required || hasLocalBinding) {
|
|
@@ -17267,15 +17267,15 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17267
17267
|
try {
|
|
17268
17268
|
environments.push(readResource(registry, root, environmentFile, `.kxm/repositories/${repositoryId}/env.yaml`, "environment", void 0, binding));
|
|
17269
17269
|
} catch (error) {
|
|
17270
|
-
if (error instanceof
|
|
17270
|
+
if (error instanceof KxmConfigError) loadIssues.push(...error.issues);
|
|
17271
17271
|
else throw error;
|
|
17272
17272
|
}
|
|
17273
17273
|
}
|
|
17274
17274
|
}
|
|
17275
17275
|
}
|
|
17276
|
-
if (loadIssues.length > 0) throw new
|
|
17276
|
+
if (loadIssues.length > 0) throw new KxmConfigError(loadIssues);
|
|
17277
17277
|
const issues = validateBundle(project, repositories, agents, models, workflows, environments, options, gateRegistry, root);
|
|
17278
|
-
if (issues.length > 0) throw new
|
|
17278
|
+
if (issues.length > 0) throw new KxmConfigError(issues);
|
|
17279
17279
|
const resources = [project, ...repositories.values(), ...agents.values(), ...models.values(), ...workflows.values(), ...environments, ...gateRegistry ? [gateRegistry] : []].sort((left, right) => compareCodeUnits3(left.logicalPath, right.logicalPath));
|
|
17280
17280
|
return {
|
|
17281
17281
|
projectRoot: root,
|
|
@@ -17292,7 +17292,7 @@ function loadVnextProject(projectRoot, options = {}) {
|
|
|
17292
17292
|
configRevision: bundleRevision(resources)
|
|
17293
17293
|
};
|
|
17294
17294
|
}
|
|
17295
|
-
var
|
|
17295
|
+
var KXM_MIGRATION_RECEIPT_PATH = ".kxm/migration-receipt.yaml";
|
|
17296
17296
|
var LEGACY_CONFIG_FILES = [".kxm/config/agents.json", ".kxm/config/gates.json"];
|
|
17297
17297
|
function legacyConfigFilesAt(root) {
|
|
17298
17298
|
const files = [];
|
|
@@ -17330,32 +17330,32 @@ function hashFileRecord(root, relativePath) {
|
|
|
17330
17330
|
}
|
|
17331
17331
|
function migrationReceiptSelfHash(receipt) {
|
|
17332
17332
|
const { receiptSha256: _ignored, ...unsigned } = receipt;
|
|
17333
|
-
return `sha256:${createHash2("sha256").update(
|
|
17333
|
+
return `sha256:${createHash2("sha256").update(kxmCanonicalJson(unsigned), "utf8").digest("hex")}`;
|
|
17334
17334
|
}
|
|
17335
|
-
function
|
|
17336
|
-
const receiptPath = join2(root, ...
|
|
17335
|
+
function readKxmMigrationReceipt(root, options = {}) {
|
|
17336
|
+
const receiptPath = join2(root, ...KXM_MIGRATION_RECEIPT_PATH.split("/"));
|
|
17337
17337
|
const legacyFiles = legacyConfigFilesAt(root);
|
|
17338
17338
|
if (!existsSync3(receiptPath)) {
|
|
17339
17339
|
return {
|
|
17340
|
-
issues: legacyFiles.map((file) => issue2("semantic", "
|
|
17340
|
+
issues: legacyFiles.map((file) => issue2("semantic", "legacy_kxm_conflict", file, "legacy and KXM configuration cannot coexist before an accepted migration receipt"))
|
|
17341
17341
|
};
|
|
17342
17342
|
}
|
|
17343
17343
|
const receiptStat = lstatSync(receiptPath);
|
|
17344
17344
|
if (receiptStat.isSymbolicLink() || !receiptStat.isFile()) {
|
|
17345
|
-
return { issues: [issue2("path", "migration_receipt_invalid",
|
|
17345
|
+
return { issues: [issue2("path", "migration_receipt_invalid", KXM_MIGRATION_RECEIPT_PATH, "migration receipt must be a regular file, not a link")] };
|
|
17346
17346
|
}
|
|
17347
17347
|
let receipt;
|
|
17348
17348
|
try {
|
|
17349
|
-
receipt = parseRestrictedYaml2(readFileSync(receiptPath),
|
|
17349
|
+
receipt = parseRestrictedYaml2(readFileSync(receiptPath), KXM_MIGRATION_RECEIPT_PATH);
|
|
17350
17350
|
} catch (error) {
|
|
17351
|
-
if (error instanceof
|
|
17351
|
+
if (error instanceof KxmConfigError) return { issues: [...error.issues] };
|
|
17352
17352
|
throw error;
|
|
17353
17353
|
}
|
|
17354
|
-
const registry = new
|
|
17355
|
-
const schemaIssues = registry.validateMigrationReceipt(receipt,
|
|
17354
|
+
const registry = new KxmSchemaRegistry(options.schemasDir);
|
|
17355
|
+
const schemaIssues = registry.validateMigrationReceipt(receipt, KXM_MIGRATION_RECEIPT_PATH);
|
|
17356
17356
|
if (schemaIssues.length > 0) return { issues: schemaIssues };
|
|
17357
17357
|
if (receipt.receiptSha256 !== migrationReceiptSelfHash(receipt)) {
|
|
17358
|
-
return { issues: [issue2("semantic", "migration_receipt_hash_mismatch",
|
|
17358
|
+
return { issues: [issue2("semantic", "migration_receipt_hash_mismatch", KXM_MIGRATION_RECEIPT_PATH, "receipt self-hash does not match its content")] };
|
|
17359
17359
|
}
|
|
17360
17360
|
const sources = (Array.isArray(receipt.sources) ? receipt.sources : []).map((candidate) => candidate && typeof candidate === "object" && !Array.isArray(candidate) ? candidate.path : void 0).filter((candidate) => typeof candidate === "string").sort(compareCodeUnits3);
|
|
17361
17361
|
const issues = [];
|
|
@@ -17379,12 +17379,12 @@ function readVnextMigrationReceipt(root, options = {}) {
|
|
|
17379
17379
|
return issues.length > 0 ? { issues } : { receipt, issues: [] };
|
|
17380
17380
|
}
|
|
17381
17381
|
|
|
17382
|
-
// plugins/kxm/src/
|
|
17382
|
+
// plugins/kxm/src/runtime-store.ts
|
|
17383
17383
|
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
17384
17384
|
import { existsSync as existsSync5, lstatSync as lstatSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
17385
17385
|
import { dirname as dirname5, join as join5, resolve as resolve4 } from "node:path";
|
|
17386
17386
|
|
|
17387
|
-
// plugins/kxm/src/
|
|
17387
|
+
// plugins/kxm/src/bindings.ts
|
|
17388
17388
|
import { homedir } from "node:os";
|
|
17389
17389
|
|
|
17390
17390
|
// plugins/kxm/src/sqlite.ts
|
|
@@ -17426,7 +17426,7 @@ var DatabaseSync = class {
|
|
|
17426
17426
|
}
|
|
17427
17427
|
};
|
|
17428
17428
|
|
|
17429
|
-
// plugins/kxm/src/
|
|
17429
|
+
// plugins/kxm/src/bindings.ts
|
|
17430
17430
|
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, parse, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
17431
17431
|
var MAX_BINDING_RECORD_BYTES = 256 * 1024;
|
|
17432
17432
|
var BINDING_LABEL = "Runtime-local repository bindings";
|
|
@@ -17434,9 +17434,9 @@ function bindingIssue(phase, code, message) {
|
|
|
17434
17434
|
return { phase, code, file: BINDING_LABEL, message };
|
|
17435
17435
|
}
|
|
17436
17436
|
function bindingError(phase, code, message) {
|
|
17437
|
-
throw new
|
|
17437
|
+
throw new KxmConfigError([bindingIssue(phase, code, message)]);
|
|
17438
17438
|
}
|
|
17439
|
-
function
|
|
17439
|
+
function kxmUserStateRoot(options = {}) {
|
|
17440
17440
|
const env = options.env ?? process.env;
|
|
17441
17441
|
const platform = options.platform ?? process.platform;
|
|
17442
17442
|
const home = options.homeDir ?? homedir();
|
|
@@ -17471,7 +17471,7 @@ import {
|
|
|
17471
17471
|
import { basename as basename2, dirname as dirname4, join as join4, resolve as resolve3 } from "node:path";
|
|
17472
17472
|
function databaseError(code, file, message) {
|
|
17473
17473
|
const issue3 = { phase: "semantic", code, file, message };
|
|
17474
|
-
return new
|
|
17474
|
+
return new KxmConfigError([issue3]);
|
|
17475
17475
|
}
|
|
17476
17476
|
function checkedParent(path, description) {
|
|
17477
17477
|
const parent = dirname4(path);
|
|
@@ -17626,9 +17626,9 @@ function withDatabaseTransaction(database, work, mode = "IMMEDIATE") {
|
|
|
17626
17626
|
}
|
|
17627
17627
|
}
|
|
17628
17628
|
|
|
17629
|
-
// plugins/kxm/src/
|
|
17630
|
-
function
|
|
17631
|
-
const stateRoot = options.stateRoot ? resolve4(options.stateRoot) :
|
|
17629
|
+
// plugins/kxm/src/runtime-store.ts
|
|
17630
|
+
function kxmRuntimePaths(options = {}) {
|
|
17631
|
+
const stateRoot = options.stateRoot ? resolve4(options.stateRoot) : kxmUserStateRoot({ ...options.env ? { env: options.env } : {}, ...options.homeDir ? { homeDir: options.homeDir } : {} });
|
|
17632
17632
|
const runtimeDir = join5(stateRoot, "runtime");
|
|
17633
17633
|
return {
|
|
17634
17634
|
stateRoot,
|
|
@@ -17641,7 +17641,7 @@ function runtimeIssue(phase, code, file, message) {
|
|
|
17641
17641
|
return { phase, code, file, message };
|
|
17642
17642
|
}
|
|
17643
17643
|
function runtimeError(code, file, message) {
|
|
17644
|
-
return new
|
|
17644
|
+
return new KxmConfigError([runtimeIssue("semantic", code, file, message)]);
|
|
17645
17645
|
}
|
|
17646
17646
|
function projectRuntimeKey(projectRoot) {
|
|
17647
17647
|
let canonical;
|
|
@@ -17653,7 +17653,7 @@ function projectRuntimeKey(projectRoot) {
|
|
|
17653
17653
|
const folded = process.platform === "win32" ? canonical.toLocaleLowerCase("en-US") : canonical;
|
|
17654
17654
|
return createHash3("sha256").update(folded, "utf8").digest("hex").slice(0, 24);
|
|
17655
17655
|
}
|
|
17656
|
-
var
|
|
17656
|
+
var KXM_REGISTRY_SCHEMA_VERSION = 1;
|
|
17657
17657
|
var REGISTRY_TABLES = {
|
|
17658
17658
|
supervisor: ["singleton_id", "runtime_id", "pid", "port", "token_hash", "started_at", "heartbeat_at", "state"],
|
|
17659
17659
|
projects: ["project_id", "project_root", "project_key", "home_runtime_id", "config_revision", "registered_at"]
|
|
@@ -17678,14 +17678,14 @@ CREATE TABLE projects (
|
|
|
17678
17678
|
registered_at TEXT NOT NULL
|
|
17679
17679
|
) STRICT;
|
|
17680
17680
|
`;
|
|
17681
|
-
var
|
|
17681
|
+
var KxmRuntimeRegistry = class {
|
|
17682
17682
|
path;
|
|
17683
17683
|
database;
|
|
17684
17684
|
constructor(path) {
|
|
17685
17685
|
this.path = resolve4(path);
|
|
17686
17686
|
this.database = openDatabase(this.path, "runtime registry", {
|
|
17687
17687
|
schema: REGISTRY_SCHEMA,
|
|
17688
|
-
version:
|
|
17688
|
+
version: KXM_REGISTRY_SCHEMA_VERSION,
|
|
17689
17689
|
tables: REGISTRY_TABLES
|
|
17690
17690
|
});
|
|
17691
17691
|
}
|
|
@@ -17844,12 +17844,12 @@ var VnextRuntimeRegistry = class {
|
|
|
17844
17844
|
} : void 0;
|
|
17845
17845
|
}
|
|
17846
17846
|
};
|
|
17847
|
-
var
|
|
17848
|
-
function
|
|
17847
|
+
var KXM_RUN_EVENT_SCHEMA = "kxm.run-event.v1";
|
|
17848
|
+
function hashKxmDriveLog(events) {
|
|
17849
17849
|
const body = events.map((event) => `${event.eventId}:${event.sequence}`).join("\n");
|
|
17850
17850
|
return `sha256:${createHash3("sha256").update(body, "utf8").digest("hex")}`;
|
|
17851
17851
|
}
|
|
17852
|
-
function
|
|
17852
|
+
function verifyKxmDriveReceipt(receipt, events, foldedStatus, binding) {
|
|
17853
17853
|
const reasons = [];
|
|
17854
17854
|
if (receipt.runId !== binding.runId) {
|
|
17855
17855
|
reasons.push(`runId ${receipt.runId} != binding ${binding.runId}`);
|
|
@@ -17863,7 +17863,7 @@ function verifyVnextDriveReceipt(receipt, events, foldedStatus, binding) {
|
|
|
17863
17863
|
reasons.push(`lastSequence ${receipt.lastSequence} != log ${currentLast}`);
|
|
17864
17864
|
}
|
|
17865
17865
|
const prefix = events.filter((event) => event.sequence >= 1 && event.sequence <= receipt.lastSequence);
|
|
17866
|
-
if (
|
|
17866
|
+
if (hashKxmDriveLog(prefix) !== receipt.logHash) {
|
|
17867
17867
|
reasons.push("logHash mismatch");
|
|
17868
17868
|
}
|
|
17869
17869
|
if (receipt.settlement.status !== foldedStatus) {
|
|
@@ -17872,8 +17872,8 @@ function verifyVnextDriveReceipt(receipt, events, foldedStatus, binding) {
|
|
|
17872
17872
|
if (reasons.length === 0) return { verified: true };
|
|
17873
17873
|
return { verified: false, divergence: reasons.join("; ") };
|
|
17874
17874
|
}
|
|
17875
|
-
var
|
|
17876
|
-
var
|
|
17875
|
+
var KXM_EVENT_STORE_SCHEMA_VERSION = 4;
|
|
17876
|
+
var KXM_DRIVE_RECEIPT_SCHEMA = "kxm.drive-receipt.v1";
|
|
17877
17877
|
var DRIVE_RECEIPT_MAX_BYTES = 8 * 1024;
|
|
17878
17878
|
var EVENT_STORE_TABLES = {
|
|
17879
17879
|
runs: ["run_id", "project_id", "home_runtime_id", "workflow_id", "prompt_sha256", "status", "config_revision", "memory_revision", "executor_policy_revision", "tool_policy_revision", "created_at", "updated_at"],
|
|
@@ -18130,14 +18130,14 @@ var EVENT_STORE_MIGRATIONS = [
|
|
|
18130
18130
|
}
|
|
18131
18131
|
}
|
|
18132
18132
|
];
|
|
18133
|
-
var
|
|
18133
|
+
var KxmRunEventStore = class {
|
|
18134
18134
|
path;
|
|
18135
18135
|
database;
|
|
18136
18136
|
constructor(path) {
|
|
18137
18137
|
this.path = resolve4(path);
|
|
18138
18138
|
this.database = openDatabase(this.path, "run event store", {
|
|
18139
18139
|
schema: EVENT_STORE_SCHEMA,
|
|
18140
|
-
version:
|
|
18140
|
+
version: KXM_EVENT_STORE_SCHEMA_VERSION,
|
|
18141
18141
|
tables: EVENT_STORE_TABLES,
|
|
18142
18142
|
migrations: EVENT_STORE_MIGRATIONS
|
|
18143
18143
|
});
|
|
@@ -18298,7 +18298,7 @@ var VnextRunEventStore = class {
|
|
|
18298
18298
|
}
|
|
18299
18299
|
insertDriveReceipt(receipt) {
|
|
18300
18300
|
validateDriveReceipt(receipt, "drive-receipt");
|
|
18301
|
-
const canonical =
|
|
18301
|
+
const canonical = kxmCanonicalJson(receipt);
|
|
18302
18302
|
if (Buffer.byteLength(canonical, "utf8") > DRIVE_RECEIPT_MAX_BYTES) {
|
|
18303
18303
|
throw runtimeError("drive_receipt_invalid", receipt.driveId, `drive receipt exceeds ${DRIVE_RECEIPT_MAX_BYTES} bytes`);
|
|
18304
18304
|
}
|
|
@@ -18592,28 +18592,28 @@ function runFromRow(row) {
|
|
|
18592
18592
|
updatedAt: row.updated_at
|
|
18593
18593
|
};
|
|
18594
18594
|
}
|
|
18595
|
-
function
|
|
18595
|
+
function newKxmRunId() {
|
|
18596
18596
|
return `run_${randomUUID().replaceAll("-", "")}`;
|
|
18597
18597
|
}
|
|
18598
|
-
function
|
|
18598
|
+
function newKxmEventId() {
|
|
18599
18599
|
return `evt_${randomUUID().replaceAll("-", "")}`;
|
|
18600
18600
|
}
|
|
18601
|
-
function
|
|
18601
|
+
function newKxmCommandId() {
|
|
18602
18602
|
return `cmd_${randomUUID().replaceAll("-", "")}`;
|
|
18603
18603
|
}
|
|
18604
|
-
function
|
|
18604
|
+
function newKxmAssignmentId() {
|
|
18605
18605
|
return `asg_${randomUUID().replaceAll("-", "")}`;
|
|
18606
18606
|
}
|
|
18607
|
-
function
|
|
18607
|
+
function newKxmAttemptId() {
|
|
18608
18608
|
return `att_${randomUUID().replaceAll("-", "")}`;
|
|
18609
18609
|
}
|
|
18610
|
-
function
|
|
18610
|
+
function newKxmEffectId() {
|
|
18611
18611
|
return `eff_${randomUUID().replaceAll("-", "")}`;
|
|
18612
18612
|
}
|
|
18613
|
-
function
|
|
18613
|
+
function newKxmObservationId() {
|
|
18614
18614
|
return `obs_${randomUUID().replaceAll("-", "")}`;
|
|
18615
18615
|
}
|
|
18616
|
-
function
|
|
18616
|
+
function newKxmEvidenceId() {
|
|
18617
18617
|
return `gev_${randomUUID().replaceAll("-", "")}`;
|
|
18618
18618
|
}
|
|
18619
18619
|
var SHA256 = /^sha256:[a-f0-9]{64}$/;
|
|
@@ -18695,7 +18695,7 @@ function gateRowContentHash(table, row) {
|
|
|
18695
18695
|
const copy = { ...row };
|
|
18696
18696
|
delete copy.contentHash;
|
|
18697
18697
|
void table;
|
|
18698
|
-
return `sha256:${createHash3("sha256").update(
|
|
18698
|
+
return `sha256:${createHash3("sha256").update(kxmCanonicalJson(copy), "utf8").digest("hex")}`;
|
|
18699
18699
|
}
|
|
18700
18700
|
function assertClosedGateObservation(kind, row, id = "observation") {
|
|
18701
18701
|
if (row.completeness === "incomplete") return;
|
|
@@ -18924,13 +18924,13 @@ function capabilityFromRow(row) {
|
|
|
18924
18924
|
} : void 0;
|
|
18925
18925
|
}
|
|
18926
18926
|
|
|
18927
|
-
// plugins/kxm/src/
|
|
18927
|
+
// plugins/kxm/src/runtime-service.ts
|
|
18928
18928
|
import { createHash as createHash5 } from "node:crypto";
|
|
18929
18929
|
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync4 } from "node:fs";
|
|
18930
18930
|
import { join as join6 } from "node:path";
|
|
18931
18931
|
|
|
18932
|
-
// plugins/kxm/src/
|
|
18933
|
-
var
|
|
18932
|
+
// plugins/kxm/src/engine-fold.ts
|
|
18933
|
+
var KXM_RUN_STATE_SCHEMA = "kxm.run-state.v2";
|
|
18934
18934
|
var FOLD_PANEL_BOUND = 1;
|
|
18935
18935
|
var RUN_STATUSES = /* @__PURE__ */ new Set(["created", "preparing", "running", "waiting", "blocked_uncertain", "cancelling", "cancelled", "completed", "failed"]);
|
|
18936
18936
|
var TERMINAL_RUN = /* @__PURE__ */ new Set(["cancelled", "completed", "failed"]);
|
|
@@ -18996,7 +18996,7 @@ function panelAttempt(current) {
|
|
|
18996
18996
|
const attemptId = assignment?.currentAttemptId;
|
|
18997
18997
|
return attemptId ? assignment.attempts[attemptId] : void 0;
|
|
18998
18998
|
}
|
|
18999
|
-
function
|
|
18999
|
+
function kxmFoldPanelAttempt(step, attemptId) {
|
|
19000
19000
|
if (!step) return void 0;
|
|
19001
19001
|
for (const assignmentId of step.panel.order) {
|
|
19002
19002
|
const assignment = step.panel.assignments[assignmentId];
|
|
@@ -19094,7 +19094,7 @@ function expectedStatusForDeclaredOutcome(step, outcome) {
|
|
|
19094
19094
|
if (outcome === "cancelled") return "cancelled";
|
|
19095
19095
|
return "failed";
|
|
19096
19096
|
}
|
|
19097
|
-
function
|
|
19097
|
+
function kxmJoinAll(step, panel) {
|
|
19098
19098
|
if (panel.order.length < step.assignments.minimum) return { tag: "unsatisfied" };
|
|
19099
19099
|
const members = [];
|
|
19100
19100
|
for (const assignmentId of panel.order) {
|
|
@@ -19150,7 +19150,7 @@ function putAssignment(current, assignmentId, assignment) {
|
|
|
19150
19150
|
}
|
|
19151
19151
|
};
|
|
19152
19152
|
}
|
|
19153
|
-
function
|
|
19153
|
+
function kxmFoldPanelAttemptIds(step) {
|
|
19154
19154
|
if (!step) return [];
|
|
19155
19155
|
const ids = [];
|
|
19156
19156
|
for (const assignmentId of step.panel.order) {
|
|
@@ -19160,12 +19160,12 @@ function vnextFoldPanelAttemptIds(step) {
|
|
|
19160
19160
|
}
|
|
19161
19161
|
return ids;
|
|
19162
19162
|
}
|
|
19163
|
-
function
|
|
19163
|
+
function foldKxmRunState(run, plan, events, options = {}) {
|
|
19164
19164
|
if (events.length === 0) {
|
|
19165
19165
|
throw runtimeError("run_events_illegal", run.runId, "run has no events");
|
|
19166
19166
|
}
|
|
19167
19167
|
const state = {
|
|
19168
|
-
schema:
|
|
19168
|
+
schema: KXM_RUN_STATE_SCHEMA,
|
|
19169
19169
|
runId: run.runId,
|
|
19170
19170
|
status: "created",
|
|
19171
19171
|
stepAttempts: /* @__PURE__ */ Object.create(null),
|
|
@@ -19402,7 +19402,7 @@ function isProvenFailure(state, plan) {
|
|
|
19402
19402
|
if (stepTerminal && settled) {
|
|
19403
19403
|
const step2 = plan?.steps[current.stepId];
|
|
19404
19404
|
if (step2 && current.status === "failed") {
|
|
19405
|
-
const joined =
|
|
19405
|
+
const joined = kxmJoinAll(step2, current.panel);
|
|
19406
19406
|
if (joined.tag === "rejected" || joined.tag === "conflict") return true;
|
|
19407
19407
|
}
|
|
19408
19408
|
if (plan && current.outcome) {
|
|
@@ -19525,7 +19525,7 @@ function foldStepStatus(state, plan, event) {
|
|
|
19525
19525
|
}
|
|
19526
19526
|
const step = plan ? requireStep(plan, current.stepId, state.runId) : void 0;
|
|
19527
19527
|
if (step) {
|
|
19528
|
-
const joined =
|
|
19528
|
+
const joined = kxmJoinAll(step, current.panel);
|
|
19529
19529
|
if (joined.tag === "outcome") {
|
|
19530
19530
|
const expectedStatus = expectedStatusForDeclaredOutcome(step, joined.outcome);
|
|
19531
19531
|
const selected = step.transitions[joined.outcome];
|
|
@@ -19585,7 +19585,7 @@ function foldOutcome(state, plan, event) {
|
|
|
19585
19585
|
throw runtimeError("run_events_illegal", state.runId, "step.outcome_recorded cannot overwrite a recorded outcome");
|
|
19586
19586
|
}
|
|
19587
19587
|
const step = requireStep(plan, stepId, state.runId);
|
|
19588
|
-
const joined =
|
|
19588
|
+
const joined = kxmJoinAll(step, current.panel);
|
|
19589
19589
|
if (joined.tag !== "outcome" || joined.outcome !== outcome) {
|
|
19590
19590
|
throw runtimeError("run_events_illegal", state.runId, "step.outcome_recorded does not match the recorded assignment outcome");
|
|
19591
19591
|
}
|
|
@@ -19613,7 +19613,7 @@ function foldTransitioned(state, plan, event) {
|
|
|
19613
19613
|
throw runtimeError("run_events_illegal", state.runId, "step.transitioned requires every panel assignment and issued attempt to be terminal");
|
|
19614
19614
|
}
|
|
19615
19615
|
const step = requireStep(plan, fromStepId, state.runId);
|
|
19616
|
-
const joined =
|
|
19616
|
+
const joined = kxmJoinAll(step, current.panel);
|
|
19617
19617
|
if (joined.tag !== "outcome" || joined.outcome !== outcome) {
|
|
19618
19618
|
throw runtimeError("run_events_illegal", state.runId, "step.transitioned requires a matching joined declared outcome");
|
|
19619
19619
|
}
|
|
@@ -19828,7 +19828,7 @@ function foldAttemptCreated(state, event) {
|
|
|
19828
19828
|
function foldAttemptStatus(state, plan, event) {
|
|
19829
19829
|
requireActiveStep(state, "attempt.status_changed");
|
|
19830
19830
|
const current = state.currentStep;
|
|
19831
|
-
if (
|
|
19831
|
+
if (kxmFoldPanelAttemptIds(current).length === 0) {
|
|
19832
19832
|
throw runtimeError("run_events_illegal", state.runId, "attempt.status_changed has no active attempt");
|
|
19833
19833
|
}
|
|
19834
19834
|
const attemptId = stringPayload(event, "attemptId");
|
|
@@ -20102,7 +20102,7 @@ function freezeCurrentStep(current) {
|
|
|
20102
20102
|
}
|
|
20103
20103
|
function freezeState(state) {
|
|
20104
20104
|
const frozen = {
|
|
20105
|
-
schema:
|
|
20105
|
+
schema: KXM_RUN_STATE_SCHEMA,
|
|
20106
20106
|
runId: state.runId,
|
|
20107
20107
|
status: state.status,
|
|
20108
20108
|
...state.runPlanHash !== void 0 ? { runPlanHash: state.runPlanHash } : {},
|
|
@@ -20130,11 +20130,11 @@ function isTerminalRunStatus(status) {
|
|
|
20130
20130
|
return TERMINAL_RUN.has(status);
|
|
20131
20131
|
}
|
|
20132
20132
|
|
|
20133
|
-
// plugins/kxm/src/
|
|
20133
|
+
// plugins/kxm/src/engine-plan.ts
|
|
20134
20134
|
import { createHash as createHash4 } from "node:crypto";
|
|
20135
20135
|
|
|
20136
|
-
// plugins/kxm/src/
|
|
20137
|
-
var
|
|
20136
|
+
// plugins/kxm/src/engine-compile.ts
|
|
20137
|
+
var KXM_COMPILED_WORKFLOW_SCHEMA = "kxm.compiled-workflow.v1";
|
|
20138
20138
|
var WORKFLOW_SCHEMA = "kxm.workflow.v1";
|
|
20139
20139
|
var STEP_ID_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/;
|
|
20140
20140
|
var SUPPORTED_STEP_KINDS = /* @__PURE__ */ new Set(["agent", "moa", "gate", "approval", "wait"]);
|
|
@@ -20144,16 +20144,16 @@ var EVIDENCE_KINDS = /* @__PURE__ */ new Set(["assignment-result", "gate", "rece
|
|
|
20144
20144
|
var REPOSITORY_ACCESS = /* @__PURE__ */ new Set(["none", "read", "write"]);
|
|
20145
20145
|
var DISTINCT_BY = /* @__PURE__ */ new Set(["provider", "model", "profile"]);
|
|
20146
20146
|
var BANNED_RUNTIME_HINT = "not yet supported";
|
|
20147
|
-
var
|
|
20147
|
+
var KxmEngineCompileError = class extends Error {
|
|
20148
20148
|
issues;
|
|
20149
20149
|
constructor(issues) {
|
|
20150
20150
|
const sorted = sortIssues3(issues);
|
|
20151
20151
|
super(sorted.map((issue3) => `${issue3.workflowId}: ${issue3.code}: ${issue3.message}`).join("\n"));
|
|
20152
|
-
this.name = "
|
|
20152
|
+
this.name = "KxmEngineCompileError";
|
|
20153
20153
|
this.issues = sorted;
|
|
20154
20154
|
}
|
|
20155
20155
|
};
|
|
20156
|
-
function
|
|
20156
|
+
function compileKxmWorkflow(input) {
|
|
20157
20157
|
const sink = { workflowId: input.id, issues: [] };
|
|
20158
20158
|
const value = input.value;
|
|
20159
20159
|
if (value.schema !== WORKFLOW_SCHEMA) {
|
|
@@ -20199,16 +20199,16 @@ function compileVnextWorkflow(input) {
|
|
|
20199
20199
|
pushIssue(sink, { code: "plan_hash_stage_unknown", message: `requirePlanHash references unknown stage ${stageId}` });
|
|
20200
20200
|
}
|
|
20201
20201
|
}
|
|
20202
|
-
if (sink.issues.length > 0) throw new
|
|
20202
|
+
if (sink.issues.length > 0) throw new KxmEngineCompileError(sink.issues);
|
|
20203
20203
|
const order = compiledSteps.map((step) => step.id);
|
|
20204
20204
|
const steps = /* @__PURE__ */ Object.create(null);
|
|
20205
20205
|
for (const step of compiledSteps) steps[step.id] = step;
|
|
20206
20206
|
const entryStepId = order[0];
|
|
20207
|
-
if (!entryStepId) throw new
|
|
20207
|
+
if (!entryStepId) throw new KxmEngineCompileError(sink.issues);
|
|
20208
20208
|
const coordinator = stringValue2(value.coordinator) ?? "coordinator";
|
|
20209
20209
|
const transitionBudget = limits.maxTransitions ?? order.length;
|
|
20210
20210
|
const plan = {
|
|
20211
|
-
schema:
|
|
20211
|
+
schema: KXM_COMPILED_WORKFLOW_SCHEMA,
|
|
20212
20212
|
workflowId: input.id,
|
|
20213
20213
|
...input.logicalPath !== void 0 ? { sourcePath: input.logicalPath } : {},
|
|
20214
20214
|
coordinator,
|
|
@@ -20636,8 +20636,8 @@ function pushIssue(sink, issue3) {
|
|
|
20636
20636
|
sink.issues.push({ workflowId: sink.workflowId, ...issue3 });
|
|
20637
20637
|
}
|
|
20638
20638
|
|
|
20639
|
-
// plugins/kxm/src/
|
|
20640
|
-
var
|
|
20639
|
+
// plugins/kxm/src/engine-plan.ts
|
|
20640
|
+
var KXM_RUN_PLAN_SCHEMA = "kxm.run-plan.v2";
|
|
20641
20641
|
var SUPPORTED_KINDS = /* @__PURE__ */ new Set(["agent", "moa", "gate", "approval", "wait"]);
|
|
20642
20642
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
20643
20643
|
var JOIN_STRATEGIES2 = /* @__PURE__ */ new Set(["all", "all-settled", "quorum", "first-success"]);
|
|
@@ -20677,13 +20677,13 @@ var JOIN_REQUIRED = ["strategy"];
|
|
|
20677
20677
|
var JOIN_OPTIONAL = ["minimumPassed", "cancelRemaining"];
|
|
20678
20678
|
var EVIDENCE_REQUIRED = ["key", "kind", "minimum", "reusableAcrossAttempts"];
|
|
20679
20679
|
var EVIDENCE_OPTIONAL = ["producerPolicy"];
|
|
20680
|
-
function
|
|
20680
|
+
function kxmSha256(input) {
|
|
20681
20681
|
return `sha256:${createHash4("sha256").update(input, "utf8").digest("hex")}`;
|
|
20682
20682
|
}
|
|
20683
|
-
function
|
|
20684
|
-
return
|
|
20683
|
+
function hashKxmRunPlanEnvelope(envelope) {
|
|
20684
|
+
return kxmSha256(kxmCanonicalJson(envelope));
|
|
20685
20685
|
}
|
|
20686
|
-
function
|
|
20686
|
+
function freezeKxmCompiledPlan(plan) {
|
|
20687
20687
|
const steps = /* @__PURE__ */ Object.create(null);
|
|
20688
20688
|
for (const id of plan.order) {
|
|
20689
20689
|
const step = plan.steps[id];
|
|
@@ -20721,7 +20721,7 @@ function freezeStep(step) {
|
|
|
20721
20721
|
join: { ...step.join }
|
|
20722
20722
|
});
|
|
20723
20723
|
}
|
|
20724
|
-
function
|
|
20724
|
+
function parseKxmRunPlanEnvelope(raw, run, expectedHash) {
|
|
20725
20725
|
let parsed;
|
|
20726
20726
|
try {
|
|
20727
20727
|
parsed = JSON.parse(raw);
|
|
@@ -20729,16 +20729,16 @@ function parseVnextRunPlanEnvelope(raw, run, expectedHash) {
|
|
|
20729
20729
|
throw runtimeError("run_plan_corrupt", run.runId, "run plan envelope is not JSON");
|
|
20730
20730
|
}
|
|
20731
20731
|
const envelope = parseEnvelope(parsed, run);
|
|
20732
|
-
const hash =
|
|
20732
|
+
const hash = hashKxmRunPlanEnvelope(envelope);
|
|
20733
20733
|
if (hash !== expectedHash) {
|
|
20734
20734
|
throw runtimeError("run_plan_corrupt", run.runId, "run plan envelope hash does not match");
|
|
20735
20735
|
}
|
|
20736
20736
|
return envelope;
|
|
20737
20737
|
}
|
|
20738
|
-
function
|
|
20738
|
+
function rehydrateKxmCompiledPlanFromStore(store, run) {
|
|
20739
20739
|
return loadPinnedEnvelope(store, run).plan;
|
|
20740
20740
|
}
|
|
20741
|
-
function
|
|
20741
|
+
function loadKxmRunPlanEnvelope(store, run) {
|
|
20742
20742
|
return loadPinnedEnvelope(store, run);
|
|
20743
20743
|
}
|
|
20744
20744
|
function loadPinnedEnvelope(store, run) {
|
|
@@ -20750,12 +20750,12 @@ function loadPinnedEnvelope(store, run) {
|
|
|
20750
20750
|
if (typeof eventHash !== "string" || eventHash !== row.runPlanHash) {
|
|
20751
20751
|
throw runtimeError("run_plan_corrupt", run.runId, "pinned runPlanHash does not match the plan row");
|
|
20752
20752
|
}
|
|
20753
|
-
return
|
|
20753
|
+
return parseKxmRunPlanEnvelope(row.envelope, run, row.runPlanHash);
|
|
20754
20754
|
}
|
|
20755
20755
|
function parseEnvelope(parsed, run) {
|
|
20756
20756
|
const value = asObject(parsed, run.runId, "run plan envelope");
|
|
20757
20757
|
assertExactKeys(value, ENVELOPE_REQUIRED, [], run.runId, "run plan envelope");
|
|
20758
|
-
if (value.schema !==
|
|
20758
|
+
if (value.schema !== KXM_RUN_PLAN_SCHEMA) {
|
|
20759
20759
|
throw runtimeError("run_plan_corrupt", run.runId, "schema is not kxm.run-plan.v2");
|
|
20760
20760
|
}
|
|
20761
20761
|
const runId = asString(value.runId, run.runId, "runId");
|
|
@@ -20783,9 +20783,9 @@ function parseEnvelope(parsed, run) {
|
|
|
20783
20783
|
...limitsValue.maxRunDurationMs !== void 0 ? { maxRunDurationMs: asDuration(limitsValue.maxRunDurationMs, run.runId, "projectLimits.maxRunDurationMs") } : {},
|
|
20784
20784
|
...limitsValue.maxAgentTimeMs !== void 0 ? { maxAgentTimeMs: asDuration(limitsValue.maxAgentTimeMs, run.runId, "projectLimits.maxAgentTimeMs") } : {}
|
|
20785
20785
|
};
|
|
20786
|
-
const plan =
|
|
20786
|
+
const plan = freezeKxmCompiledPlan(parseCompiledPlan(value.plan, run.runId));
|
|
20787
20787
|
return {
|
|
20788
|
-
schema:
|
|
20788
|
+
schema: KXM_RUN_PLAN_SCHEMA,
|
|
20789
20789
|
runId,
|
|
20790
20790
|
projectId,
|
|
20791
20791
|
homeRuntimeId,
|
|
@@ -20893,7 +20893,7 @@ function parseGateDefinition(raw, gateId, runId) {
|
|
|
20893
20893
|
throw runtimeError("run_plan_corrupt", runId, `gates.definitions.${gateId}.paths are not unique`);
|
|
20894
20894
|
}
|
|
20895
20895
|
for (const path of paths) {
|
|
20896
|
-
if (path === "." || !
|
|
20896
|
+
if (path === "." || !kxmPortablePath(path) || path.startsWith("/") || path.includes("\\")) {
|
|
20897
20897
|
throw runtimeError("run_plan_corrupt", runId, `gates.definitions.${gateId} path is not a portable relative path`);
|
|
20898
20898
|
}
|
|
20899
20899
|
}
|
|
@@ -20919,7 +20919,7 @@ function freezeGates(gates) {
|
|
|
20919
20919
|
function parseCompiledPlan(raw, runId) {
|
|
20920
20920
|
const value = asObject(raw, runId, "compiled plan");
|
|
20921
20921
|
assertExactKeys(value, PLAN_REQUIRED, PLAN_OPTIONAL, runId, "compiled plan");
|
|
20922
|
-
if (value.schema !==
|
|
20922
|
+
if (value.schema !== KXM_COMPILED_WORKFLOW_SCHEMA) {
|
|
20923
20923
|
throw runtimeError("run_plan_corrupt", runId, "compiled plan schema is not kxm.compiled-workflow.v1");
|
|
20924
20924
|
}
|
|
20925
20925
|
const order = asStringArray(value.order, runId, "order");
|
|
@@ -20950,7 +20950,7 @@ function parseCompiledPlan(raw, runId) {
|
|
|
20950
20950
|
if (!steps[stageId]) throw runtimeError("run_plan_corrupt", runId, `requirePlanHash references unknown step ${stageId}`);
|
|
20951
20951
|
}
|
|
20952
20952
|
const plan = {
|
|
20953
|
-
schema:
|
|
20953
|
+
schema: KXM_COMPILED_WORKFLOW_SCHEMA,
|
|
20954
20954
|
workflowId: asString(value.workflowId, runId, "workflowId"),
|
|
20955
20955
|
...value.sourcePath !== void 0 ? { sourcePath: asStringAllowEmpty(value.sourcePath, runId, "sourcePath") } : {},
|
|
20956
20956
|
coordinator: asString(value.coordinator, runId, "coordinator"),
|
|
@@ -21234,16 +21234,16 @@ function deepFreeze2(value) {
|
|
|
21234
21234
|
return Object.freeze(value);
|
|
21235
21235
|
}
|
|
21236
21236
|
|
|
21237
|
-
// plugins/kxm/src/
|
|
21237
|
+
// plugins/kxm/src/gate-hash.ts
|
|
21238
21238
|
function gateDefinitionHash(id, definition) {
|
|
21239
|
-
return
|
|
21239
|
+
return kxmSha256(kxmCanonicalJson({ id, ...definition }));
|
|
21240
21240
|
}
|
|
21241
21241
|
function gateRegistryHash(registryValue) {
|
|
21242
|
-
return
|
|
21242
|
+
return kxmSha256(kxmCanonicalJson(registryValue));
|
|
21243
21243
|
}
|
|
21244
21244
|
|
|
21245
|
-
// plugins/kxm/src/
|
|
21246
|
-
function
|
|
21245
|
+
// plugins/kxm/src/engine-evidence.ts
|
|
21246
|
+
function verifyKxmGateEvidence(store, run, envelope, events, state) {
|
|
21247
21247
|
const attempts = store.gateAttemptsForRun(run.runId);
|
|
21248
21248
|
const observations = store.gateObservationsForRun(run.runId);
|
|
21249
21249
|
const evidence = store.gateEvidenceForRun(run.runId);
|
|
@@ -21409,7 +21409,7 @@ function verifyVnextGateEvidence(store, run, envelope, events, state) {
|
|
|
21409
21409
|
throw runtimeError("gate_evidence_unexpected", run.runId, "non-settled attempt has evidence");
|
|
21410
21410
|
}
|
|
21411
21411
|
}
|
|
21412
|
-
void
|
|
21412
|
+
void kxmCanonicalJson;
|
|
21413
21413
|
}
|
|
21414
21414
|
function lastEffectByAttempt(events) {
|
|
21415
21415
|
const last = /* @__PURE__ */ new Map();
|
|
@@ -21470,7 +21470,7 @@ function stringField(event, field) {
|
|
|
21470
21470
|
return value;
|
|
21471
21471
|
}
|
|
21472
21472
|
|
|
21473
|
-
// plugins/kxm/src/
|
|
21473
|
+
// plugins/kxm/src/runtime-owner.ts
|
|
21474
21474
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
21475
21475
|
var owners = /* @__PURE__ */ new Map();
|
|
21476
21476
|
function record(storePath) {
|
|
@@ -21498,16 +21498,16 @@ function clearImplicitIfIdle(owner) {
|
|
|
21498
21498
|
delete owner.implicit;
|
|
21499
21499
|
}
|
|
21500
21500
|
}
|
|
21501
|
-
function
|
|
21501
|
+
function registerKxmRuntimeHandle(storePath) {
|
|
21502
21502
|
record(storePath).handles += 1;
|
|
21503
21503
|
}
|
|
21504
|
-
function
|
|
21504
|
+
function unregisterKxmRuntimeHandle(storePath) {
|
|
21505
21505
|
const owner = owners.get(storePath);
|
|
21506
21506
|
if (!owner) return;
|
|
21507
21507
|
owner.handles = Math.max(0, owner.handles - 1);
|
|
21508
21508
|
maybeDelete(storePath, owner);
|
|
21509
21509
|
}
|
|
21510
|
-
function
|
|
21510
|
+
function registerKxmAttemptController(storePath, runId, attempt) {
|
|
21511
21511
|
const owner = record(storePath);
|
|
21512
21512
|
let runAttempts = owner.attempts.get(runId);
|
|
21513
21513
|
if (!runAttempts) {
|
|
@@ -21519,15 +21519,15 @@ function registerVnextAttemptController(storePath, runId, attempt) {
|
|
|
21519
21519
|
}
|
|
21520
21520
|
runAttempts.set(attempt.attemptId, attempt);
|
|
21521
21521
|
}
|
|
21522
|
-
function
|
|
21522
|
+
function kxmAttemptController(storePath, runId, attemptId) {
|
|
21523
21523
|
return owners.get(storePath)?.attempts.get(runId)?.get(attemptId);
|
|
21524
21524
|
}
|
|
21525
|
-
function
|
|
21525
|
+
function kxmAttemptControllers(storePath, runId) {
|
|
21526
21526
|
const runAttempts = owners.get(storePath)?.attempts.get(runId);
|
|
21527
21527
|
if (!runAttempts) return [];
|
|
21528
21528
|
return [...runAttempts.values()];
|
|
21529
21529
|
}
|
|
21530
|
-
function
|
|
21530
|
+
function unregisterKxmAttemptController(storePath, runId, attemptId) {
|
|
21531
21531
|
const owner = owners.get(storePath);
|
|
21532
21532
|
if (!owner) return;
|
|
21533
21533
|
const runAttempts = owner.attempts.get(runId);
|
|
@@ -21537,7 +21537,7 @@ function unregisterVnextAttemptController(storePath, runId, attemptId) {
|
|
|
21537
21537
|
if (runAttempts.size === 0) owner.attempts.delete(runId);
|
|
21538
21538
|
maybeDelete(storePath, owner);
|
|
21539
21539
|
}
|
|
21540
|
-
function
|
|
21540
|
+
function bindKxmSchedulerPolicy(storePath, bound, configRevision) {
|
|
21541
21541
|
const owner = record(storePath);
|
|
21542
21542
|
const current = activePolicy(owner);
|
|
21543
21543
|
if (current && (current.configRevision !== configRevision || current.bound !== bound)) {
|
|
@@ -21548,10 +21548,10 @@ function bindVnextSchedulerPolicy(storePath, bound, configRevision) {
|
|
|
21548
21548
|
owner.scheduler = { bound, configRevision };
|
|
21549
21549
|
delete owner.implicit;
|
|
21550
21550
|
}
|
|
21551
|
-
function
|
|
21551
|
+
function kxmSchedulerPolicy(storePath) {
|
|
21552
21552
|
return owners.get(storePath)?.scheduler;
|
|
21553
21553
|
}
|
|
21554
|
-
function
|
|
21554
|
+
function admitKxmRun(storePath, runId, envelopeRevision, envelopeBound) {
|
|
21555
21555
|
const owner = record(storePath);
|
|
21556
21556
|
if (owner.admitted.has(runId)) {
|
|
21557
21557
|
throw runtimeError("run_busy", runId, `run ${runId} is already admitted`);
|
|
@@ -21578,7 +21578,7 @@ function admitVnextRun(storePath, runId, envelopeRevision, envelopeBound) {
|
|
|
21578
21578
|
owner.admitted.set(runId, { token, configRevision: envelopeRevision });
|
|
21579
21579
|
return token;
|
|
21580
21580
|
}
|
|
21581
|
-
function
|
|
21581
|
+
function releaseKxmRun(storePath, runId, token) {
|
|
21582
21582
|
const owner = owners.get(storePath);
|
|
21583
21583
|
if (!owner) return;
|
|
21584
21584
|
const current = owner.admitted.get(runId);
|
|
@@ -21589,7 +21589,7 @@ function releaseVnextRun(storePath, runId, token) {
|
|
|
21589
21589
|
clearImplicitIfIdle(owner);
|
|
21590
21590
|
maybeDelete(storePath, owner);
|
|
21591
21591
|
}
|
|
21592
|
-
function
|
|
21592
|
+
function armKxmGateHold(storePath, runId, token, attemptId, stop) {
|
|
21593
21593
|
const owner = record(storePath);
|
|
21594
21594
|
const current = owner.admitted.get(runId);
|
|
21595
21595
|
if (!current || current.token !== token) {
|
|
@@ -21600,7 +21600,7 @@ function armVnextGateHold(storePath, runId, token, attemptId, stop) {
|
|
|
21600
21600
|
}
|
|
21601
21601
|
current.gateHold = { attemptId, token, state: "active", stop };
|
|
21602
21602
|
}
|
|
21603
|
-
function
|
|
21603
|
+
function markKxmGateHoldUnsettled(storePath, runId, token, attemptId) {
|
|
21604
21604
|
const owner = owners.get(storePath);
|
|
21605
21605
|
const current = owner?.admitted.get(runId);
|
|
21606
21606
|
if (!current || current.token !== token) {
|
|
@@ -21612,7 +21612,7 @@ function markVnextGateHoldUnsettled(storePath, runId, token, attemptId) {
|
|
|
21612
21612
|
}
|
|
21613
21613
|
hold.state = "unsettled";
|
|
21614
21614
|
}
|
|
21615
|
-
function
|
|
21615
|
+
function finishKxmOwnedGate(storePath, runId, token, attemptId) {
|
|
21616
21616
|
const owner = owners.get(storePath);
|
|
21617
21617
|
const current = owner?.admitted.get(runId);
|
|
21618
21618
|
if (!current || current.token !== token) {
|
|
@@ -21627,12 +21627,12 @@ function finishVnextOwnedGate(storePath, runId, token, attemptId) {
|
|
|
21627
21627
|
}
|
|
21628
21628
|
delete current.gateHold;
|
|
21629
21629
|
}
|
|
21630
|
-
function
|
|
21630
|
+
function dropKxmGateStopHook(storePath, runId, attemptId) {
|
|
21631
21631
|
const hold = owners.get(storePath)?.admitted.get(runId)?.gateHold;
|
|
21632
21632
|
if (!hold || hold.attemptId !== attemptId) return;
|
|
21633
21633
|
delete hold.stop;
|
|
21634
21634
|
}
|
|
21635
|
-
function
|
|
21635
|
+
function resolveKxmGateHold(storePath, runId, attemptId) {
|
|
21636
21636
|
const owner = owners.get(storePath);
|
|
21637
21637
|
if (!owner) return;
|
|
21638
21638
|
const current = owner.admitted.get(runId);
|
|
@@ -21649,15 +21649,15 @@ function resolveVnextGateHold(storePath, runId, attemptId) {
|
|
|
21649
21649
|
clearImplicitIfIdle(owner);
|
|
21650
21650
|
maybeDelete(storePath, owner);
|
|
21651
21651
|
}
|
|
21652
|
-
function
|
|
21652
|
+
function kxmGateHold(storePath, runId) {
|
|
21653
21653
|
const hold = owners.get(storePath)?.admitted.get(runId)?.gateHold;
|
|
21654
21654
|
if (!hold) return void 0;
|
|
21655
21655
|
return { attemptId: hold.attemptId, token: hold.token, state: hold.state };
|
|
21656
21656
|
}
|
|
21657
|
-
function
|
|
21657
|
+
function kxmAdmittedToken(storePath, runId) {
|
|
21658
21658
|
return owners.get(storePath)?.admitted.get(runId)?.token;
|
|
21659
21659
|
}
|
|
21660
|
-
function
|
|
21660
|
+
function attachKxmDriveSession(storePath, runId, token, session) {
|
|
21661
21661
|
const owner = record(storePath);
|
|
21662
21662
|
const current = owner.admitted.get(runId);
|
|
21663
21663
|
if (!current || current.token !== token) {
|
|
@@ -21668,16 +21668,16 @@ function attachVnextDriveSession(storePath, runId, token, session) {
|
|
|
21668
21668
|
}
|
|
21669
21669
|
current.driveSession = session;
|
|
21670
21670
|
}
|
|
21671
|
-
function
|
|
21671
|
+
function clearKxmDriveSession(storePath, runId, token) {
|
|
21672
21672
|
const owner = owners.get(storePath);
|
|
21673
21673
|
const current = owner?.admitted.get(runId);
|
|
21674
21674
|
if (!current || current.token !== token) return;
|
|
21675
21675
|
delete current.driveSession;
|
|
21676
21676
|
}
|
|
21677
|
-
function
|
|
21677
|
+
function kxmDriveSession(storePath, runId) {
|
|
21678
21678
|
return owners.get(storePath)?.admitted.get(runId)?.driveSession;
|
|
21679
21679
|
}
|
|
21680
|
-
function
|
|
21680
|
+
function kxmOpenDriveSessions(storePath) {
|
|
21681
21681
|
const owner = owners.get(storePath);
|
|
21682
21682
|
if (!owner) return [];
|
|
21683
21683
|
const sessions = [];
|
|
@@ -21686,7 +21686,7 @@ function vnextOpenDriveSessions(storePath) {
|
|
|
21686
21686
|
}
|
|
21687
21687
|
return sessions;
|
|
21688
21688
|
}
|
|
21689
|
-
function
|
|
21689
|
+
function enqueueKxmScheduledRun(storePath, runId, configRevision, bound, start) {
|
|
21690
21690
|
const owner = record(storePath);
|
|
21691
21691
|
if (owner.admitted.has(runId) || owner.queue.some((item) => item.runId === runId)) {
|
|
21692
21692
|
return Promise.reject(runtimeError("run_busy", runId, `run ${runId} is already admitted or queued`));
|
|
@@ -21709,18 +21709,18 @@ function pump(storePath, owner) {
|
|
|
21709
21709
|
if (!next) break;
|
|
21710
21710
|
let token;
|
|
21711
21711
|
try {
|
|
21712
|
-
token =
|
|
21712
|
+
token = admitKxmRun(storePath, next.runId, next.configRevision, next.bound);
|
|
21713
21713
|
} catch (error) {
|
|
21714
21714
|
next.fail(error);
|
|
21715
21715
|
continue;
|
|
21716
21716
|
}
|
|
21717
21717
|
void next.start(token).finally(() => {
|
|
21718
|
-
|
|
21718
|
+
releaseKxmRun(storePath, next.runId, token);
|
|
21719
21719
|
});
|
|
21720
21720
|
}
|
|
21721
21721
|
}
|
|
21722
21722
|
|
|
21723
|
-
// plugins/kxm/src/
|
|
21723
|
+
// plugins/kxm/src/runtime-service.ts
|
|
21724
21724
|
function compareCodeUnits5(left, right) {
|
|
21725
21725
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
21726
21726
|
}
|
|
@@ -21730,7 +21730,7 @@ function sha256Of(input) {
|
|
|
21730
21730
|
function objectValue3(value) {
|
|
21731
21731
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
21732
21732
|
}
|
|
21733
|
-
function
|
|
21733
|
+
function kxmExecutorPolicyRevision(bundle) {
|
|
21734
21734
|
const executors = /* @__PURE__ */ new Set();
|
|
21735
21735
|
const defaultExecutor = bundle.project.value.defaultExecutor;
|
|
21736
21736
|
if (typeof defaultExecutor === "string") executors.add(defaultExecutor);
|
|
@@ -21738,9 +21738,9 @@ function vnextExecutorPolicyRevision(bundle) {
|
|
|
21738
21738
|
const executor = agent.value.executor;
|
|
21739
21739
|
if (typeof executor === "string") executors.add(executor);
|
|
21740
21740
|
}
|
|
21741
|
-
return sha256Of(
|
|
21741
|
+
return sha256Of(kxmCanonicalJson([...executors].sort()));
|
|
21742
21742
|
}
|
|
21743
|
-
function
|
|
21743
|
+
function kxmToolPolicyRevision(bundle) {
|
|
21744
21744
|
const policies = [];
|
|
21745
21745
|
for (const agent of [...bundle.agents.values()].sort((left, right) => String(left.id).localeCompare(String(right.id)))) {
|
|
21746
21746
|
policies.push({ agent: agent.id ?? "unknown", tools: objectValue3(agent.value.tools) ?? null });
|
|
@@ -21754,7 +21754,7 @@ function vnextToolPolicyRevision(bundle) {
|
|
|
21754
21754
|
}
|
|
21755
21755
|
}
|
|
21756
21756
|
}
|
|
21757
|
-
return sha256Of(
|
|
21757
|
+
return sha256Of(kxmCanonicalJson({ policies, gateRegistry: bundle.gateRegistry?.value ?? null }));
|
|
21758
21758
|
}
|
|
21759
21759
|
function collectMemoryFiles(dir, baseDir, ignoreSubdirs = /* @__PURE__ */ new Set()) {
|
|
21760
21760
|
if (!existsSync6(dir)) return [];
|
|
@@ -21772,7 +21772,7 @@ function collectMemoryFiles(dir, baseDir, ignoreSubdirs = /* @__PURE__ */ new Se
|
|
|
21772
21772
|
}
|
|
21773
21773
|
return results;
|
|
21774
21774
|
}
|
|
21775
|
-
function
|
|
21775
|
+
function computeKxmMemoryRevision(bundle, options = {}) {
|
|
21776
21776
|
const hash = createHash5("sha256");
|
|
21777
21777
|
const memoryDir = options.memoryDir ?? join6(bundle.projectRoot, ".kxm", "memory");
|
|
21778
21778
|
const memoryFiles = collectMemoryFiles(memoryDir, memoryDir, /* @__PURE__ */ new Set(["candidates"])).sort((left, right) => compareCodeUnits5(left.relPath, right.relPath));
|
|
@@ -21793,30 +21793,30 @@ function computeVnextMemoryRevision(bundle, options = {}) {
|
|
|
21793
21793
|
const currentItems = options.promotedState.filter((item) => !item.status || item.status === "current").slice().sort((left, right) => compareCodeUnits5(left.id, right.id));
|
|
21794
21794
|
for (const item of currentItems) {
|
|
21795
21795
|
hash.update(`state:${item.id}\0`, "utf8");
|
|
21796
|
-
hash.update(
|
|
21796
|
+
hash.update(kxmCanonicalJson(item), "utf8");
|
|
21797
21797
|
hash.update("\0", "utf8");
|
|
21798
21798
|
}
|
|
21799
21799
|
}
|
|
21800
21800
|
return `ctxrev_${hash.digest("hex")}`;
|
|
21801
21801
|
}
|
|
21802
|
-
function
|
|
21802
|
+
function kxmPolicyRevisions(bundle, options) {
|
|
21803
21803
|
return {
|
|
21804
21804
|
configRevision: bundle.configRevision,
|
|
21805
|
-
memoryRevision:
|
|
21806
|
-
executorPolicyRevision:
|
|
21807
|
-
toolPolicyRevision:
|
|
21805
|
+
memoryRevision: computeKxmMemoryRevision(bundle, options),
|
|
21806
|
+
executorPolicyRevision: kxmExecutorPolicyRevision(bundle),
|
|
21807
|
+
toolPolicyRevision: kxmToolPolicyRevision(bundle)
|
|
21808
21808
|
};
|
|
21809
21809
|
}
|
|
21810
|
-
function
|
|
21810
|
+
function kxmDeclaredRepositoryIds(bundle) {
|
|
21811
21811
|
return [...bundle.repositories.keys()].sort();
|
|
21812
21812
|
}
|
|
21813
|
-
function
|
|
21813
|
+
function kxmDeclaredExecutorIds(bundle) {
|
|
21814
21814
|
return [...new Set([
|
|
21815
21815
|
typeof bundle.project.value.defaultExecutor === "string" ? bundle.project.value.defaultExecutor : void 0,
|
|
21816
21816
|
...[...bundle.agents.values()].map((agent) => agent.value.executor).filter((value) => typeof value === "string")
|
|
21817
21817
|
].filter((value) => value !== void 0))].sort();
|
|
21818
21818
|
}
|
|
21819
|
-
function
|
|
21819
|
+
function kxmProjectAdmissionLimits(bundle) {
|
|
21820
21820
|
const limits = objectValue3(bundle.project.value.limits);
|
|
21821
21821
|
const maxConcurrentRuns = typeof limits?.maxConcurrentRuns === "number" && Number.isInteger(limits.maxConcurrentRuns) && limits.maxConcurrentRuns >= 1 ? limits.maxConcurrentRuns : 1;
|
|
21822
21822
|
return {
|
|
@@ -21827,10 +21827,10 @@ function vnextProjectAdmissionLimits(bundle) {
|
|
|
21827
21827
|
}
|
|
21828
21828
|
var closedRuntimeContexts = /* @__PURE__ */ new WeakSet();
|
|
21829
21829
|
var runtimeCloseHooks = /* @__PURE__ */ new WeakMap();
|
|
21830
|
-
function
|
|
21830
|
+
function isKxmRuntimeContextClosed(context) {
|
|
21831
21831
|
return closedRuntimeContexts.has(context);
|
|
21832
21832
|
}
|
|
21833
|
-
function
|
|
21833
|
+
function registerKxmRuntimeCloseHook(context, hook) {
|
|
21834
21834
|
if (closedRuntimeContexts.has(context)) {
|
|
21835
21835
|
hook();
|
|
21836
21836
|
return () => void 0;
|
|
@@ -21845,11 +21845,11 @@ function registerVnextRuntimeCloseHook(context, hook) {
|
|
|
21845
21845
|
hooks.delete(hook);
|
|
21846
21846
|
};
|
|
21847
21847
|
}
|
|
21848
|
-
function
|
|
21849
|
-
const paths =
|
|
21850
|
-
const registry = new
|
|
21848
|
+
function openKxmRuntimeContext(projectRoot, options) {
|
|
21849
|
+
const paths = kxmRuntimePaths(options.stateRoot !== void 0 ? { stateRoot: options.stateRoot } : {});
|
|
21850
|
+
const registry = new KxmRuntimeRegistry(paths.registryDb);
|
|
21851
21851
|
try {
|
|
21852
|
-
const bundle =
|
|
21852
|
+
const bundle = loadKxmProject(projectRoot, options);
|
|
21853
21853
|
const projectId = String(bundle.project.value.id);
|
|
21854
21854
|
const registration = registry.registerProject({
|
|
21855
21855
|
projectId,
|
|
@@ -21858,8 +21858,8 @@ function openVnextRuntimeContext(projectRoot, options) {
|
|
|
21858
21858
|
configRevision: bundle.configRevision,
|
|
21859
21859
|
now: options.now ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
21860
21860
|
});
|
|
21861
|
-
const eventStore = new
|
|
21862
|
-
|
|
21861
|
+
const eventStore = new KxmRunEventStore(join6(paths.projectsDir, registration.projectKey, "run-events.db"));
|
|
21862
|
+
registerKxmRuntimeHandle(eventStore.path);
|
|
21863
21863
|
return {
|
|
21864
21864
|
registry,
|
|
21865
21865
|
projectRoot: bundle.projectRoot,
|
|
@@ -21872,7 +21872,7 @@ function openVnextRuntimeContext(projectRoot, options) {
|
|
|
21872
21872
|
throw error;
|
|
21873
21873
|
}
|
|
21874
21874
|
}
|
|
21875
|
-
function
|
|
21875
|
+
function closeKxmRuntimeContext(context) {
|
|
21876
21876
|
if (closedRuntimeContexts.has(context)) return;
|
|
21877
21877
|
closedRuntimeContexts.add(context);
|
|
21878
21878
|
const hooks = runtimeCloseHooks.get(context);
|
|
@@ -21885,20 +21885,20 @@ function closeVnextRuntimeContext(context) {
|
|
|
21885
21885
|
}
|
|
21886
21886
|
}
|
|
21887
21887
|
}
|
|
21888
|
-
|
|
21888
|
+
unregisterKxmRuntimeHandle(context.eventStore.path);
|
|
21889
21889
|
context.eventStore.close();
|
|
21890
21890
|
context.registry.close();
|
|
21891
21891
|
}
|
|
21892
21892
|
var RUNTIME_EPOCH_NS = process.hrtime.bigint();
|
|
21893
|
-
function
|
|
21893
|
+
function kxmMonotonicNs() {
|
|
21894
21894
|
return (process.hrtime.bigint() - RUNTIME_EPOCH_NS).toString();
|
|
21895
21895
|
}
|
|
21896
|
-
function
|
|
21896
|
+
function kxmIncrementMonotonicNs(value) {
|
|
21897
21897
|
return (BigInt(value) + 1n).toString();
|
|
21898
21898
|
}
|
|
21899
|
-
function
|
|
21899
|
+
function kxmEventBase(context, run, now, monotonicNs, commandId) {
|
|
21900
21900
|
return {
|
|
21901
|
-
schema:
|
|
21901
|
+
schema: KXM_RUN_EVENT_SCHEMA,
|
|
21902
21902
|
projectId: context.projectId,
|
|
21903
21903
|
runId: run.runId,
|
|
21904
21904
|
homeRuntimeId: run.homeRuntimeId,
|
|
@@ -21912,15 +21912,15 @@ function vnextEventBase(context, run, now, monotonicNs, commandId) {
|
|
|
21912
21912
|
...commandId !== void 0 ? { commandId } : {}
|
|
21913
21913
|
};
|
|
21914
21914
|
}
|
|
21915
|
-
function
|
|
21916
|
-
const commandId = request.commandId ??
|
|
21915
|
+
function acceptKxmRun(context, bundle, request, options = {}) {
|
|
21916
|
+
const commandId = request.commandId ?? newKxmCommandId();
|
|
21917
21917
|
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
21918
|
-
const monotonicNs = options.monotonicNs ??
|
|
21918
|
+
const monotonicNs = options.monotonicNs ?? kxmMonotonicNs();
|
|
21919
21919
|
const workflow = bundle.workflows.get(request.workflowId);
|
|
21920
21920
|
if (!workflow) {
|
|
21921
21921
|
throw runtimeError("run_workflow_unknown", ".kxm/workflows", `workflow ${request.workflowId} does not exist in this project`);
|
|
21922
21922
|
}
|
|
21923
|
-
const revisions =
|
|
21923
|
+
const revisions = kxmPolicyRevisions(bundle, options);
|
|
21924
21924
|
const memoryRevision = options.memoryRevision ?? revisions.memoryRevision;
|
|
21925
21925
|
const promptSha256 = `sha256:${createHash5("sha256").update(request.prompt, "utf8").digest("hex")}`;
|
|
21926
21926
|
return context.eventStore.transaction(() => {
|
|
@@ -21938,17 +21938,17 @@ function acceptVnextRun(context, bundle, request, options = {}) {
|
|
|
21938
21938
|
if (events.length === 0) throw runtimeError("run_command_corrupt", commandId, "idempotent command references a run with no creation event");
|
|
21939
21939
|
return { accepted: true, idempotent: true, run: run2, event: events[0] };
|
|
21940
21940
|
}
|
|
21941
|
-
const runId =
|
|
21941
|
+
const runId = newKxmRunId();
|
|
21942
21942
|
const payload = {
|
|
21943
21943
|
workflowId: request.workflowId,
|
|
21944
21944
|
status: "created",
|
|
21945
21945
|
promptHash: promptSha256,
|
|
21946
|
-
repositoryIds:
|
|
21947
|
-
executorIds:
|
|
21946
|
+
repositoryIds: kxmDeclaredRepositoryIds(bundle),
|
|
21947
|
+
executorIds: kxmDeclaredExecutorIds(bundle)
|
|
21948
21948
|
};
|
|
21949
21949
|
const event = {
|
|
21950
|
-
schema:
|
|
21951
|
-
eventId:
|
|
21950
|
+
schema: KXM_RUN_EVENT_SCHEMA,
|
|
21951
|
+
eventId: newKxmEventId(),
|
|
21952
21952
|
eventType: "run.created",
|
|
21953
21953
|
projectId: context.projectId,
|
|
21954
21954
|
runId,
|
|
@@ -21991,14 +21991,14 @@ function acceptVnextRun(context, bundle, request, options = {}) {
|
|
|
21991
21991
|
return { accepted: true, idempotent: false, run, event };
|
|
21992
21992
|
});
|
|
21993
21993
|
}
|
|
21994
|
-
function
|
|
21994
|
+
function foldStoredKxmRun(context, run) {
|
|
21995
21995
|
const events = context.eventStore.events(run.runId, 0, 1e6);
|
|
21996
21996
|
const planRow = context.eventStore.runPlan(run.runId);
|
|
21997
21997
|
if (!planRow && events.some((event) => event.eventType.startsWith("step.") || event.eventType.startsWith("effect.") || event.payload.status === "preparing" || event.payload.status === "running" || event.payload.status === "cancelling")) {
|
|
21998
21998
|
throw runtimeError("run_plan_missing", run.runId, "run reached preparing or later without a pinned plan");
|
|
21999
21999
|
}
|
|
22000
|
-
const envelope = planRow ?
|
|
22001
|
-
const state =
|
|
22000
|
+
const envelope = planRow ? loadKxmRunPlanEnvelope(context.eventStore, run) : void 0;
|
|
22001
|
+
const state = foldKxmRunState(run, envelope?.plan, events, envelope ? {
|
|
22002
22002
|
observationLookup: (attemptId, observationId) => {
|
|
22003
22003
|
const row = context.eventStore.gateObservationForAttempt(attemptId);
|
|
22004
22004
|
if (!row || row.observationId !== observationId) return void 0;
|
|
@@ -22011,7 +22011,7 @@ function foldStoredVnextRun(context, run) {
|
|
|
22011
22011
|
},
|
|
22012
22012
|
projectLimits: envelope.projectLimits
|
|
22013
22013
|
} : {});
|
|
22014
|
-
if (envelope)
|
|
22014
|
+
if (envelope) verifyKxmGateEvidence(context.eventStore, run, envelope, events, state);
|
|
22015
22015
|
assertStoredProjection(context, run);
|
|
22016
22016
|
return state;
|
|
22017
22017
|
}
|
|
@@ -22027,37 +22027,37 @@ function assertStoredProjection(context, run) {
|
|
|
22027
22027
|
const stored = context.eventStore.runState(run.runId);
|
|
22028
22028
|
if (!stored) return;
|
|
22029
22029
|
const schema = storedProjectionSchema(stored.state);
|
|
22030
|
-
if (schema !==
|
|
22030
|
+
if (schema !== KXM_RUN_STATE_SCHEMA) {
|
|
22031
22031
|
throw runtimeError("run_projection_divergent", run.runId, "stored run_state does not match the folded projection");
|
|
22032
22032
|
}
|
|
22033
22033
|
}
|
|
22034
|
-
function
|
|
22034
|
+
function projectKxmRunReadOnly(context, runId) {
|
|
22035
22035
|
const stored = context.eventStore.run(runId);
|
|
22036
22036
|
if (!stored) throw runtimeError("run_unknown", runId, "run does not exist in this event store");
|
|
22037
|
-
const state =
|
|
22037
|
+
const state = foldStoredKxmRun(context, stored);
|
|
22038
22038
|
const events = context.eventStore.events(runId, 0, 1e6);
|
|
22039
22039
|
if (events.length === 0) throw runtimeError("run_events_corrupt", runId, "run has no events");
|
|
22040
22040
|
const last = events[events.length - 1];
|
|
22041
22041
|
return { ...stored, status: state.status, updatedAt: last.occurredAt };
|
|
22042
22042
|
}
|
|
22043
|
-
function
|
|
22043
|
+
function persistKxmRunState(context, runId, state, lastSequence) {
|
|
22044
22044
|
const stored = context.eventStore.runState(runId);
|
|
22045
22045
|
if (stored) {
|
|
22046
22046
|
const schema = storedProjectionSchema(stored.state);
|
|
22047
|
-
if (schema !==
|
|
22047
|
+
if (schema !== KXM_RUN_STATE_SCHEMA) {
|
|
22048
22048
|
throw runtimeError("run_projection_divergent", runId, "stored run_state does not match the folded projection");
|
|
22049
22049
|
}
|
|
22050
22050
|
}
|
|
22051
22051
|
context.eventStore.upsertRunState({
|
|
22052
22052
|
runId,
|
|
22053
22053
|
lastSequence,
|
|
22054
|
-
state:
|
|
22054
|
+
state: kxmCanonicalJson(state)
|
|
22055
22055
|
});
|
|
22056
22056
|
}
|
|
22057
|
-
function
|
|
22058
|
-
const commandId = options.commandId ??
|
|
22057
|
+
function cancelKxmRun(context, runId, options = {}) {
|
|
22058
|
+
const commandId = options.commandId ?? newKxmCommandId();
|
|
22059
22059
|
const now = options.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
22060
|
-
const monotonicNs = options.monotonicNs ??
|
|
22060
|
+
const monotonicNs = options.monotonicNs ?? kxmMonotonicNs();
|
|
22061
22061
|
const abortControllers = [];
|
|
22062
22062
|
const result = context.eventStore.transaction(() => {
|
|
22063
22063
|
const prior = context.eventStore.command(commandId);
|
|
@@ -22071,7 +22071,7 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22071
22071
|
}
|
|
22072
22072
|
const run = context.eventStore.run(runId);
|
|
22073
22073
|
if (!run) throw runtimeError("run_unknown", runId, "run does not exist in this event store");
|
|
22074
|
-
const folded =
|
|
22074
|
+
const folded = foldStoredKxmRun(context, run);
|
|
22075
22075
|
if (isTerminalRunStatus(folded.status) || folded.status === "cancelling") {
|
|
22076
22076
|
context.eventStore.insertCommand({
|
|
22077
22077
|
commandId,
|
|
@@ -22087,18 +22087,18 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22087
22087
|
let nextMono = monotonicNs;
|
|
22088
22088
|
const push = (eventType, payload) => {
|
|
22089
22089
|
const event = {
|
|
22090
|
-
...
|
|
22091
|
-
eventId:
|
|
22090
|
+
...kxmEventBase(context, run, now, nextMono, commandId),
|
|
22091
|
+
eventId: newKxmEventId(),
|
|
22092
22092
|
eventType,
|
|
22093
22093
|
sequence: sequence++,
|
|
22094
22094
|
payload
|
|
22095
22095
|
};
|
|
22096
|
-
nextMono =
|
|
22096
|
+
nextMono = kxmIncrementMonotonicNs(nextMono);
|
|
22097
22097
|
events.push(event);
|
|
22098
22098
|
return event;
|
|
22099
22099
|
};
|
|
22100
22100
|
const cancelReason = options.reason ?? "operator_cancel";
|
|
22101
|
-
const activeAttempt = Boolean(folded.currentStep?.attemptId) ||
|
|
22101
|
+
const activeAttempt = Boolean(folded.currentStep?.attemptId) || kxmFoldPanelAttemptIds(folded.currentStep).length > 0;
|
|
22102
22102
|
const cancelPayload = {
|
|
22103
22103
|
actor: { kind: "runtime", id: context.homeRuntimeId },
|
|
22104
22104
|
reason: cancelReason
|
|
@@ -22114,7 +22114,7 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22114
22114
|
if (folded.status === "running" && activeAttempt) {
|
|
22115
22115
|
status = "cancelling";
|
|
22116
22116
|
push("run.status_changed", { status: "cancelling", reason: cancelReason });
|
|
22117
|
-
const attemptIds = new Set(
|
|
22117
|
+
const attemptIds = new Set(kxmFoldPanelAttemptIds(folded.currentStep));
|
|
22118
22118
|
if (folded.currentStep?.attemptId) attemptIds.add(folded.currentStep.attemptId);
|
|
22119
22119
|
for (const attemptId of attemptIds) {
|
|
22120
22120
|
const capability = context.eventStore.capabilityByAttempt(attemptId);
|
|
@@ -22122,7 +22122,7 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22122
22122
|
context.eventStore.settleCapability(attemptId, "revoked");
|
|
22123
22123
|
}
|
|
22124
22124
|
}
|
|
22125
|
-
for (const owned of
|
|
22125
|
+
for (const owned of kxmAttemptControllers(context.eventStore.path, runId)) {
|
|
22126
22126
|
abortControllers.push(owned.controller);
|
|
22127
22127
|
}
|
|
22128
22128
|
} else if (folded.status === "blocked_uncertain") {
|
|
@@ -22133,9 +22133,9 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22133
22133
|
if (capability && (capability.state === "issued" || capability.state === "revoked")) {
|
|
22134
22134
|
context.eventStore.settleCapability(attemptId, "revoked");
|
|
22135
22135
|
}
|
|
22136
|
-
|
|
22136
|
+
resolveKxmGateHold(context.eventStore.path, runId, attemptId);
|
|
22137
22137
|
}
|
|
22138
|
-
for (const owned of
|
|
22138
|
+
for (const owned of kxmAttemptControllers(context.eventStore.path, runId)) {
|
|
22139
22139
|
abortControllers.push(owned.controller);
|
|
22140
22140
|
}
|
|
22141
22141
|
push("run.status_changed", { status: "cancelled", reason: cancelReason });
|
|
@@ -22147,8 +22147,8 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22147
22147
|
push("run.status_changed", { status: "cancelled", reason: cancelReason });
|
|
22148
22148
|
}
|
|
22149
22149
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
22150
|
-
const nextState =
|
|
22151
|
-
|
|
22150
|
+
const nextState = foldStoredKxmRun(context, run);
|
|
22151
|
+
persistKxmRunState(context, runId, nextState, events[events.length - 1].sequence);
|
|
22152
22152
|
context.eventStore.updateRunStatus(runId, status, now);
|
|
22153
22153
|
context.eventStore.insertCommand({
|
|
22154
22154
|
commandId,
|
|
@@ -22163,10 +22163,10 @@ function cancelVnextRun(context, runId, options = {}) {
|
|
|
22163
22163
|
return result;
|
|
22164
22164
|
}
|
|
22165
22165
|
|
|
22166
|
-
// plugins/kxm/src/
|
|
22166
|
+
// plugins/kxm/src/oneshot-producer.ts
|
|
22167
22167
|
import { join as join12 } from "node:path";
|
|
22168
22168
|
|
|
22169
|
-
// plugins/kxm/src/
|
|
22169
|
+
// plugins/kxm/src/oneshot-evidence.ts
|
|
22170
22170
|
import { createHash as createHash6, randomUUID as randomUUID3 } from "node:crypto";
|
|
22171
22171
|
import { lstat, mkdir, open, rename } from "node:fs/promises";
|
|
22172
22172
|
import { join as join7 } from "node:path";
|
|
@@ -22447,7 +22447,7 @@ function loadPriceCatalog(rootOrPath) {
|
|
|
22447
22447
|
return parsePriceCatalog(content);
|
|
22448
22448
|
}
|
|
22449
22449
|
|
|
22450
|
-
// plugins/kxm/src/
|
|
22450
|
+
// plugins/kxm/src/engine.ts
|
|
22451
22451
|
var import_yaml5 = __toESM(require_dist(), 1);
|
|
22452
22452
|
import { createHash as createHash10, randomBytes, timingSafeEqual } from "node:crypto";
|
|
22453
22453
|
import { existsSync as existsSync9, readFileSync as readFileSync7 } from "node:fs";
|
|
@@ -22743,7 +22743,7 @@ function pruneContextPacket(packet, tokenBudget) {
|
|
|
22743
22743
|
};
|
|
22744
22744
|
}
|
|
22745
22745
|
|
|
22746
|
-
// plugins/kxm/src/
|
|
22746
|
+
// plugins/kxm/src/engine-artifacts.ts
|
|
22747
22747
|
import { join as join10 } from "node:path";
|
|
22748
22748
|
|
|
22749
22749
|
// plugins/kxm/src/artifacts-exist.ts
|
|
@@ -22788,8 +22788,8 @@ function verifyArtifactExists(rootInput, pathInput) {
|
|
|
22788
22788
|
}
|
|
22789
22789
|
}
|
|
22790
22790
|
|
|
22791
|
-
// plugins/kxm/src/
|
|
22792
|
-
var
|
|
22791
|
+
// plugins/kxm/src/engine-artifacts.ts
|
|
22792
|
+
var kxmArtifactsGateSeams = {};
|
|
22793
22793
|
function evaluateArtifactsGate(context, definition) {
|
|
22794
22794
|
const root = join10(context.projectRoot, ".kxm", "assets");
|
|
22795
22795
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -22800,7 +22800,7 @@ function evaluateArtifactsGate(context, definition) {
|
|
|
22800
22800
|
checkedCount += 1;
|
|
22801
22801
|
const result = verifyArtifactExists(root, join10(root, path));
|
|
22802
22802
|
if (!result.ok) failedCount += 1;
|
|
22803
|
-
|
|
22803
|
+
kxmArtifactsGateSeams.afterPathChecked?.({ path, index, checkedCount, failedCount });
|
|
22804
22804
|
}
|
|
22805
22805
|
const elapsedNs = process.hrtime.bigint() - startTime;
|
|
22806
22806
|
const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -22829,7 +22829,7 @@ function evaluateArtifactsGate(context, definition) {
|
|
|
22829
22829
|
};
|
|
22830
22830
|
}
|
|
22831
22831
|
|
|
22832
|
-
// plugins/kxm/src/
|
|
22832
|
+
// plugins/kxm/src/engine-command.ts
|
|
22833
22833
|
import { spawn as spawn2 } from "node:child_process";
|
|
22834
22834
|
import { createHash as createHash8 } from "node:crypto";
|
|
22835
22835
|
|
|
@@ -22857,12 +22857,12 @@ var INSECURE_SSH_HOST_KEY_PATTERNS = Object.freeze([
|
|
|
22857
22857
|
/UserKnownHostsFile=\/dev\/null/i
|
|
22858
22858
|
]);
|
|
22859
22859
|
|
|
22860
|
-
// plugins/kxm/src/
|
|
22860
|
+
// plugins/kxm/src/engine-command.ts
|
|
22861
22861
|
var MAX_DIRECT_TIMER_MS = 2147483647;
|
|
22862
22862
|
var COMMAND_TERM_GRACE_MS = 2e3;
|
|
22863
22863
|
var COMMAND_FINAL_WAIT_MS = 2e3;
|
|
22864
22864
|
var COMMAND_LINGER_MS = 2e3;
|
|
22865
|
-
var
|
|
22865
|
+
var kxmCommandGateSeams = {};
|
|
22866
22866
|
var POST_SPAWN_CHILD_ERROR_CLASS = "stream-error";
|
|
22867
22867
|
function createCommandObserver(input) {
|
|
22868
22868
|
return new CommandObserver(input);
|
|
@@ -22919,7 +22919,7 @@ var CommandObserver = class {
|
|
|
22919
22919
|
this.cwd = input.cwd;
|
|
22920
22920
|
this.signal = input.signal;
|
|
22921
22921
|
this.onSpawned = input.onSpawned;
|
|
22922
|
-
const timing =
|
|
22922
|
+
const timing = kxmCommandGateSeams.timing;
|
|
22923
22923
|
this.termGraceMs = clampTimer(timing?.termGraceMs ?? COMMAND_TERM_GRACE_MS);
|
|
22924
22924
|
this.finalWaitMs = clampTimer(timing?.finalWaitMs ?? COMMAND_FINAL_WAIT_MS);
|
|
22925
22925
|
this.lingerMs = clampTimer(timing?.lingerMs ?? COMMAND_LINGER_MS);
|
|
@@ -22931,7 +22931,7 @@ var CommandObserver = class {
|
|
|
22931
22931
|
if (this.stopCause === "none") {
|
|
22932
22932
|
this.stopCause = cause;
|
|
22933
22933
|
if (errorClass && this.errorClass === null) this.errorClass = errorClass;
|
|
22934
|
-
|
|
22934
|
+
kxmCommandGateSeams.afterStopRequested?.(cause);
|
|
22935
22935
|
this.clearTimer("linger");
|
|
22936
22936
|
this.beginSignalSequence();
|
|
22937
22937
|
return;
|
|
@@ -22962,7 +22962,7 @@ var CommandObserver = class {
|
|
|
22962
22962
|
return;
|
|
22963
22963
|
}
|
|
22964
22964
|
try {
|
|
22965
|
-
|
|
22965
|
+
kxmCommandGateSeams.beforeSpawn?.(this.definition);
|
|
22966
22966
|
} catch {
|
|
22967
22967
|
this.finishNoStart("validation");
|
|
22968
22968
|
return;
|
|
@@ -23072,9 +23072,9 @@ var CommandObserver = class {
|
|
|
23072
23072
|
this.clearTimer("timeout");
|
|
23073
23073
|
child.stdout?.destroy();
|
|
23074
23074
|
child.stderr?.destroy();
|
|
23075
|
-
|
|
23075
|
+
dropKxmCommandStopCapability(this);
|
|
23076
23076
|
try {
|
|
23077
|
-
|
|
23077
|
+
kxmCommandGateSeams.afterChildClose?.();
|
|
23078
23078
|
} catch {
|
|
23079
23079
|
}
|
|
23080
23080
|
this.handoff();
|
|
@@ -23095,7 +23095,7 @@ var CommandObserver = class {
|
|
|
23095
23095
|
this.requestStop("error", "recording-error");
|
|
23096
23096
|
}
|
|
23097
23097
|
try {
|
|
23098
|
-
|
|
23098
|
+
kxmCommandGateSeams.afterSpawned?.(this.observedPid);
|
|
23099
23099
|
} catch {
|
|
23100
23100
|
this.requestStop("error", "recording-error");
|
|
23101
23101
|
}
|
|
@@ -23262,7 +23262,7 @@ var CommandObserver = class {
|
|
|
23262
23262
|
this.clearTimer("final");
|
|
23263
23263
|
this.clearTimer("linger");
|
|
23264
23264
|
this.child?.unref();
|
|
23265
|
-
|
|
23265
|
+
dropKxmCommandStopCapability(this);
|
|
23266
23266
|
this.resolveOutcome?.(outcome);
|
|
23267
23267
|
}
|
|
23268
23268
|
clearTimer(name) {
|
|
@@ -23271,7 +23271,7 @@ var CommandObserver = class {
|
|
|
23271
23271
|
this[`${name}Timer`] = void 0;
|
|
23272
23272
|
}
|
|
23273
23273
|
};
|
|
23274
|
-
function
|
|
23274
|
+
function dropKxmCommandStopCapability(observer) {
|
|
23275
23275
|
observer.requestStop = () => void 0;
|
|
23276
23276
|
}
|
|
23277
23277
|
function isCompleteNormal(observation) {
|
|
@@ -23287,20 +23287,20 @@ function schedule(ms, fn) {
|
|
|
23287
23287
|
return setTimeout(fn, clampTimer(ms));
|
|
23288
23288
|
}
|
|
23289
23289
|
|
|
23290
|
-
// plugins/kxm/src/
|
|
23290
|
+
// plugins/kxm/src/engine-gate-records.ts
|
|
23291
23291
|
function recordGateIntentInTransaction(context, run, envelope, stepId) {
|
|
23292
23292
|
const step = requireGateStep(envelope, stepId, run.runId);
|
|
23293
23293
|
const definition = envelope.gates.definitions[step.gate];
|
|
23294
23294
|
if (!definition || definition.kind === "reserved") {
|
|
23295
23295
|
throw runtimeError("gate_row_invalid", run.runId, "reserved gates cannot record intent in this slice");
|
|
23296
23296
|
}
|
|
23297
|
-
const folded =
|
|
23297
|
+
const folded = foldStoredKxmRun(context, run);
|
|
23298
23298
|
const used = folded.stepAttempts[stepId] ?? 0;
|
|
23299
23299
|
const stepAttempt = used + 1;
|
|
23300
|
-
const assignmentId =
|
|
23301
|
-
const attemptId =
|
|
23302
|
-
const effectId =
|
|
23303
|
-
const minted =
|
|
23300
|
+
const assignmentId = newKxmAssignmentId();
|
|
23301
|
+
const attemptId = newKxmAttemptId();
|
|
23302
|
+
const effectId = newKxmEffectId();
|
|
23303
|
+
const minted = mintKxmCapabilitySecret();
|
|
23304
23304
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
23305
23305
|
const seq = sequencer(context, run, now);
|
|
23306
23306
|
seq.push("step.entered", { stepId, stepAttempt, status: "pending" });
|
|
@@ -23390,7 +23390,7 @@ function recordGateSettlementInTransaction(context, run, envelope, stepId, obser
|
|
|
23390
23390
|
});
|
|
23391
23391
|
}
|
|
23392
23392
|
seq.push("attempt.status_changed", { attemptId: ids.attemptId, assignmentId: ids.assignmentId, stepId, stepAttempt: ids.stepAttempt, status: "settling" });
|
|
23393
|
-
const observationId =
|
|
23393
|
+
const observationId = newKxmObservationId();
|
|
23394
23394
|
const observed = seq.push("effect.observed", {
|
|
23395
23395
|
effect: { id: ids.effectId, policy: { class: ids.gateKind === "artifacts-exist" ? "read-only" : "unknown", sharedMutable: false } },
|
|
23396
23396
|
stepId,
|
|
@@ -23401,7 +23401,7 @@ function recordGateSettlementInTransaction(context, run, envelope, stepId, obser
|
|
|
23401
23401
|
});
|
|
23402
23402
|
const observationRow = buildObservation(ids, observation, observationId, observed.eventId);
|
|
23403
23403
|
patchReceipt(observed, observationRow);
|
|
23404
|
-
const evidenceId =
|
|
23404
|
+
const evidenceId = newKxmEvidenceId();
|
|
23405
23405
|
const evidenceDraft = {
|
|
23406
23406
|
evidenceId,
|
|
23407
23407
|
attemptId: ids.attemptId,
|
|
@@ -23449,7 +23449,7 @@ function recordGateNoStartInTransaction(context, run, envelope, stepId, observat
|
|
|
23449
23449
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
23450
23450
|
const seq = sequencer(context, run, now);
|
|
23451
23451
|
const cancelReason = cancelled ? ensureOperatorCancel(seq, ids.state, run, context) : void 0;
|
|
23452
|
-
const observationId =
|
|
23452
|
+
const observationId = newKxmObservationId();
|
|
23453
23453
|
const observed = seq.push("effect.observed", {
|
|
23454
23454
|
effect: { id: ids.effectId, policy: { class: ids.gateKind === "artifacts-exist" ? "read-only" : "unknown", sharedMutable: false } },
|
|
23455
23455
|
stepId,
|
|
@@ -23507,7 +23507,7 @@ function recordGateUncertainInTransaction(context, run, envelope, stepId, reason
|
|
|
23507
23507
|
}
|
|
23508
23508
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
23509
23509
|
const seq = sequencer(context, run, now);
|
|
23510
|
-
const observationId =
|
|
23510
|
+
const observationId = newKxmObservationId();
|
|
23511
23511
|
const blocked = seq.push("effect.blocked_uncertain", {
|
|
23512
23512
|
effect: { id: ids.effectId, policy: { class: ids.gateKind === "artifacts-exist" ? "read-only" : "unknown", sharedMutable: false } },
|
|
23513
23513
|
stepId,
|
|
@@ -23547,7 +23547,7 @@ function recordGateCancelObservedInTransaction(context, run, envelope, stepId, o
|
|
|
23547
23547
|
});
|
|
23548
23548
|
}
|
|
23549
23549
|
seq.push("attempt.status_changed", { attemptId: ids.attemptId, assignmentId: ids.assignmentId, stepId, stepAttempt: ids.stepAttempt, status: "settling" });
|
|
23550
|
-
const observationId =
|
|
23550
|
+
const observationId = newKxmObservationId();
|
|
23551
23551
|
const policyClass = ids.gateKind === "artifacts-exist" ? "read-only" : "unknown";
|
|
23552
23552
|
const observed = seq.push("effect.observed", {
|
|
23553
23553
|
effect: { id: ids.effectId, policy: { class: policyClass, sharedMutable: false } },
|
|
@@ -23595,7 +23595,7 @@ function appendEvaluatedTail(seq, envelope, ids, stepId, outcome) {
|
|
|
23595
23595
|
seq.push("run.status_changed", { status: "failed", reason: "outcome_unknown", stepId, outcome });
|
|
23596
23596
|
return;
|
|
23597
23597
|
}
|
|
23598
|
-
const budget =
|
|
23598
|
+
const budget = kxmTransitionBudgetFailure(envelope.plan, ids.state, stepId, outcome);
|
|
23599
23599
|
if (budget) {
|
|
23600
23600
|
seq.push("run.status_changed", { status: "failed", reason: budget, stepId, outcome });
|
|
23601
23601
|
return;
|
|
@@ -23648,7 +23648,7 @@ function requireGateStep(envelope, stepId, runId) {
|
|
|
23648
23648
|
}
|
|
23649
23649
|
function requireIntent(context, run, envelope, stepId) {
|
|
23650
23650
|
const step = requireGateStep(envelope, stepId, run.runId);
|
|
23651
|
-
const folded =
|
|
23651
|
+
const folded = foldStoredKxmRun(context, run);
|
|
23652
23652
|
const attemptId = folded.currentStep?.attemptId;
|
|
23653
23653
|
if (!attemptId || folded.currentStep?.stepId !== stepId) {
|
|
23654
23654
|
throw runtimeError("run_events_illegal", run.runId, "gate intent has not been recorded");
|
|
@@ -23686,27 +23686,27 @@ function cancelReasonFromLog(context, runId) {
|
|
|
23686
23686
|
}
|
|
23687
23687
|
function sequencer(context, run, now) {
|
|
23688
23688
|
let sequence = context.eventStore.nextSequence(run.runId);
|
|
23689
|
-
let mono =
|
|
23689
|
+
let mono = kxmMonotonicNs();
|
|
23690
23690
|
const events = [];
|
|
23691
23691
|
return {
|
|
23692
23692
|
events,
|
|
23693
23693
|
push(eventType, payload) {
|
|
23694
23694
|
const event = {
|
|
23695
|
-
...
|
|
23696
|
-
eventId:
|
|
23695
|
+
...kxmEventBase(context, run, now, mono),
|
|
23696
|
+
eventId: newKxmEventId(),
|
|
23697
23697
|
eventType,
|
|
23698
23698
|
sequence: sequence++,
|
|
23699
23699
|
payload
|
|
23700
23700
|
};
|
|
23701
|
-
mono =
|
|
23701
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
23702
23702
|
events.push(event);
|
|
23703
23703
|
return event;
|
|
23704
23704
|
}
|
|
23705
23705
|
};
|
|
23706
23706
|
}
|
|
23707
23707
|
function persist(context, run, now, lastSequence) {
|
|
23708
|
-
const next =
|
|
23709
|
-
|
|
23708
|
+
const next = foldStoredKxmRun(context, run);
|
|
23709
|
+
persistKxmRunState(context, run.runId, next, lastSequence);
|
|
23710
23710
|
context.eventStore.updateRunStatus(run.runId, next.status, now);
|
|
23711
23711
|
return { state: next, run: { ...run, status: next.status, updatedAt: now } };
|
|
23712
23712
|
}
|
|
@@ -23870,10 +23870,10 @@ function parseRoutingRecordV2(value) {
|
|
|
23870
23870
|
return record2;
|
|
23871
23871
|
}
|
|
23872
23872
|
|
|
23873
|
-
// plugins/kxm/src/
|
|
23873
|
+
// plugins/kxm/src/engine.ts
|
|
23874
23874
|
var trustedProducers = /* @__PURE__ */ new WeakSet();
|
|
23875
23875
|
var CAPABILITY_PREFIX = "kxm-attempt-capability\0";
|
|
23876
|
-
function
|
|
23876
|
+
function createKxmSimulatedProducer(script) {
|
|
23877
23877
|
const producer = Object.freeze({
|
|
23878
23878
|
id: "driver-simulated",
|
|
23879
23879
|
async produce(request) {
|
|
@@ -23909,14 +23909,14 @@ function requireTrustedProducer(producer) {
|
|
|
23909
23909
|
function hashCapabilitySecret(secret) {
|
|
23910
23910
|
return `sha256:${createHash10("sha256").update(`${CAPABILITY_PREFIX}${secret}`, "utf8").digest("hex")}`;
|
|
23911
23911
|
}
|
|
23912
|
-
function
|
|
23912
|
+
function mintKxmCapabilitySecret() {
|
|
23913
23913
|
const secret = `kxmcap_${randomBytes(32).toString("base64url")}`;
|
|
23914
23914
|
return { secret, hash: hashCapabilitySecret(secret) };
|
|
23915
23915
|
}
|
|
23916
23916
|
function mintCapabilitySecret() {
|
|
23917
|
-
return
|
|
23917
|
+
return mintKxmCapabilitySecret();
|
|
23918
23918
|
}
|
|
23919
|
-
function
|
|
23919
|
+
function pinKxmCompiledPlan(context, bundle, runId, options) {
|
|
23920
23920
|
return context.eventStore.transaction(() => {
|
|
23921
23921
|
const run = requireRun(context, runId);
|
|
23922
23922
|
if (run.projectId !== context.projectId || run.homeRuntimeId !== context.homeRuntimeId) {
|
|
@@ -23927,17 +23927,17 @@ function pinVnextCompiledPlan(context, bundle, runId, options) {
|
|
|
23927
23927
|
}
|
|
23928
23928
|
const workflow = bundle.workflows.get(run.workflowId);
|
|
23929
23929
|
if (!workflow) throw runtimeError("run_workflow_unknown", run.workflowId, `workflow ${run.workflowId} does not exist in this project`);
|
|
23930
|
-
const revisions =
|
|
23930
|
+
const revisions = kxmPolicyRevisions(bundle, options);
|
|
23931
23931
|
if (revisions.configRevision !== run.configRevision || revisions.executorPolicyRevision !== run.executorPolicyRevision || revisions.toolPolicyRevision !== run.toolPolicyRevision || revisions.memoryRevision !== run.memoryRevision) {
|
|
23932
23932
|
throw runtimeError("run_revision_drift", runId, "bundle revisions do not match the accepted run");
|
|
23933
23933
|
}
|
|
23934
|
-
const compiled =
|
|
23934
|
+
const compiled = freezeKxmCompiledPlan(compileKxmWorkflow({
|
|
23935
23935
|
id: run.workflowId,
|
|
23936
23936
|
value: workflow.value,
|
|
23937
23937
|
...workflow.logicalPath !== void 0 ? { logicalPath: workflow.logicalPath } : {}
|
|
23938
23938
|
}));
|
|
23939
23939
|
const envelope = {
|
|
23940
|
-
schema:
|
|
23940
|
+
schema: KXM_RUN_PLAN_SCHEMA,
|
|
23941
23941
|
runId: run.runId,
|
|
23942
23942
|
projectId: run.projectId,
|
|
23943
23943
|
homeRuntimeId: run.homeRuntimeId,
|
|
@@ -23948,11 +23948,11 @@ function pinVnextCompiledPlan(context, bundle, runId, options) {
|
|
|
23948
23948
|
toolPolicy: run.toolPolicyRevision,
|
|
23949
23949
|
memory: run.memoryRevision
|
|
23950
23950
|
},
|
|
23951
|
-
projectLimits:
|
|
23951
|
+
projectLimits: kxmProjectAdmissionLimits(bundle),
|
|
23952
23952
|
plan: compiled,
|
|
23953
23953
|
gates: pinnedGatesForCompiledPlan(compiled, bundle, context.projectRoot)
|
|
23954
23954
|
};
|
|
23955
|
-
const runPlanHash =
|
|
23955
|
+
const runPlanHash = hashKxmRunPlanEnvelope(envelope);
|
|
23956
23956
|
const existing = context.eventStore.runPlan(runId);
|
|
23957
23957
|
if (existing) {
|
|
23958
23958
|
if (existing.runPlanHash !== runPlanHash) {
|
|
@@ -23966,8 +23966,8 @@ function pinVnextCompiledPlan(context, bundle, runId, options) {
|
|
|
23966
23966
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
23967
23967
|
const sequence = context.eventStore.nextSequence(runId);
|
|
23968
23968
|
const event = {
|
|
23969
|
-
...
|
|
23970
|
-
eventId:
|
|
23969
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
23970
|
+
eventId: newKxmEventId(),
|
|
23971
23971
|
eventType: "run.status_changed",
|
|
23972
23972
|
sequence,
|
|
23973
23973
|
payload: { status: "preparing", runPlanHash }
|
|
@@ -23975,22 +23975,22 @@ function pinVnextCompiledPlan(context, bundle, runId, options) {
|
|
|
23975
23975
|
context.eventStore.insertRunPlan({
|
|
23976
23976
|
runId,
|
|
23977
23977
|
runPlanHash,
|
|
23978
|
-
envelope:
|
|
23978
|
+
envelope: kxmCanonicalJson(envelope),
|
|
23979
23979
|
pinnedSequence: sequence
|
|
23980
23980
|
});
|
|
23981
23981
|
context.eventStore.appendEvent(event);
|
|
23982
|
-
const state =
|
|
23983
|
-
|
|
23982
|
+
const state = foldStoredKxmRun(context, run);
|
|
23983
|
+
persistKxmRunState(context, runId, state, sequence);
|
|
23984
23984
|
context.eventStore.updateRunStatus(runId, "preparing", now);
|
|
23985
23985
|
return { plan: compiled, runPlanHash, idempotent: false, event };
|
|
23986
23986
|
});
|
|
23987
23987
|
}
|
|
23988
|
-
function
|
|
23988
|
+
function startKxmRun(context, runId, options = {}) {
|
|
23989
23989
|
return context.eventStore.transaction(() => {
|
|
23990
23990
|
const run = requireRun(context, runId);
|
|
23991
|
-
const envelope =
|
|
23991
|
+
const envelope = loadKxmRunPlanEnvelope(context.eventStore, run);
|
|
23992
23992
|
const unsupported = options.allowLimits ? void 0 : unsupportedLimit(envelope);
|
|
23993
|
-
const state =
|
|
23993
|
+
const state = foldStoredKxmRun(context, run);
|
|
23994
23994
|
if (unsupported) {
|
|
23995
23995
|
return { state, handoff: unsupported };
|
|
23996
23996
|
}
|
|
@@ -24000,15 +24000,15 @@ function startVnextRun(context, runId, options = {}) {
|
|
|
24000
24000
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24001
24001
|
const sequence = context.eventStore.nextSequence(runId);
|
|
24002
24002
|
const event = {
|
|
24003
|
-
...
|
|
24004
|
-
eventId:
|
|
24003
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
24004
|
+
eventId: newKxmEventId(),
|
|
24005
24005
|
eventType: "run.status_changed",
|
|
24006
24006
|
sequence,
|
|
24007
24007
|
payload: { status: "running" }
|
|
24008
24008
|
};
|
|
24009
24009
|
context.eventStore.appendEvent(event);
|
|
24010
|
-
const next =
|
|
24011
|
-
|
|
24010
|
+
const next = foldStoredKxmRun(context, run);
|
|
24011
|
+
persistKxmRunState(context, runId, next, sequence);
|
|
24012
24012
|
context.eventStore.updateRunStatus(runId, "running", now);
|
|
24013
24013
|
return { state: next };
|
|
24014
24014
|
});
|
|
@@ -24016,10 +24016,10 @@ function startVnextRun(context, runId, options = {}) {
|
|
|
24016
24016
|
async function driveAdmitted(context, runId, producer, token, options = {}) {
|
|
24017
24017
|
const run = requireRun(context, runId);
|
|
24018
24018
|
if (run.status === "preparing") {
|
|
24019
|
-
const started =
|
|
24019
|
+
const started = startKxmRun(context, runId, options);
|
|
24020
24020
|
if (started.handoff || isTerminalRunStatus(started.state.status)) return started;
|
|
24021
24021
|
}
|
|
24022
|
-
let latest = { state:
|
|
24022
|
+
let latest = { state: foldStoredKxmRun(context, requireRun(context, runId)) };
|
|
24023
24023
|
while (latest.state.status === "running") {
|
|
24024
24024
|
const overBudget = cancelRunDurationIfExceeded(context, runId);
|
|
24025
24025
|
if (overBudget) return overBudget;
|
|
@@ -24039,9 +24039,9 @@ function newDriveId(runId, token, runtimeId, monotonicNs) {
|
|
|
24039
24039
|
return `drv_${createHash10("sha256").update(`${runId}\0${token}\0${runtimeId}\0${monotonicNs}`, "utf8").digest("hex").slice(0, 24)}`;
|
|
24040
24040
|
}
|
|
24041
24041
|
function driveErrorSummary(error) {
|
|
24042
|
-
const raw = error instanceof
|
|
24042
|
+
const raw = error instanceof KxmConfigError ? error.issues[0]?.code : void 0;
|
|
24043
24043
|
const className = raw && /^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/.test(raw) ? raw : "drive-failure";
|
|
24044
|
-
return { class: className, component: "
|
|
24044
|
+
return { class: className, component: "engine", retryable: false };
|
|
24045
24045
|
}
|
|
24046
24046
|
function receiptHandoff(handoff) {
|
|
24047
24047
|
return {
|
|
@@ -24057,24 +24057,24 @@ function appendDriveOpened(context, runId, driveId, mode) {
|
|
|
24057
24057
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24058
24058
|
const sequence = context.eventStore.nextSequence(runId);
|
|
24059
24059
|
const event = {
|
|
24060
|
-
...
|
|
24061
|
-
eventId:
|
|
24060
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
24061
|
+
eventId: newKxmEventId(),
|
|
24062
24062
|
eventType: "run.drive_opened",
|
|
24063
24063
|
sequence,
|
|
24064
24064
|
payload: { driveId, mode }
|
|
24065
24065
|
};
|
|
24066
24066
|
context.eventStore.appendEvent(event);
|
|
24067
|
-
const next =
|
|
24068
|
-
|
|
24067
|
+
const next = foldStoredKxmRun(context, run);
|
|
24068
|
+
persistKxmRunState(context, runId, next, sequence);
|
|
24069
24069
|
return { sequence, occurredAt: now };
|
|
24070
24070
|
});
|
|
24071
24071
|
}
|
|
24072
24072
|
function recordDriveReceipt(context, session, closeInfo) {
|
|
24073
|
-
if (
|
|
24073
|
+
if (isKxmRuntimeContextClosed(context)) return;
|
|
24074
24074
|
try {
|
|
24075
24075
|
const run = context.eventStore.run(session.runId);
|
|
24076
24076
|
if (!run) return;
|
|
24077
|
-
const state =
|
|
24077
|
+
const state = foldStoredKxmRun(context, run);
|
|
24078
24078
|
const events = context.eventStore.events(session.runId, 0, 1e6);
|
|
24079
24079
|
if (events.length === 0) return;
|
|
24080
24080
|
const opened = state.drive;
|
|
@@ -24084,7 +24084,7 @@ function recordDriveReceipt(context, session, closeInfo) {
|
|
|
24084
24084
|
if (openedSequence === void 0) return;
|
|
24085
24085
|
const closedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
24086
24086
|
const receipt = {
|
|
24087
|
-
schema:
|
|
24087
|
+
schema: KXM_DRIVE_RECEIPT_SCHEMA,
|
|
24088
24088
|
driveId: session.driveId,
|
|
24089
24089
|
runId: session.runId,
|
|
24090
24090
|
projectId: run.projectId,
|
|
@@ -24094,7 +24094,7 @@ function recordDriveReceipt(context, session, closeInfo) {
|
|
|
24094
24094
|
openedSequence,
|
|
24095
24095
|
closedAt,
|
|
24096
24096
|
lastSequence: last.sequence,
|
|
24097
|
-
logHash:
|
|
24097
|
+
logHash: hashKxmDriveLog(events.filter((event) => event.sequence >= 1 && event.sequence <= last.sequence)),
|
|
24098
24098
|
settlement: {
|
|
24099
24099
|
kind: closeInfo.kind,
|
|
24100
24100
|
status: state.status,
|
|
@@ -24109,7 +24109,7 @@ function recordDriveReceipt(context, session, closeInfo) {
|
|
|
24109
24109
|
} catch {
|
|
24110
24110
|
}
|
|
24111
24111
|
}
|
|
24112
|
-
function
|
|
24112
|
+
function kxmDrivePollProjection(context, runId, state) {
|
|
24113
24113
|
if (!state.drive) return void 0;
|
|
24114
24114
|
const events = context.eventStore.events(runId, 0, 1e6);
|
|
24115
24115
|
const openedEvent = events.find((event) => event.sequence === state.drive.openedSequence);
|
|
@@ -24135,7 +24135,7 @@ function vnextDrivePollProjection(context, runId, state) {
|
|
|
24135
24135
|
projection.divergence = "no receipt";
|
|
24136
24136
|
return projection;
|
|
24137
24137
|
}
|
|
24138
|
-
const checked =
|
|
24138
|
+
const checked = verifyKxmDriveReceipt(receipt, events, state.status, {
|
|
24139
24139
|
runId,
|
|
24140
24140
|
driveId: state.drive.driveId
|
|
24141
24141
|
});
|
|
@@ -24147,7 +24147,7 @@ function inflightAttemptId(state) {
|
|
|
24147
24147
|
const leftover = unreconciledPanelAttemptId(state);
|
|
24148
24148
|
if (leftover) return leftover;
|
|
24149
24149
|
if (state.currentStep?.attemptId) {
|
|
24150
|
-
const located =
|
|
24150
|
+
const located = kxmFoldPanelAttempt(state.currentStep, state.currentStep.attemptId);
|
|
24151
24151
|
const status = located?.attempt.status;
|
|
24152
24152
|
if (status === "starting" || status === "executing" || status === "settling") return state.currentStep.attemptId;
|
|
24153
24153
|
}
|
|
@@ -24159,32 +24159,32 @@ function recordExecutingUnrecordedFailure(context, runId, attemptId, stepId) {
|
|
|
24159
24159
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24160
24160
|
const sequence = context.eventStore.nextSequence(runId);
|
|
24161
24161
|
const event = {
|
|
24162
|
-
...
|
|
24163
|
-
eventId:
|
|
24162
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
24163
|
+
eventId: newKxmEventId(),
|
|
24164
24164
|
eventType: "run.status_changed",
|
|
24165
24165
|
sequence,
|
|
24166
24166
|
payload: { status: "failed", reason: "executing_unrecorded", stepId }
|
|
24167
24167
|
};
|
|
24168
24168
|
context.eventStore.appendEvent(event);
|
|
24169
24169
|
context.eventStore.settleCapability(attemptId, "revoked");
|
|
24170
|
-
const next =
|
|
24171
|
-
|
|
24170
|
+
const next = foldStoredKxmRun(context, run);
|
|
24171
|
+
persistKxmRunState(context, runId, next, sequence);
|
|
24172
24172
|
context.eventStore.updateRunStatus(runId, "failed", now);
|
|
24173
24173
|
});
|
|
24174
24174
|
}
|
|
24175
24175
|
function recordBareDriveFailure(context, runId) {
|
|
24176
|
-
if (
|
|
24176
|
+
if (isKxmRuntimeContextClosed(context)) return;
|
|
24177
24177
|
try {
|
|
24178
24178
|
const run = context.eventStore.run(runId);
|
|
24179
24179
|
if (!run) return;
|
|
24180
|
-
const state =
|
|
24180
|
+
const state = foldStoredKxmRun(context, run);
|
|
24181
24181
|
if (isTerminalRunStatus(state.status) || state.status === "cancelling") return;
|
|
24182
24182
|
const inflight = inflightAttemptId(state);
|
|
24183
24183
|
if (inflight) {
|
|
24184
24184
|
const currentStep = state.currentStep;
|
|
24185
|
-
const located =
|
|
24185
|
+
const located = kxmFoldPanelAttempt(currentStep, inflight);
|
|
24186
24186
|
if (currentStep && currentStep.panel.order.length === 1 && located?.attempt.status === "starting") {
|
|
24187
|
-
const plan =
|
|
24187
|
+
const plan = rehydrateKxmCompiledPlanFromStore(context.eventStore, run);
|
|
24188
24188
|
const step = plan.steps[currentStep.stepId];
|
|
24189
24189
|
if (step?.kind === "gate") return;
|
|
24190
24190
|
if (step && (step.kind === "agent" || step.kind === "moa") && step.assignments.maximum > 1) return;
|
|
@@ -24192,7 +24192,7 @@ function recordBareDriveFailure(context, runId) {
|
|
|
24192
24192
|
}
|
|
24193
24193
|
return;
|
|
24194
24194
|
}
|
|
24195
|
-
|
|
24195
|
+
cancelKxmRun(context, runId, { reason: "drive_error" });
|
|
24196
24196
|
} catch {
|
|
24197
24197
|
}
|
|
24198
24198
|
}
|
|
@@ -24203,7 +24203,7 @@ async function closeDriveProducer(producer) {
|
|
|
24203
24203
|
} catch {
|
|
24204
24204
|
}
|
|
24205
24205
|
}
|
|
24206
|
-
var
|
|
24206
|
+
var KxmRunScheduler = class _KxmRunScheduler {
|
|
24207
24207
|
context;
|
|
24208
24208
|
bundle;
|
|
24209
24209
|
configRevision;
|
|
@@ -24216,20 +24216,20 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24216
24216
|
if (String(bundle.project.value.id) !== context.projectId) {
|
|
24217
24217
|
throw runtimeError("run_owner_mismatch", context.projectId, "scheduler bundle project does not match the runtime context");
|
|
24218
24218
|
}
|
|
24219
|
-
const limits =
|
|
24220
|
-
|
|
24221
|
-
return new
|
|
24219
|
+
const limits = kxmProjectAdmissionLimits(bundle);
|
|
24220
|
+
bindKxmSchedulerPolicy(context.eventStore.path, limits.maxConcurrentRuns, bundle.configRevision);
|
|
24221
|
+
return new _KxmRunScheduler(context, bundle);
|
|
24222
24222
|
}
|
|
24223
24223
|
enqueue(runId, producer, options = {}) {
|
|
24224
24224
|
requireTrustedProducer(producer);
|
|
24225
|
-
const policy =
|
|
24225
|
+
const policy = kxmSchedulerPolicy(this.context.eventStore.path);
|
|
24226
24226
|
if (!policy || policy.configRevision !== this.configRevision) {
|
|
24227
24227
|
return Promise.reject(runtimeError("scheduler_policy_conflict", runId, "scheduler handle does not match the active policy"));
|
|
24228
24228
|
}
|
|
24229
24229
|
try {
|
|
24230
24230
|
const run = requireRun(this.context, runId);
|
|
24231
|
-
const envelope =
|
|
24232
|
-
return
|
|
24231
|
+
const envelope = loadKxmRunPlanEnvelope(this.context.eventStore, run);
|
|
24232
|
+
return enqueueKxmScheduledRun(
|
|
24233
24233
|
this.context.eventStore.path,
|
|
24234
24234
|
runId,
|
|
24235
24235
|
envelope.revisions.config,
|
|
@@ -24241,7 +24241,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24241
24241
|
}
|
|
24242
24242
|
}
|
|
24243
24243
|
openDriveSession(runId, options) {
|
|
24244
|
-
const policy =
|
|
24244
|
+
const policy = kxmSchedulerPolicy(this.context.eventStore.path);
|
|
24245
24245
|
if (!policy || policy.configRevision !== this.configRevision) {
|
|
24246
24246
|
return Promise.reject(runtimeError("scheduler_policy_conflict", runId, "scheduler handle does not match the active policy"));
|
|
24247
24247
|
}
|
|
@@ -24253,7 +24253,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24253
24253
|
} catch (error) {
|
|
24254
24254
|
return Promise.reject(error);
|
|
24255
24255
|
}
|
|
24256
|
-
const limits =
|
|
24256
|
+
const limits = kxmProjectAdmissionLimits(this.bundle);
|
|
24257
24257
|
const driveOptions = {
|
|
24258
24258
|
liveMode: options.liveMode ?? options.mode === "live"
|
|
24259
24259
|
};
|
|
@@ -24269,7 +24269,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24269
24269
|
});
|
|
24270
24270
|
void settled.then(void 0, () => void 0);
|
|
24271
24271
|
return new Promise((resolveOpen, rejectOpen) => {
|
|
24272
|
-
const queued =
|
|
24272
|
+
const queued = enqueueKxmScheduledRun(
|
|
24273
24273
|
this.context.eventStore.path,
|
|
24274
24274
|
runId,
|
|
24275
24275
|
this.configRevision,
|
|
@@ -24281,17 +24281,17 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24281
24281
|
requireTrustedProducer(producer);
|
|
24282
24282
|
const current = requireRun(this.context, runId);
|
|
24283
24283
|
if (current.status === "created") {
|
|
24284
|
-
|
|
24284
|
+
pinKxmCompiledPlan(this.context, this.bundle, runId);
|
|
24285
24285
|
}
|
|
24286
|
-
const started =
|
|
24286
|
+
const started = startKxmRun(this.context, runId, driveOptions);
|
|
24287
24287
|
if (started.handoff) {
|
|
24288
24288
|
const error = runtimeError("run_handoff_required", runId, started.handoff.detail);
|
|
24289
24289
|
Object.assign(error, { handoff: started.handoff });
|
|
24290
24290
|
throw error;
|
|
24291
24291
|
}
|
|
24292
|
-
const driveId = newDriveId(runId, token, this.context.homeRuntimeId,
|
|
24292
|
+
const driveId = newDriveId(runId, token, this.context.homeRuntimeId, kxmMonotonicNs());
|
|
24293
24293
|
const openedMeta = appendDriveOpened(this.context, runId, driveId, options.mode);
|
|
24294
|
-
const startedState =
|
|
24294
|
+
const startedState = foldStoredKxmRun(this.context, requireRun(this.context, runId));
|
|
24295
24295
|
const deadlineAt = driveDeadlineAt(this.context, runId, startedState);
|
|
24296
24296
|
const session = {
|
|
24297
24297
|
driveId,
|
|
@@ -24305,7 +24305,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24305
24305
|
settled,
|
|
24306
24306
|
...deadlineAt !== void 0 ? { deadlineAt } : {}
|
|
24307
24307
|
};
|
|
24308
|
-
|
|
24308
|
+
attachKxmDriveSession(this.context.eventStore.path, runId, token, session);
|
|
24309
24309
|
opened = true;
|
|
24310
24310
|
resolveOpen({ driveId, settled });
|
|
24311
24311
|
try {
|
|
@@ -24324,7 +24324,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24324
24324
|
recordBareDriveFailure(this.context, runId);
|
|
24325
24325
|
let foldedStatus;
|
|
24326
24326
|
try {
|
|
24327
|
-
foldedStatus =
|
|
24327
|
+
foldedStatus = foldStoredKxmRun(this.context, requireRun(this.context, runId)).status;
|
|
24328
24328
|
} catch {
|
|
24329
24329
|
foldedStatus = void 0;
|
|
24330
24330
|
}
|
|
@@ -24339,7 +24339,7 @@ var VnextRunScheduler = class _VnextRunScheduler {
|
|
|
24339
24339
|
}
|
|
24340
24340
|
} finally {
|
|
24341
24341
|
if (producer) await closeDriveProducer(producer);
|
|
24342
|
-
|
|
24342
|
+
clearKxmDriveSession(this.context.eventStore.path, runId, token);
|
|
24343
24343
|
}
|
|
24344
24344
|
}
|
|
24345
24345
|
);
|
|
@@ -24363,7 +24363,7 @@ function invokeProducer(producer, request) {
|
|
|
24363
24363
|
() => ({ error: true })
|
|
24364
24364
|
);
|
|
24365
24365
|
}
|
|
24366
|
-
var
|
|
24366
|
+
var kxmGateDispatchSeams = {};
|
|
24367
24367
|
async function stepLocked(context, runId, producer, token) {
|
|
24368
24368
|
const prepared = context.eventStore.transaction(() => prepareDispatch(context, runId, producer.id));
|
|
24369
24369
|
if (prepared.kind === "return") {
|
|
@@ -24381,15 +24381,15 @@ async function stepLocked(context, runId, producer, token) {
|
|
|
24381
24381
|
if (!definition || definition.kind !== "artifacts-exist") {
|
|
24382
24382
|
throw runtimeError("run_events_illegal", prepared.run.runId, "prepared gate is not artifacts-exist");
|
|
24383
24383
|
}
|
|
24384
|
-
|
|
24384
|
+
registerKxmAttemptController(context.eventStore.path, runId, { attemptId: prepared.attemptId, controller: prepared.controller });
|
|
24385
24385
|
const clearBudget = armRunDurationBudgetTimer(context, runId);
|
|
24386
24386
|
try {
|
|
24387
24387
|
const observation = evaluateArtifactsGate(context, definition);
|
|
24388
|
-
|
|
24388
|
+
kxmGateDispatchSeams.afterEvaluate?.(prepared);
|
|
24389
24389
|
return context.eventStore.transaction(() => settlePreparedGate(context, prepared, observation));
|
|
24390
24390
|
} finally {
|
|
24391
24391
|
clearBudget();
|
|
24392
|
-
|
|
24392
|
+
unregisterKxmAttemptController(context.eventStore.path, runId, prepared.attemptId);
|
|
24393
24393
|
}
|
|
24394
24394
|
}
|
|
24395
24395
|
return drivePanel(context, prepared.panel, producer);
|
|
@@ -24402,39 +24402,39 @@ async function runPreparedCommandGate(context, prepared, definition, token) {
|
|
|
24402
24402
|
cwd: context.projectRoot,
|
|
24403
24403
|
signal: prepared.controller.signal,
|
|
24404
24404
|
onSpawned: () => {
|
|
24405
|
-
if (
|
|
24405
|
+
if (isKxmRuntimeContextClosed(context)) return;
|
|
24406
24406
|
try {
|
|
24407
24407
|
context.eventStore.transaction(() => {
|
|
24408
24408
|
recordGateSpawnedInTransaction(context, prepared.run, prepared.envelope, prepared.stepId);
|
|
24409
|
-
|
|
24409
|
+
kxmGateDispatchSeams.afterSpawnRecord?.(prepared);
|
|
24410
24410
|
});
|
|
24411
24411
|
} catch (error) {
|
|
24412
24412
|
try {
|
|
24413
|
-
|
|
24413
|
+
markKxmGateHoldUnsettled(storePath, prepared.run.runId, token, prepared.attemptId);
|
|
24414
24414
|
} catch {
|
|
24415
24415
|
}
|
|
24416
24416
|
throw error;
|
|
24417
24417
|
}
|
|
24418
24418
|
}
|
|
24419
24419
|
});
|
|
24420
|
-
|
|
24421
|
-
|
|
24420
|
+
armKxmGateHold(storePath, prepared.run.runId, token, prepared.attemptId, () => observer.requestStop("cancel"));
|
|
24421
|
+
registerKxmAttemptController(storePath, prepared.run.runId, { attemptId: prepared.attemptId, controller: prepared.controller });
|
|
24422
24422
|
const clearBudget = armRunDurationBudgetTimer(context, prepared.run.runId);
|
|
24423
|
-
const unhookClose =
|
|
24423
|
+
const unhookClose = registerKxmRuntimeCloseHook(context, () => {
|
|
24424
24424
|
try {
|
|
24425
|
-
|
|
24425
|
+
markKxmGateHoldUnsettled(storePath, prepared.run.runId, token, prepared.attemptId);
|
|
24426
24426
|
} catch {
|
|
24427
24427
|
}
|
|
24428
|
-
|
|
24428
|
+
dropKxmGateStopHook(storePath, prepared.run.runId, prepared.attemptId);
|
|
24429
24429
|
observer.beginBoundedCleanup();
|
|
24430
24430
|
});
|
|
24431
24431
|
try {
|
|
24432
|
-
|
|
24432
|
+
kxmGateDispatchSeams.beforeCommandSpawn?.(prepared);
|
|
24433
24433
|
const outcome = await observer.run();
|
|
24434
|
-
|
|
24435
|
-
if (
|
|
24434
|
+
dropKxmGateStopHook(storePath, prepared.run.runId, prepared.attemptId);
|
|
24435
|
+
if (isKxmRuntimeContextClosed(context)) {
|
|
24436
24436
|
try {
|
|
24437
|
-
|
|
24437
|
+
markKxmGateHoldUnsettled(storePath, prepared.run.runId, token, prepared.attemptId);
|
|
24438
24438
|
} catch {
|
|
24439
24439
|
}
|
|
24440
24440
|
return closedCommandHandoff(context, prepared, outcome.kind === "uncertain" ? outcome.reason : "lost-close");
|
|
@@ -24444,13 +24444,13 @@ async function runPreparedCommandGate(context, prepared, definition, token) {
|
|
|
24444
24444
|
}
|
|
24445
24445
|
if (outcome.kind === "complete") {
|
|
24446
24446
|
try {
|
|
24447
|
-
|
|
24447
|
+
kxmGateDispatchSeams.beforeCommandSettle?.(prepared);
|
|
24448
24448
|
} catch (error) {
|
|
24449
24449
|
return recoverCommandRecordingFailure(context, prepared, token, outcome.observation, error);
|
|
24450
24450
|
}
|
|
24451
|
-
if (
|
|
24451
|
+
if (isKxmRuntimeContextClosed(context)) {
|
|
24452
24452
|
try {
|
|
24453
|
-
|
|
24453
|
+
markKxmGateHoldUnsettled(storePath, prepared.run.runId, token, prepared.attemptId);
|
|
24454
24454
|
} catch {
|
|
24455
24455
|
}
|
|
24456
24456
|
return closedCommandHandoff(context, prepared, "lost-close");
|
|
@@ -24461,13 +24461,13 @@ async function runPreparedCommandGate(context, prepared, definition, token) {
|
|
|
24461
24461
|
} finally {
|
|
24462
24462
|
unhookClose();
|
|
24463
24463
|
clearBudget();
|
|
24464
|
-
|
|
24464
|
+
unregisterKxmAttemptController(storePath, prepared.run.runId, prepared.attemptId);
|
|
24465
24465
|
}
|
|
24466
24466
|
}
|
|
24467
24467
|
function closedCommandHandoff(context, prepared, reason) {
|
|
24468
24468
|
let state;
|
|
24469
24469
|
try {
|
|
24470
|
-
state =
|
|
24470
|
+
state = foldStoredKxmRun(context, requireRun(context, prepared.run.runId));
|
|
24471
24471
|
} catch {
|
|
24472
24472
|
state = prepared.state;
|
|
24473
24473
|
}
|
|
@@ -24489,12 +24489,12 @@ function commitOwnedCommandSettlement(context, prepared, token, write, observati
|
|
|
24489
24489
|
return recoverCommandRecordingFailure(context, prepared, token, observation, error);
|
|
24490
24490
|
}
|
|
24491
24491
|
try {
|
|
24492
|
-
|
|
24492
|
+
kxmGateDispatchSeams.afterSettlementCommit?.(prepared);
|
|
24493
24493
|
} catch (error) {
|
|
24494
24494
|
return retainCommittedCommandProof(context, prepared, token, error);
|
|
24495
24495
|
}
|
|
24496
24496
|
try {
|
|
24497
|
-
|
|
24497
|
+
finishKxmOwnedGate(context.eventStore.path, prepared.run.runId, token, prepared.attemptId);
|
|
24498
24498
|
} catch (error) {
|
|
24499
24499
|
return retainCommittedCommandProof(context, prepared, token, error);
|
|
24500
24500
|
}
|
|
@@ -24508,7 +24508,7 @@ function retainCommittedCommandProof(context, prepared, token, error) {
|
|
|
24508
24508
|
throw error;
|
|
24509
24509
|
}
|
|
24510
24510
|
function finishOwnedGateAfterCommittedTerminalProof(context, prepared, token) {
|
|
24511
|
-
if (
|
|
24511
|
+
if (isKxmRuntimeContextClosed(context)) return;
|
|
24512
24512
|
const run = context.eventStore.run(prepared.run.runId);
|
|
24513
24513
|
if (!run || run.projectId !== context.projectId || run.homeRuntimeId !== context.homeRuntimeId) return;
|
|
24514
24514
|
const row = context.eventStore.gateAttempt(prepared.attemptId);
|
|
@@ -24527,7 +24527,7 @@ function finishOwnedGateAfterCommittedTerminalProof(context, prepared, token) {
|
|
|
24527
24527
|
const events = context.eventStore.events(prepared.run.runId, 0, 1e6);
|
|
24528
24528
|
let state;
|
|
24529
24529
|
try {
|
|
24530
|
-
state =
|
|
24530
|
+
state = foldStoredKxmRun(context, run);
|
|
24531
24531
|
} catch {
|
|
24532
24532
|
return;
|
|
24533
24533
|
}
|
|
@@ -24537,16 +24537,16 @@ function finishOwnedGateAfterCommittedTerminalProof(context, prepared, token) {
|
|
|
24537
24537
|
}
|
|
24538
24538
|
const terminalProof = isEvaluatedSettledProof(row, observation, evidence) || isExcludedTerminalProof(state, row, observation, evidence, events);
|
|
24539
24539
|
if (!terminalProof) return;
|
|
24540
|
-
const hold =
|
|
24541
|
-
const admittedToken =
|
|
24540
|
+
const hold = kxmGateHold(context.eventStore.path, prepared.run.runId);
|
|
24541
|
+
const admittedToken = kxmAdmittedToken(context.eventStore.path, prepared.run.runId);
|
|
24542
24542
|
if (!hold || hold.state !== "active" || hold.attemptId !== prepared.attemptId || hold.token !== token || admittedToken !== token) {
|
|
24543
24543
|
return;
|
|
24544
24544
|
}
|
|
24545
|
-
|
|
24545
|
+
finishKxmOwnedGate(context.eventStore.path, prepared.run.runId, token, prepared.attemptId);
|
|
24546
24546
|
}
|
|
24547
24547
|
function recoverCommandRecordingFailure(context, prepared, token, observation, error) {
|
|
24548
|
-
|
|
24549
|
-
if (
|
|
24548
|
+
markKxmGateHoldUnsettled(context.eventStore.path, prepared.run.runId, token, prepared.attemptId);
|
|
24549
|
+
if (isKxmRuntimeContextClosed(context)) {
|
|
24550
24550
|
throw error;
|
|
24551
24551
|
}
|
|
24552
24552
|
const existing = context.eventStore.gateObservationForAttempt(prepared.attemptId);
|
|
@@ -24557,7 +24557,7 @@ function recoverCommandRecordingFailure(context, prepared, token, observation, e
|
|
|
24557
24557
|
`command observation recording failed after committed proof: ${error instanceof Error ? error.message : String(error)}`
|
|
24558
24558
|
);
|
|
24559
24559
|
}
|
|
24560
|
-
const folded =
|
|
24560
|
+
const folded = foldStoredKxmRun(context, requireRun(context, prepared.run.runId));
|
|
24561
24561
|
if (folded.currentStep?.attemptId === prepared.attemptId && folded.currentStep.observationId) {
|
|
24562
24562
|
throw runtimeError(
|
|
24563
24563
|
"run_events_illegal",
|
|
@@ -24575,10 +24575,10 @@ function recoverCommandRecordingFailure(context, prepared, token, observation, e
|
|
|
24575
24575
|
}
|
|
24576
24576
|
function commitCommandUncertainty(context, prepared, token, reason, observation, priorError) {
|
|
24577
24577
|
try {
|
|
24578
|
-
|
|
24578
|
+
markKxmGateHoldUnsettled(context.eventStore.path, prepared.run.runId, token, prepared.attemptId);
|
|
24579
24579
|
} catch {
|
|
24580
24580
|
}
|
|
24581
|
-
if (
|
|
24581
|
+
if (isKxmRuntimeContextClosed(context)) {
|
|
24582
24582
|
if (priorError) throw priorError;
|
|
24583
24583
|
return closedCommandHandoff(context, prepared, reason);
|
|
24584
24584
|
}
|
|
@@ -24594,7 +24594,7 @@ function commitCommandUncertainty(context, prepared, token, reason, observation,
|
|
|
24594
24594
|
try {
|
|
24595
24595
|
const written = context.eventStore.transaction(() => {
|
|
24596
24596
|
const result = recordGateUncertainInTransaction(context, prepared.run, prepared.envelope, prepared.stepId, reason, incomplete);
|
|
24597
|
-
|
|
24597
|
+
kxmGateDispatchSeams.afterUncertaintyWrite?.(prepared);
|
|
24598
24598
|
return result;
|
|
24599
24599
|
});
|
|
24600
24600
|
return {
|
|
@@ -24611,7 +24611,7 @@ function commitCommandUncertainty(context, prepared, token, reason, observation,
|
|
|
24611
24611
|
throw error;
|
|
24612
24612
|
}
|
|
24613
24613
|
}
|
|
24614
|
-
var
|
|
24614
|
+
var kxmPanelDispatchSeams = {};
|
|
24615
24615
|
function unreconciledPanelAttemptId(state) {
|
|
24616
24616
|
const current = state.currentStep;
|
|
24617
24617
|
if (!current) return void 0;
|
|
@@ -24690,12 +24690,12 @@ function resolveProducerRoute(projectRoot, step, agentId) {
|
|
|
24690
24690
|
}
|
|
24691
24691
|
function prepareDispatch(context, runId, producerId) {
|
|
24692
24692
|
const run = requireRun(context, runId);
|
|
24693
|
-
const plan =
|
|
24694
|
-
const state =
|
|
24695
|
-
if (
|
|
24693
|
+
const plan = rehydrateKxmCompiledPlanFromStore(context.eventStore, run);
|
|
24694
|
+
const state = foldStoredKxmRun(context, run);
|
|
24695
|
+
if (kxmPanelDispatchSeams.skipDispatch?.()) {
|
|
24696
24696
|
return { kind: "return", state };
|
|
24697
24697
|
}
|
|
24698
|
-
if (state.status === "cancelling" &&
|
|
24698
|
+
if (state.status === "cancelling" && kxmAttemptControllers(context.eventStore.path, runId).length === 0) {
|
|
24699
24699
|
return {
|
|
24700
24700
|
kind: "return",
|
|
24701
24701
|
state,
|
|
@@ -24774,7 +24774,7 @@ function prepareDispatch(context, runId, producerId) {
|
|
|
24774
24774
|
return { kind: "return", ...failBudget(context, run, plan, state, "budget_unmetered_attempts", stepId) };
|
|
24775
24775
|
}
|
|
24776
24776
|
if (step.kind === "gate") {
|
|
24777
|
-
const envelope =
|
|
24777
|
+
const envelope = loadKxmRunPlanEnvelope(context.eventStore, run);
|
|
24778
24778
|
const unsupported2 = unsupportedGateStep(plan, step, envelope, context);
|
|
24779
24779
|
if (unsupported2) return { kind: "return", state, handoff: { ...unsupported2, stepId } };
|
|
24780
24780
|
const definition = envelope.gates.definitions[step.gate];
|
|
@@ -24833,23 +24833,23 @@ function prepareDispatch(context, runId, producerId) {
|
|
|
24833
24833
|
const stepAttempt = used + 1;
|
|
24834
24834
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24835
24835
|
let sequence = context.eventStore.nextSequence(runId);
|
|
24836
|
-
let mono =
|
|
24836
|
+
let mono = kxmMonotonicNs();
|
|
24837
24837
|
const events = [];
|
|
24838
24838
|
const push = (eventType, payload) => {
|
|
24839
24839
|
events.push({
|
|
24840
|
-
...
|
|
24841
|
-
eventId:
|
|
24840
|
+
...kxmEventBase(context, run, now, mono),
|
|
24841
|
+
eventId: newKxmEventId(),
|
|
24842
24842
|
eventType,
|
|
24843
24843
|
sequence: sequence++,
|
|
24844
24844
|
payload
|
|
24845
24845
|
});
|
|
24846
|
-
mono =
|
|
24846
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
24847
24847
|
};
|
|
24848
24848
|
push("step.entered", { stepId, stepAttempt, status: "pending" });
|
|
24849
24849
|
push("step.status_changed", { stepId, status: "preparing", previousStatus: "pending" });
|
|
24850
24850
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
24851
|
-
const entered =
|
|
24852
|
-
|
|
24851
|
+
const entered = foldStoredKxmRun(context, run);
|
|
24852
|
+
persistKxmRunState(context, runId, entered, events[events.length - 1].sequence);
|
|
24853
24853
|
const first = birthMember(context, {
|
|
24854
24854
|
run,
|
|
24855
24855
|
plan,
|
|
@@ -24902,7 +24902,7 @@ function birthAllowed(state, step) {
|
|
|
24902
24902
|
}
|
|
24903
24903
|
function birthMember(context, input) {
|
|
24904
24904
|
const run = requireRun(context, input.run.runId);
|
|
24905
|
-
const folded =
|
|
24905
|
+
const folded = foldStoredKxmRun(context, run);
|
|
24906
24906
|
if (!birthAllowed(folded, input.step)) {
|
|
24907
24907
|
throw runtimeError("run_events_illegal", run.runId, "member birth is not legal");
|
|
24908
24908
|
}
|
|
@@ -24925,23 +24925,23 @@ function birthMember(context, input) {
|
|
|
24925
24925
|
resolvedRoute = routeResult;
|
|
24926
24926
|
}
|
|
24927
24927
|
}
|
|
24928
|
-
const assignmentId =
|
|
24929
|
-
const attemptId =
|
|
24928
|
+
const assignmentId = newKxmAssignmentId();
|
|
24929
|
+
const attemptId = newKxmAttemptId();
|
|
24930
24930
|
const minted = mintCapabilitySecret();
|
|
24931
24931
|
const controller = new AbortController();
|
|
24932
24932
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
24933
24933
|
let sequence = context.eventStore.nextSequence(run.runId);
|
|
24934
|
-
let mono =
|
|
24934
|
+
let mono = kxmMonotonicNs();
|
|
24935
24935
|
const events = [];
|
|
24936
24936
|
const push = (eventType, payload) => {
|
|
24937
24937
|
events.push({
|
|
24938
|
-
...
|
|
24939
|
-
eventId:
|
|
24938
|
+
...kxmEventBase(context, run, now, mono),
|
|
24939
|
+
eventId: newKxmEventId(),
|
|
24940
24940
|
eventType,
|
|
24941
24941
|
sequence: sequence++,
|
|
24942
24942
|
payload
|
|
24943
24943
|
});
|
|
24944
|
-
mono =
|
|
24944
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
24945
24945
|
};
|
|
24946
24946
|
push("assignment.created", { assignmentId, stepId: input.stepId, stepAttempt: input.stepAttempt, agentId, status: "created" });
|
|
24947
24947
|
push("assignment.accepted", { assignmentId, status: "accepted" });
|
|
@@ -24967,8 +24967,8 @@ function birthMember(context, input) {
|
|
|
24967
24967
|
capabilityHash: minted.hash,
|
|
24968
24968
|
state: "issued"
|
|
24969
24969
|
});
|
|
24970
|
-
const next =
|
|
24971
|
-
|
|
24970
|
+
const next = foldStoredKxmRun(context, run);
|
|
24971
|
+
persistKxmRunState(context, run.runId, next, events[events.length - 1].sequence);
|
|
24972
24972
|
const rawContextPacket = buildFormalContextPacket({
|
|
24973
24973
|
project: run.projectId,
|
|
24974
24974
|
targetRole: agentId,
|
|
@@ -25028,33 +25028,33 @@ ${generatedPrompt}` : generatedPrompt,
|
|
|
25028
25028
|
controller,
|
|
25029
25029
|
state: next
|
|
25030
25030
|
};
|
|
25031
|
-
|
|
25031
|
+
kxmPanelDispatchSeams.afterBirth?.(member);
|
|
25032
25032
|
return member;
|
|
25033
25033
|
}
|
|
25034
25034
|
function appendExecuting(context, dispatch) {
|
|
25035
25035
|
const run = requireRun(context, dispatch.run.runId);
|
|
25036
25036
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
25037
25037
|
let sequence = context.eventStore.nextSequence(dispatch.run.runId);
|
|
25038
|
-
let mono =
|
|
25038
|
+
let mono = kxmMonotonicNs();
|
|
25039
25039
|
const events = [
|
|
25040
25040
|
{
|
|
25041
|
-
...
|
|
25042
|
-
eventId:
|
|
25041
|
+
...kxmEventBase(context, run, now, mono),
|
|
25042
|
+
eventId: newKxmEventId(),
|
|
25043
25043
|
eventType: "assignment.executing",
|
|
25044
25044
|
sequence: sequence++,
|
|
25045
25045
|
payload: { assignmentId: dispatch.assignmentId, status: "executing" }
|
|
25046
25046
|
},
|
|
25047
25047
|
{
|
|
25048
|
-
...
|
|
25049
|
-
eventId:
|
|
25048
|
+
...kxmEventBase(context, run, now, kxmIncrementMonotonicNs(mono)),
|
|
25049
|
+
eventId: newKxmEventId(),
|
|
25050
25050
|
eventType: "attempt.status_changed",
|
|
25051
25051
|
sequence: sequence++,
|
|
25052
25052
|
payload: { attemptId: dispatch.attemptId, status: "executing" }
|
|
25053
25053
|
}
|
|
25054
25054
|
];
|
|
25055
25055
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25056
|
-
const next =
|
|
25057
|
-
|
|
25056
|
+
const next = foldStoredKxmRun(context, run);
|
|
25057
|
+
persistKxmRunState(context, run.runId, next, events[events.length - 1].sequence);
|
|
25058
25058
|
}
|
|
25059
25059
|
function singletonPanel(step) {
|
|
25060
25060
|
return step.assignments.maximum === 1 && step.assignments.target === 1;
|
|
@@ -25088,7 +25088,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25088
25088
|
let settlementFailed = false;
|
|
25089
25089
|
const budgetClears = /* @__PURE__ */ new Map();
|
|
25090
25090
|
const register = (member) => {
|
|
25091
|
-
|
|
25091
|
+
registerKxmAttemptController(context.eventStore.path, runId, { attemptId: member.attemptId, controller: member.controller });
|
|
25092
25092
|
budgetClears.set(member.attemptId, armRunDurationBudgetTimer(context, runId));
|
|
25093
25093
|
owned.set(member.attemptId, member);
|
|
25094
25094
|
};
|
|
@@ -25099,15 +25099,15 @@ async function drivePanel(context, panel, producer) {
|
|
|
25099
25099
|
register(member);
|
|
25100
25100
|
const work = (async () => {
|
|
25101
25101
|
try {
|
|
25102
|
-
|
|
25102
|
+
kxmPanelDispatchSeams.beforeAppendExecuting?.(member);
|
|
25103
25103
|
const started = context.eventStore.transaction(() => {
|
|
25104
|
-
if (
|
|
25104
|
+
if (kxmPanelDispatchSeams.failAppendExecuting?.(member)) {
|
|
25105
25105
|
throw runtimeError("run_events_illegal", runId, "appendExecuting failed");
|
|
25106
25106
|
}
|
|
25107
25107
|
const run = requireRun(context, runId);
|
|
25108
|
-
const state =
|
|
25108
|
+
const state = foldStoredKxmRun(context, run);
|
|
25109
25109
|
const capability = context.eventStore.capabilityByAttempt(member.attemptId);
|
|
25110
|
-
const located =
|
|
25110
|
+
const located = kxmFoldPanelAttempt(state.currentStep, member.attemptId);
|
|
25111
25111
|
if (state.cancelRequested || state.status === "cancelling" || !capabilityMatchesDispatch(capability, member, ["issued"], producer.id) || !located || located.assignmentId !== member.assignmentId || located.attempt.status !== "starting") {
|
|
25112
25112
|
return false;
|
|
25113
25113
|
}
|
|
@@ -25117,16 +25117,16 @@ async function drivePanel(context, panel, producer) {
|
|
|
25117
25117
|
if (!started) return { attemptId: member.attemptId, invoked: false, skipped: true };
|
|
25118
25118
|
const executingBound = () => {
|
|
25119
25119
|
const run = requireRun(context, runId);
|
|
25120
|
-
const state =
|
|
25120
|
+
const state = foldStoredKxmRun(context, run);
|
|
25121
25121
|
const capability = context.eventStore.capabilityByAttempt(member.attemptId);
|
|
25122
|
-
const located =
|
|
25122
|
+
const located = kxmFoldPanelAttempt(state.currentStep, member.attemptId);
|
|
25123
25123
|
if (state.cancelRequested || state.status === "cancelling" || !capabilityMatchesDispatch(capability, member, ["issued"], producer.id) || !located || located.assignmentId !== member.assignmentId || located.attempt.status !== "executing") {
|
|
25124
25124
|
return false;
|
|
25125
25125
|
}
|
|
25126
25126
|
return true;
|
|
25127
25127
|
};
|
|
25128
25128
|
if (!executingBound()) return { attemptId: member.attemptId, invoked: false, skipped: true };
|
|
25129
|
-
|
|
25129
|
+
kxmPanelDispatchSeams.beforeInvoke?.(member);
|
|
25130
25130
|
if (!executingBound()) return { attemptId: member.attemptId, invoked: false, skipped: true };
|
|
25131
25131
|
const produced = await invokeProducer(producer, member.request);
|
|
25132
25132
|
return { attemptId: member.attemptId, invoked: true, produced };
|
|
@@ -25141,7 +25141,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25141
25141
|
if (stopBirths) return void 0;
|
|
25142
25142
|
return context.eventStore.transaction(() => {
|
|
25143
25143
|
const run = requireRun(context, runId);
|
|
25144
|
-
const state =
|
|
25144
|
+
const state = foldStoredKxmRun(context, run);
|
|
25145
25145
|
if (!birthAllowed(state, panel.step)) return void 0;
|
|
25146
25146
|
return birthMember(context, {
|
|
25147
25147
|
run,
|
|
@@ -25161,7 +25161,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25161
25161
|
}
|
|
25162
25162
|
try {
|
|
25163
25163
|
context.eventStore.transaction(() => {
|
|
25164
|
-
if (
|
|
25164
|
+
if (kxmPanelDispatchSeams.failSettleMember?.(member)) {
|
|
25165
25165
|
throw runtimeError("run_events_illegal", runId, "member settlement write failed");
|
|
25166
25166
|
}
|
|
25167
25167
|
settleMember(context, member, produced.result, produced.error);
|
|
@@ -25200,7 +25200,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25200
25200
|
stopBirths = true;
|
|
25201
25201
|
abortOwned();
|
|
25202
25202
|
await drainPendingInvoked();
|
|
25203
|
-
const state =
|
|
25203
|
+
const state = foldStoredKxmRun(context, requireRun(context, runId));
|
|
25204
25204
|
return unreconciledHandoff(state, panel.stepId);
|
|
25205
25205
|
}
|
|
25206
25206
|
}
|
|
@@ -25224,7 +25224,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25224
25224
|
settleInvoked(sibling, item.produced);
|
|
25225
25225
|
}
|
|
25226
25226
|
}
|
|
25227
|
-
const state =
|
|
25227
|
+
const state = foldStoredKxmRun(context, requireRun(context, runId));
|
|
25228
25228
|
return unreconciledHandoff(state, panel.stepId, member.attemptId);
|
|
25229
25229
|
}
|
|
25230
25230
|
if (!finished.invoked) {
|
|
@@ -25241,18 +25241,18 @@ async function drivePanel(context, panel, producer) {
|
|
|
25241
25241
|
settleInvoked(sibling, item.produced);
|
|
25242
25242
|
}
|
|
25243
25243
|
}
|
|
25244
|
-
const state =
|
|
25244
|
+
const state = foldStoredKxmRun(context, requireRun(context, runId));
|
|
25245
25245
|
return unreconciledHandoff(state, panel.stepId, member.attemptId);
|
|
25246
25246
|
}
|
|
25247
25247
|
}
|
|
25248
|
-
const folded =
|
|
25248
|
+
const folded = foldStoredKxmRun(context, requireRun(context, runId));
|
|
25249
25249
|
const leftover = unreconciledPanelAttemptId(folded);
|
|
25250
25250
|
if (leftover || settlementFailed) {
|
|
25251
25251
|
return unreconciledHandoff(folded, panel.stepId, leftover);
|
|
25252
25252
|
}
|
|
25253
25253
|
const born = folded.currentStep?.panel.order.length ?? 0;
|
|
25254
25254
|
const allTerminal = Boolean(
|
|
25255
|
-
folded.currentStep && born > 0 && folded.currentStep.panel.order.every((assignmentId) => folded.currentStep?.panel.assignments[assignmentId]?.status === "terminal") &&
|
|
25255
|
+
folded.currentStep && born > 0 && folded.currentStep.panel.order.every((assignmentId) => folded.currentStep?.panel.assignments[assignmentId]?.status === "terminal") && kxmFoldPanelAttemptIds(folded.currentStep).every((attemptId) => kxmFoldPanelAttempt(folded.currentStep, attemptId)?.attempt.status === "terminal")
|
|
25256
25256
|
);
|
|
25257
25257
|
if (!allTerminal) {
|
|
25258
25258
|
return unreconciledHandoff(folded, panel.stepId, leftover);
|
|
@@ -25263,7 +25263,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25263
25263
|
try {
|
|
25264
25264
|
return context.eventStore.transaction(() => joinPanel(context, panel));
|
|
25265
25265
|
} catch {
|
|
25266
|
-
const state =
|
|
25266
|
+
const state = foldStoredKxmRun(context, requireRun(context, runId));
|
|
25267
25267
|
return unreconciledHandoff(state, panel.stepId);
|
|
25268
25268
|
}
|
|
25269
25269
|
} catch (error) {
|
|
@@ -25273,7 +25273,7 @@ async function drivePanel(context, panel, producer) {
|
|
|
25273
25273
|
} finally {
|
|
25274
25274
|
for (const attemptId of owned.keys()) {
|
|
25275
25275
|
budgetClears.get(attemptId)?.();
|
|
25276
|
-
|
|
25276
|
+
unregisterKxmAttemptController(context.eventStore.path, runId, attemptId);
|
|
25277
25277
|
}
|
|
25278
25278
|
}
|
|
25279
25279
|
}
|
|
@@ -25288,7 +25288,7 @@ function producerRoutingRecord(context, dispatch, result, now) {
|
|
|
25288
25288
|
if (result.costBasis === "metered" && (typeof result.costUsd !== "number" || !Number.isFinite(result.costUsd) || result.costUsd < 0)) {
|
|
25289
25289
|
throw runtimeError("settle_invalid_cost", run.runId, "attempt settlement rejected: metered costBasis requires non-negative finite costUsd");
|
|
25290
25290
|
}
|
|
25291
|
-
const envelope =
|
|
25291
|
+
const envelope = loadKxmRunPlanEnvelope(context.eventStore, run);
|
|
25292
25292
|
const rawHash = result.behavioralSha256 ?? behavioralConfigHash({
|
|
25293
25293
|
requestedModel: result.requestedModel ?? "simulated",
|
|
25294
25294
|
effectiveModel: result.effectiveModel ?? result.requestedModel ?? "simulated",
|
|
@@ -25321,26 +25321,26 @@ function producerRoutingRecord(context, dispatch, result, now) {
|
|
|
25321
25321
|
}
|
|
25322
25322
|
function settleMember(context, dispatch, result, produceError) {
|
|
25323
25323
|
const run = requireRun(context, dispatch.run.runId);
|
|
25324
|
-
const state =
|
|
25324
|
+
const state = foldStoredKxmRun(context, run);
|
|
25325
25325
|
const capability = context.eventStore.capabilityByAttempt(dispatch.attemptId);
|
|
25326
|
-
const located =
|
|
25326
|
+
const located = kxmFoldPanelAttempt(state.currentStep, dispatch.attemptId);
|
|
25327
25327
|
if (!located || located.assignmentId !== dispatch.assignmentId || located.attempt.status !== "executing" || !capability || !capabilityMatchesDispatch(capability, dispatch, ["issued", "revoked"])) {
|
|
25328
25328
|
throw runtimeError("run_events_illegal", run.runId, "settle attempted for a non-current capability");
|
|
25329
25329
|
}
|
|
25330
25330
|
const cancelling = state.status === "cancelling" || capability.state === "revoked";
|
|
25331
25331
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
25332
25332
|
let sequence = context.eventStore.nextSequence(run.runId);
|
|
25333
|
-
let mono =
|
|
25333
|
+
let mono = kxmMonotonicNs();
|
|
25334
25334
|
const events = [];
|
|
25335
25335
|
const push = (eventType, payload) => {
|
|
25336
25336
|
events.push({
|
|
25337
|
-
...
|
|
25338
|
-
eventId:
|
|
25337
|
+
...kxmEventBase(context, run, now, mono),
|
|
25338
|
+
eventId: newKxmEventId(),
|
|
25339
25339
|
eventType,
|
|
25340
25340
|
sequence: sequence++,
|
|
25341
25341
|
payload
|
|
25342
25342
|
});
|
|
25343
|
-
mono =
|
|
25343
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
25344
25344
|
};
|
|
25345
25345
|
push("attempt.status_changed", { attemptId: dispatch.attemptId, status: "settling" });
|
|
25346
25346
|
if (cancelling) {
|
|
@@ -25354,7 +25354,7 @@ function settleMember(context, dispatch, result, produceError) {
|
|
|
25354
25354
|
push("attempt.status_changed", { attemptId: dispatch.attemptId, status: "terminal" });
|
|
25355
25355
|
push("assignment.terminal", { assignmentId: dispatch.assignmentId, outcome: "cancelled", status: "terminal" });
|
|
25356
25356
|
} else if (produceError) {
|
|
25357
|
-
const envelope =
|
|
25357
|
+
const envelope = loadKxmRunPlanEnvelope(context.eventStore, run);
|
|
25358
25358
|
const rawHash = result?.behavioralSha256 ?? behavioralConfigHash({
|
|
25359
25359
|
requestedModel: result?.requestedModel ?? "simulated",
|
|
25360
25360
|
effectiveModel: result?.effectiveModel ?? result?.requestedModel ?? "simulated",
|
|
@@ -25416,37 +25416,37 @@ function settleMember(context, dispatch, result, produceError) {
|
|
|
25416
25416
|
}
|
|
25417
25417
|
context.eventStore.settleCapability(dispatch.attemptId, "settled");
|
|
25418
25418
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25419
|
-
const next =
|
|
25420
|
-
|
|
25419
|
+
const next = foldStoredKxmRun(context, run);
|
|
25420
|
+
persistKxmRunState(context, run.runId, next, events[events.length - 1].sequence);
|
|
25421
25421
|
}
|
|
25422
25422
|
function joinPanel(context, panel) {
|
|
25423
25423
|
const run = requireRun(context, panel.run.runId);
|
|
25424
|
-
const state =
|
|
25424
|
+
const state = foldStoredKxmRun(context, run);
|
|
25425
25425
|
const current = state.currentStep;
|
|
25426
25426
|
if (!current || current.stepId !== panel.stepId) {
|
|
25427
25427
|
throw runtimeError("run_events_illegal", run.runId, "join attempted without the prepared step");
|
|
25428
25428
|
}
|
|
25429
|
-
const joined =
|
|
25429
|
+
const joined = kxmJoinAll(panel.step, current.panel);
|
|
25430
25430
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
25431
25431
|
let sequence = context.eventStore.nextSequence(run.runId);
|
|
25432
|
-
let mono =
|
|
25432
|
+
let mono = kxmMonotonicNs();
|
|
25433
25433
|
const events = [];
|
|
25434
25434
|
const push = (eventType, payload) => {
|
|
25435
25435
|
events.push({
|
|
25436
|
-
...
|
|
25437
|
-
eventId:
|
|
25436
|
+
...kxmEventBase(context, run, now, mono),
|
|
25437
|
+
eventId: newKxmEventId(),
|
|
25438
25438
|
eventType,
|
|
25439
25439
|
sequence: sequence++,
|
|
25440
25440
|
payload
|
|
25441
25441
|
});
|
|
25442
|
-
mono =
|
|
25442
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
25443
25443
|
};
|
|
25444
25444
|
const failRun = (reason) => {
|
|
25445
25445
|
push("step.status_changed", { stepId: panel.stepId, status: "failed", previousStatus: "running" });
|
|
25446
25446
|
push("run.status_changed", { status: "failed", reason, stepId: panel.stepId });
|
|
25447
25447
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25448
|
-
const next2 =
|
|
25449
|
-
|
|
25448
|
+
const next2 = foldStoredKxmRun(context, run);
|
|
25449
|
+
persistKxmRunState(context, run.runId, next2, events[events.length - 1].sequence);
|
|
25450
25450
|
context.eventStore.updateRunStatus(run.runId, "failed", now);
|
|
25451
25451
|
return { state: next2 };
|
|
25452
25452
|
};
|
|
@@ -25454,8 +25454,8 @@ function joinPanel(context, panel) {
|
|
|
25454
25454
|
push("step.status_changed", { stepId: panel.stepId, status: "cancelled", previousStatus: "running" });
|
|
25455
25455
|
push("run.status_changed", { status: "cancelled", reason: cancelReasonFromLog2(context, run.runId) });
|
|
25456
25456
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25457
|
-
const next2 =
|
|
25458
|
-
|
|
25457
|
+
const next2 = foldStoredKxmRun(context, run);
|
|
25458
|
+
persistKxmRunState(context, run.runId, next2, events[events.length - 1].sequence);
|
|
25459
25459
|
context.eventStore.updateRunStatus(run.runId, "cancelled", now);
|
|
25460
25460
|
return { state: next2 };
|
|
25461
25461
|
};
|
|
@@ -25491,8 +25491,8 @@ function joinPanel(context, panel) {
|
|
|
25491
25491
|
if (budget) {
|
|
25492
25492
|
push("run.status_changed", { status: "failed", reason: budget, stepId: panel.stepId, outcome });
|
|
25493
25493
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25494
|
-
const next2 =
|
|
25495
|
-
|
|
25494
|
+
const next2 = foldStoredKxmRun(context, run);
|
|
25495
|
+
persistKxmRunState(context, run.runId, next2, events[events.length - 1].sequence);
|
|
25496
25496
|
context.eventStore.updateRunStatus(run.runId, "failed", now);
|
|
25497
25497
|
return { state: next2 };
|
|
25498
25498
|
}
|
|
@@ -25503,8 +25503,8 @@ function joinPanel(context, panel) {
|
|
|
25503
25503
|
push("run.status_changed", { status: selected.terminalStatus });
|
|
25504
25504
|
}
|
|
25505
25505
|
for (const event of events) context.eventStore.appendEvent(event);
|
|
25506
|
-
const next =
|
|
25507
|
-
|
|
25506
|
+
const next = foldStoredKxmRun(context, run);
|
|
25507
|
+
persistKxmRunState(context, run.runId, next, events[events.length - 1].sequence);
|
|
25508
25508
|
context.eventStore.updateRunStatus(run.runId, next.status, now);
|
|
25509
25509
|
return { state: next };
|
|
25510
25510
|
}
|
|
@@ -25512,15 +25512,15 @@ function failBudget(context, run, plan, state, reason, stepId) {
|
|
|
25512
25512
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
25513
25513
|
const sequence = context.eventStore.nextSequence(run.runId);
|
|
25514
25514
|
const event = {
|
|
25515
|
-
...
|
|
25516
|
-
eventId:
|
|
25515
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
25516
|
+
eventId: newKxmEventId(),
|
|
25517
25517
|
eventType: "run.status_changed",
|
|
25518
25518
|
sequence,
|
|
25519
25519
|
payload: { status: "failed", reason, stepId }
|
|
25520
25520
|
};
|
|
25521
25521
|
context.eventStore.appendEvent(event);
|
|
25522
|
-
const next =
|
|
25523
|
-
|
|
25522
|
+
const next = foldStoredKxmRun(context, run);
|
|
25523
|
+
persistKxmRunState(context, run.runId, next, sequence);
|
|
25524
25524
|
context.eventStore.updateRunStatus(run.runId, "failed", now);
|
|
25525
25525
|
void state;
|
|
25526
25526
|
return { state: next };
|
|
@@ -25530,19 +25530,19 @@ function hardStopUnrecorded(context, dispatch, reason) {
|
|
|
25530
25530
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
25531
25531
|
const sequence = context.eventStore.nextSequence(run.runId);
|
|
25532
25532
|
const event = {
|
|
25533
|
-
...
|
|
25534
|
-
eventId:
|
|
25533
|
+
...kxmEventBase(context, run, now, kxmMonotonicNs()),
|
|
25534
|
+
eventId: newKxmEventId(),
|
|
25535
25535
|
eventType: "run.status_changed",
|
|
25536
25536
|
sequence,
|
|
25537
25537
|
payload: { status: "failed", reason, stepId: dispatch.stepId }
|
|
25538
25538
|
};
|
|
25539
25539
|
context.eventStore.appendEvent(event);
|
|
25540
25540
|
context.eventStore.settleCapability(dispatch.attemptId, "revoked");
|
|
25541
|
-
const next =
|
|
25542
|
-
|
|
25541
|
+
const next = foldStoredKxmRun(context, run);
|
|
25542
|
+
persistKxmRunState(context, run.runId, next, sequence);
|
|
25543
25543
|
context.eventStore.updateRunStatus(run.runId, "failed", now);
|
|
25544
25544
|
}
|
|
25545
|
-
function
|
|
25545
|
+
function kxmTransitionBudgetFailure(plan, state, fromStepId, outcome) {
|
|
25546
25546
|
return transitionBudgetFailure(plan, state, fromStepId, outcome);
|
|
25547
25547
|
}
|
|
25548
25548
|
function transitionBudgetFailure(plan, state, fromStepId, outcome) {
|
|
@@ -25570,7 +25570,7 @@ function declaredRunDurationBudget(context, runId) {
|
|
|
25570
25570
|
const run = context.eventStore.run(runId);
|
|
25571
25571
|
if (!run) return void 0;
|
|
25572
25572
|
try {
|
|
25573
|
-
const envelope =
|
|
25573
|
+
const envelope = loadKxmRunPlanEnvelope(context.eventStore, run);
|
|
25574
25574
|
return effectiveRunDurationBudget(envelope.plan.limits, envelope.projectLimits);
|
|
25575
25575
|
} catch {
|
|
25576
25576
|
return void 0;
|
|
@@ -25581,7 +25581,7 @@ function runDurationOverrunPayload(context, runId, nowIso = (/* @__PURE__ */ new
|
|
|
25581
25581
|
if (!declared) return void 0;
|
|
25582
25582
|
const run = context.eventStore.run(runId);
|
|
25583
25583
|
if (!run) return void 0;
|
|
25584
|
-
const state =
|
|
25584
|
+
const state = foldStoredKxmRun(context, run);
|
|
25585
25585
|
if (!state.runningSince) return void 0;
|
|
25586
25586
|
if (isTerminalRunStatus(state.status) || state.status === "cancelling") return void 0;
|
|
25587
25587
|
const elapsedMs = elapsedMsBetween(state.runningSince, nowIso);
|
|
@@ -25589,11 +25589,11 @@ function runDurationOverrunPayload(context, runId, nowIso = (/* @__PURE__ */ new
|
|
|
25589
25589
|
return { budgetMs: declared.budgetMs, elapsedMs, source: declared.source };
|
|
25590
25590
|
}
|
|
25591
25591
|
function cancelRunDurationIfExceeded(context, runId) {
|
|
25592
|
-
if (
|
|
25592
|
+
if (isKxmRuntimeContextClosed(context)) return void 0;
|
|
25593
25593
|
const payload = runDurationOverrunPayload(context, runId);
|
|
25594
25594
|
if (!payload) return void 0;
|
|
25595
|
-
|
|
25596
|
-
return { state:
|
|
25595
|
+
cancelKxmRun(context, runId, { reason: "budget_run_duration", budget: payload });
|
|
25596
|
+
return { state: foldStoredKxmRun(context, requireRun(context, runId)) };
|
|
25597
25597
|
}
|
|
25598
25598
|
function driveDeadlineAt(context, runId, state) {
|
|
25599
25599
|
const declared = declaredRunDurationBudget(context, runId);
|
|
@@ -25629,7 +25629,7 @@ function armRunDurationBudgetTimer(context, runId) {
|
|
|
25629
25629
|
if (!declared) return () => void 0;
|
|
25630
25630
|
const run = context.eventStore.run(runId);
|
|
25631
25631
|
if (!run) return () => void 0;
|
|
25632
|
-
const state =
|
|
25632
|
+
const state = foldStoredKxmRun(context, run);
|
|
25633
25633
|
if (!state.runningSince) return () => void 0;
|
|
25634
25634
|
const startMs = Date.parse(state.runningSince);
|
|
25635
25635
|
if (!Number.isFinite(startMs)) return () => void 0;
|
|
@@ -25638,7 +25638,7 @@ function armRunDurationBudgetTimer(context, runId) {
|
|
|
25638
25638
|
let cleared = false;
|
|
25639
25639
|
const fire = () => {
|
|
25640
25640
|
timer = void 0;
|
|
25641
|
-
if (cleared ||
|
|
25641
|
+
if (cleared || isKxmRuntimeContextClosed(context)) return;
|
|
25642
25642
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
25643
25643
|
const elapsedMs = elapsedMsBetween(state.runningSince, nowIso);
|
|
25644
25644
|
if (elapsedMs < declared.budgetMs) {
|
|
@@ -25646,7 +25646,7 @@ function armRunDurationBudgetTimer(context, runId) {
|
|
|
25646
25646
|
return;
|
|
25647
25647
|
}
|
|
25648
25648
|
try {
|
|
25649
|
-
|
|
25649
|
+
cancelKxmRun(context, runId, {
|
|
25650
25650
|
reason: "budget_run_duration",
|
|
25651
25651
|
budget: { budgetMs: declared.budgetMs, elapsedMs, source: declared.source }
|
|
25652
25652
|
});
|
|
@@ -25659,7 +25659,7 @@ function armRunDurationBudgetTimer(context, runId) {
|
|
|
25659
25659
|
timer = setTimeout(fire, delay);
|
|
25660
25660
|
timer.unref();
|
|
25661
25661
|
};
|
|
25662
|
-
const unhook =
|
|
25662
|
+
const unhook = registerKxmRuntimeCloseHook(context, () => {
|
|
25663
25663
|
cleared = true;
|
|
25664
25664
|
if (timer !== void 0) clearTimeout(timer);
|
|
25665
25665
|
timer = void 0;
|
|
@@ -25934,7 +25934,7 @@ function classifyRecoverableGateAttempt(context, row, capability) {
|
|
|
25934
25934
|
}
|
|
25935
25935
|
let state;
|
|
25936
25936
|
try {
|
|
25937
|
-
state =
|
|
25937
|
+
state = foldStoredKxmRun(context, run);
|
|
25938
25938
|
} catch (error) {
|
|
25939
25939
|
throw runtimeError(
|
|
25940
25940
|
"gate_recovery_corrupt",
|
|
@@ -25965,10 +25965,10 @@ function classifyRecoverableGateAttempt(context, row, capability) {
|
|
|
25965
25965
|
}
|
|
25966
25966
|
const current = state.currentStep;
|
|
25967
25967
|
const sameAttempt = current?.attemptId === row.attemptId && current.assignmentId === row.assignmentId && current.effectId === row.effectId && current.stepId === row.stepId;
|
|
25968
|
-
const controller =
|
|
25968
|
+
const controller = kxmAttemptController(context.eventStore.path, row.runId, row.attemptId);
|
|
25969
25969
|
if (row.gateKind === "command") {
|
|
25970
|
-
const hold =
|
|
25971
|
-
const admittedToken =
|
|
25970
|
+
const hold = kxmGateHold(context.eventStore.path, row.runId);
|
|
25971
|
+
const admittedToken = kxmAdmittedToken(context.eventStore.path, row.runId);
|
|
25972
25972
|
if (hold && hold.attemptId !== row.attemptId) {
|
|
25973
25973
|
throw runtimeError("gate_recovery_corrupt", row.attemptId, "gate recovery preflight: gate hold does not match the attempt");
|
|
25974
25974
|
}
|
|
@@ -26031,7 +26031,7 @@ function isExcludedTerminalProof(state, row, observation, evidence, events) {
|
|
|
26031
26031
|
}
|
|
26032
26032
|
function settlePreparedGate(context, prepared, observation) {
|
|
26033
26033
|
const run = requireRun(context, prepared.run.runId);
|
|
26034
|
-
const folded =
|
|
26034
|
+
const folded = foldStoredKxmRun(context, run);
|
|
26035
26035
|
const current = folded.currentStep;
|
|
26036
26036
|
if (!current || current.stepId !== prepared.stepId || current.stepAttempt !== prepared.stepAttempt || current.assignmentId !== prepared.assignmentId || current.attemptId !== prepared.attemptId || current.effectId !== prepared.effectId) {
|
|
26037
26037
|
throw runtimeError("run_events_illegal", run.runId, "settlement identity does not match the prepared gate attempt");
|
|
@@ -26045,7 +26045,7 @@ function settlePreparedGate(context, prepared, observation) {
|
|
|
26045
26045
|
throw runtimeError("gate_row_invalid", run.runId, "gate settlement requires a complete observation");
|
|
26046
26046
|
}
|
|
26047
26047
|
const settled = cancelled ? recordGateCancelObservedInTransaction(context, run, prepared.envelope, prepared.stepId, observation) : recordGateSettlementInTransaction(context, run, prepared.envelope, prepared.stepId, observation);
|
|
26048
|
-
|
|
26048
|
+
kxmGateDispatchSeams.afterObservationWrite?.(prepared);
|
|
26049
26049
|
return settled;
|
|
26050
26050
|
}
|
|
26051
26051
|
function requireRun(context, runId) {
|
|
@@ -26056,10 +26056,10 @@ function requireRun(context, runId) {
|
|
|
26056
26056
|
}
|
|
26057
26057
|
return run;
|
|
26058
26058
|
}
|
|
26059
|
-
function
|
|
26059
|
+
function recoverKxmRun(context, runId, request) {
|
|
26060
26060
|
return context.eventStore.transaction(() => {
|
|
26061
26061
|
const run = requireRun(context, runId);
|
|
26062
|
-
let state =
|
|
26062
|
+
let state = foldStoredKxmRun(context, run);
|
|
26063
26063
|
if (state.status !== "blocked_uncertain" && state.status !== "cancelling" && state.currentStep?.effectState !== "blocked_uncertain") {
|
|
26064
26064
|
throw runtimeError("run_events_illegal", runId, `run ${runId} is not in blocked_uncertain status`);
|
|
26065
26065
|
}
|
|
@@ -26068,17 +26068,17 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26068
26068
|
}
|
|
26069
26069
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
26070
26070
|
let sequence = context.eventStore.nextSequence(runId);
|
|
26071
|
-
let mono =
|
|
26071
|
+
let mono = kxmMonotonicNs();
|
|
26072
26072
|
const events = [];
|
|
26073
26073
|
const push = (eventType, payload) => {
|
|
26074
26074
|
events.push({
|
|
26075
|
-
...
|
|
26076
|
-
eventId:
|
|
26075
|
+
...kxmEventBase(context, run, now, mono, request.commandId),
|
|
26076
|
+
eventId: newKxmEventId(),
|
|
26077
26077
|
eventType,
|
|
26078
26078
|
sequence: sequence++,
|
|
26079
26079
|
payload
|
|
26080
26080
|
});
|
|
26081
|
-
mono =
|
|
26081
|
+
mono = kxmIncrementMonotonicNs(mono);
|
|
26082
26082
|
};
|
|
26083
26083
|
if (state.status === "running" && state.currentStep?.effectState === "blocked_uncertain") {
|
|
26084
26084
|
push("run.status_changed", {
|
|
@@ -26088,13 +26088,13 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26088
26088
|
});
|
|
26089
26089
|
for (const ev of events) context.eventStore.appendEvent(ev);
|
|
26090
26090
|
events.length = 0;
|
|
26091
|
-
state =
|
|
26091
|
+
state = foldStoredKxmRun(context, run);
|
|
26092
26092
|
context.eventStore.updateRunStatus(runId, "blocked_uncertain", now);
|
|
26093
26093
|
}
|
|
26094
26094
|
const attemptId = state.currentStep?.attemptId;
|
|
26095
26095
|
if (attemptId) {
|
|
26096
|
-
|
|
26097
|
-
|
|
26096
|
+
resolveKxmGateHold(context.eventStore.path, runId, attemptId);
|
|
26097
|
+
unregisterKxmAttemptController(context.eventStore.path, runId, attemptId);
|
|
26098
26098
|
const cap = context.eventStore.capabilityByAttempt(attemptId);
|
|
26099
26099
|
if (cap && cap.state !== "settled") {
|
|
26100
26100
|
context.eventStore.settleCapability(attemptId, "settled");
|
|
@@ -26107,8 +26107,8 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26107
26107
|
reason: request.reason ?? "operator_retry"
|
|
26108
26108
|
});
|
|
26109
26109
|
for (const ev of events) context.eventStore.appendEvent(ev);
|
|
26110
|
-
const nextState =
|
|
26111
|
-
|
|
26110
|
+
const nextState = foldStoredKxmRun(context, run);
|
|
26111
|
+
persistKxmRunState(context, runId, nextState, events[events.length - 1].sequence);
|
|
26112
26112
|
context.eventStore.updateRunStatus(runId, "running", now);
|
|
26113
26113
|
return { state: nextState, unblocked: true };
|
|
26114
26114
|
}
|
|
@@ -26119,8 +26119,8 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26119
26119
|
reason: request.reason ?? "operator_fail"
|
|
26120
26120
|
});
|
|
26121
26121
|
for (const ev of events) context.eventStore.appendEvent(ev);
|
|
26122
|
-
const nextState =
|
|
26123
|
-
|
|
26122
|
+
const nextState = foldStoredKxmRun(context, run);
|
|
26123
|
+
persistKxmRunState(context, runId, nextState, events[events.length - 1].sequence);
|
|
26124
26124
|
context.eventStore.updateRunStatus(runId, "failed", now);
|
|
26125
26125
|
return { state: nextState, unblocked: true };
|
|
26126
26126
|
}
|
|
@@ -26140,8 +26140,8 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26140
26140
|
reason: request.reason ?? "operator_cancel"
|
|
26141
26141
|
});
|
|
26142
26142
|
for (const ev of events) context.eventStore.appendEvent(ev);
|
|
26143
|
-
const nextState =
|
|
26144
|
-
|
|
26143
|
+
const nextState = foldStoredKxmRun(context, run);
|
|
26144
|
+
persistKxmRunState(context, runId, nextState, events[events.length - 1].sequence);
|
|
26145
26145
|
context.eventStore.updateRunStatus(runId, "cancelled", now);
|
|
26146
26146
|
return { state: nextState, unblocked: true };
|
|
26147
26147
|
}
|
|
@@ -26149,7 +26149,7 @@ function recoverVnextRun(context, runId, request) {
|
|
|
26149
26149
|
});
|
|
26150
26150
|
}
|
|
26151
26151
|
|
|
26152
|
-
// plugins/kxm/src/
|
|
26152
|
+
// plugins/kxm/src/oneshot-producer.ts
|
|
26153
26153
|
function determineOutcome(text, allowedOutcomes) {
|
|
26154
26154
|
try {
|
|
26155
26155
|
const result = JSON.parse(text.trim());
|
|
@@ -26161,7 +26161,7 @@ function determineOutcome(text, allowedOutcomes) {
|
|
|
26161
26161
|
}
|
|
26162
26162
|
return "failed";
|
|
26163
26163
|
}
|
|
26164
|
-
function
|
|
26164
|
+
function createKxmOneShotProducer(options = {}) {
|
|
26165
26165
|
const defaultHarness = options.defaultHarness ?? "claude";
|
|
26166
26166
|
const running = /* @__PURE__ */ new Map();
|
|
26167
26167
|
let closed = false;
|
|
@@ -26323,7 +26323,7 @@ Return a final JSON object with an "outcome" field chosen from ${JSON.stringify(
|
|
|
26323
26323
|
}
|
|
26324
26324
|
const spawnFn = options.spawnProcess ?? defaultSpawn;
|
|
26325
26325
|
const cwd = options.projectRoot ?? process.cwd();
|
|
26326
|
-
const evidence = await beginOneShotEvidence(options.evidenceRoot ?? join12(
|
|
26326
|
+
const evidence = await beginOneShotEvidence(options.evidenceRoot ?? join12(kxmUserStateRoot(), "runtime", "oneshot-evidence"), {
|
|
26327
26327
|
runId: request.runId,
|
|
26328
26328
|
stepId: request.stepId,
|
|
26329
26329
|
attemptId: request.attemptId,
|
|
@@ -26466,12 +26466,12 @@ Return a final JSON object with an "outcome" field chosen from ${JSON.stringify(
|
|
|
26466
26466
|
return producer;
|
|
26467
26467
|
}
|
|
26468
26468
|
|
|
26469
|
-
// plugins/kxm/src/
|
|
26470
|
-
function
|
|
26469
|
+
// plugins/kxm/src/runtime-supervisor.ts
|
|
26470
|
+
function kxmSupervisorTokenFile(paths) {
|
|
26471
26471
|
return join13(paths.runtimeDir, "supervisor.token");
|
|
26472
26472
|
}
|
|
26473
|
-
function
|
|
26474
|
-
const file =
|
|
26473
|
+
function publishKxmSupervisorToken(paths, token) {
|
|
26474
|
+
const file = kxmSupervisorTokenFile(paths);
|
|
26475
26475
|
mkdirSync4(dirname6(file), { recursive: true, mode: 448 });
|
|
26476
26476
|
const temp = `${file}.${process.pid}.tmp`;
|
|
26477
26477
|
writeFileSync4(temp, `${token}
|
|
@@ -26486,11 +26486,11 @@ function publishVnextSupervisorToken(paths, token) {
|
|
|
26486
26486
|
} catch {
|
|
26487
26487
|
}
|
|
26488
26488
|
}
|
|
26489
|
-
function
|
|
26489
|
+
function hashKxmSupervisorToken(token) {
|
|
26490
26490
|
return `sha256:${createHash11("sha256").update(`kxm-runtime-supervisor\0${token}`, "utf8").digest("hex")}`;
|
|
26491
26491
|
}
|
|
26492
|
-
function
|
|
26493
|
-
const file =
|
|
26492
|
+
function readKxmSupervisorToken(paths) {
|
|
26493
|
+
const file = kxmSupervisorTokenFile(paths);
|
|
26494
26494
|
const stat = lstatSync5(file, { throwIfNoEntry: false });
|
|
26495
26495
|
if (!stat) return void 0;
|
|
26496
26496
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
@@ -26536,9 +26536,9 @@ function readRecentSupervisorError(paths) {
|
|
|
26536
26536
|
return void 0;
|
|
26537
26537
|
}
|
|
26538
26538
|
}
|
|
26539
|
-
function
|
|
26539
|
+
function kxmSupervisorStatus(paths) {
|
|
26540
26540
|
if (!existsSync10(paths.registryDb)) return { running: false };
|
|
26541
|
-
const registry = new
|
|
26541
|
+
const registry = new KxmRuntimeRegistry(paths.registryDb);
|
|
26542
26542
|
try {
|
|
26543
26543
|
const record2 = registry.supervisor();
|
|
26544
26544
|
if (!record2) return { running: false };
|
|
@@ -26573,7 +26573,7 @@ async function probeSupervisor(port, expectedRuntimeId, token, timeoutMs = 750)
|
|
|
26573
26573
|
const response = await fetch(`http://127.0.0.1:${port}/healthz?nonce=${nonce}`, { signal: controller.signal });
|
|
26574
26574
|
if (!response.ok) return false;
|
|
26575
26575
|
const payload = await response.json();
|
|
26576
|
-
const expectedProof =
|
|
26576
|
+
const expectedProof = hashKxmTokenProof(token, nonce);
|
|
26577
26577
|
return payload.runtimeId === expectedRuntimeId && payload.tokenProof === expectedProof;
|
|
26578
26578
|
} catch {
|
|
26579
26579
|
return false;
|
|
@@ -26581,15 +26581,15 @@ async function probeSupervisor(port, expectedRuntimeId, token, timeoutMs = 750)
|
|
|
26581
26581
|
clearTimeout(timeout);
|
|
26582
26582
|
}
|
|
26583
26583
|
}
|
|
26584
|
-
function
|
|
26584
|
+
function hashKxmTokenProof(token, nonce) {
|
|
26585
26585
|
return createHmac("sha256", token).update(`kxm-runtime-token-proof\0${nonce}`, "utf8").digest("hex");
|
|
26586
26586
|
}
|
|
26587
|
-
async function
|
|
26588
|
-
const paths =
|
|
26589
|
-
const status =
|
|
26587
|
+
async function ensureKxmSupervisor(options = {}) {
|
|
26588
|
+
const paths = kxmRuntimePaths(options.stateRoot !== void 0 ? { stateRoot: options.stateRoot } : { ...options.env ? { env: options.env } : {} });
|
|
26589
|
+
const status = kxmSupervisorStatus(paths);
|
|
26590
26590
|
if (status.running && status.port) {
|
|
26591
26591
|
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
26592
|
-
const token =
|
|
26592
|
+
const token = readKxmSupervisorToken(paths);
|
|
26593
26593
|
if (token && await probeSupervisorWithRetry(status.port, status.runtimeId, token)) {
|
|
26594
26594
|
return { runtimeId: status.runtimeId, port: status.port, token, started: false };
|
|
26595
26595
|
}
|
|
@@ -26617,9 +26617,9 @@ async function ensureVnextSupervisor(options = {}) {
|
|
|
26617
26617
|
const deadline = Date.now() + 1e4;
|
|
26618
26618
|
while (Date.now() < deadline) {
|
|
26619
26619
|
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
26620
|
-
const next =
|
|
26620
|
+
const next = kxmSupervisorStatus(paths);
|
|
26621
26621
|
if (next.running && next.port) {
|
|
26622
|
-
const token =
|
|
26622
|
+
const token = readKxmSupervisorToken(paths);
|
|
26623
26623
|
if (token && await probeSupervisor(next.port, next.runtimeId, token)) {
|
|
26624
26624
|
return { runtimeId: next.runtimeId, port: next.port, token, started: true };
|
|
26625
26625
|
}
|
|
@@ -26653,7 +26653,7 @@ async function readJsonBody(request, limit = 64 * 1024) {
|
|
|
26653
26653
|
}
|
|
26654
26654
|
return parsed;
|
|
26655
26655
|
} catch (error) {
|
|
26656
|
-
if (error instanceof
|
|
26656
|
+
if (error instanceof KxmConfigError) throw error;
|
|
26657
26657
|
throw runtimeError("runtime_request_invalid", request.url ?? "<request>", "request body is not valid JSON");
|
|
26658
26658
|
}
|
|
26659
26659
|
}
|
|
@@ -26705,24 +26705,24 @@ async function driveSessionStillPending(settled) {
|
|
|
26705
26705
|
await Promise.resolve();
|
|
26706
26706
|
return pending;
|
|
26707
26707
|
}
|
|
26708
|
-
async function
|
|
26708
|
+
async function startKxmRuntimeSupervisor(options = {}) {
|
|
26709
26709
|
const now = options.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
26710
|
-
const paths =
|
|
26710
|
+
const paths = kxmRuntimePaths(options.stateRoot !== void 0 ? { stateRoot: options.stateRoot } : {});
|
|
26711
26711
|
try {
|
|
26712
|
-
return await
|
|
26712
|
+
return await startKxmRuntimeSupervisorInner(paths, options.port, now);
|
|
26713
26713
|
} catch (error) {
|
|
26714
|
-
if (!(error instanceof
|
|
26714
|
+
if (!(error instanceof KxmConfigError && error.issues.some((issue3) => issue3.code === "runtime_supervisor_conflict"))) {
|
|
26715
26715
|
recordSupervisorError(paths, error.message);
|
|
26716
26716
|
}
|
|
26717
26717
|
throw error;
|
|
26718
26718
|
}
|
|
26719
26719
|
}
|
|
26720
|
-
async function
|
|
26720
|
+
async function startKxmRuntimeSupervisorInner(paths, requestedPortOption, now) {
|
|
26721
26721
|
mkdirSync4(paths.runtimeDir, { recursive: true, mode: 448 });
|
|
26722
26722
|
mkdirSync4(paths.projectsDir, { recursive: true, mode: 448 });
|
|
26723
26723
|
const token = randomBytes2(32).toString("hex");
|
|
26724
|
-
const tokenHash =
|
|
26725
|
-
const registry = new
|
|
26724
|
+
const tokenHash = hashKxmSupervisorToken(token);
|
|
26725
|
+
const registry = new KxmRuntimeRegistry(paths.registryDb);
|
|
26726
26726
|
const runtimeId = `rtm_${createHash11("sha256").update(`${paths.stateRoot}\0${process.pid}\0${now()}\0${randomBytes2(16).toString("hex")}`, "utf8").digest("hex").slice(0, 24)}`;
|
|
26727
26727
|
const requestedPort = requestedPortOption ?? 0;
|
|
26728
26728
|
let activeRuntimeId = runtimeId;
|
|
@@ -26734,14 +26734,14 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26734
26734
|
const key = projectRuntimeKey(projectRoot);
|
|
26735
26735
|
const existing = contexts.get(key);
|
|
26736
26736
|
if (existing) return existing;
|
|
26737
|
-
const context =
|
|
26737
|
+
const context = openKxmRuntimeContext(projectRoot, { homeRuntimeId: activeRuntimeId, stateRoot: paths.stateRoot });
|
|
26738
26738
|
contexts.set(key, context);
|
|
26739
26739
|
return context;
|
|
26740
26740
|
};
|
|
26741
26741
|
const requireAuth = (request) => {
|
|
26742
26742
|
const header = request.headers.authorization ?? "";
|
|
26743
26743
|
const presented = header.startsWith("Bearer ") ? header.slice("Bearer ".length) : "";
|
|
26744
|
-
const presentedHash = presented.length > 0 ? Buffer.from(
|
|
26744
|
+
const presentedHash = presented.length > 0 ? Buffer.from(hashKxmSupervisorToken(presented), "utf8") : Buffer.alloc(0);
|
|
26745
26745
|
const expectedHash = Buffer.from(tokenHash, "utf8");
|
|
26746
26746
|
if (presentedHash.length !== expectedHash.length || !timingSafeEqual2(presentedHash, expectedHash)) {
|
|
26747
26747
|
throw runtimeError("runtime_auth_failed", request.url ?? "<request>", "missing or invalid supervisor token");
|
|
@@ -26759,7 +26759,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26759
26759
|
state: "running",
|
|
26760
26760
|
// Proof of token knowledge: an impostor that merely binds the
|
|
26761
26761
|
// stale port cannot answer the keyed challenge.
|
|
26762
|
-
tokenProof: nonce.length > 0 ?
|
|
26762
|
+
tokenProof: nonce.length > 0 ? hashKxmTokenProof(token, nonce) : void 0
|
|
26763
26763
|
});
|
|
26764
26764
|
return;
|
|
26765
26765
|
}
|
|
@@ -26781,8 +26781,8 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26781
26781
|
return;
|
|
26782
26782
|
}
|
|
26783
26783
|
const context = contextFor(projectRoot);
|
|
26784
|
-
const bundle =
|
|
26785
|
-
const acceptance =
|
|
26784
|
+
const bundle = loadKxmProject(projectRoot, {});
|
|
26785
|
+
const acceptance = acceptKxmRun(context, bundle, {
|
|
26786
26786
|
...typeof body.commandId === "string" && body.commandId.length > 0 ? { commandId: body.commandId } : {},
|
|
26787
26787
|
workflowId,
|
|
26788
26788
|
prompt
|
|
@@ -26805,11 +26805,11 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26805
26805
|
return;
|
|
26806
26806
|
}
|
|
26807
26807
|
const context = contextFor(projectRoot);
|
|
26808
|
-
const bundle =
|
|
26808
|
+
const bundle = loadKxmProject(projectRoot, {});
|
|
26809
26809
|
if (request.method === "GET" && !sub) {
|
|
26810
|
-
const projected =
|
|
26811
|
-
const folded =
|
|
26812
|
-
const drive =
|
|
26810
|
+
const projected = projectKxmRunReadOnly(context, runId);
|
|
26811
|
+
const folded = foldStoredKxmRun(context, projected);
|
|
26812
|
+
const drive = kxmDrivePollProjection(context, runId, folded);
|
|
26813
26813
|
sendJson(response, 200, { ok: true, run: projected, ...drive !== void 0 ? { drive } : {} });
|
|
26814
26814
|
return;
|
|
26815
26815
|
}
|
|
@@ -26822,7 +26822,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26822
26822
|
const run = context.eventStore.run(runId);
|
|
26823
26823
|
if (!run) throw runtimeError("run_unknown", runId, "run not found");
|
|
26824
26824
|
const delayMs = typeof body.delayMs === "number" && body.delayMs > 0 ? body.delayMs : 0;
|
|
26825
|
-
const createProducer = () => body.mode === "live" ?
|
|
26825
|
+
const createProducer = () => body.mode === "live" ? createKxmOneShotProducer({
|
|
26826
26826
|
projectRoot,
|
|
26827
26827
|
defaultHarness: String(bundle.project.value.defaultHarness ?? "pi"),
|
|
26828
26828
|
resolveHarness: (agentId) => {
|
|
@@ -26841,7 +26841,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26841
26841
|
}
|
|
26842
26842
|
return { provider, model: modelName };
|
|
26843
26843
|
}
|
|
26844
|
-
}) :
|
|
26844
|
+
}) : createKxmSimulatedProducer(async () => {
|
|
26845
26845
|
if (delayMs > 0) {
|
|
26846
26846
|
await new Promise((r) => setTimeout(r, delayMs));
|
|
26847
26847
|
}
|
|
@@ -26850,7 +26850,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26850
26850
|
let session;
|
|
26851
26851
|
let earlyError;
|
|
26852
26852
|
try {
|
|
26853
|
-
const scheduler =
|
|
26853
|
+
const scheduler = KxmRunScheduler.for(context, bundle);
|
|
26854
26854
|
const opening = scheduler.openDriveSession(runId, {
|
|
26855
26855
|
mode: body.mode,
|
|
26856
26856
|
allowLimits: false,
|
|
@@ -26899,7 +26899,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26899
26899
|
if (request.method === "GET" && sub === "drive") {
|
|
26900
26900
|
const run = context.eventStore.run(runId);
|
|
26901
26901
|
if (!run) throw runtimeError("run_unknown", runId, "run not found");
|
|
26902
|
-
const activeSession =
|
|
26902
|
+
const activeSession = kxmDriveSession(context.eventStore.path, runId);
|
|
26903
26903
|
const session = activeSession ? {
|
|
26904
26904
|
driveId: activeSession.driveId,
|
|
26905
26905
|
mode: activeSession.mode,
|
|
@@ -26912,7 +26912,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26912
26912
|
}
|
|
26913
26913
|
if (request.method === "POST" && sub === "cancel") {
|
|
26914
26914
|
const body = await readJsonBody(request);
|
|
26915
|
-
const result =
|
|
26915
|
+
const result = cancelKxmRun(context, runId, {
|
|
26916
26916
|
...typeof body.commandId === "string" && body.commandId.length > 0 ? { commandId: body.commandId } : {}
|
|
26917
26917
|
});
|
|
26918
26918
|
sendJson(response, 200, { ok: true, idempotent: result.idempotent, run: result.run, events: result.events });
|
|
@@ -26922,11 +26922,11 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26922
26922
|
const body = await readJsonBody(request);
|
|
26923
26923
|
const run = context.eventStore.run(runId);
|
|
26924
26924
|
if (!run) throw runtimeError("run_unknown", runId, "run not found");
|
|
26925
|
-
const state =
|
|
26925
|
+
const state = foldStoredKxmRun(context, run);
|
|
26926
26926
|
let unblocked = false;
|
|
26927
26927
|
if (state.status === "blocked_uncertain" || state.status === "cancelling" || state.currentStep?.effectState === "blocked_uncertain") {
|
|
26928
26928
|
const action = body.action === "cancel" || body.action === "fail" || body.action === "retry" || body.action === "unblock" ? body.action : "unblock";
|
|
26929
|
-
const rec =
|
|
26929
|
+
const rec = recoverKxmRun(context, runId, {
|
|
26930
26930
|
action,
|
|
26931
26931
|
reason: typeof body.summary === "string" ? body.summary : `signal_${body.signalKey ?? "callback"}`
|
|
26932
26932
|
});
|
|
@@ -26969,9 +26969,9 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26969
26969
|
sendJson(response, 200, { ok: true, receipt, verified: false, divergence: "run missing" });
|
|
26970
26970
|
return;
|
|
26971
26971
|
}
|
|
26972
|
-
const state =
|
|
26972
|
+
const state = foldStoredKxmRun(context, stored);
|
|
26973
26973
|
const events = context.eventStore.events(runId, 0, 1e6);
|
|
26974
|
-
const checked =
|
|
26974
|
+
const checked = verifyKxmDriveReceipt(receipt, events, state.status, { runId, driveId });
|
|
26975
26975
|
sendJson(response, 200, {
|
|
26976
26976
|
ok: true,
|
|
26977
26977
|
receipt,
|
|
@@ -26999,7 +26999,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
26999
26999
|
}
|
|
27000
27000
|
sendJson(response, 404, { ok: false, error: "runtime_not_found" });
|
|
27001
27001
|
} catch (error) {
|
|
27002
|
-
if (error instanceof
|
|
27002
|
+
if (error instanceof KxmConfigError) {
|
|
27003
27003
|
const code = error.issues[0]?.code ?? "runtime_error";
|
|
27004
27004
|
const status = code === "runtime_auth_failed" ? 401 : code === "run_unknown" ? 404 : 400;
|
|
27005
27005
|
sendJson(response, status, { ok: false, error: code, issues: error.issues });
|
|
@@ -27040,7 +27040,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
27040
27040
|
}
|
|
27041
27041
|
}
|
|
27042
27042
|
try {
|
|
27043
|
-
|
|
27043
|
+
publishKxmSupervisorToken(paths, token);
|
|
27044
27044
|
clearSupervisorError(paths);
|
|
27045
27045
|
} catch (error) {
|
|
27046
27046
|
registry.close();
|
|
@@ -27066,10 +27066,10 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
27066
27066
|
registry.markStopping(process.pid, now());
|
|
27067
27067
|
} catch {
|
|
27068
27068
|
}
|
|
27069
|
-
const openSessions = [...contexts.values()].flatMap((context) =>
|
|
27069
|
+
const openSessions = [...contexts.values()].flatMap((context) => kxmOpenDriveSessions(context.eventStore.path).map((session) => ({ context, session })));
|
|
27070
27070
|
for (const { context, session } of openSessions) {
|
|
27071
27071
|
try {
|
|
27072
|
-
|
|
27072
|
+
cancelKxmRun(context, session.runId, { reason: "runtime_shutdown" });
|
|
27073
27073
|
} catch {
|
|
27074
27074
|
}
|
|
27075
27075
|
try {
|
|
@@ -27087,7 +27087,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
27087
27087
|
producerClosed: false
|
|
27088
27088
|
});
|
|
27089
27089
|
}
|
|
27090
|
-
for (const context of contexts.values())
|
|
27090
|
+
for (const context of contexts.values()) closeKxmRuntimeContext(context);
|
|
27091
27091
|
contexts.clear();
|
|
27092
27092
|
const closed = new Promise((resolveStop) => server.close(() => resolveStop()));
|
|
27093
27093
|
server.closeIdleConnections?.();
|
|
@@ -27106,7 +27106,7 @@ async function startVnextRuntimeSupervisorInner(paths, requestedPortOption, now)
|
|
|
27106
27106
|
});
|
|
27107
27107
|
return { server, port, runtimeId: activeRuntimeId, stop };
|
|
27108
27108
|
}
|
|
27109
|
-
async function
|
|
27109
|
+
async function kxmRuntimeRequest(handle, method, path, body) {
|
|
27110
27110
|
const response = await fetch(`http://127.0.0.1:${handle.port}${path}`, {
|
|
27111
27111
|
method,
|
|
27112
27112
|
headers: {
|
|
@@ -27126,13 +27126,13 @@ async function vnextRuntimeRequest(handle, method, path, body) {
|
|
|
27126
27126
|
export {
|
|
27127
27127
|
DEFAULT_RUNTIME_STOP_GRACE_MS,
|
|
27128
27128
|
MAX_RUNTIME_STOP_GRACE_MS,
|
|
27129
|
-
|
|
27130
|
-
|
|
27131
|
-
|
|
27132
|
-
|
|
27129
|
+
ensureKxmSupervisor,
|
|
27130
|
+
hashKxmSupervisorToken,
|
|
27131
|
+
hashKxmTokenProof,
|
|
27132
|
+
kxmRuntimeRequest,
|
|
27133
|
+
kxmSupervisorStatus,
|
|
27134
|
+
kxmSupervisorTokenFile,
|
|
27135
|
+
readKxmSupervisorToken,
|
|
27133
27136
|
runtimeStopGraceMs,
|
|
27134
|
-
|
|
27135
|
-
vnextRuntimeRequest,
|
|
27136
|
-
vnextSupervisorStatus,
|
|
27137
|
-
vnextSupervisorTokenFile
|
|
27137
|
+
startKxmRuntimeSupervisor
|
|
27138
27138
|
};
|