@kontextmind/kxm 0.7.13 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/package.json +1 -1
- package/plugins/kxm/.claude-plugin/plugin.json +1 -1
- package/plugins/kxm/dist/cli.js +16 -3
- package/plugins/kxm/dist/mcp-server.js +1 -1
- package/plugins/kxm/dist/runtime.js +259 -70
- package/plugins/kxm/dist/vnext-runtime-supervisor.js +259 -70
- package/plugins/kxm/package.json +1 -1
- package/plugins/kxm/src/cli/vnext.ts +20 -3
- package/plugins/kxm/src/mcp-server.ts +1 -1
- package/plugins/kxm/src/policy-draft.d.mts +1 -0
- package/plugins/kxm/src/policy-draft.mjs +16 -1
- package/plugins/kxm/src/vnext-engine.ts +183 -3
- package/plugins/kxm/src/vnext-runtime-owner.ts +50 -0
- package/plugins/kxm/src/vnext-runtime-supervisor.ts +83 -58
- package/plugins/kxm/src/vnext-runtime.ts +9 -8
- package/scripts/harness-run.d.mts +3 -1
- package/scripts/harness-run.mjs +46 -13
- package/scripts/roster-policy.d.mts +4 -0
- package/scripts/roster-policy.mjs +30 -8
package/scripts/harness-run.mjs
CHANGED
|
@@ -72,8 +72,14 @@ export const NATIVE_PI_BRAKE_PROVIDERS = Object.freeze([
|
|
|
72
72
|
"deepseek",
|
|
73
73
|
]);
|
|
74
74
|
|
|
75
|
-
/** Verified Pi aggregator prefixes. Not a catalog and not a writer grant. */
|
|
76
|
-
export const PI_ALLOWED_PROVIDERS = Object.freeze(["openrouter", "nous-portal"]);
|
|
75
|
+
/** Verified Pi aggregator prefixes and native-vendor Pi providers. Not a catalog and not a writer grant. */
|
|
76
|
+
export const PI_ALLOWED_PROVIDERS = Object.freeze(["openrouter", "nous-portal", "antigravity"]);
|
|
77
|
+
|
|
78
|
+
/** Native-vendor Pi providers own one braked vendor. Aggregators are not listed here. */
|
|
79
|
+
export const PI_NATIVE_VENDOR_PROVIDERS = Object.freeze({ antigravity: "google" });
|
|
80
|
+
|
|
81
|
+
/** Gemini kebab ids for antigravity two-segment models (`antigravity/gemini-...`). */
|
|
82
|
+
export const PI_ANTIGRAVITY_MODEL_ID = /^gemini-[a-z0-9.-]+$/;
|
|
77
83
|
|
|
78
84
|
/** Exact helper model string after `@jayteelabs/pi-nous-portal-provider` is installed. */
|
|
79
85
|
export const PI_NOUS_PORTAL_HY4 = "nous-portal/tencent/hy4-preview";
|
|
@@ -171,8 +177,19 @@ export const ROUTES = Object.freeze({
|
|
|
171
177
|
|
|
172
178
|
const UNVERIFIED_HARNESSES = Object.freeze(["kimi", "gemini", "deepseek"]);
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
function piNativeVendor(provider) {
|
|
181
|
+
return Object.hasOwn(PI_NATIVE_VENDOR_PROVIDERS, provider)
|
|
182
|
+
? PI_NATIVE_VENDOR_PROVIDERS[provider]
|
|
183
|
+
: undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const PI_NATIVE_VENDOR_EFFORTS = Object.freeze(["low", "medium", "high"]);
|
|
187
|
+
|
|
188
|
+
export function clampEffort(harness, effort, model) {
|
|
189
|
+
const provider = typeof model === "string" ? piProviderOf(model) : undefined;
|
|
190
|
+
const accepted = provider && piNativeVendor(provider)
|
|
191
|
+
? PI_NATIVE_VENDOR_EFFORTS
|
|
192
|
+
: (ROUTES[harness]?.efforts ?? []);
|
|
176
193
|
if (!effort) return { effort: undefined, clamped: undefined };
|
|
177
194
|
if (!EFFORT.includes(effort)) {
|
|
178
195
|
throw failClosed(`unknown effort ${effort}; expected one of ${EFFORT.join(", ")}`);
|
|
@@ -220,6 +237,9 @@ function piLoginHint(provider) {
|
|
|
220
237
|
return "pi install npm:@jayteelabs/pi-nous-portal-provider, then /login → subscription or API key → Nous Research Portal (or NOUS_API_KEY)";
|
|
221
238
|
}
|
|
222
239
|
if (provider === "openrouter") return "pi /login openrouter";
|
|
240
|
+
if (provider === "antigravity") {
|
|
241
|
+
return "pi /login antigravity (Google OAuth, localhost:51121, paste-URL fallback)";
|
|
242
|
+
}
|
|
223
243
|
return ROUTES.pi.auth.loginHint;
|
|
224
244
|
}
|
|
225
245
|
|
|
@@ -245,6 +265,7 @@ export function piModelId(model) {
|
|
|
245
265
|
function piProviderLabel(provider) {
|
|
246
266
|
if (provider === "nous-portal") return "Nous Portal";
|
|
247
267
|
if (provider === "openrouter") return "OpenRouter";
|
|
268
|
+
if (provider === "antigravity") return "Antigravity";
|
|
248
269
|
return "Pi provider";
|
|
249
270
|
}
|
|
250
271
|
|
|
@@ -433,11 +454,13 @@ export function parseAuth(harness, stdio, options = {}) {
|
|
|
433
454
|
const reportedFromJson = typeof payload?.provider === "string"
|
|
434
455
|
? payload.provider.trim().toLowerCase()
|
|
435
456
|
: undefined;
|
|
436
|
-
const reportedFromText = /\
|
|
437
|
-
? "
|
|
438
|
-
: /\
|
|
439
|
-
? "
|
|
440
|
-
:
|
|
457
|
+
const reportedFromText = /\bantigravity\b/i.test(text)
|
|
458
|
+
? "antigravity"
|
|
459
|
+
: /\bnous-portal\b/i.test(text)
|
|
460
|
+
? "nous-portal"
|
|
461
|
+
: /\bopenrouter\b/i.test(text)
|
|
462
|
+
? "openrouter"
|
|
463
|
+
: undefined;
|
|
441
464
|
const reported = reportedFromJson ?? reportedFromText ?? requested;
|
|
442
465
|
const jsonStatus = typeof payload?.status === "string" ? payload.status : undefined;
|
|
443
466
|
if (/not[_ ]ready/i.test(text) || (jsonStatus !== undefined && jsonStatus !== "ready")
|
|
@@ -452,7 +475,7 @@ export function parseAuth(harness, stdio, options = {}) {
|
|
|
452
475
|
}
|
|
453
476
|
if (!PI_ALLOWED_PROVIDERS.includes(reported)) {
|
|
454
477
|
throw failClosed(
|
|
455
|
-
loginHint("pi", `pi helper allows only openrouter
|
|
478
|
+
loginHint("pi", `pi helper allows only openrouter/*, nous-portal/*, or antigravity/*; ${reported} is not allowlisted.`, requested),
|
|
456
479
|
"auth",
|
|
457
480
|
);
|
|
458
481
|
}
|
|
@@ -1510,13 +1533,20 @@ export function preflightRequest(request) {
|
|
|
1510
1533
|
if (harness === "pi") {
|
|
1511
1534
|
const provider = piProviderOf(request.model);
|
|
1512
1535
|
if (!provider) {
|
|
1513
|
-
throw failClosed("pi model must be provider/id (openrouter
|
|
1536
|
+
throw failClosed("pi model must be provider/id (openrouter/*, nous-portal/*, or antigravity/* in this helper)");
|
|
1514
1537
|
}
|
|
1515
1538
|
if (NATIVE_PI_BRAKE_PROVIDERS.includes(provider)) {
|
|
1516
1539
|
throw failClosed(`pi brake: ${provider} has a native harness; refusing Pi impersonation`);
|
|
1517
1540
|
}
|
|
1518
1541
|
if (!PI_ALLOWED_PROVIDERS.includes(provider)) {
|
|
1519
|
-
throw failClosed(`pi helper allows only openrouter
|
|
1542
|
+
throw failClosed(`pi helper allows only openrouter/*, nous-portal/*, or antigravity/*; ${provider} is not a native CLI and is not allowlisted`);
|
|
1543
|
+
}
|
|
1544
|
+
if (piNativeVendor(provider)) {
|
|
1545
|
+
const modelId = piModelId(request.model);
|
|
1546
|
+
const parts = String(request.model).split("/");
|
|
1547
|
+
if (parts.length !== 2 || parts.some((part) => !part) || !modelId || !PI_ANTIGRAVITY_MODEL_ID.test(modelId)) {
|
|
1548
|
+
throw failClosed("pi antigravity models must be exactly two-segment Gemini kebab ids (antigravity/gemini-...)");
|
|
1549
|
+
}
|
|
1520
1550
|
}
|
|
1521
1551
|
if (request.role === "writer" && (request.model !== PI_ADMITTED_WRITER || request.permission !== "edit")) {
|
|
1522
1552
|
throw failClosed("pi writer refuses unsupported route; allows only authenticated openrouter/qwen/qwen3-coder-plus with edit permission; other models need reviewed route admission");
|
|
@@ -1602,7 +1632,7 @@ export async function runHarness(request, deps = {}) {
|
|
|
1602
1632
|
: undefined;
|
|
1603
1633
|
const cwd = request.cwd ?? process.cwd();
|
|
1604
1634
|
const env = deps.env ?? process.env;
|
|
1605
|
-
const { effort, clamped } = clampEffort(request.harness, request.effort);
|
|
1635
|
+
const { effort, clamped } = clampEffort(request.harness, request.effort, request.model);
|
|
1606
1636
|
const prepared = { ...request, effort };
|
|
1607
1637
|
const outputDir = ensureOutputDir(
|
|
1608
1638
|
request.output_dir ?? join(cwd, ".kxm", "logs", `harness-${now()}`),
|
|
@@ -1780,6 +1810,9 @@ export async function runHarness(request, deps = {}) {
|
|
|
1780
1810
|
} else if (request.harness === "agy" && authStatus.method === "antigravity-oauth") {
|
|
1781
1811
|
fields.costBasis = "unmetered";
|
|
1782
1812
|
fields.costUsd = undefined;
|
|
1813
|
+
} else if (request.harness === "pi" && authStatus.method === "antigravity") {
|
|
1814
|
+
fields.costBasis = "unmetered";
|
|
1815
|
+
fields.costUsd = undefined;
|
|
1783
1816
|
} else if (fields.costUsd === undefined && fields.providerReportedCostUsd === undefined) {
|
|
1784
1817
|
fields.costBasis = fields.costBasis ?? "unknown";
|
|
1785
1818
|
}
|
|
@@ -18,3 +18,7 @@ export interface LoadedPolicy { readonly identity: PolicyIdentity; readonly poli
|
|
|
18
18
|
export function loadTrustedRosterPolicy(): LoadedPolicy;
|
|
19
19
|
export function resolveBoundPolicy(identity: PolicyIdentity): LoadedPolicy;
|
|
20
20
|
export function canonicalVendor(value: string): string;
|
|
21
|
+
export function validateRosterDocument(
|
|
22
|
+
policy: RosterPolicy,
|
|
23
|
+
readBlob: (source: string) => string | Uint8Array | null | undefined,
|
|
24
|
+
): RosterPolicy;
|
|
@@ -4,7 +4,7 @@ import { createHash } from 'node:crypto';
|
|
|
4
4
|
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { NATIVE_PI_BRAKE_PROVIDERS, PI_ALLOWED_PROVIDERS, ROUTES } from './harness-run.mjs';
|
|
7
|
+
import { NATIVE_PI_BRAKE_PROVIDERS, PI_ALLOWED_PROVIDERS, PI_ANTIGRAVITY_MODEL_ID, PI_NATIVE_VENDOR_PROVIDERS, ROUTES } from './harness-run.mjs';
|
|
8
8
|
|
|
9
9
|
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
10
|
const POLICY = '.kxm/roster.json';
|
|
@@ -84,19 +84,20 @@ function workingBytes(source) {
|
|
|
84
84
|
}
|
|
85
85
|
return readFileSync(current);
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
let policy;
|
|
89
|
-
try { policy = JSON.parse(bytes.toString('utf8')); } catch { refuse('invalid policy JSON'); }
|
|
87
|
+
export function validateRosterDocument(policy, readBlob) {
|
|
90
88
|
keys(policy, ['schema', 'routes', 'lineup', 'required_critics', 'model_origins'], 'policy');
|
|
91
89
|
if (policy.schema !== 'kxm.developer-roster.v1') refuse('unsupported schema');
|
|
92
90
|
record(policy.routes, 'routes'); record(policy.lineup, 'lineup'); record(policy.model_origins, 'model origins');
|
|
93
91
|
if (!Object.keys(policy.routes).length) refuse('empty routes');
|
|
92
|
+
if (typeof readBlob !== 'function') refuse('origin evidence reader required');
|
|
94
93
|
for (const [model, origin] of Object.entries(policy.model_origins)) {
|
|
95
94
|
text(model, 'origin model'); keys(origin, ['vendor', 'evidence'], 'origin');
|
|
96
95
|
text(origin.vendor, 'origin vendor');
|
|
97
96
|
if (PI_ALLOWED_PROVIDERS.includes(canonical(origin.vendor.toLowerCase()))) refuse('origin/vendor must name the model vendor, not billing provider');
|
|
98
97
|
keys(origin.evidence, ['source', 'sha256'], 'origin evidence'); digest(origin.evidence.sha256);
|
|
99
|
-
|
|
98
|
+
sourcePath(origin.evidence.source);
|
|
99
|
+
const bytes = readBlob(origin.evidence.source);
|
|
100
|
+
if (bytes == null || sha256(bytes) !== origin.evidence.sha256) refuse('origin evidence hash mismatch');
|
|
100
101
|
}
|
|
101
102
|
for (const [id, route] of Object.entries(policy.routes)) {
|
|
102
103
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(id)) refuse('invalid route id');
|
|
@@ -108,10 +109,26 @@ function validate(bytes, commit) {
|
|
|
108
109
|
if (!['admitted', 'retired'].includes(route.status)) refuse('unsupported status');
|
|
109
110
|
if (route.harness === 'pi') {
|
|
110
111
|
const parts = route.model.split('/');
|
|
111
|
-
|
|
112
|
-
const
|
|
112
|
+
const provider = parts[0];
|
|
113
|
+
const owned = Object.hasOwn(PI_NATIVE_VENDOR_PROVIDERS, provider)
|
|
114
|
+
? canonical(PI_NATIVE_VENDOR_PROVIDERS[provider])
|
|
115
|
+
: '';
|
|
116
|
+
const minParts = owned ? 2 : 3;
|
|
117
|
+
const maxParts = owned ? 2 : Number.POSITIVE_INFINITY;
|
|
118
|
+
if (
|
|
119
|
+
parts.length < minParts
|
|
120
|
+
|| parts.length > maxParts
|
|
121
|
+
|| !PI_ALLOWED_PROVIDERS.includes(provider)
|
|
122
|
+
|| parts.some(part => !part)
|
|
123
|
+
|| (owned && !PI_ANTIGRAVITY_MODEL_ID.test(parts[1]))
|
|
124
|
+
) refuse('unsupported Pi provider/model');
|
|
113
125
|
const vendor = canonical(route.vendor.toLowerCase());
|
|
114
|
-
if (
|
|
126
|
+
if (owned) {
|
|
127
|
+
if (owned !== vendor) refuse('native vendor cannot use Pi');
|
|
128
|
+
} else {
|
|
129
|
+
const prefix = canonical(parts[1].toLowerCase());
|
|
130
|
+
if (NATIVE_PI_BRAKE_PROVIDERS.includes(prefix) || NATIVE_PI_BRAKE_PROVIDERS.includes(vendor)) refuse('native vendor cannot use Pi');
|
|
131
|
+
}
|
|
115
132
|
if (!own(policy.model_origins, route.model)) refuse('missing exact model origin');
|
|
116
133
|
const origin = policy.model_origins[route.model];
|
|
117
134
|
if (canonical(origin.vendor.toLowerCase()) !== vendor || PI_ALLOWED_PROVIDERS.includes(vendor)) refuse('model origin/vendor mismatch');
|
|
@@ -140,6 +157,11 @@ function validate(bytes, commit) {
|
|
|
140
157
|
}
|
|
141
158
|
return policy;
|
|
142
159
|
}
|
|
160
|
+
function validate(bytes, commit) {
|
|
161
|
+
let policy;
|
|
162
|
+
try { policy = JSON.parse(bytes.toString('utf8')); } catch { refuse('invalid policy JSON'); }
|
|
163
|
+
return validateRosterDocument(policy, source => blobAt(commit, source).bytes);
|
|
164
|
+
}
|
|
143
165
|
export function loadTrustedRosterPolicy() {
|
|
144
166
|
const snapshot = control();
|
|
145
167
|
const { blob, bytes } = blobAt(snapshot.head, POLICY);
|