`runProbe` wrote its progress notes and three separate JSON blobs to stdout, so every consumer parsing the output — `seal-use probe | jq`, the Agent Harness — got prose interleaved with data. The command is also in the help registry, so this was a documented command breaking its own contract. The probe now returns one `ProbeResult` and the command prints it through `printJson`; the `[probe] …` narration moves to stderr, which is the diagnostics channel. The dev-script entry point keeps the same payload and its exit code. Classified read-only too: `probe` reads tenant state and writes nothing, but the allow-list had no entry, so the MCP read-only tool refused it. Its trailing token is an enterprise selector rather than a verb, so the matcher accepts the bare form and bare-plus-selector while still refusing a third token.
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { getEnterprisesDirCandidates, loadCorpConfigs, loadGlobalConfig } from "./core/config/loader.js";
|
|
import { resolveCorpConfig } from "./core/config/manager.js";
|
|
import { createSealClient } from "./core/http/factory.js";
|
|
import type { SealEnterpriseConfig } from "./core/auth/types.js";
|
|
import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js";
|
|
import { getApprovalContext } from "./domains/seal/api.js";
|
|
import { printJson } from "./cli/printer.js";
|
|
|
|
/** One probe run's payload — the entire stdout of `seal-use probe`. */
|
|
export type ProbeResult = {
|
|
corp: { id: string; name: string; sourceType: string };
|
|
enterprise: SealEnterpriseConfig;
|
|
summary: {
|
|
rules: number;
|
|
hasPendingRuleDeletes: boolean;
|
|
documents: number;
|
|
documentsTotal?: number;
|
|
stylePreferences: string;
|
|
};
|
|
};
|
|
|
|
export async function runProbe(options: { corpId?: string } = {}): Promise<ProbeResult> {
|
|
const corps = loadCorpConfigs();
|
|
const globalConfig = loadGlobalConfig();
|
|
const corp = resolveCorpConfig(
|
|
corps,
|
|
{
|
|
stateful: globalConfig.stateful,
|
|
defaultCorpId: globalConfig.defaultCorpId,
|
|
corpId: options.corpId
|
|
},
|
|
getEnterprisesDirCandidates()
|
|
);
|
|
|
|
// Progress notes go to stderr: stdout carries the JSON payload alone, so
|
|
// `seal-use probe | jq` keeps working (it previously held three prose lines
|
|
// interleaved with three JSON blobs).
|
|
console.error(`[probe] corp=${corp.id} source=${corp.source.type}`);
|
|
|
|
const enterprise = await resolveLiveSealEnterpriseConfig(corp);
|
|
console.error("[probe] seal enterprise");
|
|
|
|
const client = await createSealClient(corp);
|
|
const context = await getApprovalContext(client, {
|
|
documentLimit: 20,
|
|
stylePreferencesEndpoint: corp.seal.endpoints.approvalStylePreferences
|
|
});
|
|
|
|
console.error("[probe] approval context summary");
|
|
|
|
return {
|
|
corp: { id: corp.id, name: corp.name, sourceType: corp.source.type },
|
|
enterprise,
|
|
summary: {
|
|
rules: context.rules.rules.length,
|
|
hasPendingRuleDeletes: context.rules.hasPendingDeletes,
|
|
documents: context.documents.articles.length,
|
|
documentsTotal: context.documents.total,
|
|
stylePreferences: context.stylePreferences.ok
|
|
? "ok"
|
|
: `error: ${context.stylePreferences.error}`
|
|
}
|
|
};
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
const args = process.argv.slice(2);
|
|
const corpId = args[0] === "--corp" ? args[1] : args[0];
|
|
runProbe({ corpId })
|
|
.then((result) => printJson(result))
|
|
.catch((error) => {
|
|
console.error(error instanceof Error ? error.message : error);
|
|
process.exit(1);
|
|
});
|
|
}
|