@cydm/pie 1.0.25 → 1.0.27

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.
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createAskUserCapability
4
- } from "../../../chunks/chunk-O4DPFYYP.js";
4
+ } from "../../../chunks/chunk-L63BJMTT.js";
5
5
  import "../../../chunks/chunk-4B42ZU4B.js";
6
6
  import "../../../chunks/chunk-64XJIKVK.js";
7
7
  import "../../../chunks/chunk-TG2EQLX2.js";
@@ -7,7 +7,7 @@ import {
7
7
  isPlanModeSafeCommand,
8
8
  markCompletedPlanSteps,
9
9
  restoreExecutionState
10
- } from "../../../chunks/chunk-O4DPFYYP.js";
10
+ } from "../../../chunks/chunk-L63BJMTT.js";
11
11
  import "../../../chunks/chunk-4B42ZU4B.js";
12
12
  import "../../../chunks/chunk-64XJIKVK.js";
13
13
  import "../../../chunks/chunk-TG2EQLX2.js";
@@ -1,11 +1,11 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createCliHostCapabilities
4
- } from "../../../chunks/chunk-BEWVRLCP.js";
4
+ } from "../../../chunks/chunk-GARJAWH6.js";
5
5
  import {
6
6
  createSharedFileSystemTools,
7
7
  createSubagentCapability
8
- } from "../../../chunks/chunk-O4DPFYYP.js";
8
+ } from "../../../chunks/chunk-L63BJMTT.js";
9
9
  import "../../../chunks/chunk-4B42ZU4B.js";
10
10
  import "../../../chunks/chunk-64XJIKVK.js";
11
11
  import "../../../chunks/chunk-TG2EQLX2.js";
@@ -7,7 +7,7 @@ import {
7
7
  executeManageTodoList,
8
8
  executionStateToTodos,
9
9
  restoreExecutionState
10
- } from "../../../chunks/chunk-O4DPFYYP.js";
10
+ } from "../../../chunks/chunk-L63BJMTT.js";
11
11
  import "../../../chunks/chunk-4B42ZU4B.js";
12
12
  import "../../../chunks/chunk-64XJIKVK.js";
13
13
  import "../../../chunks/chunk-TG2EQLX2.js";
@@ -7,7 +7,7 @@ import {
7
7
  createSharedWebSearchTool,
8
8
  interpretShellExit,
9
9
  requestInteraction
10
- } from "./chunk-O4DPFYYP.js";
10
+ } from "./chunk-L63BJMTT.js";
11
11
  import {
12
12
  Type
13
13
  } from "./chunk-64XJIKVK.js";
@@ -2945,6 +2945,62 @@ function generateSessionId() {
2945
2945
  const random = Math.random().toString(36).substring(2, 8);
2946
2946
  return `${timestamp}-${random}`;
2947
2947
  }
