pi-muse-tether 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +24 -8
- package/assets/batch-boundary-schemas.json +202 -0
- package/assets/qualification-seeds.json +24 -0
- package/docs/CLIENT-LIFECYCLE.md +107 -0
- package/docs/CLIENT-QUALIFICATION.md +97 -0
- package/docs/DETAILS.md +4 -4
- package/index.ts +36 -12
- package/package.json +5 -3
- package/src/batch-schema.ts +33 -0
- package/src/catalog.ts +28 -25
- package/src/cli-version.ts +40 -17
- package/src/doctor.ts +20 -8
- package/src/features.ts +25 -0
- package/src/host.ts +147 -28
- package/src/model-route.ts +23 -12
- package/src/provider.ts +56 -11
- package/src/qualification-records.ts +99 -0
- package/src/qualification.ts +205 -0
- package/src/request-ledger.ts +17 -2
- package/src/settings.ts +13 -4
- package/src/tool-result-receipt.ts +207 -102
package/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { registerApiDispatch } from "pi-tether-core/register";
|
|
|
5
5
|
import { streamViaMuse, retireAll, setSessionManager, rawCompletionQualified, committedCompaction } from "./src/provider.js";
|
|
6
6
|
|
|
7
7
|
import { discoverMuseCatalog } from "./src/host.js";
|
|
8
|
+
import { featureNotice } from "./src/features.js";
|
|
9
|
+
import { clientStatus, clientBuildLabel } from "./src/qualification-records.js";
|
|
8
10
|
import { museDoctor } from "./src/doctor.js";
|
|
9
11
|
import { setQuotaListener, quotaStatusLine } from "./src/rate-limit.js";
|
|
10
12
|
import { setRetryStatusListener } from "./src/retry-status.js";
|
|
@@ -18,22 +20,24 @@ export async function registerMuseExtension(pi: ExtensionAPI, provider = {stream
|
|
|
18
20
|
if (!template)
|
|
19
21
|
throw new Error("Pi supplied no catalog template for offline echo");
|
|
20
22
|
const stream = streamViaMuse;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const discover = async () => {
|
|
24
|
+
if (process.env.PI_MUSE_TETHER_LIVE !== "1")
|
|
25
|
+
return {models: [], diagnostics: {status: "live disabled"}};
|
|
26
|
+
try {
|
|
27
|
+
const catalog = await discoverMuseCatalog();
|
|
28
|
+
return {models: museCatalogModels(catalog), diagnostics: museCatalogAssessment(catalog).diagnostics};
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return {models: [], diagnostics: {status: "discovery failed", error: error instanceof Error ? error.message : String(error)}};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
let catalogue = await discover();
|
|
30
34
|
registerApiDispatch(ID, stream);
|
|
31
|
-
pi.registerProvider(ID, {
|
|
35
|
+
const registerProvider = () => pi.registerProvider(ID, {
|
|
32
36
|
api: ID,
|
|
33
37
|
apiKey: "unused",
|
|
34
38
|
baseUrl: "pi-muse-tether",
|
|
35
39
|
models: [
|
|
36
|
-
...
|
|
40
|
+
...catalogue.models,
|
|
37
41
|
{
|
|
38
42
|
id: "echo",
|
|
39
43
|
name: "Muse echo (offline fixture)",
|
|
@@ -46,8 +50,28 @@ export async function registerMuseExtension(pi: ExtensionAPI, provider = {stream
|
|
|
46
50
|
],
|
|
47
51
|
streamSimple: stream,
|
|
48
52
|
});
|
|
49
|
-
|
|
53
|
+
registerProvider();
|
|
54
|
+
// Lifecycle refresh, not a timer or inference request. Also compare metadata:
|
|
55
|
+
// changed limits/efforts must reach Pi even when the IDs have not changed.
|
|
56
|
+
const modelShape = (models: typeof catalogue.models) =>
|
|
57
|
+
JSON.stringify([...models].sort((a, b) => a.id.localeCompare(b.id)));
|
|
58
|
+
pi.on("agent_end", async () => {
|
|
59
|
+
const next = await discover();
|
|
60
|
+
const changed = modelShape(next.models) !== modelShape(catalogue.models);
|
|
61
|
+
catalogue = next;
|
|
62
|
+
if (changed) registerProvider();
|
|
63
|
+
});
|
|
64
|
+
pi.registerCommand("muse-doctor", {description:"Muse client and qualification diagnostic; qualify [build] [--live]",handler:async(args,ctx)=>{
|
|
65
|
+
if (args.split(/\s+/).includes("--live") && !await ctx.ui.confirm("Live Muse qualification", "Runs model requests (batch, private prompt, MCP, resume, image) in isolated state using your existing login. Proceed?")) return;
|
|
66
|
+
try { ctx.ui.notify(JSON.stringify({...JSON.parse(await museDoctor(ctx.model?.id, args)),catalogue:catalogue.diagnostics},null,2),"info"); }
|
|
67
|
+
catch(error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "error"); }
|
|
68
|
+
}});
|
|
50
69
|
pi.on("session_start", async (_event, ctx) => {
|
|
70
|
+
if (process.env.PI_MUSE_TETHER_LIVE !== "1") ctx.ui.notify(featureNotice(clientBuildLabel(),"catalogue","PI_MUSE_TETHER_LIVE is unset","empty live catalogue; set PI_MUSE_TETHER_LIVE=1 to enable official discovery"),"warning");
|
|
71
|
+
if (process.env.PI_MUSE_TETHER_LIVE === "1") {
|
|
72
|
+
try { const status=clientStatus(false); ctx.ui.notify(`[pi-muse-tether] ${JSON.stringify(status)}; vendor updates are governed by capability/schema checks.`, "info"); }
|
|
73
|
+
catch(error) { ctx.ui.notify(String(error), "error"); }
|
|
74
|
+
}
|
|
51
75
|
setQuotaListener(payload=>ctx.ui.setStatus("muse-rate-limit",quotaStatusLine(payload)));
|
|
52
76
|
setRetryStatusListener(status=>ctx.ui.setStatus("muse-retry",status));
|
|
53
77
|
await retireAll("session_start");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-muse-tether",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Use your Muse Code subscription in Pi through the official client",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"homepage": "https://github.com/kyraneth/pi-muse-tether#readme",
|
|
10
10
|
"bugs": {"url": "https://github.com/kyraneth/pi-muse-tether/issues"},
|
|
11
11
|
"engines": {"node": ">=24"},
|
|
12
|
-
"files": ["index.ts", "src/", "README.md", "CHANGELOG.md", "LICENSE", "assets/", "docs/DETAILS.md"],
|
|
12
|
+
"files": ["index.ts", "src/", "README.md", "CHANGELOG.md", "LICENSE", "assets/", "docs/DETAILS.md", "docs/CLIENT-LIFECYCLE.md", "docs/CLIENT-QUALIFICATION.md"],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@muse-code/sdk": "1.4.14",
|
|
15
15
|
"pi-tether-core": "0.1.1"
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"typescript": "^5"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"test": "
|
|
36
|
+
"test": "node scripts/test-guard.mjs",
|
|
37
|
+
"typecheck": "tsc --noEmit --target ES2023 --module NodeNext --moduleResolution NodeNext --allowImportingTsExtensions --skipLibCheck index.ts src/*.ts",
|
|
38
|
+
"test:proof": "node scripts/test-guard.mjs --proof -- node --import tsx",
|
|
37
39
|
"dev:install-core": "node scripts/install-core-main.mjs",
|
|
38
40
|
"scan:public": "node scripts/check-public-tree.mjs",
|
|
39
41
|
"export:manifest": "node scripts/export-manifest"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/** Retained structural schema definitions (documentation descriptions stripped
|
|
3
|
+
* from this distributable projection), not a version-string allowlist. Meta's
|
|
4
|
+
* envelope explicitly declares payload unstable/free-form: the consumed event
|
|
5
|
+
* shape below is additionally checked from the two observed batch fixtures. */
|
|
6
|
+
const recorded = JSON.parse(readFileSync(new URL("../assets/batch-boundary-schemas.json", import.meta.url), "utf8"));
|
|
7
|
+
export const BATCH_SCHEMA_SOURCES: Array<{build:string;sha256:string}> = recorded.sources;
|
|
8
|
+
function matches(value: any, schema: any, defs: any): boolean {
|
|
9
|
+
if (schema.$ref) return matches(value, defs[schema.$ref.split("/").at(-1)], defs);
|
|
10
|
+
if (Array.isArray(schema.type)) return schema.type.some((type: string) => matches(value, {...schema,type}, defs));
|
|
11
|
+
if (schema.type === "null") return value === null;
|
|
12
|
+
if (schema.type === "integer") return Number.isSafeInteger(value);
|
|
13
|
+
if (schema.type === "string") return typeof value === "string";
|
|
14
|
+
if (schema.type === "object") {
|
|
15
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
16
|
+
if (schema.required?.some((key: string) => !(key in value))) return false;
|
|
17
|
+
return Object.entries(schema.properties ?? {}).every(([key, child]) => !(key in value) || matches(value[key], child, defs));
|
|
18
|
+
}
|
|
19
|
+
return false; // Fail closed on schema constructs this owning subset does not use.
|
|
20
|
+
}
|
|
21
|
+
export function batchBoundarySchemaMatches(params: unknown): boolean {
|
|
22
|
+
return recorded.schemas.some(({ $defs }: any) => matches(params, $defs.LogRecordParams, $defs) && matches((params as any).record, $defs.RawLogRecordEnvelope, $defs));
|
|
23
|
+
}
|
|
24
|
+
export function committedCalls(params: any): Array<{callId:string;name:string;args:Record<string,unknown>}> {
|
|
25
|
+
if (!batchBoundarySchemaMatches(params)) throw new Error("Batch envelope schema mismatch");
|
|
26
|
+
const payload=params.record.payload, event=payload?.event;
|
|
27
|
+
if (payload?.kind !== "run" || typeof payload.run_id !== "string" || event?.kind !== "assistant_tool_calls_committed" || !Array.isArray(event.tool_calls) || !event.tool_calls.length) throw new Error("Batch payload schema mismatch");
|
|
28
|
+
return event.tool_calls.map((call: any) => {
|
|
29
|
+
const args=typeof call.args === "string" ? JSON.parse(call.args) : call.args;
|
|
30
|
+
if (typeof call.call_id !== "string" || !call.call_id || typeof call.name !== "string" || !call.name || !args || typeof args !== "object" || Array.isArray(args)) throw new Error("Batch tool-call schema mismatch");
|
|
31
|
+
return {callId:call.call_id,name:call.name,args};
|
|
32
|
+
});
|
|
33
|
+
}
|
package/src/catalog.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import { museThinkingLevelMap } from "./thinking-config.js";
|
|
2
2
|
import { museModelCost } from "./usage.js";
|
|
3
|
+
import { isMuseModelId, museModelRoute } from "./model-route.js";
|
|
3
4
|
export { isQualifiedMuseModel, museResponseIdentity } from "./model-route.js";
|
|
4
5
|
|
|
5
|
-
/** Supported official logical IDs, never invented contributor aliases. Limits
|
|
6
|
-
* and efforts come exclusively from the receiving official model/list. */
|
|
7
|
-
export const MUSE_MODEL_GROUPS = [
|
|
8
|
-
["muse-spark-1.3", "muse-spark-1.3-contributor"],
|
|
9
|
-
["muse-wonder-1.0"],
|
|
10
|
-
["muse-wonder-full-1.0"],
|
|
11
|
-
] as const;
|
|
12
|
-
const isCatalogueModel = (id: string) =>
|
|
13
|
-
MUSE_MODEL_GROUPS.some(group => (group as readonly string[]).includes(id));
|
|
14
|
-
|
|
15
6
|
/** Diagnosis only, no workaround: an official client may receive no models
|
|
16
7
|
* on one network path while the same account works on another. */
|
|
17
8
|
export const EMPTY_CATALOGUE_HINT = ". The official Muse client received an empty model catalogue. "
|
|
@@ -19,33 +10,45 @@ export const EMPTY_CATALOGUE_HINT = ". The official Muse client received an empt
|
|
|
19
10
|
+ "account works elsewhere, Meta may be refusing this network path (seen on datacenter IPv6); "
|
|
20
11
|
+ "see the pi-muse-tether README section \"Empty catalogue on some cloud networks\"";
|
|
21
12
|
|
|
13
|
+
/** Contributor suffixes belong to the picker, never the native namespace. */
|
|
14
|
+
function catalogueIdProblem(id: unknown): string | undefined {
|
|
15
|
+
if (!isMuseModelId(id)) return "invalid Muse model ID shape";
|
|
16
|
+
if (id.endsWith("-contributor")) return "reserved local -contributor suffix";
|
|
17
|
+
}
|
|
18
|
+
|
|
22
19
|
export function museCatalogAssessment(catalog: any) {
|
|
23
20
|
const rows: any[] = Array.isArray(catalog?.models) ? catalog.models : [];
|
|
24
|
-
const valid = (catalog?.source === "providerCatalog" ? rows : []).filter(m => m && typeof m === "object" &&
|
|
21
|
+
const valid = (catalog?.source === "providerCatalog" ? rows : []).filter(m => m && typeof m === "object" && !catalogueIdProblem(m.modelId) &&
|
|
25
22
|
m.providerId === "meta" && typeof m.displayLabel === "string" && m.displayLabel.length &&
|
|
26
23
|
Number.isSafeInteger(m.contextLimit) && m.contextLimit > 0 &&
|
|
27
24
|
Number.isSafeInteger(m.outputLimit) && m.outputLimit > 0 &&
|
|
28
25
|
Array.isArray(m.variants) && m.variants.length &&
|
|
29
26
|
m.variants.every((tier: unknown) => typeof tier === "string" &&
|
|
30
|
-
Object.values(museThinkingLevelMap([tier])).
|
|
27
|
+
Object.values(museThinkingLevelMap([tier])).some(value => value === tier)) &&
|
|
31
28
|
m.variants.includes(m.defaultReasoningEffort));
|
|
32
|
-
const missing = MUSE_MODEL_GROUPS.filter(group => !valid.some(m => (group as readonly string[]).includes(m.modelId)));
|
|
33
29
|
return { valid, diagnostics: { source: catalog?.source ?? null, providerId: catalog?.providerId ?? null,
|
|
34
|
-
profileId: catalog?.profileId ?? null,
|
|
30
|
+
profileId: catalog?.profileId ?? null,
|
|
31
|
+
rejectedRoutes: rows.flatMap(m => {
|
|
32
|
+
const reason = catalogueIdProblem(m?.modelId);
|
|
33
|
+
return reason ? [`${String(m?.modelId)}: ${reason}`] : [];
|
|
34
|
+
}), models: rows.map(m => ({modelId:m?.modelId,contextLimit:m?.contextLimit,outputLimit:m?.outputLimit,variants:m?.variants})),
|
|
35
35
|
...(!rows.length ? {hint:EMPTY_CATALOGUE_HINT} : {}) } };
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function museCatalogModels(catalog: any) {
|
|
39
39
|
const {valid} = museCatalogAssessment(catalog);
|
|
40
|
-
return valid.flatMap(m =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
return valid.flatMap(m => [m.modelId, `${m.modelId}-contributor`].filter(id => museModelRoute(id)).map(id => {
|
|
41
|
+
const {contributorMode} = museModelRoute(id)!;
|
|
42
|
+
return {
|
|
43
|
+
id,
|
|
44
|
+
name: `${m.displayLabel} · ${contributorMode === "on" ? "Contributor" : "Normal"}${museModelCost(m.modelId).input === null ? " · pricing unknown" : ""}`,
|
|
45
|
+
reasoning: m.variants.some((tier: string) => tier !== "none"),
|
|
46
|
+
input: ["text", "image"] as ("text" | "image")[],
|
|
47
|
+
thinkingLevelMap: museThinkingLevelMap(m.variants),
|
|
48
|
+
contextWindow: m.contextLimit, maxTokens: m.outputLimit,
|
|
49
|
+
// Pi's numeric-only cost interface has no unknown variant. Nulls are
|
|
50
|
+
// intentional runtime metadata, not zero prices; never borrow Spark rates.
|
|
51
|
+
cost: museModelCost(m.modelId) as any,
|
|
52
|
+
};
|
|
53
|
+
}));
|
|
51
54
|
}
|
package/src/cli-version.ts
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
+
import { qualifiedBatchBuilds } from "./qualification-records.js";
|
|
1
2
|
import { execFile } from "node:child_process";
|
|
2
3
|
import { promisify } from "node:util";
|
|
3
4
|
import { readFile, realpath, stat } from "node:fs/promises";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { dirname, resolve } from "node:path";
|
|
6
|
-
|
|
7
|
+
/** Oldest client with the tested private-XDG prompt/isolation controls. */
|
|
8
|
+
export const MIN_CLI_VERSION = "1.4.14";
|
|
9
|
+
/** Raise only after qualification; newer clients are not thereby qualified. */
|
|
10
|
+
export const TESTED_CLI_MAX = "1.4.15";
|
|
11
|
+
/** Exact builds whose experimental rawLog committed-batch boundary was live
|
|
12
|
+
* qualified: 1.4.14-R7309.1 (original), 1.4.15-R8339.1 (2026-11-10: parallel
|
|
13
|
+
* two-call batch, private prompt, session MCP readiness, Ember). */
|
|
14
|
+
export const QUALIFIED_BATCH_BUILDS = () => qualifiedBatchBuilds();
|
|
15
|
+
/** The tether's SDK is pinned independently, not required to equal the CLI. */
|
|
7
16
|
export const QUALIFIED_SDK = "1.4.14";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const warnedNewerCliVersions = new Set<string>();
|
|
18
|
+
const compareVersions = (a: string, b: string) => {
|
|
19
|
+
const right = b.split(".").map(Number);
|
|
20
|
+
for (const [i, value] of a.split(".").map(Number).entries()) {
|
|
21
|
+
if (value !== right[i]) return value > right[i] ? 1 : -1;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
};
|
|
25
|
+
export const isNewerThanTestedCli = (version: string) => compareVersions(version, TESTED_CLI_MAX) > 0;
|
|
26
|
+
export const strictCliVersion = (env: NodeJS.ProcessEnv = process.env) => env.PI_MUSE_TETHER_STRICT_VERSION === "1";
|
|
27
|
+
|
|
28
|
+
export function assertQualifiedVersions(clientOutput: string, sdk: string, env: NodeJS.ProcessEnv = process.env) {
|
|
29
|
+
const match = /^Muse Code (\d+\.\d+\.\d+)(?: \(\1-R[\d.]+\))?$/.exec(clientOutput.trim());
|
|
30
|
+
if (!match || compareVersions(match[1], MIN_CLI_VERSION) < 0 || sdk !== QUALIFIED_SDK)
|
|
31
|
+
throw new Error(`Unqualified Muse client/SDK: client=${clientOutput.trim()}, SDK=${sdk}; requires Muse Code >=${MIN_CLI_VERSION}, SDK ${QUALIFIED_SDK}; no model request submitted.`);
|
|
32
|
+
// Experimental capability is negotiated and its frames checked at runtime.
|
|
33
|
+
// Qualification records report evidence; they do not deny unknown builds.
|
|
34
|
+
if (isNewerThanTestedCli(match[1])) {
|
|
35
|
+
if (strictCliVersion(env)) throw new Error(`Unqualified Muse Code ${match[1]}: PI_MUSE_TETHER_STRICT_VERSION=1 refuses newer than tested ${TESTED_CLI_MAX}; no model request submitted.`);
|
|
36
|
+
if (!warnedNewerCliVersions.has(match[1])) {
|
|
37
|
+
warnedNewerCliVersions.add(match[1]);
|
|
38
|
+
console.warn(`[pi-muse-tether] Muse Code ${match[1]}: continuing, not yet qualified; capability/schema checks govern batching. PI_MUSE_TETHER_STRICT_VERSION=1 opts into refusing newer builds.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {client: match[1], sdk};
|
|
19
42
|
}
|
|
20
43
|
// Cache only the known official selector layout. Unknown launchers may delegate
|
|
21
44
|
// according to arbitrary state, so their version is probed for every host.
|
|
@@ -35,7 +58,6 @@ export async function qualifyMuseVersion(
|
|
|
35
58
|
binary: string,
|
|
36
59
|
env: NodeJS.ProcessEnv,
|
|
37
60
|
signal?: AbortSignal,
|
|
38
|
-
rawLog = false,
|
|
39
61
|
) {
|
|
40
62
|
const entry = createRequire(import.meta.url).resolve("@muse-code/sdk");
|
|
41
63
|
const sdk = JSON.parse(
|
|
@@ -44,15 +66,16 @@ export async function qualifyMuseVersion(
|
|
|
44
66
|
signal?.throwIfAborted();
|
|
45
67
|
const identity = await binaryIdentity(binary);
|
|
46
68
|
signal?.throwIfAborted();
|
|
47
|
-
const key = identity && JSON.stringify([identity, sdk
|
|
69
|
+
const key = identity && JSON.stringify([identity, sdk]);
|
|
48
70
|
const cached = key && versionCache.get(key);
|
|
49
|
-
if (cached) return assertQualifiedVersions(cached, sdk,
|
|
71
|
+
if (cached) return assertQualifiedVersions(cached, sdk, env);
|
|
50
72
|
const { stdout } = await promisify(execFile)(binary, ["--version"], {
|
|
51
|
-
env
|
|
73
|
+
env,
|
|
52
74
|
signal,
|
|
53
75
|
});
|
|
54
|
-
const result = assertQualifiedVersions(stdout, sdk,
|
|
76
|
+
const result = assertQualifiedVersions(stdout, sdk, env);
|
|
55
77
|
signal?.throwIfAborted();
|
|
56
78
|
if (key && identity === await binaryIdentity(binary)) versionCache.set(key, stdout);
|
|
57
79
|
return result;
|
|
58
80
|
}
|
|
81
|
+
|
package/src/doctor.ts
CHANGED
|
@@ -1,26 +1,38 @@
|
|
|
1
1
|
import { museModelRoute } from "./model-route.js";
|
|
2
2
|
import { assertLoginSafe } from "./settings.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { clientStatus, resolveMuseBinary } from "./qualification-records.js";
|
|
4
|
+
import { museFeatureStatus } from "./features.js";
|
|
5
|
+
import { qualifyClient } from "./qualification.js";
|
|
6
|
+
import { qualifyMuseVersion, MIN_CLI_VERSION, TESTED_CLI_MAX, isNewerThanTestedCli, strictCliVersion } from "./cli-version.js";
|
|
6
7
|
import { museLedgerPath } from "./request-ledger.js";
|
|
7
8
|
import { MUSE_CACHE_POLICY } from "./cache-policy.js";
|
|
8
9
|
/** Local diagnostic only: --version, no account/auth contents, quota or inference. */
|
|
9
|
-
export async function museDoctor(modelId?: string) {
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
export async function museDoctor(modelId?: string, args = "") {
|
|
11
|
+
const [command, ...arguments_] = args.trim().split(/\s+/);
|
|
12
|
+
if (command === "qualify") {
|
|
13
|
+
const builds=arguments_.filter(value=>!value.startsWith("--"));
|
|
14
|
+
if (builds.length > 1 || arguments_.some(value=>value.startsWith("--") && value !== "--live")) throw new Error("Usage: /muse-doctor qualify [build] [--live]");
|
|
15
|
+
return JSON.stringify(await qualifyClient(builds[0],arguments_.includes("--live"),modelId ? museModelRoute(modelId)?.modelId : undefined),null,2);
|
|
16
|
+
}
|
|
17
|
+
if (command && command !== "qualify") throw new Error("Unknown /muse-doctor command; use /muse-doctor or /muse-doctor qualify [build] [--live]");
|
|
18
|
+
const binary = resolveMuseBinary();
|
|
12
19
|
const { META_API_KEY: _, ...env } = process.env;
|
|
13
20
|
try {
|
|
14
21
|
assertLoginSafe();
|
|
15
|
-
const versions = await qualifyMuseVersion(binary, env);
|
|
22
|
+
const versions = await qualifyMuseVersion(binary, {...env, MUSE_NO_AUTO_UPDATE:"1"});
|
|
23
|
+
let status:unknown;
|
|
24
|
+
try { status=clientStatus(); } catch (error) { status={unavailable:String(error)}; }
|
|
16
25
|
return JSON.stringify(
|
|
17
26
|
{
|
|
18
27
|
ok: true,
|
|
19
28
|
binary,
|
|
29
|
+
clientStatus:status,
|
|
30
|
+
features:museFeatureStatus(),
|
|
20
31
|
...versions,
|
|
32
|
+
versionPolicy: {minimum:MIN_CLI_VERSION, testedMaximum:TESTED_CLI_MAX, newerThanTested:isNewerThanTestedCli(versions.client), strict:strictCliVersion()},
|
|
21
33
|
contributorMode: modelId ? museModelRoute(modelId)?.contributorMode ?? null : null,
|
|
22
34
|
apiKeyForwarded: false,
|
|
23
|
-
promptRecipe: "private-xdg-settings;
|
|
35
|
+
promptRecipe: "private-xdg-settings;private-trusted-workspaceRoot",
|
|
24
36
|
ledger: museLedgerPath(),
|
|
25
37
|
cache: MUSE_CACHE_POLICY,
|
|
26
38
|
quota:
|
package/src/features.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MuseFeature = "rawLog" | "privatePrompt" | "sessionMcp" | "catalogue";
|
|
2
|
+
const observed = new Map<MuseFeature,{build:string;status:string;reason?:string}>();
|
|
3
|
+
export function featureNotice(build:string,feature:MuseFeature,reason:string,fallback:string) {
|
|
4
|
+
observed.set(feature,{build,status:fallback,reason});
|
|
5
|
+
return `[pi-muse-tether] ${JSON.stringify({code:"MUSE_FEATURE_DEGRADED",build,feature,reason,fallback,remedy:"/muse-doctor qualify [build]"})}`;
|
|
6
|
+
}
|
|
7
|
+
export function featureActive(build:string,feature:MuseFeature) { observed.set(feature,{build,status:"active"}); }
|
|
8
|
+
export const MUSE_FEATURE_CONTRACT = {
|
|
9
|
+
rawLog:{stability:"experimental",check:"qualification evidence + initialize grant + recorded envelope and consumed payload schema",fallback:"sequential Pi tools; no replay"},
|
|
10
|
+
privatePrompt:{stability:"experimental",check:"experimentalApi negotiation + session reviewer shape; exact instruction delivery attested by live qualification",fallback:"supported run.developer_prompt; appended, not replacement"},
|
|
11
|
+
sessionMcp:{stability:"stable capability with experimental configuration",check:"initialize sessionMcp grant + session/start identity + inventory readiness/tool names",fallback:"typed refusal; Pi must own tools"},
|
|
12
|
+
versionPolicy:{minimum:"protocol-compatible floor",testedRange:"declared evidence, warning above maximum",strict:"explicit opt-in refuses above maximum",updates:"vendor-owned; no production suppression"},
|
|
13
|
+
} as const;
|
|
14
|
+
export const museFeatureStatus = () => ({
|
|
15
|
+
rawLog:{status:"not negotiated",fallback:"sequential unless qualified and granted"},
|
|
16
|
+
privatePrompt:{status:"not negotiated",fallback:"append supported developer instructions"},
|
|
17
|
+
sessionMcp:{status:"not negotiated",fallback:"refuse if unavailable"},
|
|
18
|
+
...Object.fromEntries(observed),
|
|
19
|
+
});
|
|
20
|
+
export class MuseFeatureUnavailable extends Error {
|
|
21
|
+
readonly code="MUSE_FEATURE_UNAVAILABLE";
|
|
22
|
+
constructor(readonly build:string,readonly feature:MuseFeature,readonly causeDescription:string) {
|
|
23
|
+
super(`${featureNotice(build,feature,causeDescription,"refused: Pi must own tools")}; MUSE_FEATURE_UNAVAILABLE: run /muse-doctor qualify ${build}`);
|
|
24
|
+
}
|
|
25
|
+
}
|