fullstackgtm 0.48.0 → 0.50.0
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 +91 -0
- package/CONTRIBUTING.md +23 -4
- package/DATA-FLOWS.md +8 -2
- package/INSTALL_FOR_AGENTS.md +13 -4
- package/README.md +53 -1
- package/SECURITY.md +27 -3
- package/dist/acquireCheckpoint.d.ts +33 -0
- package/dist/acquireCheckpoint.js +149 -0
- package/dist/acquireLinkedIn.d.ts +2 -0
- package/dist/acquireLinkedIn.js +1 -1
- package/dist/cli/audit.js +10 -7
- package/dist/cli/auth.js +8 -4
- package/dist/cli/enrich.js +283 -79
- package/dist/cli/fix.js +20 -7
- package/dist/cli/help.js +23 -15
- package/dist/cli/market.js +180 -2
- package/dist/cli/plans.js +154 -9
- package/dist/cli/shared.d.ts +3 -1
- package/dist/cli/shared.js +2 -2
- package/dist/cli/ui.d.ts +10 -5
- package/dist/cli/ui.js +18 -5
- package/dist/cli.js +1 -1
- package/dist/config.d.ts +13 -1
- package/dist/config.js +23 -2
- package/dist/connectors/linkedin.d.ts +2 -0
- package/dist/connectors/linkedin.js +5 -0
- package/dist/connectors/prospectSources.d.ts +23 -0
- package/dist/connectors/prospectSources.js +25 -14
- package/dist/connectors/salesforce.js +12 -5
- package/dist/connectors/salesforceAuth.d.ts +9 -0
- package/dist/connectors/salesforceAuth.js +47 -5
- package/dist/connectors/theirstack.d.ts +0 -19
- package/dist/connectors/theirstack.js +3 -10
- package/dist/credentials.js +36 -26
- package/dist/enrich.d.ts +44 -1
- package/dist/hostedAcquireCheckpoint.d.ts +43 -0
- package/dist/hostedAcquireCheckpoint.js +129 -0
- package/dist/hostedPatchPlan.d.ts +87 -0
- package/dist/hostedPatchPlan.js +270 -0
- package/dist/icp.js +13 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +6 -2
- package/dist/market.d.ts +1 -1
- package/dist/market.js +7 -127
- package/dist/marketClassify.d.ts +10 -0
- package/dist/marketClassify.js +52 -1
- package/dist/marketSourcing.js +7 -45
- package/dist/mcp.js +67 -115
- package/dist/planStore.d.ts +42 -1
- package/dist/planStore.js +268 -49
- package/dist/progress.d.ts +2 -2
- package/dist/progress.js +2 -2
- package/dist/providerError.d.ts +21 -0
- package/dist/providerError.js +30 -0
- package/dist/publicHttp.d.ts +28 -0
- package/dist/publicHttp.js +143 -0
- package/dist/secureFile.d.ts +15 -0
- package/dist/secureFile.js +164 -0
- package/dist/types.d.ts +1 -1
- package/docs/api.md +53 -2
- package/docs/architecture.md +22 -2
- package/llms.txt +7 -0
- package/package.json +5 -3
- package/skills/fullstackgtm/SKILL.md +8 -2
- package/src/acquireCheckpoint.ts +186 -0
- package/src/acquireLinkedIn.ts +3 -1
- package/src/cli/audit.ts +10 -7
- package/src/cli/auth.ts +8 -4
- package/src/cli/enrich.ts +322 -78
- package/src/cli/fix.ts +28 -7
- package/src/cli/help.ts +24 -15
- package/src/cli/market.ts +181 -2
- package/src/cli/plans.ts +159 -9
- package/src/cli/shared.ts +2 -1
- package/src/cli/ui.ts +19 -9
- package/src/cli.ts +1 -1
- package/src/config.ts +39 -1
- package/src/connectors/linkedin.ts +6 -0
- package/src/connectors/prospectSources.ts +50 -15
- package/src/connectors/salesforce.ts +12 -5
- package/src/connectors/salesforceAuth.ts +46 -6
- package/src/connectors/theirstack.ts +3 -10
- package/src/credentials.ts +47 -28
- package/src/enrich.ts +47 -1
- package/src/hostedAcquireCheckpoint.ts +156 -0
- package/src/hostedPatchPlan.ts +286 -0
- package/src/icp.ts +14 -2
- package/src/index.ts +24 -0
- package/src/market.ts +7 -111
- package/src/marketClassify.ts +61 -1
- package/src/marketSourcing.ts +7 -43
- package/src/mcp.ts +93 -136
- package/src/planStore.ts +322 -57
- package/src/progress.ts +2 -2
- package/src/providerError.ts +37 -0
- package/src/publicHttp.ts +147 -0
- package/src/secureFile.ts +169 -0
- package/src/types.ts +1 -0
package/dist/marketSourcing.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* Sitemaps / redirects / logo bytes are plain resources — they never need a
|
|
17
17
|
* headless browser, so the default fetch is sufficient even in the hosted layer.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { publicHttpGet } from "./publicHttp.js";
|
|
20
20
|
import { DEFAULT_MODELS, forcedToolCall } from "./llm.js";
|
|
21
21
|
const USER_AGENT = "fullstackgtm-market/0 (+https://github.com/fullstackgtm/core)";
|
|
22
22
|
const FETCH_TIMEOUT_MS = 15_000;
|
|
@@ -156,28 +156,9 @@ export function extractLogoUrl(html, baseUrl) {
|
|
|
156
156
|
// ── Default SSRF-guarded fetchers ────────────────────────────────────────────
|
|
157
157
|
/** Manual-redirect fetch that re-validates every hop against the SSRF guard. */
|
|
158
158
|
async function guardedFetch(url) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const res = await fetch(current, {
|
|
163
|
-
redirect: "manual",
|
|
164
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
165
|
-
headers: { "User-Agent": USER_AGENT },
|
|
166
|
-
});
|
|
167
|
-
const location = res.headers.get("location");
|
|
168
|
-
if (res.status >= 300 && res.status < 400 && location) {
|
|
169
|
-
try {
|
|
170
|
-
await res.body?.cancel();
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
/* ignore */
|
|
174
|
-
}
|
|
175
|
-
current = new URL(location, current).toString();
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
return res;
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
159
|
+
const res = await publicHttpGet(url, { maxRedirects: MAX_REDIRECTS, timeoutMs: FETCH_TIMEOUT_MS,
|
|
160
|
+
headers: { "User-Agent": USER_AGENT } });
|
|
161
|
+
return new Response(res.body.length ? Buffer.from(res.body) : null, { status: res.status, headers: res.headers });
|
|
181
162
|
}
|
|
182
163
|
const defaultFetchText = async (url) => {
|
|
183
164
|
try {
|
|
@@ -206,28 +187,9 @@ const defaultFetchBytes = async (url) => {
|
|
|
206
187
|
* + status WITHOUT downloading the body. Used to detect identity drift.
|
|
207
188
|
*/
|
|
208
189
|
export const resolveFinalUrl = async (rawUrl) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const res = await fetch(current, {
|
|
213
|
-
redirect: "manual",
|
|
214
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
215
|
-
headers: { "User-Agent": USER_AGENT },
|
|
216
|
-
});
|
|
217
|
-
try {
|
|
218
|
-
await res.body?.cancel();
|
|
219
|
-
}
|
|
220
|
-
catch {
|
|
221
|
-
/* ignore */
|
|
222
|
-
}
|
|
223
|
-
const location = res.headers.get("location");
|
|
224
|
-
if (res.status >= 300 && res.status < 400 && location) {
|
|
225
|
-
current = new URL(location, current).toString();
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
return { finalUrl: current, status: res.status };
|
|
229
|
-
}
|
|
230
|
-
return { finalUrl: current, status: 0 };
|
|
190
|
+
const res = await publicHttpGet(rawUrl, { maxRedirects: MAX_REDIRECTS, timeoutMs: FETCH_TIMEOUT_MS,
|
|
191
|
+
maxBytes: 0, headers: { "User-Agent": USER_AGENT } });
|
|
192
|
+
return { finalUrl: res.finalUrl, status: res.status };
|
|
231
193
|
};
|
|
232
194
|
// ── Fetching helpers ─────────────────────────────────────────────────────────
|
|
233
195
|
/**
|
package/dist/mcp.js
CHANGED
|
@@ -158,12 +158,19 @@ const toolDefinitions = [
|
|
|
158
158
|
},
|
|
159
159
|
handler: async ({ provider, inputPath, configPath, rules, output, today, staleDealDays }) => {
|
|
160
160
|
const loaded = configPath ? loadConfig(configPath) : null;
|
|
161
|
+
if (loaded?.config.rulePackages?.length) {
|
|
162
|
+
throw new Error("MCP refuses executable rulePackages from tool-call configPath. " +
|
|
163
|
+
"MCP plugin execution is disabled because mutable tool-call paths are not a durable code-trust boundary. " +
|
|
164
|
+
"Run reviewed plugins through the CLI with --config <path> --allow-plugins instead.");
|
|
165
|
+
}
|
|
161
166
|
const policy = mergePolicy(defaultPolicy(today), loaded?.config);
|
|
162
167
|
if (today)
|
|
163
168
|
policy.today = today;
|
|
164
169
|
if (staleDealDays !== undefined)
|
|
165
170
|
policy.staleDealDays = staleDealDays;
|
|
166
|
-
const ruleSet = await resolveConfiguredRules(loaded
|
|
171
|
+
const ruleSet = await resolveConfiguredRules(loaded, undefined, {
|
|
172
|
+
disableRulePackages: true,
|
|
173
|
+
});
|
|
167
174
|
const selected = rules?.length
|
|
168
175
|
? ruleSet.filter((rule) => rules.includes(rule.id))
|
|
169
176
|
: ruleSet;
|
|
@@ -273,122 +280,79 @@ const toolDefinitions = [
|
|
|
273
280
|
writesCrm: true,
|
|
274
281
|
config: {
|
|
275
282
|
title: "Apply Approved Patch Operations",
|
|
276
|
-
description: "Apply
|
|
277
|
-
"
|
|
278
|
-
"
|
|
279
|
-
"
|
|
280
|
-
"the store's HMAC approval digests — ids not approved with `plans approve` are " +
|
|
281
|
-
"refused — and the run is recorded onto the stored plan so `plans show` and " +
|
|
283
|
+
description: "Apply a stored, human-approved patch plan through a provider connector. The plan, " +
|
|
284
|
+
"approved operation ids, and concrete placeholder values are loaded exclusively from " +
|
|
285
|
+
"the local plan store and verified against its HMAC approval digests. Callers cannot " +
|
|
286
|
+
"supply or widen approvals. Every apply run is recorded so `plans show` and " +
|
|
282
287
|
"`audit-log export` include it.",
|
|
283
288
|
inputSchema: strictSchema({
|
|
284
289
|
provider: z.enum(["hubspot", "salesforce"]),
|
|
285
|
-
|
|
286
|
-
approvedOperationIds: z.array(z.string()).min(1),
|
|
287
|
-
valueOverrides: z.record(z.string(), z.string()).optional(),
|
|
290
|
+
planId: z.string().regex(/^[\w.-]+$/),
|
|
288
291
|
output: z.enum(["json", "markdown"]).optional(),
|
|
289
292
|
}),
|
|
290
293
|
},
|
|
291
|
-
handler: async ({ provider,
|
|
292
|
-
// The
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (!filePlan || !Array.isArray(filePlan.operations)) {
|
|
297
|
-
throw new Error(`${planPath} is not a patch plan (expected { id, operations: [...] }).`);
|
|
298
|
-
}
|
|
299
|
-
// Governance parity with CLI apply: when this plan id exists in the local
|
|
300
|
-
// plan store, the STORE is the source of truth — the approved-id set must
|
|
301
|
-
// come from `plans approve` (which HMAC-signed each approved op), the
|
|
302
|
-
// signatures are re-verified here, and the run is recorded back onto the
|
|
303
|
-
// plan so audit-log export sees MCP applies exactly like CLI applies.
|
|
294
|
+
handler: async ({ provider, planId, output }) => {
|
|
295
|
+
// The store is the only authority accepted over MCP. In particular, do
|
|
296
|
+
// not accept a plan body/path, approval ids, or value overrides from the
|
|
297
|
+
// agent call: combining proposal and approval in one call defeats the
|
|
298
|
+
// human approval boundary the plan lifecycle is meant to enforce.
|
|
304
299
|
const store = createFilePlanStore();
|
|
305
|
-
const stored =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
let plan;
|
|
309
|
-
let effectiveOverrides;
|
|
310
|
-
if (stored) {
|
|
311
|
-
if (stored.status !== "approved") {
|
|
312
|
-
throw new Error(`Plan ${filePlan.id} is ${stored.status}; approve operations first with ` +
|
|
313
|
-
`\`fullstackgtm plans approve ${filePlan.id} --operations <ids|all>\`.`);
|
|
314
|
-
}
|
|
315
|
-
// Downgrade guard (same as CLI apply): an approved plan with no
|
|
316
|
-
// signatures either predates 0.26 or had approvalDigests stripped to
|
|
317
|
-
// skip the integrity check. Refuse rather than trust the file.
|
|
318
|
-
if (stored.approvedOperationIds.length > 0 && !stored.approvalDigests) {
|
|
319
|
-
throw new Error(`Refusing to apply plan ${filePlan.id}: it was approved without integrity signatures ` +
|
|
320
|
-
"(approved before 0.26.0, or its signatures were removed). Re-approve it with " +
|
|
321
|
-
`\`fullstackgtm plans approve ${filePlan.id} --operations <ids|all>\`.`);
|
|
322
|
-
}
|
|
323
|
-
// Never widen: every id the tool wants applied must already be
|
|
324
|
-
// store-approved. (A subset is fine — narrowing never writes more.)
|
|
325
|
-
const storeApproved = new Set(stored.approvedOperationIds);
|
|
326
|
-
const unapproved = approvedOperationIds.filter((id) => !storeApproved.has(id));
|
|
327
|
-
if (unapproved.length > 0) {
|
|
328
|
-
throw new Error(`Refusing to apply plan ${filePlan.id}: operation(s) ${unapproved.join(", ")} were never ` +
|
|
329
|
-
"approved in the plan store. Approve them first with " +
|
|
330
|
-
`\`fullstackgtm plans approve ${filePlan.id} --operations <ids>\`.`);
|
|
331
|
-
}
|
|
332
|
-
// Integrity gate: verify against the EFFECTIVE overrides (stored ∪ tool
|
|
333
|
-
// args), so a tool-supplied value that changes what the human approved
|
|
334
|
-
// is treated as tamper, not a live override — what gets written must
|
|
335
|
-
// equal what was signed.
|
|
336
|
-
effectiveOverrides = { ...stored.valueOverrides, ...(valueOverrides ?? {}) };
|
|
337
|
-
const verification = verifyApprovalDigests(stored.plan.operations, stored.approvedOperationIds, effectiveOverrides, stored.approvalDigests);
|
|
338
|
-
if (!verification.ok) {
|
|
339
|
-
const detail = verification.reason === "no_key"
|
|
340
|
-
? "the plan-signing key is missing (was this plan approved on another machine?). Re-approve it here with `fullstackgtm plans approve`."
|
|
341
|
-
: `these operations differ from what was approved: ${verification.tampered.join(", ")}. ` +
|
|
342
|
-
"If you want a different value, set it at approval (`plans approve --value <op>=<v>`) and re-approve; " +
|
|
343
|
-
"otherwise the plan was edited after approval — review and re-approve.";
|
|
344
|
-
throw new Error(`Refusing to apply plan ${filePlan.id}: ${detail}`);
|
|
345
|
-
}
|
|
346
|
-
plan = stored.plan; // apply what was signed, not what the file says now
|
|
300
|
+
const stored = await store.get(planId);
|
|
301
|
+
if (!stored) {
|
|
302
|
+
throw new Error(`No stored plan with id ${planId}. Save it with \`fullstackgtm audit --save\`, then approve it with \`fullstackgtm plans approve\`.`);
|
|
347
303
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
plan = filePlan;
|
|
352
|
-
const known = new Set(plan.operations.map((operation) => operation.id));
|
|
353
|
-
const unknown = approvedOperationIds.filter((id) => !known.has(id));
|
|
354
|
-
if (unknown.length > 0) {
|
|
355
|
-
throw new Error(`Plan ${planPath} has no operation(s) ${unknown.join(", ")} — approvedOperationIds ` +
|
|
356
|
-
"must reference operations in the plan.");
|
|
357
|
-
}
|
|
358
|
-
effectiveOverrides = valueOverrides ?? {};
|
|
304
|
+
if (stored.status !== "approved") {
|
|
305
|
+
throw new Error(`Plan ${planId} is ${stored.status}; approve operations first with ` +
|
|
306
|
+
`\`fullstackgtm plans approve ${planId} --operations <ids|all>\`.`);
|
|
359
307
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
308
|
+
if (stored.approvedOperationIds.length === 0) {
|
|
309
|
+
throw new Error(`Plan ${planId} has no approved operations.`);
|
|
310
|
+
}
|
|
311
|
+
if (!stored.approvalDigests) {
|
|
312
|
+
throw new Error(`Refusing to apply plan ${planId}: it was approved without integrity signatures ` +
|
|
313
|
+
"(approved before 0.26.0, or its signatures were removed). Re-approve it with " +
|
|
314
|
+
`\`fullstackgtm plans approve ${planId} --operations <ids|all>\`.`);
|
|
315
|
+
}
|
|
316
|
+
const verification = verifyApprovalDigests(stored.plan.operations, stored.approvedOperationIds, stored.valueOverrides, stored.approvalDigests);
|
|
317
|
+
if (!verification.ok) {
|
|
318
|
+
const detail = verification.reason === "no_key"
|
|
319
|
+
? "the plan-signing key is missing (was this plan approved on another machine?). Re-approve it here with `fullstackgtm plans approve`."
|
|
320
|
+
: `these operations differ from what was approved: ${verification.tampered.join(", ")}. ` +
|
|
321
|
+
"The stored plan or approved values changed after approval — review and re-approve.";
|
|
322
|
+
throw new Error(`Refusing to apply plan ${planId}: ${detail}`);
|
|
371
323
|
}
|
|
324
|
+
const connector = await connectorFor(provider);
|
|
325
|
+
// Claim only after all preflight checks and credential resolution. The
|
|
326
|
+
// atomic store transition prevents a second CLI/MCP process from
|
|
327
|
+
// applying the same approval concurrently.
|
|
328
|
+
const claimed = await store.claimApply(planId, { provider, source: "mcp" });
|
|
329
|
+
const claimedVerification = verifyApprovalDigests(claimed.stored.plan.operations, claimed.stored.approvedOperationIds, claimed.stored.valueOverrides, claimed.stored.approvalDigests);
|
|
330
|
+
if (!claimedVerification.ok) {
|
|
331
|
+
await store.abortApplyPreflight(planId, claimed.claimId, "Approval integrity verification failed after the claim and before provider I/O.");
|
|
332
|
+
throw new Error(`Refusing to apply plan ${planId}: the claimed plan differs from what was approved: ` +
|
|
333
|
+
`${claimedVerification.tampered.join(", ") || "signing key unavailable"}.`);
|
|
334
|
+
}
|
|
335
|
+
let run;
|
|
336
|
+
try {
|
|
337
|
+
run = await applyPatchPlan(connector, claimed.stored.plan, {
|
|
338
|
+
approvedOperationIds: claimed.stored.approvedOperationIds,
|
|
339
|
+
valueOverrides: claimed.stored.valueOverrides,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
catch (error) {
|
|
343
|
+
await store.markApplyUncertain(planId, claimed.claimId);
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
await store.recordRun(claimed.stored.plan.id, run, claimed.claimId);
|
|
372
347
|
const governance = {
|
|
373
|
-
planSource:
|
|
374
|
-
approvalDigestsVerified:
|
|
375
|
-
runRecorded,
|
|
376
|
-
...(stored
|
|
377
|
-
? {}
|
|
378
|
-
: {
|
|
379
|
-
note: "Plan file is not in the local plan store: approvals came from tool arguments " +
|
|
380
|
-
"(verified against the plan content only — no approval-digest check) and the run " +
|
|
381
|
-
"was not recorded. Use `fullstackgtm audit --save` + `plans approve` for " +
|
|
382
|
-
"store-backed governance.",
|
|
383
|
-
}),
|
|
348
|
+
planSource: "store",
|
|
349
|
+
approvalDigestsVerified: true,
|
|
350
|
+
runRecorded: true,
|
|
384
351
|
};
|
|
385
352
|
if (output === "markdown") {
|
|
386
353
|
return content(`${formatPatchPlanRun(run)}\n\nGovernance: plan source ${governance.planSource}; ` +
|
|
387
|
-
(
|
|
388
|
-
? "approval digests verified; run recorded on the stored plan (audit-log export includes it)."
|
|
389
|
-
: governance.note));
|
|
354
|
+
"approval digests verified; run recorded on the stored plan (audit-log export includes it).");
|
|
390
355
|
}
|
|
391
|
-
// Backward compatible: the run's own fields stay top-level; governance is additive.
|
|
392
356
|
return content({ ...run, governance });
|
|
393
357
|
},
|
|
394
358
|
},
|
|
@@ -470,7 +434,7 @@ toolDefinitions.unshift({
|
|
|
470
434
|
writesCrm,
|
|
471
435
|
})),
|
|
472
436
|
safety: "Only tools flagged writesCrm can reach a CRM; fullstackgtm_apply writes only operations " +
|
|
473
|
-
"
|
|
437
|
+
"from a stored plan whose ids and values were human-approved and HMAC-verified.",
|
|
474
438
|
server: { command: "npx -y fullstackgtm-mcp" },
|
|
475
439
|
cli: {
|
|
476
440
|
command: "npx fullstackgtm <command> [--json]",
|
|
@@ -497,18 +461,6 @@ export async function startMcpServer() {
|
|
|
497
461
|
const transport = new StdioServerTransport();
|
|
498
462
|
await server.connect(transport);
|
|
499
463
|
}
|
|
500
|
-
/**
|
|
501
|
-
* A plan-store file is a StoredPlan envelope ({ plan, status, runs, ... });
|
|
502
|
-
* `audit --out` writes a bare PatchPlan. fullstackgtm_apply accepts either.
|
|
503
|
-
*/
|
|
504
|
-
function isStoredPlanFile(value) {
|
|
505
|
-
if (typeof value !== "object" || value === null || !("plan" in value))
|
|
506
|
-
return false;
|
|
507
|
-
const plan = value.plan;
|
|
508
|
-
return (typeof plan === "object" &&
|
|
509
|
-
plan !== null &&
|
|
510
|
-
Array.isArray(plan.operations));
|
|
511
|
-
}
|
|
512
464
|
function loadMarketConfigOrHint(path) {
|
|
513
465
|
try {
|
|
514
466
|
return loadMarketConfig(path);
|
package/dist/planStore.d.ts
CHANGED
|
@@ -17,18 +17,59 @@ export type StoredPlan = {
|
|
|
17
17
|
* file is caught instead of written. Absent on plans approved before 0.26.0.
|
|
18
18
|
*/
|
|
19
19
|
approvalDigests?: Record<string, string>;
|
|
20
|
+
/** Monotonic store revision used to make lifecycle changes explicit. */
|
|
21
|
+
revision: number;
|
|
22
|
+
/** Present only while one process owns the right to apply this plan. */
|
|
23
|
+
applyClaim?: {
|
|
24
|
+
id: string;
|
|
25
|
+
claimedAt: string;
|
|
26
|
+
revision: number;
|
|
27
|
+
hostedClaimId?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Durable journal of apply ownership. An unresolved entry must never be replayed automatically. */
|
|
30
|
+
applyAttempts?: ApplyAttempt[];
|
|
20
31
|
runs: PatchPlanRun[];
|
|
21
32
|
createdAt: string;
|
|
22
33
|
updatedAt: string;
|
|
23
34
|
};
|
|
35
|
+
export type ApplyAttempt = {
|
|
36
|
+
id: string;
|
|
37
|
+
claimedAt: string;
|
|
38
|
+
provider: string;
|
|
39
|
+
source: "cli" | "fix" | "mcp";
|
|
40
|
+
status: "in_progress" | "preflight_aborted" | "completed" | "uncertain";
|
|
41
|
+
resolvedAt?: string;
|
|
42
|
+
/** Deliberately generic: provider errors can contain CRM data or credentials. */
|
|
43
|
+
note?: string;
|
|
44
|
+
hostedClaimId?: string;
|
|
45
|
+
};
|
|
24
46
|
export interface PlanStore {
|
|
25
47
|
save(plan: PatchPlan): Promise<StoredPlan>;
|
|
26
48
|
get(planId: string): Promise<StoredPlan | null>;
|
|
27
49
|
list(status?: ApprovalStatus): Promise<StoredPlan[]>;
|
|
28
50
|
approveOperations(planId: string, operationIds: string[], valueOverrides?: Record<string, unknown>): Promise<StoredPlan>;
|
|
29
51
|
reject(planId: string): Promise<StoredPlan>;
|
|
30
|
-
|
|
52
|
+
claimApply(planId: string, metadata?: Pick<ApplyAttempt, "provider" | "source">): Promise<{
|
|
53
|
+
stored: StoredPlan;
|
|
54
|
+
claimId: string;
|
|
55
|
+
}>;
|
|
56
|
+
recordHostedClaim(planId: string, claimId: string, hostedClaimId: string): Promise<StoredPlan>;
|
|
57
|
+
recordRun(planId: string, run: PatchPlanRun, claimId: string): Promise<StoredPlan>;
|
|
58
|
+
abortApplyPreflight(planId: string, claimId: string, note: string): Promise<StoredPlan>;
|
|
59
|
+
markApplyUncertain(planId: string, claimId: string): Promise<StoredPlan>;
|
|
60
|
+
recoverApply(planId: string): Promise<StoredPlan>;
|
|
61
|
+
reconcileReplica(planId: string, remote: ReplicaPlanState): Promise<{
|
|
62
|
+
stored: StoredPlan;
|
|
63
|
+
changed: boolean;
|
|
64
|
+
}>;
|
|
31
65
|
}
|
|
66
|
+
/** A validated lifecycle snapshot received from another plan replica. */
|
|
67
|
+
export type ReplicaPlanState = {
|
|
68
|
+
status: "approved" | "rejected" | "applied";
|
|
69
|
+
approvedOperationIds: string[];
|
|
70
|
+
valueOverrides?: Record<string, unknown>;
|
|
71
|
+
run?: PatchPlanRun;
|
|
72
|
+
};
|
|
32
73
|
/**
|
|
33
74
|
* Plans as JSON files in a directory (default `$FSGTM_HOME/plans`), one file
|
|
34
75
|
* per plan id. Filesystem-shaped on purpose: greppable, diffable, and any
|