2948
+ function isRecord2(value) {
2949
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2950
+ }
2951
+ function normalizeSessionDisplayName(raw) {
2952
+ const title = raw.trim().replace(/\s+/g, " ").slice(0, 60);
2953
+ if (!title) return null;
2954
+ if (title.startsWith("/")) return null;
2955
+ return title;
2956
+ }
2957
+ function extractUserText(message) {
2958
+ if (!isRecord2(message) || message.role !== "user") return "";
2959
+ const content = message.content;
2960
+ if (typeof content === "string") return content;
2961
+ if (!Array.isArray(content)) return "";
2962
+ return content.map((block) => isRecord2(block) && block.type === "text" && typeof block.text === "string" ? block.text : "").join(" ");
2963
+ }
2964
+ function isAutoGeneratedSessionName(name) {
2965
+ return /^Session (\d|[a-z0-9]{6,8}$)/i.test(name.trim());
2966
+ }
2967
+ function firstUserTitleOnActivePath(entries, activeEntryId) {
2968
+ if (!activeEntryId) return null;
2969
+ const byId = new Map(entries.map((entry) => [entry.id, entry]));
2970
+ const path4 = [];
2971
+ let current = activeEntryId;
2972
+ while (current) {
2973
+ const entry = byId.get(current);
2974
+ if (!entry) break;
2975
+ path4.unshift(entry);
2976
+ current = entry.parentId;
2977
+ }
2978
+ for (const entry of path4) {
2979
+ if (entry.type !== "message") continue;
2980
+ const title = normalizeSessionDisplayName(extractUserText(entry.message));
2981
+ if (title) return title;
2982
+ }
2983
+ return null;
2984
+ }
2985
+ function canAutoDeriveSessionName(metadata) {
2986
+ const nameSource = metadata.nameSource;
2987
+ return nameSource === "generated" || nameSource === "derived" || nameSource === void 0 && isAutoGeneratedSessionName(metadata.name);
2988
+ }
2989
+ function applyDerivedSessionName(metadata, entries) {
2990
+ if (!canAutoDeriveSessionName(metadata)) return false;
2991
+ const title = firstUserTitleOnActivePath(entries, metadata.activeEntryId);
2992
+ if (title) {
2993
+ const changed = metadata.name !== title || metadata.nameSource !== "derived";
2994
+ metadata.name = title;
2995
+ metadata.nameSource = "derived";
2996
+ return changed;
2997
+ }
2998
+ if (metadata.nameSource === void 0) {
2999
+ metadata.nameSource = "generated";
3000
+ return true;
3001
+ }
3002
+ return false;
3003
+ }
2948
3004
  var SessionManager = class {
2949
3005
  store;
2950
3006
  activeSession = null;
@@ -3008,6 +3064,7 @@ var SessionManager = class {
3008
3064
  metadata: {
3009
3065
  id,
3010
3066
  name: name ?? `Session ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
3067
+ nameSource: name ? "manual" : "generated",
3011
3068
  createdAt: Date.now(),
3012
3069
  updatedAt: Date.now(),
3013
3070
  entryCount: 0,
@@ -3070,6 +3127,7 @@ var SessionManager = class {
3070
3127
  this.activeSession.metadata.rootEntryId = this.activeSession.entries.find(
3071
3128
  (e) => e.parentId === null
3072
3129
  )?.id ?? null;
3130
+ applyDerivedSessionName(this.activeSession.metadata, this.activeSession.entries);
3073
3131
  await this.store.save(
3074
3132
  this.activeSession.id,
3075
3133
  this.activeSession.entries,
@@ -3316,6 +3374,7 @@ var SessionManager = class {
3316
3374
  throw new Error("No active session");
3317
3375
  }
3318
3376
  this.activeSession.metadata.name = name;
3377
+ this.activeSession.metadata.nameSource = "manual";
3319
3378
  this.activeSession.isDirty = true;
3320
3379
  await this.save();
3321
3380
  }
@@ -3354,6 +3413,25 @@ var SessionManager = class {
3354
3413
  const all = await this.store.listMetadata();
3355
3414
  return { metadata: all.slice(0, limit), totalCount: all.length };
3356
3415
  }
3416
+ /**
3417
+ * Refresh an inactive session's display name from its first user prompt when
3418
+ * it still has an auto-generated name. This is used by /resume to lazily
3419
+ * repair legacy sessions as the user points at them, without scanning every
3420
+ * session on open or changing its metadata updatedAt value.
3421
+ */
3422
+ async refreshDerivedName(sessionId) {
3423
+ const data = await this.store.load(sessionId);
3424
+ if (!data) return null;
3425
+ const nextMetadata = { ...data.metadata };
3426
+ if (!applyDerivedSessionName(nextMetadata, data.entries)) {
3427
+ return data.metadata;
3428
+ }
3429
+ await this.store.save(sessionId, data.entries, {
3430
+ ...nextMetadata,
3431
+ updatedAt: data.metadata.updatedAt
3432
+ });
3433
+ return await this.store.getMetadata(sessionId) ?? nextMetadata;
3434
+ }
3357
3435
  /**
3358
3436
  * Check if a session exists
3359
3437
  */
@@ -10511,23 +10589,23 @@ async function understandFileWithModel(deps, request) {
10511
10589
  }
10512
10590
 
10513
10591
  // ../../packages/shared-headless-capabilities/src/session-trace.ts
10514
- function isRecord2(value) {
10592
+ function isRecord3(value) {
10515
10593
  return !!value && typeof value === "object" && !Array.isArray(value);
10516
10594
  }
10517
10595
  function getTextFromMessageContent(content) {
10518
10596
  if (typeof content === "string") return content;
10519
10597
  if (!Array.isArray(content)) return "";
10520
- return content.filter((block) => isRecord2(block) && block.type === "text").map((block) => String(block.text || "")).join("");
10598
+ return content.filter((block) => isRecord3(block) && block.type === "text").map((block) => String(block.text || "")).join("");
10521
10599
  }
10522
10600
  function summarizeToolResult(result) {
10523
- if (!isRecord2(result)) return void 0;
10601
+ if (!isRecord3(result)) return void 0;
10524
10602
  const content = Array.isArray(result.content) ? result.content : [];
10525
- const text = content.filter((item) => isRecord2(item) && item.type === "text").map((item) => String(item.text || "")).join("\n").trim();
10603
+ const text = content.filter((item) => isRecord3(item) && item.type === "text").map((item) => String(item.text || "")).join("\n").trim();
10526
10604
  if (!text) return void 0;
10527
10605
  return text.length > 500 ? `${text.slice(0, 500)}...` : text;
10528
10606
  }
10529
10607
  function summarizeToolResultDetails(result) {
10530
- if (!isRecord2(result) || !isRecord2(result.details)) return void 0;
10608
+ if (!isRecord3(result) || !isRecord3(result.details)) return void 0;
10531
10609
  const details = result.details;
10532
10610
  const keys = [
10533
10611
  "providerMode",
@@ -10562,7 +10640,7 @@ function summarizeToolResultDetails(result) {
10562
10640
  const value = details[key];
10563
10641
  if (key === "attempts" && Array.isArray(value)) {
10564
10642
  summary[key] = value.slice(-5).map((attempt) => {
10565
- if (!isRecord2(attempt)) return attempt;
10643
+ if (!isRecord3(attempt)) return attempt;
10566
10644
  return {
10567
10645
  provider: attempt.provider,
10568
10646
  modelId: attempt.modelId,
@@ -10580,7 +10658,7 @@ function summarizeToolResultDetails(result) {
10580
10658
  summary[key] = {
10581
10659
  count: value.length,
10582
10660
  items: value.slice(0, 5).map((entry) => {
10583
- if (!isRecord2(entry)) return entry;
10661
+ if (!isRecord3(entry)) return entry;
10584
10662
  return {
10585
10663
  url: entry.finalUrl || entry.url,
10586
10664
  title: entry.title,
@@ -10596,7 +10674,7 @@ function summarizeToolResultDetails(result) {
10596
10674
  }
10597
10675
  if (key === "providerHealth" && Array.isArray(value)) {
10598
10676
  summary[key] = value.slice(0, 5).map((entry) => {
10599
- if (!isRecord2(entry)) return entry;
10677
+ if (!isRecord3(entry)) return entry;
10600
10678
  return {
10601
10679
  routeKey: entry.routeKey,
10602
10680
  attempts: entry.attempts,
@@ -10611,7 +10689,7 @@ function summarizeToolResultDetails(result) {
10611
10689
  }
10612
10690
  if (key === "providerAttempts" && Array.isArray(value)) {
10613
10691
  summary[key] = value.slice(-5).map((attempt) => {
10614
- if (!isRecord2(attempt)) return attempt;
10692
+ if (!isRecord3(attempt)) return attempt;
10615
10693
  return {
10616
10694
  provider: attempt.provider,
10617
10695
  modelId: attempt.modelId,
@@ -10643,10 +10721,10 @@ function summarizeString(value, maxLength = 300) {
10643
10721
  return value.length > maxLength ? `${value.slice(0, maxLength)}...` : value;
10644
10722
  }
10645
10723
  function summarizeMessage(message) {
10646
- if (!isRecord2(message)) return typeof message;
10724
+ if (!isRecord3(message)) return typeof message;
10647
10725
  if ("contentBlocks" in message && !("content" in message)) return message;
10648
10726
  const content = Array.isArray(message.content) ? message.content : [];
10649
- const blockTypes = content.filter(isRecord2).map((block) => String(block.type || "unknown")).slice(0, 10);
10727
+ const blockTypes = content.filter(isRecord3).map((block) => String(block.type || "unknown")).slice(0, 10);
10650
10728
  const text = getTextFromMessageContent(content);
10651
10729
  return {
10652
10730
  role: message.role,
@@ -10658,12 +10736,12 @@ function summarizeMessage(message) {
10658
10736
  };
10659
10737
  }
10660
10738
  function summarizeToolResults(value) {
10661
- if (isRecord2(value) && typeof value.count === "number" && !Array.isArray(value)) return value;
10739
+ if (isRecord3(value) && typeof value.count === "number" && !Array.isArray(value)) return value;
10662
10740
  if (!Array.isArray(value)) return typeof value;
10663
10741
  let errors = 0;
10664
10742
  const toolNames = [];
10665
10743
  for (const result of value) {
10666
- if (!isRecord2(result)) continue;
10744
+ if (!isRecord3(result)) continue;
10667
10745
  if (result.isError === true) errors++;
10668
10746
  const toolName = typeof result.toolName === "string" ? result.toolName : typeof result.name === "string" ? result.name : void 0;
10669
10747
  if (toolName && toolNames.length < 10) toolNames.push(toolName);
@@ -10675,7 +10753,7 @@ function collectTextLength(content) {
10675
10753
  if (!Array.isArray(content)) return 0;
10676
10754
  let length = 0;
10677
10755
  for (const block of content) {
10678
- if (!isRecord2(block)) continue;
10756
+ if (!isRecord3(block)) continue;
10679
10757
  if (typeof block.text === "string") length += block.text.length;
10680
10758
  }
10681
10759
  return length;
@@ -10684,7 +10762,7 @@ function collectArgumentLength(content) {
10684
10762
  if (!Array.isArray(content)) return 0;
10685
10763
  let length = 0;
10686
10764
  for (const block of content) {
10687
- if (!isRecord2(block) || !("arguments" in block)) continue;
10765
+ if (!isRecord3(block) || !("arguments" in block)) continue;
10688
10766
  if (typeof block.arguments === "string") {
10689
10767
  length += block.arguments.length;
10690
10768
  continue;
@@ -10707,7 +10785,7 @@ function summarizeMessages(value) {
10707
10785
  let textLength = 0;
10708
10786
  let argumentLength = 0;
10709
10787
  for (const message of value) {
10710
- if (!isRecord2(message)) continue;
10788
+ if (!isRecord3(message)) continue;
10711
10789
  const role = typeof message.role === "string" ? message.role : void 0;
10712
10790
  if (role && roles.length < 20) roles.push(role);
10713
10791
  if (typeof message.stopReason === "string" && stopReasons.length < 20) stopReasons.push(message.stopReason);
@@ -10718,7 +10796,7 @@ function summarizeMessages(value) {
10718
10796
  textLength += collectTextLength(message.content);
10719
10797
  argumentLength += collectArgumentLength(message.content);
10720
10798
  for (const block of content) {
10721
- if (isRecord2(block) && typeof block.name === "string" && toolNames.length < 20) {
10799
+ if (isRecord3(block) && typeof block.name === "string" && toolNames.length < 20) {
10722
10800
  toolNames.push(block.name);
10723
10801
  }
10724
10802
  }
@@ -10735,7 +10813,7 @@ function summarizeMessages(value) {
10735
10813
  };
10736
10814
  }
10737
10815
  function summarizeFailure(value) {
10738
- if (!isRecord2(value)) return typeof value;
10816
+ if (!isRecord3(value)) return typeof value;
10739
10817
  return {
10740
10818
  kind: value.kind,
10741
10819
  retryable: value.retryable,
@@ -10746,7 +10824,7 @@ function summarizeFailure(value) {
10746
10824
  };
10747
10825
  }
10748
10826
  function summarizeRuntimeEvent(value) {
10749
- if (!isRecord2(value)) return typeof value;
10827
+ if (!isRecord3(value)) return typeof value;
10750
10828
  const summary = {
10751
10829
  type: value.type
10752
10830
  };
@@ -10779,7 +10857,7 @@ function recomputeRuntimeSummaryFromTimeline(events) {
10779
10857
  return summary;
10780
10858
  }
10781
10859
  function summarizeMeta(meta) {
10782
- if (!isRecord2(meta)) return meta;
10860
+ if (!isRecord3(meta)) return meta;
10783
10861
  const summary = {};
10784
10862
  for (const [key, value] of Object.entries(meta)) {
10785
10863
  if (key === "messages" || key === "queuedInputs" || key === "result") {
@@ -10806,7 +10884,7 @@ function summarizeMeta(meta) {
10806
10884
  summary[key] = summarizeRuntimeEvent(value);
10807
10885
  continue;
10808
10886
  }
10809
- if (key === "queuedInput" && isRecord2(value)) {
10887
+ if (key === "queuedInput" && isRecord3(value)) {
10810
10888
  summary[key] = {
10811
10889
  mode: value.mode,
10812
10890
  source: value.source,
@@ -10826,18 +10904,18 @@ function toStringArray(value) {
10826
10904
  }
10827
10905
  function summarizeExcludedTools(value) {
10828
10906
  if (!Array.isArray(value)) return void 0;
10829
- const entries = value.filter(isRecord2).map((entry) => ({
10907
+ const entries = value.filter(isRecord3).map((entry) => ({
10830
10908
  name: String(entry.name || ""),
10831
10909
  reason: String(entry.reason || "")
10832
10910
  })).filter((entry) => entry.name);
10833
10911
  return entries.length > 0 ? entries : void 0;
10834
10912
  }
10835
10913
  function extractSubagentSummaries(toolCallId, toolName, result) {
10836
- if (toolName !== "spawn_subagents_parallel" || !isRecord2(result)) return [];
10837
- const details = isRecord2(result.details) ? result.details : void 0;
10914
+ if (toolName !== "spawn_subagents_parallel" || !isRecord3(result)) return [];
10915
+ const details = isRecord3(result.details) ? result.details : void 0;
10838
10916
  const tasks = Array.isArray(details?.tasks) ? details.tasks : [];
10839
- return tasks.filter(isRecord2).map((task) => {
10840
- const plan = isRecord2(task.plan) ? task.plan : void 0;
10917
+ return tasks.filter(isRecord3).map((task) => {
10918
+ const plan = isRecord3(task.plan) ? task.plan : void 0;
10841
10919
  const evidence = Array.isArray(task.evidence) ? task.evidence : [];
10842
10920
  const confidenceSignals = Array.isArray(task.confidenceSignals) ? task.confidenceSignals : [];
10843
10921
  const runtimeEvidence = Array.isArray(task.runtimeEvidence) ? task.runtimeEvidence : [];
@@ -10864,7 +10942,7 @@ function extractSubagentSummaries(toolCallId, toolName, result) {
10864
10942
  }
10865
10943
  function timelineEventFromTraceEvent(type, meta) {
10866
10944
  const normalizedType = type.startsWith("runtime:") ? type.slice("runtime:".length) : type;
10867
- const data = isRecord2(meta) ? meta : {};
10945
+ const data = isRecord3(meta) ? meta : {};
10868
10946
  const detail = summarizeMeta(meta);
10869
10947
  if (normalizedType === "assistant_update" || normalizedType === "dispatch_settled" || normalizedType === "wait_for_idle_settled") {
10870
10948
  return null;
@@ -11660,14 +11738,14 @@ function extractAnthropicContent(content, originalQuery) {
11660
11738
  results.push(makeTextSegment(block.text));
11661
11739
  }
11662
11740
  if (block?.type === "server_tool_use") {
11663
- const input = isRecord3(block.input) ? block.input : void 0;
11741
+ const input = isRecord4(block.input) ? block.input : void 0;
11664
11742
  if (typeof input?.query === "string" && input.query.trim()) {
11665
11743
  actualQueries.push(input.query.trim());
11666
11744
  }
11667
11745
  }
11668
11746
  if (block?.type === "web_search_tool_result") {
11669
11747
  if (!Array.isArray(block.content)) {
11670
- const errorCode = isRecord3(block.content) && typeof block.content.error_code === "string" ? block.content.error_code : "unknown";
11748
+ const errorCode = isRecord4(block.content) && typeof block.content.error_code === "string" ? block.content.error_code : "unknown";
11671
11749
  results.push({
11672
11750
  type: "error",
11673
11751
  toolUseId: typeof block.tool_use_id === "string" ? block.tool_use_id : void 0,
@@ -11711,7 +11789,7 @@ function collectUrlStrings(text, sources) {
11711
11789
  function resolveResponsesEndpoint(baseUrl) {
11712
11790
  return `${baseUrl.replace(/\/+$/, "")}/responses`;
11713
11791
  }
11714
- function isRecord3(value) {
11792
+ function isRecord4(value) {
11715
11793
  return typeof value === "object" && value !== null;
11716
11794
  }
11717
11795
  function collectUrlCitations(value, sources) {
@@ -11719,7 +11797,7 @@ function collectUrlCitations(value, sources) {
11719
11797
  for (const item of value) collectUrlCitations(item, sources);
11720
11798
  return;
11721
11799
  }
11722
- if (!isRecord3(value)) return;
11800
+ if (!isRecord4(value)) return;
11723
11801
  if (value.type === "url_citation" && typeof value.url === "string") {
11724
11802
  sources.push(sourceFromUrl(value.url, typeof value.title === "string" ? value.title : void 0));
11725
11803
  }
@@ -11738,7 +11816,7 @@ function collectOutputText(value, chunks) {
11738
11816
  for (const item of value) collectOutputText(item, chunks);
11739
11817
  return;
11740
11818
  }
11741
- if (!isRecord3(value)) return;
11819
+ if (!isRecord4(value)) return;
11742
11820
  if (value.type === "output_text" && typeof value.text === "string") {
11743
11821
  chunks.push(value.text);
11744
11822
  return;
@@ -11752,7 +11830,7 @@ function collectOutputText(value, chunks) {
11752
11830
  }
11753
11831
  }
11754
11832
  function extractOpenAIResponsesContent(response, originalQuery) {
11755
- const body = isRecord3(response) ? response : {};
11833
+ const body = isRecord4(response) ? response : {};
11756
11834
  const sources = [];
11757
11835
  collectUrlCitations(body.output, sources);
11758
11836
  if (typeof body.output_text === "string" && body.output_text.trim()) {
@@ -11769,12 +11847,12 @@ function extractOpenAIResponsesContent(response, originalQuery) {
11769
11847
  return { text, sources: uniqueSources(sources), results: text ? [makeTextSegment(text)] : [], actualQueries: [originalQuery] };
11770
11848
  }
11771
11849
  function extractChatCompletionsContent(response, originalQuery) {
11772
- const body = isRecord3(response) ? response : {};
11850
+ const body = isRecord4(response) ? response : {};
11773
11851
  const sources = [];
11774
11852
  collectUrlCitations(body, sources);
11775
11853
  const choices = Array.isArray(body.choices) ? body.choices : [];
11776
- const firstChoice = isRecord3(choices[0]) ? choices[0] : {};
11777
- const message = isRecord3(firstChoice.message) ? firstChoice.message : {};
11854
+ const firstChoice = isRecord4(choices[0]) ? choices[0] : {};
11855
+ const message = isRecord4(firstChoice.message) ? firstChoice.message : {};
11778
11856
  const content = typeof message.content === "string" ? message.content : "";
11779
11857
  if (content) {
11780
11858
  collectUrlStrings(content, sources);
@@ -12586,7 +12664,7 @@ var webResearchSchema = Type.Object({
12586
12664
  var DEFAULT_WEB_RESEARCH_SEARCH_ATTEMPT_TIMEOUT_MS = 45e3;
12587
12665
  var DEFAULT_WEB_RESEARCH_FETCH_ATTEMPT_TIMEOUT_MS = 3e4;
12588
12666
  var DEFAULT_WEB_RESEARCH_BROWSER_ATTEMPT_TIMEOUT_MS = 45e3;
12589
- function isRecord4(value) {
12667
+ function isRecord5(value) {
12590
12668
  return !!value && typeof value === "object" && !Array.isArray(value);
12591
12669
  }
12592
12670
  function textFromResult(result) {
@@ -12800,7 +12878,7 @@ function updateProviderHealth(current, attempts) {
12800
12878
  return [...byKey.values()].sort((a, b) => b.updatedAt - a.updatedAt).slice(0, 20);
12801
12879
  }
12802
12880
  function contentDetails(result) {
12803
- return isRecord4(result.details) ? result.details : {};
12881
+ return isRecord5(result.details) ? result.details : {};
12804
12882
  }
12805
12883
  function excerpt(text, max = 1400) {
12806
12884
  const clean = text.replace(/\s+/g, " ").trim();
package/dist/cli.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  getSettingsPath,
18
18
  getThemesDir,
19
19
  migrateConfigFromAgentDir
20
- } from "./chunks/chunk-BEWVRLCP.js";
20
+ } from "./chunks/chunk-GARJAWH6.js";
21
21
  import {
22
22
  AGENTS_CONTEXT_FILE_NAME,
23
23
  AgentSessionController,
@@ -67,7 +67,7 @@ import {
67
67
  setExtensionEnabledInSettings,
68
68
  shouldPreserveExecutionStateForUserText,
69
69
  supersedeExecutionState
70
- } from "./chunks/chunk-O4DPFYYP.js";
70
+ } from "./chunks/chunk-L63BJMTT.js";
71
71
  import "./chunks/chunk-4B42ZU4B.js";
72
72
  import {
73
73
  Deref,
@@ -45727,6 +45727,45 @@ var ModelRegistry = class {
45727
45727
  // src/core/settings-manager.ts
45728
45728
  import * as fs3 from "fs";
45729
45729
  import * as path3 from "path";
45730
+
45731
+ // src/tool-set.ts
45732
+ var DEFAULT_TOOL_SET = "lean";
45733
+ var LEAN_CODING_TOOL_NAMES = [
45734
+ "read_file",
45735
+ "edit_file",
45736
+ "write_file",
45737
+ "bash"
45738
+ ];
45739
+ var CLI_DEFAULT_TOOL_NAMES = /* @__PURE__ */ new Set([
45740
+ "read_file",
45741
+ "write_file",
45742
+ "edit_file",
45743
+ "list_dir",
45744
+ "grep_text",
45745
+ "find_files",
45746
+ "bash",
45747
+ "web_research",
45748
+ "web_search",
45749
+ "web_fetch",
45750
+ "code_intel"
45751
+ ]);
45752
+ var LEAN_CODING_TOOL_NAME_SET = new Set(LEAN_CODING_TOOL_NAMES);
45753
+ function normalizeDefaultToolSet(value) {
45754
+ return value === "full" ? "full" : DEFAULT_TOOL_SET;
45755
+ }
45756
+ function selectDefaultTools(tools, defaultSet) {
45757
+ if (defaultSet === "full") {
45758
+ return [...tools];
45759
+ }
45760
+ return tools.filter(
45761
+ (tool) => !CLI_DEFAULT_TOOL_NAMES.has(tool.name) || LEAN_CODING_TOOL_NAME_SET.has(tool.name)
45762
+ );
45763
+ }
45764
+ function formatDefaultToolSet(defaultSet) {
45765
+ return defaultSet === "full" ? "Full" : "Lean";
45766
+ }
45767
+
45768
+ // src/core/settings-manager.ts
45730
45769
  var SettingsManager = class {
45731
45770
  settingsPath;
45732
45771
  legacyConfigPath;
@@ -45815,6 +45854,16 @@ var SettingsManager = class {
45815
45854
  }
45816
45855
  return "auto";
45817
45856
  }
45857
+ getDefaultToolSet() {
45858
+ return normalizeDefaultToolSet(this.settings.tools?.defaultSet);
45859
+ }
45860
+ setDefaultToolSet(defaultSet) {
45861
+ this.settings.tools = {
45862
+ ...this.settings.tools,
45863
+ defaultSet
45864
+ };
45865
+ this.writeSettings();
45866
+ }
45818
45867
  // ==========================================================================
45819
45868
  // Extension enablement (user ~/.pie/settings.json + project ./.pie/settings.json)
45820
45869
  // ==========================================================================
@@ -46663,7 +46712,7 @@ async function renameSession(args) {
46663
46712
  const store = new FileSessionStore(getSessionsDir());
46664
46713
  const data = await store.load(sessionId);
46665
46714
  if (!data) throw new Error(`Session not found: ${sessionId}`);
46666
- await store.save(sessionId, data.entries, { ...data.metadata, name, ...cwd ? { cwd } : {}, updatedAt: Date.now() });
46715
+ await store.save(sessionId, data.entries, { ...data.metadata, name, nameSource: "manual", ...cwd ? { cwd } : {}, updatedAt: Date.now() });
46667
46716
  const updated = await store.getMetadata(sessionId);
46668
46717
  if (!updated) throw new Error(`Session not found after rename: ${sessionId}`);
46669
46718
  const response = { ok: true, session: sessionSummary(updated) };
@@ -60224,6 +60273,34 @@ var SettingsSelectorComponent = class extends Container {
60224
60273
  }
60225
60274
  )
60226
60275
  },
60276
+ {
60277
+ id: "tools",
60278
+ label: "Tools",
60279
+ description: "Default model-visible tool set",
60280
+ currentValue: config.defaultToolSet,
60281
+ submenu: (currentValue, done) => new SelectSubmenu(
60282
+ "Default Tools",
60283
+ "Choose which built-in tools are visible in new coding sessions",
60284
+ [
60285
+ {
60286
+ value: "lean",
60287
+ label: "Lean",
60288
+ description: "read_file, edit_file, write_file, bash"
60289
+ },
60290
+ {
60291
+ value: "full",
60292
+ label: "Full",
60293
+ description: "All built-in tools, including search, web, and code intel"
60294
+ }
60295
+ ],
60296
+ currentValue,
60297
+ (value) => {
60298
+ callbacks.onDefaultToolSetChange(value);
60299
+ done(value);
60300
+ },
60301
+ () => done()
60302
+ )
60303
+ },
60227
60304
  {
60228
60305
  id: "extensions",
60229
60306
  label: "Extensions",
@@ -61196,6 +61273,12 @@ var SessionSelectorComponent = class extends Container {
61196
61273
  sessions;
61197
61274
  callbacks;
61198
61275
  options;
61276
+ items;
61277
+ refreshAttempted = /* @__PURE__ */ new Set();
61278
+ refreshInFlight = false;
61279
+ pendingRefreshId;
61280
+ refreshTimer;
61281
+ destroyed = false;
61199
61282
  constructor(sessions, callbacks, options = {}) {
61200
61283
  super();
61201
61284
  this.sessions = sessions;
@@ -61205,10 +61288,10 @@ var SessionSelectorComponent = class extends Container {
61205
61288
  const title = truncated ? `Resume Session (recent ${sessions.length} of ${options.totalCount})` : "Resume Session";
61206
61289
  this.addChild(new Text(theme.bold(theme.fg("accent", title)), 0, 0));
61207
61290
  this.addChild(new Spacer(1));
61208
- const items = sessions.map((session) => this.createItem(session));
61291
+ this.items = sessions.map((session) => this.createItem(session));
61209
61292
  this.selectList = new SelectList(
61210
- items,
61211
- Math.min(items.length, 8),
61293
+ this.items,
61294
+ Math.min(this.items.length, 8),
61212
61295
  {
61213
61296
  selectedPrefix: (text) => theme.fg("accent", text),
61214
61297
  selectedText: (text) => theme.fg("accent", text),
@@ -61218,16 +61301,25 @@ var SessionSelectorComponent = class extends Container {
61218
61301
  }
61219
61302
  );
61220
61303
  this.selectList.onSelect = (item) => {
61304
+ this.destroyed = true;
61305
+ this.clearRefreshTimer();
61221
61306
  this.callbacks.onSelect(item.value);
61222
61307
  };
61223
61308
  this.selectList.onCancel = () => {
61309
+ this.destroyed = true;
61310
+ this.clearRefreshTimer();
61224
61311
  this.callbacks.onCancel();
61225
61312
  };
61313
+ this.selectList.onSelectionChange = (item) => {
61314
+ this.scheduleRefresh(item.value);
61315
+ };
61226
61316
  this.addChild(this.selectList);
61227
61317
  this.addChild(new Spacer(1));
61228
61318
  this.addChild(
61229
61319
  new Text(theme.fg("dim", " \u2191\u2193 to navigate \xB7 \u2190\u2192 to page \xB7 Enter to select \xB7 Esc to cancel"), 0, 0)
61230
61320
  );
61321
+ const selected = this.selectList.getSelectedItem();
61322
+ if (selected) this.scheduleRefresh(selected.value);
61231
61323
  }
61232
61324
  handleInput(data) {
61233
61325
  this.selectList.handleInput(data);
@@ -61243,6 +61335,55 @@ var SessionSelectorComponent = class extends Container {
61243
61335
  description: cwdTag ? `${cwdTag} \xB7 ${session.messageCount} messages \xB7 ${formatDate(session.updatedAt)}` : `${session.messageCount} messages \xB7 ${formatDate(session.updatedAt)}`
61244
61336
  };
61245
61337
  }
61338
+ clearRefreshTimer() {
61339
+ if (this.refreshTimer) {
61340
+ clearTimeout(this.refreshTimer);
61341
+ this.refreshTimer = void 0;
61342
+ }
61343
+ }
61344
+ scheduleRefresh(sessionId) {
61345
+ if (!this.options.refreshMetadata || this.destroyed || this.refreshAttempted.has(sessionId)) return;
61346
+ this.pendingRefreshId = sessionId;
61347
+ this.clearRefreshTimer();
61348
+ this.refreshTimer = setTimeout(() => {
61349
+ this.refreshTimer = void 0;
61350
+ void this.runPendingRefresh();
61351
+ }, this.options.refreshDelayMs ?? 150);
61352
+ }
61353
+ async runPendingRefresh() {
61354
+ if (this.destroyed || !this.options.refreshMetadata) return;
61355
+ if (this.refreshInFlight) return;
61356
+ const sessionId = this.pendingRefreshId;
61357
+ this.pendingRefreshId = void 0;
61358
+ if (!sessionId || this.refreshAttempted.has(sessionId)) return;
61359
+ this.refreshAttempted.add(sessionId);
61360
+ this.refreshInFlight = true;
61361
+ try {
61362
+ const metadata = await this.options.refreshMetadata(sessionId);
61363
+ if (metadata && !this.destroyed) {
61364
+ this.updateItem(metadata);
61365
+ }
61366
+ } catch {
61367
+ } finally {
61368
+ this.refreshInFlight = false;
61369
+ if (this.pendingRefreshId && !this.destroyed) {
61370
+ void this.runPendingRefresh();
61371
+ }
61372
+ }
61373
+ }
61374
+ updateItem(metadata) {
61375
+ const sessionIndex = this.sessions.findIndex((session) => session.id === metadata.id);
61376
+ if (sessionIndex >= 0) this.sessions[sessionIndex] = metadata;
61377
+ const itemIndex = this.items.findIndex((item2) => item2.value === metadata.id);
61378
+ if (itemIndex < 0) return;
61379
+ const nextItem = this.createItem(metadata);
61380
+ const item = this.items[itemIndex];
61381
+ if (item.label === nextItem.label && item.description === nextItem.description) return;
61382
+ item.label = nextItem.label;
61383
+ item.description = nextItem.description;
61384
+ this.selectList.invalidate();
61385
+ this.options.requestRender?.();
61386
+ }
61246
61387
  };
61247
61388
 
61248
61389
  // src/components/tree-selector.ts
@@ -62809,6 +62950,8 @@ async function handleResumeCommand(host) {
62809
62950
  }, {
62810
62951
  currentCwd: host.options.cwd,
62811
62952
  homeDir: os5.homedir(),
62953
+ refreshMetadata: (sessionId) => host.sessionManager.refreshDerivedName(sessionId),
62954
+ requestRender: () => host.ui.requestRender(),
62812
62955
  totalCount
62813
62956
  });
62814
62957
  return { component: selector, focus: selector.getSelectList() };
@@ -63500,10 +63643,7 @@ async function handleSkillsReload(host) {
63500
63643
  const result = loadSkills({ builtinDir, userDir, projectDir });
63501
63644
  host.skills = result.skills;
63502
63645
  host.skillsSection = formatSkillsForPrompt(host.skills);
63503
- const rebuiltTools = host.rebuildSkillAwareTools(host.agent.state.tools);
63504
- host.agent.state.tools = rebuiltTools.currentTools;
63505
- host.allTools = [...rebuiltTools.currentTools];
63506
- host.originalTools = [...rebuiltTools.originalTools];
63646
+ host.applyRuntimeToolMode(host.allTools.length > 0 ? host.allTools : host.agent.state.tools);
63507
63647
  host.updateSystemPromptTools();
63508
63648
  for (const skill of host.skills) {
63509
63649
  const skillPath = ["skills", `skill:${skill.name}`];
@@ -63548,7 +63688,8 @@ function showSettingsSelector(host) {
63548
63688
  availableThemes: getAvailableThemes(),
63549
63689
  currentModel: currentModelId,
63550
63690
  availableModels,
63551
- yoloMode: host.yoloMode
63691
+ yoloMode: host.yoloMode,
63692
+ defaultToolSet: host.options.settingsManager.getDefaultToolSet()
63552
63693
  },
63553
63694
  {
63554
63695
  onThinkingLevelChange: (level) => {
@@ -63577,6 +63718,10 @@ function showSettingsSelector(host) {
63577
63718
  host.showError(`Failed to switch model: ${err}`);
63578
63719
  }
63579
63720
  },
63721
+ onDefaultToolSetChange: (defaultToolSet) => {
63722
+ host.options.settingsManager.setDefaultToolSet(defaultToolSet);
63723
+ host.showStatus(`Default tools: ${formatDefaultToolSet(defaultToolSet)} (restart Pie to apply)`);
63724
+ },
63580
63725
  onYoloToggle: async () => {
63581
63726
  await host.handleYoloCommand();
63582
63727
  done();
@@ -64034,26 +64179,6 @@ function createExtensionContextForCommands(host) {
64034
64179
  };
64035
64180
  }
64036
64181
  function registerBuiltinCommands(host) {
64037
- commandTree.register(["new"], {
64038
- description: "Start a new session",
64039
- handler: () => host.handleClearCommand()
64040
- });
64041
- commandTree.register(["resume"], {
64042
- description: "Resume a different session",
64043
- handler: () => host.handleResumeCommand()
64044
- });
64045
- commandTree.register(["tree"], {
64046
- description: "Navigate session tree",
64047
- handler: () => host.handleTreeCommand()
64048
- });
64049
- commandTree.register(["session"], {
64050
- description: "Show session info and stats",
64051
- handler: () => host.handleSessionCommand()
64052
- });
64053
- commandTree.register(["fork"], {
64054
- description: "Create a new fork from a previous message",
64055
- handler: () => host.handleForkCommand()
64056
- });
64057
64182
  commandTree.register(["sessions", "compact"], {
64058
64183
  description: "Summarize history and replace it with a compact checkpoint",
64059
64184
  handler: () => host.handleCompactCommand()
@@ -64082,18 +64207,6 @@ function registerBuiltinCommands(host) {
64082
64207
  description: "Show help information (keyboard shortcuts and commands)",
64083
64208
  handler: () => host.handleHotkeysCommand()
64084
64209
  });
64085
- commandTree.register(["model"], {
64086
- description: "Select model (e.g., /model kimi-api/kimi-k2.5)",
64087
- handler: (_2, args) => host.handleModelCommand(args)
64088
- });
64089
- commandTree.register(["hotkeys"], {
64090
- description: "Show all keyboard shortcuts",
64091
- handler: () => host.handleHotkeysCommand()
64092
- });
64093
- commandTree.register(["export"], {
64094
- description: "Export session to HTML file",
64095
- handler: (_2, args) => host.handleExportCommand(args ? `/export ${args}` : "/export")
64096
- });
64097
64210
  commandTree.register(["settings"], {
64098
64211
  description: "Open settings menu",
64099
64212
  handler: () => host.showSettingsSelector()
@@ -64110,6 +64223,10 @@ function registerBuiltinCommands(host) {
64110
64223
  description: "Change theme",
64111
64224
  handler: () => host.showSettingsSelector()
64112
64225
  });
64226
+ commandTree.register(["settings", "tools"], {
64227
+ description: "Choose the default model-visible tool set",
64228
+ handler: () => host.showSettingsSelector()
64229
+ });
64113
64230
  commandTree.register(["settings", "thinking"], {
64114
64231
  description: "Set thinking level (off/minimal/low/medium/high/xhigh)",
64115
64232
  handler: (_2, args) => host.handleThinkingCommand(args)
@@ -64138,14 +64255,6 @@ function registerBuiltinCommands(host) {
64138
64255
  description: "List available skills",
64139
64256
  handler: () => host.handleSkillsCommand()
64140
64257
  });
64141
- commandTree.register(["skills"], {
64142
- description: "List available skills",
64143
- handler: () => host.handleSkillsCommand()
64144
- });
64145
- commandTree.register(["skill"], {
64146
- description: "Activate a skill (e.g., /skill code-review)",
64147
- handler: (_2, args) => host.handleSkillCommand(args || "")
64148
- });
64149
64258
  commandTree.register(["skills", "use"], {
64150
64259
  description: "Use a skill",
64151
64260
  handler: (_2, args) => host.handleSkillCommand(args || "")
@@ -66968,7 +67077,6 @@ function buildCodingAgentGuidelinesSection(tools = []) {
66968
67077
  const hasRead = toolNames.has("read_file");
66969
67078
  const hasWrite = toolNames.has("write_file");
66970
67079
  const hasEdit = toolNames.has("edit_file");
66971
- const hasList = toolNames.has("list_dir");
66972
67080
  const hasGrep = toolNames.has("grep_text");
66973
67081
  const hasFind = toolNames.has("find_files");
66974
67082
  const hasBash = toolNames.has("bash");
@@ -66978,68 +67086,38 @@ function buildCodingAgentGuidelinesSection(tools = []) {
66978
67086
  const hasCodeIntel = toolNames.has("code_intel");
66979
67087
  const hasTodo = toolNames.has("manage_todo_list");
66980
67088
  const guidelines = [
66981
- "Complete coding tasks by modifying or creating files when needed; do not stop at analysis."
67089
+ "Complete coding tasks by making the needed file changes; do not stop at analysis."
66982
67090
  ];
66983
- if (hasRead || hasList || hasGrep || hasFind) {
66984
- guidelines.push("Explore with targeted search and relevant file reads; avoid repeated broad directory listings.");
66985
- guidelines.push("Prefer first-class Pie tools for the task's semantic intent before lower-level shell preprocessing.");
66986
- }
66987
- if (hasGrep || hasFind || hasList) {
66988
- guidelines.push("Prefer grep_text, find_files, and list_dir for workspace exploration when they are sufficient.");
66989
- }
66990
- if (hasGrep) {
66991
- guidelines.push("Use grep_text outputMode='files_with_matches' to find candidate files, outputMode='count' to estimate impact, and outputMode='content' when you need matching lines and context.");
66992
- guidelines.push("After a broad grep_text search, narrow the path, glob, pattern, outputMode, offset, or limit instead of repeating the same broad search.");
66993
- }
66994
- if (hasWebResearch) {
66995
- guidelines.push("Use web_research for general public web research, current information, official docs, news, releases, issues, or webpage summaries; it searches, fetches, and returns cited sources.");
66996
- guidelines.push("When web_research returns fetched sources that answer the request, synthesize the answer from that pack instead of calling web_search or web_fetch again.");
66997
- }
66998
- if (hasWebSearch && !hasWebResearch) {
66999
- guidelines.push("Use web_search for public web research and grep_text/find_files/list_dir for local workspace search.");
67000
- }
67001
- if (hasWebFetch && !hasWebResearch) {
67002
- guidelines.push("After web_search identifies a public source, use web_fetch to read the chosen URL before relying on it; also use web_fetch for user-supplied URLs.");
67003
- } else if (hasWebResearch && hasWebSearch && hasWebFetch) {
67004
- guidelines.push("Use web_search and web_fetch directly only when you need low-level control over exact queries or URLs.");
67005
- }
67006
- if (hasCodeIntel) {
67007
- guidelines.push("Use code_intel for JS/TS diagnostics, definitions, references, symbols, or hover when type or symbol information matters before editing.");
67008
- }
67009
67091
  if (hasRead && hasEdit) {
67010
- guidelines.push("Read the current file before edit_file changes, then use a precise unique replacement.");
67092
+ guidelines.push("Read the current file before edit_file; use precise replacements and batch related edits when possible.");
67011
67093
  }
67012
- if (hasRead) {
67013
- guidelines.push("Use read_file offset/limit for large files; if read_file says a range is unchanged, do not repeat the same read and choose a different range or search instead.");
67014
- guidelines.push("Use read_file directly for media and documents when the file-understanding route is available.");
67094
+ if (hasGrep || hasFind) {
67095
+ guidelines.push("Use targeted search to locate files, then read only the ranges needed for the edit.");
67015
67096
  }
67016
- if (hasEdit) {
67017
- guidelines.push("If edit_file fails because text is missing, read the current file and retry with exact text copied from the latest file contents.");
67018
- guidelines.push("If edit_file fails because text is not unique, read the current file and retry with a larger exact block, or set replaceAll to true if every occurrence should be replaced.");
67097
+ if (hasRead && !hasEdit) {
67098
+ guidelines.push("Read only the relevant ranges; avoid repeating unchanged reads.");
67019
67099
  }
67020
67100
  if (hasWrite) {
67021
- guidelines.push("Use write_file for new files or true complete rewrites; before overwriting an existing file, read the current full file with read_file, and prefer edit_file for targeted changes.");
67101
+ guidelines.push("Use write_file for new files or true complete rewrites; prefer edit_file for targeted changes.");
67022
67102
  }
67023
67103
  if (hasBash) {
67024
- guidelines.push("Pass only executable shell commands to bash, not numbered plan items, headings, or prose.");
67025
67104
  if (hasWrite || hasEdit) {
67026
- guidelines.push("Do not use shell redirection, cat > file, tee, or heredoc to create or overwrite files when write_file or edit_file can do it; never use Bash to bypass write_file overwrite guards.");
67105
+ guidelines.push("Use file tools for file writes; do not use shell redirection or heredocs to bypass write_file/edit_file guards.");
67027
67106
  }
67028
- guidelines.push("If bash times out or truncates output, adjust the command or inspect the reported full output path instead of repeating the same command.");
67107
+ guidelines.push("Use bash for tests, builds, and inspection commands; if a command fails or times out, change the approach instead of repeating it.");
67108
+ }
67109
+ if (hasWebResearch || hasWebSearch || hasWebFetch) {
67110
+ guidelines.push("Use web tools only when current or external public information is required.");
67111
+ }
67112
+ if (hasCodeIntel) {
67113
+ guidelines.push("Use code_intel when type, diagnostic, definition, or reference information would materially reduce code-reading churn.");
67029
67114
  }
67030
67115
  if (hasTodo) {
67031
- guidelines.push("Use manage_todo_list only for multi-step work: create the list, complete only the current item when it is genuinely done, and let the tool advance the next item.");
67032
- guidelines.push("Do not complete a todo item while implementation is partial, tests or verification are failing, or the required verification has not run.");
67116
+ guidelines.push("Use manage_todo_list only for genuinely multi-step work, and mark items done only after the work is complete.");
67033
67117
  }
67034
67118
  guidelines.push(
67035
- "Once the root cause or required change is clear, make a small concrete edit instead of continuing unrelated exploration.",
67036
- "Treat task-relative paths as relative to the current working directory; do not prefix paths with .pie unless the task explicitly names .pie.",
67037
- "Prefer existing repository or task test commands over ad-hoc smoke checks; self-authored checks are useful only before running the authoritative local test.",
67038
- "Read test or error output carefully and patch the failing code path directly before doing more broad debugging.",
67039
- "When writing a module or library file, implement and export the exact functions or API names the task asks for; do not only write a standalone script.",
67040
- "For multi-step work, keep checkpoints brief and avoid progress reports after every sub-step; batch related edits and advance.",
67041
- "When the provided public verification command passes, stop immediately and let the harness run any further checks.",
67042
- "Stop once the requested work is complete and verification is satisfactory; answer with one short final sentence and do not keep rechecking already-passed work."
67119
+ "Run the relevant existing test or build after changes; if it passes, stop and report the result.",
67120
+ "Keep task-relative paths relative to the current working directory."
67043
67121
  );
67044
67122
  return `## Guidelines
67045
67123
 
@@ -67055,7 +67133,7 @@ When the user asks about Pie itself, its extensions, skills, TUI, model configur
67055
67133
  function buildCliSystemPrompt(options) {
67056
67134
  const tools = options.tools.map((tool) => ({
67057
67135
  name: tool.name,
67058
- description: tool.description ?? ""
67136
+ description: ""
67059
67137
  }));
67060
67138
  return [
67061
67139
  options.customPrompt?.trim() || "You are Pie, a helpful AI coding assistant.",
@@ -68771,12 +68849,18 @@ async function loadInteractiveExtensions(host) {
68771
68849
  }
68772
68850
  }
68773
68851
  const extensionTools = convertExtensionTools(extensions);
68774
- host.agent.state.tools.push(...extensionTools);
68775
- host.agent.state.tools = wrapToolsWithExtensions(host.agent.state.tools, host.extensionRunner);
68852
+ const activeTools = [...host.agent.state.tools, ...extensionTools];
68853
+ host.agent.state.tools = wrapToolsWithExtensions(activeTools, host.extensionRunner);
68854
+ const availableTools = [
68855
+ ...host.allTools.length > 0 ? host.allTools : host.originalTools.length > 0 ? host.originalTools : host.agent.state.tools,
68856
+ ...extensionTools
68857
+ ];
68858
+ host.allTools = wrapToolsWithExtensions(availableTools, host.extensionRunner);
68859
+ host.originalTools = [...host.allTools];
68776
68860
  if (host.options.compositionTrace) {
68777
68861
  recordCliCompositionStep(host.options.compositionTrace, {
68778
68862
  id: "extensions_tool_wrapping",
68779
- inputSummary: `baseTools=${host.agent.state.tools.length - extensionTools.length} extensionPaths=${host.options.extensionPaths?.length ?? 0}`,
68863
+ inputSummary: `baseTools=${host.agent.state.tools.length - extensionTools.length} availableTools=${host.allTools.length - extensionTools.length} extensionPaths=${host.options.extensionPaths?.length ?? 0}`,
68780
68864
  outputSummary: `extensions=${extensions.length}`,
68781
68865
  toolCount: host.agent.state.tools.length,
68782
68866
  extensionWrapping: {
@@ -68786,8 +68870,6 @@ async function loadInteractiveExtensions(host) {
68786
68870
  }
68787
68871
  });
68788
68872
  }
68789
- host.allTools = [...host.agent.state.tools];
68790
- host.originalTools = [...host.agent.state.tools];
68791
68873
  host.updateSystemPromptTools();
68792
68874
  if (process.env.PIE_VERBOSE) {
68793
68875
  console.error("[System Prompt] Tools section updated:");
@@ -68929,7 +69011,8 @@ var InteractiveMode = class {
68929
69011
  this.sessionManager = options.sessionManager;
68930
69012
  this.sessionTrace = new SessionTraceWriter(options.sessionTraceDir, this.sessionManager);
68931
69013
  this.skills = options.skills;
68932
- this.originalTools = [...options.tools];
69014
+ this.allTools = [...options.allTools];
69015
+ this.originalTools = [...options.allTools];
68933
69016
  this.skillsSection = formatSkillsForPrompt(options.skills);
68934
69017
  this.knowledgeSection = buildCliProjectContextSection(options.cwd);
68935
69018
  }
@@ -69051,8 +69134,10 @@ var InteractiveMode = class {
69051
69134
  const rebuilt = this.rebuildSkillAwareTools(completeToolSet);
69052
69135
  const currentTools = this.extensionRunner ? wrapToolsWithExtensions(rebuilt.currentTools, this.extensionRunner) : rebuilt.currentTools;
69053
69136
  const originalTools = this.extensionRunner ? wrapToolsWithExtensions(rebuilt.originalTools, this.extensionRunner) : rebuilt.originalTools;
69137
+ const defaultToolSet = this.options.settingsManager.getDefaultToolSet();
69138
+ const defaultTools = selectDefaultTools(currentTools, defaultToolSet);
69054
69139
  const activeTools = selectToolsForRuntimeMode(
69055
- currentTools,
69140
+ defaultTools,
69056
69141
  this.planModeEnabled ? "plan" : "normal"
69057
69142
  );
69058
69143
  this.agent.setTools(activeTools);
@@ -69615,15 +69700,17 @@ async function composeCliRuntime(params) {
69615
69700
  outputSummary: summarizeToolNames(rawTools),
69616
69701
  toolCount: rawTools.length
69617
69702
  });
69618
- const tools = createPolicyEnforcedTools(rawTools, {
69703
+ const allTools = createPolicyEnforcedTools(rawTools, {
69619
69704
  getContext: () => ({ mode: "normal", confirmationPolicy: "allow" })
69620
69705
  });
69706
+ const defaultToolSet = settingsManager.getDefaultToolSet();
69707
+ const tools = selectDefaultTools(allTools, defaultToolSet);
69621
69708
  recordCliCompositionStep(compositionTrace, {
69622
69709
  id: "policy_filtering",
69623
69710
  inputSummary: `tools=${rawTools.length}`,
69624
- outputSummary: summarizeToolNames(tools),
69711
+ outputSummary: `${summarizeToolNames(tools)} (defaultSet=${defaultToolSet}; available=${allTools.length})`,
69625
69712
  toolCount: tools.length,
69626
- policyDecisions: rawTools.length === tools.length ? ["allow:default"] : [`filtered:${rawTools.length - tools.length}`]
69713
+ policyDecisions: rawTools.length === allTools.length ? ["allow:default"] : [`filtered:${rawTools.length - allTools.length}`]
69627
69714
  });
69628
69715
  for (const diag of diagnostics.filter((d) => d.type === "collision")) {
69629
69716
  console.log(`[CLI] ${diag.message}`);
@@ -69672,6 +69759,7 @@ async function composeCliRuntime(params) {
69672
69759
  skillsSection,
69673
69760
  knowledgeSection,
69674
69761
  tools,
69762
+ allTools,
69675
69763
  fileObservationState,
69676
69764
  extensionPaths: params.extensionPaths,
69677
69765
  extensionFlags: params.extensionFlags ?? {},
@@ -69681,6 +69769,7 @@ async function composeCliRuntime(params) {
69681
69769
  model,
69682
69770
  apiKey,
69683
69771
  tools,
69772
+ allTools,
69684
69773
  fileObservationState,
69685
69774
  sessionManager,
69686
69775
  skills,
@@ -69721,11 +69810,13 @@ async function loadPrintModeExtensions(params) {
69721
69810
  const executionState = new ExecutionStateManager();
69722
69811
  const activeSession = params.sessionManager.getActiveSession();
69723
69812
  executionState.restoreFromMetadata(activeSession?.metadata?.executionState);
69813
+ let availableTools = [...params.allTools ?? []];
69724
69814
  const actions = {
69725
69815
  setActiveTools: (toolNames) => {
69726
69816
  const agent = params.getAgent();
69727
69817
  if (!agent) return;
69728
- const nextTools = agent.state.tools.filter((tool) => toolNames.includes(tool.name));
69818
+ const toolList = availableTools.length ? availableTools : agent.state.tools;
69819
+ const nextTools = toolList.filter((tool) => toolNames.includes(tool.name));
69729
69820
  agent.state.tools = nextTools;
69730
69821
  },
69731
69822
  getActiveTools: () => params.getAgent()?.state.tools.map((tool) => tool.name) ?? [],
@@ -69755,11 +69846,11 @@ async function loadPrintModeExtensions(params) {
69755
69846
  apiKey: params.apiKey,
69756
69847
  model: params.model,
69757
69848
  skills: params.skills,
69758
- getAllTools: () => params.getAgent()?.state.tools.map((tool) => ({
69849
+ getAllTools: () => (availableTools.length ? availableTools : params.getAgent()?.state.tools ?? []).map((tool) => ({
69759
69850
  name: tool.name,
69760
69851
  description: tool.description,
69761
69852
  parameters: tool.parameters
69762
- })) ?? [],
69853
+ })),
69763
69854
  getRuntimeTools: () => params.getAgent()?.state.tools ?? [],
69764
69855
  resolveModelClass: (modelClass) => params.modelRegistry.resolveModelClass(modelClass),
69765
69856
  getMessages: () => params.getAgent()?.state.messages ?? [],
@@ -69792,10 +69883,12 @@ async function loadPrintModeExtensions(params) {
69792
69883
  false
69793
69884
  );
69794
69885
  runner.setUIContext(uiContext);
69886
+ const extensionTools = convertExtensionTools(extensions);
69887
+ availableTools = [...availableTools, ...extensionTools];
69795
69888
  return {
69796
69889
  extensions,
69797
69890
  runner,
69798
- extensionTools: convertExtensionTools(extensions)
69891
+ extensionTools
69799
69892
  };
69800
69893
  }
69801
69894
  async function runPrintMode(params) {
@@ -69827,7 +69920,8 @@ async function runPrintMode(params) {
69827
69920
  skills: runtime.skills,
69828
69921
  getAgent: () => agent,
69829
69922
  sessionManager: runtime.sessionManager,
69830
- settingsManager: runtime.settingsManager
69923
+ settingsManager: runtime.settingsManager,
69924
+ allTools: runtime.allTools
69831
69925
  });
69832
69926
  const printModeTools = [...runtime.tools, ...printModeExtensions.extensionTools];
69833
69927
  recordCliCompositionStep(runtime.compositionTrace, {
@@ -70119,11 +70213,13 @@ async function loadJsonModeExtensions(params) {
70119
70213
  const executionState = new ExecutionStateManager();
70120
70214
  const activeSession = params.runtime.sessionManager.getActiveSession();
70121
70215
  executionState.restoreFromMetadata(activeSession?.metadata?.executionState);
70216
+ let availableTools = [...params.runtime.allTools];
70122
70217
  const actions = {
70123
70218
  setActiveTools: (toolNames) => {
70124
70219
  const agent = params.getAgent();
70125
70220
  if (!agent) return;
70126
- agent.state.tools = agent.state.tools.filter((tool) => toolNames.includes(tool.name));
70221
+ const toolList = availableTools.length > 0 ? availableTools : agent.state.tools;
70222
+ agent.state.tools = toolList.filter((tool) => toolNames.includes(tool.name));
70127
70223
  },
70128
70224
  getActiveTools: () => params.getAgent()?.state.tools.map((tool) => tool.name) ?? [],
70129
70225
  sendUserMessage: () => {
@@ -70156,11 +70252,11 @@ async function loadJsonModeExtensions(params) {
70156
70252
  return params.runtime.model;
70157
70253
  },
70158
70254
  skills: params.runtime.skills,
70159
- getAllTools: () => params.getAgent()?.state.tools.map((tool) => ({
70255
+ getAllTools: () => (availableTools.length > 0 ? availableTools : params.getAgent()?.state.tools ?? []).map((tool) => ({
70160
70256
  name: tool.name,
70161
70257
  description: tool.description,
70162
70258
  parameters: tool.parameters
70163
- })) ?? [],
70259
+ })),
70164
70260
  getRuntimeTools: () => params.getAgent()?.state.tools ?? [],
70165
70261
  resolveModelClass: (modelClass) => params.runtime.modelRegistry.resolveModelClass(modelClass),
70166
70262
  getMessages: () => params.getAgent()?.state.messages ?? [],
@@ -70193,9 +70289,11 @@ async function loadJsonModeExtensions(params) {
70193
70289
  false
70194
70290
  );
70195
70291
  runner.setUIContext(uiContext);
70292
+ const extensionTools = convertExtensionTools(extensions);
70293
+ availableTools = [...availableTools, ...extensionTools];
70196
70294
  return {
70197
70295
  runner,
70198
- extensionTools: convertExtensionTools(extensions),
70296
+ extensionTools,
70199
70297
  extensionCount: extensions.length
70200
70298
  };
70201
70299
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/pie",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Pie AI Agent CLI",
5
5
  "type": "module",
6
6
  "bin": {