Keep seal-use probe's stdout to a single JSON document
`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.
This commit is contained in:
1 parent
289ef664da
commit
97bf3301a3
5 files changed
+190
-19
No files matched your search
+42
-18
@@ -1,10 +1,25 @@
|
||||
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";
|
||||
|
||||
export async function runProbe(options: { corpId?: string } = {}) {
|
||||
/** 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(
|
||||
@@ -17,11 +32,13 @@ export async function runProbe(options: { corpId?: string } = {}) {
|
||||
getEnterprisesDirCandidates()
|
||||
);
|
||||
|
||||
console.log(`[probe] corp=${corp.id} source=${corp.source.type}`);
|
||||
// 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.log("[probe] seal enterprise");
|
||||
console.log(JSON.stringify(enterprise, null, 2));
|
||||
console.error("[probe] seal enterprise");
|
||||
|
||||
const client = await createSealClient(corp);
|
||||
const context = await getApprovalContext(client, {
|
||||
@@ -29,23 +46,30 @@ export async function runProbe(options: { corpId?: string } = {}) {
|
||||
stylePreferencesEndpoint: corp.seal.endpoints.approvalStylePreferences
|
||||
});
|
||||
|
||||
console.log("[probe] approval context summary");
|
||||
console.log(JSON.stringify({
|
||||
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}`
|
||||
}, null, 2));
|
||||
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 }).catch((error) => {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exit(1);
|
||||
});
|
||||
runProbe({ corpId })
|
||||
.then((result) => printJson(result))
|
||||
.catch((error) => {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user