@plune-ai/cli 0.35.0 → 0.37.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/dist/index.js CHANGED
@@ -1100,7 +1100,9 @@ var providerConfigSchema = z.object({
1100
1100
  max_tokens: z.number().int().positive().optional(),
1101
1101
  concurrency: z.number().int().positive().optional(),
1102
1102
  timeout: z.number().int().positive().optional(),
1103
- max_retries: z.number().int().min(0).optional()
1103
+ max_retries: z.number().int().min(0).optional(),
1104
+ // The values the OpenAI SDK's Chat Completions `reasoning_effort` accepts; only `openai` sends it.
1105
+ reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional()
1104
1106
  });
1105
1107
  var modelPriceSchema = z.object({
1106
1108
  input_per_1k_usd: z.number().nonnegative(),
@@ -1177,7 +1179,7 @@ var toolCallAssertionSchemas = [
1177
1179
  z.object({
1178
1180
  type: z.literal("tool-args"),
1179
1181
  tool: toolName,
1180
- args: z.record(z.string(), z.unknown()),
1182
+ args: z.union([z.record(z.string(), z.unknown()), z.array(z.record(z.string(), z.unknown())).min(1)]),
1181
1183
  match: z.enum(["partial", "exact", "ignore"]).optional(),
1182
1184
  min_count: count.optional()
1183
1185
  }),
@@ -1575,6 +1577,41 @@ var STOP = {
1575
1577
  end_turn: "stop",
1576
1578
  max_tokens: "length"
1577
1579
  };
1580
+ var TAKES_TEMPERATURE = [
1581
+ "claude-opus-4-6",
1582
+ "claude-sonnet-4-6",
1583
+ "claude-opus-4-5",
1584
+ "claude-sonnet-4-5",
1585
+ "claude-haiku-4-5",
1586
+ "claude-opus-4-1",
1587
+ "claude-opus-4-0",
1588
+ "claude-sonnet-4-0",
1589
+ "claude-opus-4-2025",
1590
+ "claude-sonnet-4-2025",
1591
+ "claude-3"
1592
+ ];
1593
+ var warnedNoTemperature = /* @__PURE__ */ new Set();
1594
+ function temperatureFor(model, temperature) {
1595
+ if (temperature === void 0) return {};
1596
+ if (TAKES_TEMPERATURE.some((prefix) => model.startsWith(prefix))) return { temperature };
1597
+ if (!warnedNoTemperature.has(model)) {
1598
+ warnedNoTemperature.add(model);
1599
+ process.stderr.write(
1600
+ `warning: ${model} does not take a temperature; the configured temperature ${temperature} is not sent
1601
+ `
1602
+ );
1603
+ }
1604
+ return {};
1605
+ }
1606
+ var warnedNoReasoningEffort = /* @__PURE__ */ new Set();
1607
+ function warnReasoningEffortNotSent(model, effort) {
1608
+ if (effort === void 0 || warnedNoReasoningEffort.has(model)) return;
1609
+ warnedNoReasoningEffort.add(model);
1610
+ process.stderr.write(
1611
+ `warning: ${model} does not take reasoning_effort; the configured value ${effort} is not sent
1612
+ `
1613
+ );
1614
+ }
1578
1615
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1579
1616
  function toAnthropicMessages(messages) {
1580
1617
  return messages.map((m) => {
@@ -1617,6 +1654,7 @@ function makeAnthropicProvider(config, env, pricing) {
1617
1654
  ...config.timeout !== void 0 ? { timeout: config.timeout } : {}
1618
1655
  });
1619
1656
  const maxRetries = config.max_retries ?? DEFAULT_MAX_RETRIES;
1657
+ warnReasoningEffortNotSent(config.model, config.reasoning_effort);
1620
1658
  return {
1621
1659
  async complete(req) {
1622
1660
  try {
@@ -1624,7 +1662,7 @@ function makeAnthropicProvider(config, env, pricing) {
1624
1662
  () => client.messages.create({
1625
1663
  model: req.model,
1626
1664
  max_tokens: req.max_tokens,
1627
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
1665
+ ...temperatureFor(req.model, req.temperature),
1628
1666
  messages: [{ role: "user", content: req.prompt_resolved }]
1629
1667
  }),
1630
1668
  { max_retries: maxRetries }
@@ -1648,7 +1686,7 @@ function makeAnthropicProvider(config, env, pricing) {
1648
1686
  () => client.messages.create({
1649
1687
  model: req.model,
1650
1688
  max_tokens: req.max_tokens,
1651
- ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
1689
+ ...temperatureFor(req.model, req.temperature),
1652
1690
  messages: toAnthropicMessages(req.messages),
1653
1691
  tools: req.tools.map((t) => ({
1654
1692
  name: t.name,
@@ -1713,7 +1751,8 @@ function parseToolArguments(id, name, raw) {
1713
1751
  }
1714
1752
  var DEFAULT_MAX_RETRIES2 = 2;
1715
1753
  function makeOpenAiCompatibleProvider(opts) {
1716
- const { config, env, pricing, apiKeyEnv, baseURL, reportsCost } = opts;
1754
+ const { config, env, pricing, apiKeyEnv, baseURL, reportsCost, maxCompletionTokens, sendsReasoningEffort } = opts;
1755
+ const reasoning = sendsReasoningEffort && config.reasoning_effort !== void 0 ? { reasoning_effort: config.reasoning_effort } : {};
1717
1756
  const apiKey = env[apiKeyEnv];
1718
1757
  if (apiKey === void 0 || apiKey.trim() === "") {
1719
1758
  throw new AuthError(
@@ -1736,7 +1775,8 @@ function makeOpenAiCompatibleProvider(opts) {
1736
1775
  () => client.chat.completions.create({
1737
1776
  model: req.model,
1738
1777
  ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
1739
- max_tokens: req.max_tokens,
1778
+ ...maxCompletionTokens ? { max_completion_tokens: req.max_tokens } : { max_tokens: req.max_tokens },
1779
+ ...reasoning,
1740
1780
  messages: [{ role: "user", content: req.prompt_resolved }],
1741
1781
  // OpenRouter extension: ask it to include the call's actual cost in `usage` (ADR-PRC02).
1742
1782
  ...reportsCost ? { usage: { include: true } } : {}
@@ -1765,7 +1805,8 @@ function makeOpenAiCompatibleProvider(opts) {
1765
1805
  () => client.chat.completions.create({
1766
1806
  model: req.model,
1767
1807
  ...req.temperature !== void 0 ? { temperature: req.temperature } : {},
1768
- max_tokens: req.max_tokens,
1808
+ ...maxCompletionTokens ? { max_completion_tokens: req.max_tokens } : { max_tokens: req.max_tokens },
1809
+ ...reasoning,
1769
1810
  messages: toOpenAiMessages(req.messages),
1770
1811
  tools: req.tools.map((t) => ({
1771
1812
  type: "function",
@@ -1804,7 +1845,14 @@ function makeOpenAiCompatibleProvider(opts) {
1804
1845
  };
1805
1846
  }
1806
1847
  function makeOpenAiProvider(config, env, pricing) {
1807
- return makeOpenAiCompatibleProvider({ config, env, pricing, apiKeyEnv: "OPENAI_API_KEY" });
1848
+ return makeOpenAiCompatibleProvider({
1849
+ config,
1850
+ env,
1851
+ pricing,
1852
+ apiKeyEnv: "OPENAI_API_KEY",
1853
+ maxCompletionTokens: true,
1854
+ sendsReasoningEffort: true
1855
+ });
1808
1856
  }
1809
1857
 
1810
1858
  // src/providers/openrouter.ts
@@ -2620,8 +2668,9 @@ function checkNames(type, t, names) {
2620
2668
  `${type}: no tool "${unknown}" was offered to the model; offered: ${list}.${AFTER}`
2621
2669
  );
2622
2670
  }
2623
- function absence(type, t, what) {
2624
- if (t.collection === "complete") return pass;
2671
+ function absence(type, t, what, reads) {
2672
+ if (t.collection === "complete" || reads === "calls" && t.stop.reason === "complete")
2673
+ return pass;
2625
2674
  const why = t.stop.reason === "limit" ? `the loop was stopped by ${t.stop.limit ?? "a limit"}` : "the transcript is partial (a stored excerpt was cut)";
2626
2675
  throw unmeasured(
2627
2676
  type,
@@ -2663,7 +2712,7 @@ var toolNotCalled = check((ctx) => {
2663
2712
  const t = transcriptOf("tool-not-called", ctx);
2664
2713
  checkNames("tool-not-called", t, [tool]);
2665
2714
  const calls = callsFor(t, tool);
2666
- if (calls.length === 0) return absence("tool-not-called", t, `a call to "${tool}"`);
2715
+ if (calls.length === 0) return absence("tool-not-called", t, `a call to "${tool}"`, "calls");
2667
2716
  return fail(
2668
2717
  `expected "${tool}" never called; got ${plural(calls.length, "call")}: ${describeCalls(calls)}; check what in the prompt or the tool list led the model to it`
2669
2718
  );
@@ -2686,13 +2735,15 @@ var toolArgs = check((ctx) => {
2686
2735
  const { tool, match = "partial", min_count: min = 1 } = ctx.params;
2687
2736
  const t = transcriptOf("tool-args", ctx);
2688
2737
  checkNames("tool-args", t, [tool]);
2689
- const args = interpolateDeep(ctx.params.args, ctx);
2690
- const matches = (actual) => match === "ignore" || (match === "exact" ? sameJson(args, actual) : partialMatch(args, actual));
2738
+ const sets = (Array.isArray(ctx.params.args) ? ctx.params.args : [ctx.params.args]).map(
2739
+ (a) => interpolateDeep(a, ctx)
2740
+ );
2741
+ const matches = (actual) => match === "ignore" || sets.some((args) => match === "exact" ? sameJson(args, actual) : partialMatch(args, actual));
2691
2742
  const calls = callsFor(t, tool);
2692
2743
  const hits = calls.filter((c) => matches(c.call.args)).length;
2693
2744
  if (hits >= min) return pass;
2694
2745
  return fail(
2695
- `expected a call to "${tool}" with arguments ${describeArgs(args)} (${match}) at least ${plural(min, "time")}; got ${hits} of ${plural(calls.length, "call")}: ${describeCalls(calls)}; check the argument names and values against the tool's input schema`
2746
+ `expected a call to "${tool}" with arguments ${sets.map(describeArgs).join(" or ")} (${match}) at least ${plural(min, "time")}; got ${hits} of ${plural(calls.length, "call")}: ${describeCalls(calls)}; check the argument names and values against the tool's input schema`
2696
2747
  );
2697
2748
  });
2698
2749
  var onlyTools = check((ctx) => {
@@ -2700,7 +2751,7 @@ var onlyTools = check((ctx) => {
2700
2751
  const t = transcriptOf("only-tools", ctx);
2701
2752
  checkNames("only-tools", t, tools);
2702
2753
  const off = callsOf(t).filter((c) => !tools.includes(c.call.name));
2703
- if (off.length === 0) return absence("only-tools", t, "a call to another tool");
2754
+ if (off.length === 0) return absence("only-tools", t, "a call to another tool", "calls");
2704
2755
  const allowed = tools.length > 0 ? `only ${tools.join(", ")} called` : "no tool call";
2705
2756
  return fail(
2706
2757
  `expected ${allowed}; got ${describeCalls(off)}; check whether allowed_tools should leave the others out`
@@ -2769,7 +2820,7 @@ var noToolErrors = check((ctx) => {
2769
2820
  const t = transcriptOf("no-tool-errors", ctx);
2770
2821
  checkNames("no-tool-errors", t, [tool]);
2771
2822
  const errors = callsFor(t, tool).filter((c) => c.call.is_error);
2772
- if (errors.length === 0) return absence("no-tool-errors", t, "a call with an error");
2823
+ if (errors.length === 0) return absence("no-tool-errors", t, "a call with an error", "calls");
2773
2824
  return fail(
2774
2825
  `expected no tool call with an error; got ${describeCalls(errors, (c) => `${describeCall(c)} (${c.call.error_kind ?? "error"})`)}; check the arguments the model sent against the tool's input schema`
2775
2826
  );
@@ -2793,7 +2844,8 @@ var noDestructiveTool = check((ctx) => {
2793
2844
  const why = riskOf(c.call.name, listed.get(c.call.name));
2794
2845
  if (why !== void 0) risky.push({ c, why });
2795
2846
  }
2796
- if (risky.length === 0) return absence("no-destructive-tool", t, "a call to a destructive tool");
2847
+ if (risky.length === 0)
2848
+ return absence("no-destructive-tool", t, "a call to a destructive tool", "calls");
2797
2849
  return fail(
2798
2850
  `expected no call to a tool that may be destructive; got ${failedOn(risky)}; the hints are the server's own claim, so check them on the server`
2799
2851
  );
@@ -3235,30 +3287,49 @@ async function runAgentRow(p) {
3235
3287
  if (err instanceof LimitStop) throw err;
3236
3288
  throw new AgentError("MCP_CONNECT", err.message);
3237
3289
  }
3238
- let listed;
3239
- try {
3240
- listed = listedTools(await bounded(session.listTools(limits.tool_timeout_ms)));
3241
- } catch (err) {
3242
- if (err instanceof LimitStop) throw err;
3243
- throw new AgentError("MCP_LIST_TOOLS", `tools/list failed: ${err.message}`);
3244
- }
3245
- const offered = listed.filter(
3246
- (t) => p.allowedTools === void 0 || p.allowedTools.includes(t.name)
3247
- );
3248
- transcript.tools = listed.map((t) => ({
3249
- name: t.name,
3250
- offered: offered.includes(t),
3251
- ...isRecord2(t.annotations) ? { annotations: t.annotations } : {}
3252
- }));
3253
- const names = wireNames(offered.map((t) => t.name));
3254
- const tools = offered.map((t) => ({
3255
- name: names.toWire.get(t.name),
3256
- ...typeof t.description === "string" ? { description: t.description } : {},
3257
- input_schema: isRecord2(t.inputSchema) ? t.inputSchema : { type: "object" }
3258
- }));
3290
+ const open2 = session;
3291
+ let names = wireNames([]);
3292
+ let tools = [];
3293
+ let offeredNames = [];
3294
+ const list = async () => {
3295
+ let listed;
3296
+ try {
3297
+ listed = listedTools(await bounded(open2.listTools(limits.tool_timeout_ms)));
3298
+ } catch (err) {
3299
+ if (err instanceof LimitStop) throw err;
3300
+ throw new AgentError("MCP_LIST_TOOLS", `tools/list failed: ${err.message}`);
3301
+ }
3302
+ const offered = listed.filter(
3303
+ (t) => p.allowedTools === void 0 || p.allowedTools.includes(t.name)
3304
+ );
3305
+ for (const t of listed) {
3306
+ const isOffered = offered.includes(t);
3307
+ const known = transcript.tools.find((k) => k.name === t.name);
3308
+ if (known !== void 0) known.offered ||= isOffered;
3309
+ else
3310
+ transcript.tools.push({
3311
+ name: t.name,
3312
+ offered: isOffered,
3313
+ ...isRecord2(t.annotations) ? { annotations: t.annotations } : {}
3314
+ });
3315
+ }
3316
+ const now = offered.map((t) => t.name);
3317
+ const added = now.filter((n) => !offeredNames.includes(n));
3318
+ const removed = offeredNames.filter((n) => !now.includes(n));
3319
+ offeredNames = now;
3320
+ names = wireNames(now);
3321
+ tools = offered.map((t) => ({
3322
+ name: names.toWire.get(t.name),
3323
+ ...typeof t.description === "string" ? { description: t.description } : {},
3324
+ input_schema: isRecord2(t.inputSchema) ? t.inputSchema : { type: "object" }
3325
+ }));
3326
+ return added.length + removed.length > 0 ? { added, removed } : void 0;
3327
+ };
3328
+ await list();
3259
3329
  const messages = [{ role: "user", content: prompt5 }];
3260
3330
  let calls = 0;
3261
3331
  let tokens = 0;
3332
+ let changed;
3262
3333
  for (let index = 1; ; index++) {
3263
3334
  const res = await bounded(
3264
3335
  respond({
@@ -3289,8 +3360,10 @@ async function runAgentRow(p) {
3289
3360
  text: kept.cut(res.text).text,
3290
3361
  ...res.finish_reason !== void 0 ? { finish_reason: res.finish_reason } : {},
3291
3362
  usage: usage2,
3292
- calls: records2
3363
+ calls: records2,
3364
+ ...changed !== void 0 ? { offered_changed: changed } : {}
3293
3365
  };
3366
+ changed = void 0;
3294
3367
  transcript.steps.push(step);
3295
3368
  if (res.finish_reason === "error")
3296
3369
  throw new AgentError(
@@ -3307,6 +3380,7 @@ async function runAgentRow(p) {
3307
3380
  if (tokens > limits.max_total_tokens) throw new LimitStop("max_total_tokens");
3308
3381
  const results = [];
3309
3382
  const answer = (rec, c, content) => results.push({ id: c.id, content, is_error: rec.is_error });
3383
+ let succeeded = false;
3310
3384
  for (const [i, c] of res.tool_calls.entries()) {
3311
3385
  const rec = records2[i];
3312
3386
  if (calls >= limits.max_tool_calls) throw new LimitStop("max_tool_calls");
@@ -3335,6 +3409,7 @@ async function runAgentRow(p) {
3335
3409
  if (got.kind === "error") Object.assign(rec, { is_error: true, error_kind: "protocol" });
3336
3410
  else if (isRecord2(got.result) && got.result.isError === true)
3337
3411
  Object.assign(rec, { is_error: true, error_kind: "content" });
3412
+ succeeded ||= !rec.is_error;
3338
3413
  rec.result = kept.cut(text);
3339
3414
  answer(rec, c, text);
3340
3415
  }
@@ -3342,6 +3417,7 @@ async function runAgentRow(p) {
3342
3417
  { role: "assistant", text: res.text, tool_calls: res.tool_calls },
3343
3418
  { role: "tool", results }
3344
3419
  );
3420
+ if (succeeded) changed = await list();
3345
3421
  }
3346
3422
  } catch (err) {
3347
3423
  if (err instanceof LimitStop) transcript.stop = { reason: "limit", limit: err.limit };
@@ -4042,7 +4118,9 @@ var rowResultSchema = z3.object({
4042
4118
  duration_ms: z3.number().optional(),
4043
4119
  result: z3.object({ text: z3.string(), bytes: z3.number(), truncated: z3.boolean() }).optional()
4044
4120
  })
4045
- )
4121
+ ),
4122
+ /** Optional and additive: the step whose request first offered a changed list. */
4123
+ offered_changed: z3.object({ added: z3.array(z3.string()), removed: z3.array(z3.string()) }).optional()
4046
4124
  })
4047
4125
  ),
4048
4126
  stop: z3.object({
@@ -204,6 +204,7 @@ var writeOutput = import_zod.z.object({
204
204
  request: plannedRequest.optional(),
205
205
  result: entity.optional()
206
206
  });
207
+ var strategyOutput = writeOutput.extend({ checked: import_zod.z.boolean().optional(), findings: import_zod.z.array(import_zod.z.unknown()).optional() });
207
208
  var batchOutput = import_zod.z.object({
208
209
  dryRun: import_zod.z.boolean(),
209
210
  requested: import_zod.z.number().int(),
@@ -239,7 +240,7 @@ var PLUNE_TOOLS = [
239
240
  define({
240
241
  name: "plune_project_context",
241
242
  title: "Project context",
242
- description: "Start here: learn the project you are working in with one call \u2014 its projects, the suite tree, how many test cases it has, its testing missions, and how much waits in the review queue.",
243
+ description: "Start here: learn the project you are working in with one call \u2014 its projects, the suite tree, how many test cases it has, its testing missions, how much waits in the review queue, and the rules of its memory: what a person accepted for this project, to follow without asking again.",
243
244
  input: import_zod2.z.strictObject({}),
244
245
  output: import_zod2.z.object({
245
246
  projectId: import_zod2.z.string().nullable(),
@@ -247,11 +248,12 @@ var PLUNE_TOOLS = [
247
248
  suites: import_zod2.z.array(entity),
248
249
  cases: import_zod2.z.object({ total: import_zod2.z.number().int() }),
249
250
  missions: import_zod2.z.array(entity),
250
- reviewQueue: import_zod2.z.object({ pending: import_zod2.z.number().int(), more: import_zod2.z.boolean() })
251
+ reviewQueue: import_zod2.z.object({ pending: import_zod2.z.number().int(), more: import_zod2.z.boolean() }),
252
+ memoryRules: import_zod2.z.array(import_zod2.z.object({ id: import_zod2.z.string(), text: import_zod2.z.string() })).describe("Rules a person accepted in the review queue and has not retired; a proposed or rejected rule is never here")
251
253
  }),
252
254
  write: false,
253
255
  visibility: "core",
254
- endpoints: ["GET /v1/projects", "GET /v1/suites", "GET /v1/test-cases", "GET /v1/missions", "GET /v1/review-items"]
256
+ endpoints: ["GET /v1/projects", "GET /v1/suites", "GET /v1/test-cases", "GET /v1/missions", "GET /v1/review-items", "GET /v1/memory/rules"]
255
257
  }),
256
258
  define({
257
259
  name: "plune_get",
@@ -284,10 +286,11 @@ var PLUNE_TOOLS = [
284
286
  define({
285
287
  name: "plune_review_list",
286
288
  title: "Read the review queue",
287
- description: "See what waits for a decision in the review queue \u2014 proposed cases, discovered tests, endpoints, strategies, reports \u2014 narrowed by state and kind, newest first, one page at a time.",
289
+ description: "See what waits for a decision in the review queue \u2014 proposed cases, discovered tests, endpoints, strategies, reports \u2014 narrowed by state, kind and mission, newest first, one page at a time. The mission filter needs a platform that supports it; an older one returns the whole queue.",
288
290
  input: import_zod2.z.strictObject({
289
291
  state: import_zod2.z.enum(REVIEW_STATES).optional(),
290
292
  kinds: import_zod2.z.array(import_zod2.z.enum(REVIEW_KINDS)).min(1).optional().describe("Questions are read with the question tool"),
293
+ missionId: import_zod2.z.string().min(1).optional().describe("Only the entries of this mission"),
291
294
  ...listPage
292
295
  }),
293
296
  output: import_zod2.z.object({ items: import_zod2.z.array(entity), nextCursor: import_zod2.z.string().nullable() }),
@@ -322,10 +325,11 @@ var PLUNE_TOOLS = [
322
325
  description: "Propose up to 100 new test cases for a person to review: they land in the review queue as proposals and become cases only when someone approves them. Nothing is created silently.",
323
326
  input: import_zod2.z.strictObject({
324
327
  target: import_zod2.z.string().trim().min(1).max(2048).describe("What the cases test: the product address, or the mission name"),
328
+ missionId: import_zod2.z.string().min(1).optional().describe("The mission these cases are for: the review queue can then be read by it"),
325
329
  cases: import_zod2.z.array(proposedCase).min(1).max(BATCH_MAX),
326
330
  dry_run: dryRun
327
331
  }),
328
- output: batchOutput,
332
+ output: batchOutput.extend({ itemIds: import_zod2.z.array(import_zod2.z.string()).optional().describe("The ids of the review-queue entries created, when the platform names them") }),
329
333
  write: true,
330
334
  visibility: "core",
331
335
  endpoints: ["POST /v1/ingest/cairn"]
@@ -442,7 +446,7 @@ var PLUNE_TOOLS = [
442
446
  title: "Propose a test strategy",
443
447
  description: "Propose a test strategy for a mission in ISTQB sections \u2014 objectives, scope in and out, approach, levels and techniques, risks, entry and exit criteria \u2014 for a person to accept.",
444
448
  input: import_zod2.z.strictObject({ missionId, content: strategyContent, dry_run: dryRun }),
445
- output: writeOutput,
449
+ output: strategyOutput,
446
450
  write: true,
447
451
  visibility: "core",
448
452
  endpoints: ["POST /v1/missions/:id/strategy"]
@@ -658,6 +662,17 @@ var fail = (code, message, extra = {}) => ({
658
662
  ok: false,
659
663
  error: { code, message, ...extra }
660
664
  });
665
+ function detailLines(body) {
666
+ const b = asRecord(body);
667
+ const lines = [...asArray(b["findings"]), ...asArray(b["details"])].map((d) => {
668
+ if (typeof d === "string") return `- ${d}`;
669
+ const f = asRecord(d);
670
+ const where = [f["rule"], f["path"]].filter((x) => typeof x === "string").join(" at ");
671
+ const said = typeof f["message"] === "string" ? f["message"] : where === "" ? JSON.stringify(d) : "";
672
+ return `- ${[where, said].filter(Boolean).join(": ")}`;
673
+ });
674
+ return lines.length === 0 ? "" : "\n" + lines.join("\n");
675
+ }
661
676
  function errorOf(err) {
662
677
  if (err instanceof PluneApiError) {
663
678
  if (err.status === 401)
@@ -665,7 +680,7 @@ function errorOf(err) {
665
680
  if (err.status === 403 && err.message === READ_ONLY_REFUSAL)
666
681
  return { status: 403, code: "read_only_token", message: `Plune refused (403): ${readScopeMessage("it cannot write")}` };
667
682
  const code = err.code ?? `http_${err.status}`;
668
- return { status: err.status, code, message: `Plune refused (${err.status} ${code}): ${err.message}`, details: err.body };
683
+ return { status: err.status, code, message: `Plune refused (${err.status} ${code}): ${err.message}${detailLines(err.body)}`, details: err.body };
669
684
  }
670
685
  if (err instanceof PluneNetworkError) return { code: "network", message: `${err.message}. Check PLUNE_API_URL and the network.` };
671
686
  throw err;
@@ -738,13 +753,19 @@ function createPluneToolExecutor(opts) {
738
753
  const str = (v) => v;
739
754
  const handlers = {
740
755
  async plune_project_context() {
741
- const [projects, suites, cases, missions, queue] = await Promise.all([
756
+ const [projects, suites, cases, missions, queue, memory] = await Promise.all([
742
757
  call({ method: "GET", path: "/v1/projects" }),
743
758
  call({ method: "GET", path: "/v1/suites" }),
744
759
  call({ method: "GET", path: "/v1/test-cases", query: { limit: "1", stability: "0" } }),
745
760
  call({ method: "GET", path: "/v1/missions" }),
746
- call({ method: "GET", path: "/v1/review-items", query: { state: "pending", limit: "100" } })
761
+ call({ method: "GET", path: "/v1/review-items", query: { state: "pending", limit: "100" } }),
762
+ // A platform that keeps no project memory yet answers 404: no rules, and the rest of the context still stands.
763
+ call({ method: "GET", path: "/v1/memory/rules", query: { state: "in_force" } }).catch((err) => {
764
+ if (err instanceof PluneApiError && err.status === 404) return { status: 404, body: { rules: [] } };
765
+ throw err;
766
+ })
747
767
  ]);
768
+ const memoryRules = asArray(asRecord(memory.body)["rules"]).map(asRecord).filter((r) => r["inForce"] === true && typeof r["id"] === "string" && typeof r["text"] === "string").map((r) => ({ id: str(r["id"]), text: str(r["text"]) }));
748
769
  const projectList = asArray(asRecord(projects.body)["projects"]);
749
770
  const only = projectList.length === 1 ? asRecord(projectList[0])["id"] : void 0;
750
771
  const projectId2 = opts.projectId ?? (typeof only === "string" ? only : null);
@@ -755,7 +776,8 @@ function createPluneToolExecutor(opts) {
755
776
  suites: asArray(asRecord(suites.body)["suites"]),
756
777
  cases: { total: typeof total === "number" ? total : 0 },
757
778
  missions: asArray(asRecord(missions.body)["missions"]),
758
- reviewQueue: { pending: asArray(asRecord(queue.body)["items"]).length, more: cursorOf(asRecord(queue.body)["nextCursor"]) !== null }
779
+ reviewQueue: { pending: asArray(asRecord(queue.body)["items"]).length, more: cursorOf(asRecord(queue.body)["nextCursor"]) !== null },
780
+ memoryRules
759
781
  };
760
782
  },
761
783
  async plune_get(i) {
@@ -783,6 +805,7 @@ function createPluneToolExecutor(opts) {
783
805
  const query = withoutUndefined({
784
806
  state: i["state"],
785
807
  kind: kinds?.join(","),
808
+ missionId: i["missionId"],
786
809
  limit: i["limit"] === void 0 ? void 0 : String(i["limit"]),
787
810
  cursor: i["cursor"]
788
811
  });
@@ -812,12 +835,17 @@ function createPluneToolExecutor(opts) {
812
835
  const req = {
813
836
  method: "POST",
814
837
  path: "/v1/ingest/cairn",
815
- body: { schemaVersion: 1, run: { runId: `mcp-${sessionId}-${proposals}`, mode: "design", target: str(i["target"]) }, cases }
838
+ body: {
839
+ schemaVersion: 1,
840
+ run: withoutUndefined({ runId: `mcp-${sessionId}-${proposals}`, mode: "design", target: str(i["target"]), missionId: i["missionId"] }),
841
+ cases
842
+ }
816
843
  };
817
844
  if (i["dry_run"] === true) return { dryRun: true, requested: cases.length, applied: 0, requests: [planned(req)] };
818
845
  const summary = asRecord((await call(req)).body);
819
846
  const proposed = summary["proposed"];
820
- return { dryRun: false, requested: cases.length, applied: typeof proposed === "number" ? proposed : 0, report: summary };
847
+ const ids = asArray(summary["itemIds"]).filter((x) => typeof x === "string");
848
+ return { dryRun: false, requested: cases.length, applied: typeof proposed === "number" ? proposed : 0, ...ids.length > 0 ? { itemIds: ids } : {}, report: summary };
821
849
  },
822
850
  async plune_cases_generate(i) {
823
851
  const { dry_run, projectId: projectId2, ...body } = i;
@@ -869,6 +897,16 @@ function createPluneToolExecutor(opts) {
869
897
  return { questions, nextCursor: cursorOf(body["nextCursor"]) };
870
898
  },
871
899
  async plune_strategy_propose(i) {
900
+ const req = { method: "POST", path: path("/v1/missions/:id/strategy", str(i["missionId"])), body: i["content"] };
901
+ if (i["dry_run"] === true) {
902
+ try {
903
+ const res = await call({ ...req, path: `${req.path}/check` });
904
+ return { dryRun: true, checked: true, findings: asArray(asRecord(res.body)["findings"]), request: planned(req) };
905
+ } catch (err) {
906
+ if (!(err instanceof PluneApiError && (err.status === 404 && err.code !== "mission_not_found" || err.status === 403 && err.message === READ_ONLY_REFUSAL))) throw err;
907
+ return { dryRun: true, checked: false, request: planned(req) };
908
+ }
909
+ }
872
910
  return write({ method: "POST", path: path("/v1/missions/:id/strategy", str(i["missionId"])), body: i["content"] }, i["dry_run"]);
873
911
  },
874
912
  async plune_report_request(i) {
@@ -46,6 +46,10 @@ declare const PLUNE_TOOLS: readonly [{
46
46
  pending: z.ZodNumber;
47
47
  more: z.ZodBoolean;
48
48
  }, z.core.$strip>;
49
+ memoryRules: z.ZodArray<z.ZodObject<{
50
+ id: z.ZodString;
51
+ text: z.ZodString;
52
+ }, z.core.$strip>>;
49
53
  }, z.core.$strip>;
50
54
  write: false;
51
55
  visibility: "core";
@@ -113,6 +117,7 @@ declare const PLUNE_TOOLS: readonly [{
113
117
  report: "report";
114
118
  memory_rule: "memory_rule";
115
119
  }>>>;
120
+ missionId: z.ZodOptional<z.ZodString>;
116
121
  }, z.core.$strict>;
117
122
  output: z.ZodObject<{
118
123
  items: z.ZodArray<z.ZodObject<{
@@ -163,6 +168,7 @@ declare const PLUNE_TOOLS: readonly [{
163
168
  description: string;
164
169
  input: z.ZodObject<{
165
170
  target: z.ZodString;
171
+ missionId: z.ZodOptional<z.ZodString>;
166
172
  cases: z.ZodArray<z.ZodObject<{
167
173
  title: z.ZodString;
168
174
  steps: z.ZodArray<z.ZodString>;
@@ -204,6 +210,7 @@ declare const PLUNE_TOOLS: readonly [{
204
210
  code: z.ZodOptional<z.ZodString>;
205
211
  }, z.core.$strip>>>;
206
212
  report: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
213
+ itemIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
207
214
  }, z.core.$strip>;
208
215
  write: true;
209
216
  visibility: "core";
@@ -634,6 +641,8 @@ declare const PLUNE_TOOLS: readonly [{
634
641
  result: z.ZodOptional<z.ZodObject<{
635
642
  id: z.ZodOptional<z.ZodString>;
636
643
  }, z.core.$loose>>;
644
+ checked: z.ZodOptional<z.ZodBoolean>;
645
+ findings: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
637
646
  }, z.core.$strip>;
638
647
  write: true;
639
648
  visibility: "core";
@@ -46,6 +46,10 @@ declare const PLUNE_TOOLS: readonly [{
46
46
  pending: z.ZodNumber;
47
47
  more: z.ZodBoolean;
48
48
  }, z.core.$strip>;
49
+ memoryRules: z.ZodArray<z.ZodObject<{
50
+ id: z.ZodString;
51
+ text: z.ZodString;
52
+ }, z.core.$strip>>;
49
53
  }, z.core.$strip>;
50
54
  write: false;
51
55
  visibility: "core";
@@ -113,6 +117,7 @@ declare const PLUNE_TOOLS: readonly [{
113
117
  report: "report";
114
118
  memory_rule: "memory_rule";
115
119
  }>>>;
120
+ missionId: z.ZodOptional<z.ZodString>;
116
121
  }, z.core.$strict>;
117
122
  output: z.ZodObject<{
118
123
  items: z.ZodArray<z.ZodObject<{
@@ -163,6 +168,7 @@ declare const PLUNE_TOOLS: readonly [{
163
168
  description: string;
164
169
  input: z.ZodObject<{
165
170
  target: z.ZodString;
171
+ missionId: z.ZodOptional<z.ZodString>;
166
172
  cases: z.ZodArray<z.ZodObject<{
167
173
  title: z.ZodString;
168
174
  steps: z.ZodArray<z.ZodString>;
@@ -204,6 +210,7 @@ declare const PLUNE_TOOLS: readonly [{
204
210
  code: z.ZodOptional<z.ZodString>;
205
211
  }, z.core.$strip>>>;
206
212
  report: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
213
+ itemIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
207
214
  }, z.core.$strip>;
208
215
  write: true;
209
216
  visibility: "core";
@@ -634,6 +641,8 @@ declare const PLUNE_TOOLS: readonly [{
634
641
  result: z.ZodOptional<z.ZodObject<{
635
642
  id: z.ZodOptional<z.ZodString>;
636
643
  }, z.core.$loose>>;
644
+ checked: z.ZodOptional<z.ZodBoolean>;
645
+ findings: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
637
646
  }, z.core.$strip>;
638
647
  write: true;
639
648
  visibility: "core";