@oyasmi/pipiclaw 0.5.2 → 0.5.4

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.
Files changed (216) hide show
  1. package/README.md +308 -209
  2. package/dist/agent/channel-runner.d.ts +3 -2
  3. package/dist/agent/channel-runner.js +22 -14
  4. package/dist/{command-extension.d.ts → agent/command-extension.d.ts} +0 -1
  5. package/dist/{command-extension.js → agent/command-extension.js} +1 -2
  6. package/dist/{commands.d.ts → agent/commands.d.ts} +0 -1
  7. package/dist/{commands.js → agent/commands.js} +0 -1
  8. package/dist/agent/index.d.ts +0 -1
  9. package/dist/agent/index.js +0 -1
  10. package/dist/agent/progress-formatter.d.ts +0 -1
  11. package/dist/agent/progress-formatter.js +0 -1
  12. package/dist/{prompt-builder.d.ts → agent/prompt-builder.d.ts} +1 -2
  13. package/dist/{prompt-builder.js → agent/prompt-builder.js} +0 -1
  14. package/dist/agent/run-queue.d.ts +0 -1
  15. package/dist/agent/run-queue.js +0 -1
  16. package/dist/agent/runner-factory.d.ts +0 -1
  17. package/dist/agent/runner-factory.js +0 -1
  18. package/dist/agent/session-events.d.ts +0 -1
  19. package/dist/agent/session-events.js +0 -1
  20. package/dist/agent/session-resource-gate.d.ts +10 -0
  21. package/dist/agent/session-resource-gate.js +44 -0
  22. package/dist/agent/type-guards.d.ts +0 -1
  23. package/dist/agent/type-guards.js +1 -2
  24. package/dist/agent/types.d.ts +1 -2
  25. package/dist/agent/types.js +0 -1
  26. package/dist/{config-loader.d.ts → agent/workspace-resources.d.ts} +3 -10
  27. package/dist/{config-loader.js → agent/workspace-resources.js} +3 -19
  28. package/dist/index.d.ts +9 -9
  29. package/dist/index.js +9 -9
  30. package/dist/log.d.ts +0 -1
  31. package/dist/log.js +0 -1
  32. package/dist/main.d.ts +0 -1
  33. package/dist/main.js +0 -1
  34. package/dist/memory/bootstrap.d.ts +0 -1
  35. package/dist/memory/bootstrap.js +0 -1
  36. package/dist/memory/candidates.d.ts +0 -1
  37. package/dist/memory/candidates.js +0 -1
  38. package/dist/memory/chinese-words.d.ts +0 -1
  39. package/dist/memory/chinese-words.js +64 -1
  40. package/dist/memory/consolidation.d.ts +0 -1
  41. package/dist/memory/consolidation.js +2 -3
  42. package/dist/memory/files.d.ts +0 -1
  43. package/dist/memory/files.js +0 -1
  44. package/dist/memory/lifecycle.d.ts +1 -2
  45. package/dist/memory/lifecycle.js +0 -1
  46. package/dist/memory/recall.d.ts +1 -1
  47. package/dist/memory/recall.js +77 -11
  48. package/dist/memory/session.d.ts +0 -1
  49. package/dist/memory/session.js +2 -3
  50. package/dist/{sidecar-worker.d.ts → memory/sidecar-worker.d.ts} +0 -1
  51. package/dist/{sidecar-worker.js → memory/sidecar-worker.js} +1 -2
  52. package/dist/models/api-keys.d.ts +7 -0
  53. package/dist/models/api-keys.js +16 -0
  54. package/dist/{model-utils.d.ts → models/utils.d.ts} +1 -2
  55. package/dist/{model-utils.js → models/utils.js} +0 -1
  56. package/dist/paths.d.ts +0 -1
  57. package/dist/paths.js +0 -1
  58. package/dist/runtime/bootstrap.d.ts +0 -1
  59. package/dist/runtime/bootstrap.js +2 -3
  60. package/dist/runtime/delivery.d.ts +0 -1
  61. package/dist/runtime/delivery.js +0 -1
  62. package/dist/runtime/dingtalk.d.ts +0 -1
  63. package/dist/runtime/dingtalk.js +1 -2
  64. package/dist/runtime/events.d.ts +0 -1
  65. package/dist/runtime/events.js +0 -1
  66. package/dist/runtime/store.d.ts +0 -1
  67. package/dist/runtime/store.js +0 -1
  68. package/dist/sandbox.d.ts +0 -1
  69. package/dist/sandbox.js +1 -2
  70. package/dist/{context.d.ts → settings.d.ts} +1 -2
  71. package/dist/{context.js → settings.js} +1 -2
  72. package/dist/{llm-json.d.ts → shared/llm-json.d.ts} +0 -1
  73. package/dist/{llm-json.js → shared/llm-json.js} +0 -1
  74. package/dist/shared/markdown-sections.d.ts +0 -1
  75. package/dist/shared/markdown-sections.js +0 -1
  76. package/dist/{shell-escape.d.ts → shared/shell-escape.d.ts} +0 -1
  77. package/dist/{shell-escape.js → shared/shell-escape.js} +0 -1
  78. package/dist/shared/text-utils.d.ts +0 -1
  79. package/dist/shared/text-utils.js +0 -1
  80. package/dist/shared/type-guards.d.ts +0 -1
  81. package/dist/shared/type-guards.js +0 -1
  82. package/dist/shared/types.d.ts +0 -1
  83. package/dist/shared/types.js +0 -1
  84. package/dist/subagents/discovery.d.ts +0 -1
  85. package/dist/subagents/discovery.js +1 -2
  86. package/dist/subagents/tool.d.ts +1 -2
  87. package/dist/subagents/tool.js +1 -2
  88. package/dist/tools/attach.d.ts +0 -1
  89. package/dist/tools/attach.js +0 -1
  90. package/dist/tools/bash.d.ts +0 -1
  91. package/dist/tools/bash.js +0 -1
  92. package/dist/tools/edit.d.ts +0 -1
  93. package/dist/tools/edit.js +1 -2
  94. package/dist/tools/index.d.ts +1 -2
  95. package/dist/tools/index.js +0 -1
  96. package/dist/tools/read.d.ts +0 -1
  97. package/dist/tools/read.js +1 -2
  98. package/dist/tools/truncate.d.ts +0 -1
  99. package/dist/tools/truncate.js +0 -1
  100. package/dist/tools/write-content.d.ts +0 -1
  101. package/dist/tools/write-content.js +1 -2
  102. package/dist/tools/write.d.ts +0 -1
  103. package/dist/tools/write.js +0 -1
  104. package/package.json +9 -3
  105. package/CHANGELOG.md +0 -47
  106. package/dist/agent/channel-runner.d.ts.map +0 -1
  107. package/dist/agent/channel-runner.js.map +0 -1
  108. package/dist/agent/index.d.ts.map +0 -1
  109. package/dist/agent/index.js.map +0 -1
  110. package/dist/agent/progress-formatter.d.ts.map +0 -1
  111. package/dist/agent/progress-formatter.js.map +0 -1
  112. package/dist/agent/run-queue.d.ts.map +0 -1
  113. package/dist/agent/run-queue.js.map +0 -1
  114. package/dist/agent/runner-factory.d.ts.map +0 -1
  115. package/dist/agent/runner-factory.js.map +0 -1
  116. package/dist/agent/session-events.d.ts.map +0 -1
  117. package/dist/agent/session-events.js.map +0 -1
  118. package/dist/agent/type-guards.d.ts.map +0 -1
  119. package/dist/agent/type-guards.js.map +0 -1
  120. package/dist/agent/types.d.ts.map +0 -1
  121. package/dist/agent/types.js.map +0 -1
  122. package/dist/agent.d.ts +0 -3
  123. package/dist/agent.d.ts.map +0 -1
  124. package/dist/agent.js +0 -2
  125. package/dist/agent.js.map +0 -1
  126. package/dist/command-extension.d.ts.map +0 -1
  127. package/dist/command-extension.js.map +0 -1
  128. package/dist/commands.d.ts.map +0 -1
  129. package/dist/commands.js.map +0 -1
  130. package/dist/config-loader.d.ts.map +0 -1
  131. package/dist/config-loader.js.map +0 -1
  132. package/dist/context.d.ts.map +0 -1
  133. package/dist/context.js.map +0 -1
  134. package/dist/index.d.ts.map +0 -1
  135. package/dist/index.js.map +0 -1
  136. package/dist/llm-json.d.ts.map +0 -1
  137. package/dist/llm-json.js.map +0 -1
  138. package/dist/log.d.ts.map +0 -1
  139. package/dist/log.js.map +0 -1
  140. package/dist/main.d.ts.map +0 -1
  141. package/dist/main.js.map +0 -1
  142. package/dist/memory/bootstrap.d.ts.map +0 -1
  143. package/dist/memory/bootstrap.js.map +0 -1
  144. package/dist/memory/candidates.d.ts.map +0 -1
  145. package/dist/memory/candidates.js.map +0 -1
  146. package/dist/memory/chinese-words.d.ts.map +0 -1
  147. package/dist/memory/chinese-words.js.map +0 -1
  148. package/dist/memory/consolidation.d.ts.map +0 -1
  149. package/dist/memory/consolidation.js.map +0 -1
  150. package/dist/memory/files.d.ts.map +0 -1
  151. package/dist/memory/files.js.map +0 -1
  152. package/dist/memory/lifecycle.d.ts.map +0 -1
  153. package/dist/memory/lifecycle.js.map +0 -1
  154. package/dist/memory/recall.d.ts.map +0 -1
  155. package/dist/memory/recall.js.map +0 -1
  156. package/dist/memory/session.d.ts.map +0 -1
  157. package/dist/memory/session.js.map +0 -1
  158. package/dist/model-utils.d.ts.map +0 -1
  159. package/dist/model-utils.js.map +0 -1
  160. package/dist/paths.d.ts.map +0 -1
  161. package/dist/paths.js.map +0 -1
  162. package/dist/prompt-builder.d.ts.map +0 -1
  163. package/dist/prompt-builder.js.map +0 -1
  164. package/dist/runtime/bootstrap.d.ts.map +0 -1
  165. package/dist/runtime/bootstrap.js.map +0 -1
  166. package/dist/runtime/delivery.d.ts.map +0 -1
  167. package/dist/runtime/delivery.js.map +0 -1
  168. package/dist/runtime/dingtalk.d.ts.map +0 -1
  169. package/dist/runtime/dingtalk.js.map +0 -1
  170. package/dist/runtime/events.d.ts.map +0 -1
  171. package/dist/runtime/events.js.map +0 -1
  172. package/dist/runtime/store.d.ts.map +0 -1
  173. package/dist/runtime/store.js.map +0 -1
  174. package/dist/sandbox.d.ts.map +0 -1
  175. package/dist/sandbox.js.map +0 -1
  176. package/dist/shared/markdown-sections.d.ts.map +0 -1
  177. package/dist/shared/markdown-sections.js.map +0 -1
  178. package/dist/shared/text-utils.d.ts.map +0 -1
  179. package/dist/shared/text-utils.js.map +0 -1
  180. package/dist/shared/type-guards.d.ts.map +0 -1
  181. package/dist/shared/type-guards.js.map +0 -1
  182. package/dist/shared/types.d.ts.map +0 -1
  183. package/dist/shared/types.js.map +0 -1
  184. package/dist/shell-escape.d.ts.map +0 -1
  185. package/dist/shell-escape.js.map +0 -1
  186. package/dist/sidecar-worker.d.ts.map +0 -1
  187. package/dist/sidecar-worker.js.map +0 -1
  188. package/dist/subagents/discovery.d.ts.map +0 -1
  189. package/dist/subagents/discovery.js.map +0 -1
  190. package/dist/subagents/tool.d.ts.map +0 -1
  191. package/dist/subagents/tool.js.map +0 -1
  192. package/dist/tools/attach.d.ts.map +0 -1
  193. package/dist/tools/attach.js.map +0 -1
  194. package/dist/tools/bash.d.ts.map +0 -1
  195. package/dist/tools/bash.js.map +0 -1
  196. package/dist/tools/edit.d.ts.map +0 -1
  197. package/dist/tools/edit.js.map +0 -1
  198. package/dist/tools/index.d.ts.map +0 -1
  199. package/dist/tools/index.js.map +0 -1
  200. package/dist/tools/read.d.ts.map +0 -1
  201. package/dist/tools/read.js.map +0 -1
  202. package/dist/tools/truncate.d.ts.map +0 -1
  203. package/dist/tools/truncate.js.map +0 -1
  204. package/dist/tools/write-content.d.ts.map +0 -1
  205. package/dist/tools/write-content.js.map +0 -1
  206. package/dist/tools/write.d.ts.map +0 -1
  207. package/dist/tools/write.js.map +0 -1
  208. package/docs/memory-audit.md +0 -330
  209. package/docs/memory-optimization-round2.md +0 -319
  210. package/docs/specs/001-implement-memory/memory-rfc.md +0 -297
  211. package/docs/specs/002-subagent/pi-subagent-analyse.txt +0 -190
  212. package/docs/specs/002-subagent/pi-subagent-design.txt +0 -266
  213. package/docs/specs/002-subagent/pi-subagent-phase1-plan.txt +0 -529
  214. package/docs/specs/003-improve-memory/design.md +0 -537
  215. package/docs/specs/003-improve-memory/interfaces-and-tests.md +0 -473
  216. package/docs/specs/003-improve-memory/spec.md +0 -357
@@ -1,7 +1,7 @@
1
- import { type BuiltInCommand } from "../commands.js";
2
1
  import type { DingTalkContext } from "../runtime/dingtalk.js";
3
2
  import type { ChannelStore } from "../runtime/store.js";
4
3
  import { type SandboxConfig } from "../sandbox.js";
4
+ import { type BuiltInCommand } from "./commands.js";
5
5
  import { type AgentRunner } from "./types.js";
6
6
  export declare class ChannelRunner implements AgentRunner {
7
7
  private readonly sandboxConfig;
@@ -15,6 +15,7 @@ export declare class ChannelRunner implements AgentRunner {
15
15
  private readonly settingsManager;
16
16
  private readonly modelRegistry;
17
17
  private readonly memoryLifecycle;
18
+ private readonly sessionResourceGate;
18
19
  private readonly sessionReady;
19
20
  private subAgentDiscovery;
20
21
  private activeModel;
@@ -38,9 +39,9 @@ export declare class ChannelRunner implements AgentRunner {
38
39
  private resetRunState;
39
40
  private refreshSessionResources;
40
41
  private initializeSession;
42
+ private reloadSessionResources;
41
43
  private ensureSessionReady;
42
44
  private refreshSubAgentDiscovery;
43
45
  private subscribeToSessionEvents;
44
46
  private buildFirstTurnMemoryBootstrap;
45
47
  }
46
- //# sourceMappingURL=channel-runner.d.ts.map
@@ -2,29 +2,31 @@ import { Agent } from "@mariozechner/pi-agent-core";
2
2
  import { AgentSession, AuthStorage, convertToLlm, DefaultResourceLoader, ModelRegistry, SessionManager, } from "@mariozechner/pi-coding-agent";
3
3
  import { mkdir, readFile, writeFile } from "fs/promises";
4
4
  import { dirname, join, resolve } from "path";
5
- import { createCommandExtension } from "../command-extension.js";
6
- import { renderBuiltInHelp } from "../commands.js";
7
- import { getAgentConfig, getApiKeyForModel, getSoul, loadPipiclawSkills } from "../config-loader.js";
8
- import { PipiclawSettingsManager } from "../context.js";
9
5
  import * as log from "../log.js";
10
6
  import { buildFirstTurnMemoryBootstrap as renderFirstTurnMemoryBootstrap } from "../memory/bootstrap.js";
11
7
  import { createMemoryCandidateCache } from "../memory/candidates.js";
12
8
  import { getChannelMemoryPath } from "../memory/files.js";
13
9
  import { MemoryLifecycle } from "../memory/lifecycle.js";
14
10
  import { recallRelevantMemory } from "../memory/recall.js";
15
- import { resolveInitialModel } from "../model-utils.js";
11
+ import { getApiKeyForModel } from "../models/api-keys.js";
12
+ import { resolveInitialModel } from "../models/utils.js";
16
13
  import { APP_HOME_DIR, AUTH_CONFIG_PATH, MODELS_CONFIG_PATH } from "../paths.js";
17
- import { buildAppendSystemPrompt } from "../prompt-builder.js";
18
14
  import { createExecutor } from "../sandbox.js";
15
+ import { PipiclawSettingsManager } from "../settings.js";
19
16
  import { HAN_REGEX } from "../shared/text-utils.js";
20
17
  import { isRecord } from "../shared/type-guards.js";
21
18
  import { discoverSubAgents, formatSubAgentList } from "../subagents/discovery.js";
22
19
  import { createPipiclawTools } from "../tools/index.js";
20
+ import { createCommandExtension } from "./command-extension.js";
21
+ import { renderBuiltInHelp } from "./commands.js";
23
22
  import { clipUserInput } from "./progress-formatter.js";
23
+ import { buildAppendSystemPrompt } from "./prompt-builder.js";
24
24
  import { createRunQueue } from "./run-queue.js";
25
25
  import { handleSessionEvent } from "./session-events.js";
26
+ import { SessionResourceGate } from "./session-resource-gate.js";
26
27
  import { getLastAssistantUsage } from "./type-guards.js";
27
28
  import { createEmptyRunState, MAX_USER_MESSAGE_CHARS, } from "./types.js";
29
+ import { getAgentConfig, getSoul, loadPipiclawSkills } from "./workspace-resources.js";
28
30
  function isSilentOutcome(outcome) {
29
31
  return outcome.kind === "silent";
30
32
  }
@@ -158,6 +160,9 @@ export class ChannelRunner {
158
160
  resourceLoader,
159
161
  baseToolsOverride,
160
162
  });
163
+ this.sessionResourceGate = new SessionResourceGate(async () => {
164
+ await this.reloadSessionResources();
165
+ });
161
166
  // Subscribe to session events
162
167
  this.subscribeToSessionEvents();
163
168
  this.sessionReady = this.initializeSession();
@@ -218,7 +223,9 @@ export class ChannelRunner {
218
223
  };
219
224
  await writeFile(join(this.channelDir, "last_prompt.json"), JSON.stringify(debugContext, null, 2));
220
225
  }
221
- await this.session.prompt(promptText);
226
+ await this.sessionResourceGate.runPrompt(async () => {
227
+ await this.session.prompt(promptText);
228
+ });
222
229
  }
223
230
  catch (err) {
224
231
  this.runState.stopReason = "error";
@@ -354,8 +361,10 @@ export class ChannelRunner {
354
361
  if (clippedText !== text.trim()) {
355
362
  log.logWarning(`[${this.channelId}] Queued message exceeded ${MAX_USER_MESSAGE_CHARS} chars and was clipped`);
356
363
  }
357
- await this.session.prompt(this.formatUserMessage(clippedText, userName), {
358
- streamingBehavior: delivery,
364
+ await this.sessionResourceGate.runPrompt(async () => {
365
+ await this.session.prompt(this.formatUserMessage(clippedText, userName), {
366
+ streamingBehavior: delivery,
367
+ });
359
368
  });
360
369
  }
361
370
  resetRunState(ctx, store) {
@@ -370,12 +379,12 @@ export class ChannelRunner {
370
379
  }
371
380
  async refreshSessionResources() {
372
381
  await this.ensureSessionReady();
373
- const skills = loadPipiclawSkills(this.channelDir, this.workspacePath);
374
- this.currentSkills = skills;
375
- this.subAgentDiscovery = this.refreshSubAgentDiscovery();
376
- await this.session.reload();
382
+ await this.sessionResourceGate.requestRefresh();
377
383
  }
378
384
  async initializeSession() {
385
+ await this.reloadSessionResources();
386
+ }
387
+ async reloadSessionResources() {
379
388
  const skills = loadPipiclawSkills(this.channelDir, this.workspacePath);
380
389
  this.currentSkills = skills;
381
390
  this.subAgentDiscovery = this.refreshSubAgentDiscovery();
@@ -431,4 +440,3 @@ export class ChannelRunner {
431
440
  });
432
441
  }
433
442
  }
434
- //# sourceMappingURL=channel-runner.js.map
@@ -11,4 +11,3 @@ export interface PipiclawCommandExtensionOptions {
11
11
  refreshSessionResources: () => Promise<void>;
12
12
  }
13
13
  export declare function createCommandExtension(options: PipiclawCommandExtensionOptions): ExtensionFactory;
14
- //# sourceMappingURL=command-extension.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { basename } from "path";
2
- import { findExactModelReferenceMatch, formatModelList, formatModelReference } from "./model-utils.js";
2
+ import { findExactModelReferenceMatch, formatModelList, formatModelReference } from "../models/utils.js";
3
3
  export const COMMAND_RESULT_CUSTOM_TYPE = "pipiclaw.command_result";
4
4
  function buildSessionText(stats, currentModel, thinkingLevel) {
5
5
  const modelText = currentModel ? `\`${formatModelReference(currentModel)}\`` : "(none)";
@@ -109,4 +109,3 @@ ${result.summary}
109
109
  });
110
110
  };
111
111
  }
112
- //# sourceMappingURL=command-extension.js.map
@@ -6,4 +6,3 @@ export interface BuiltInCommand {
6
6
  }
7
7
  export declare function parseBuiltInCommand(text: string): BuiltInCommand | null;
8
8
  export declare function renderBuiltInHelp(): string;
9
- //# sourceMappingURL=commands.d.ts.map
@@ -61,4 +61,3 @@ export function parseBuiltInCommand(text) {
61
61
  export function renderBuiltInHelp() {
62
62
  return HELP_TEXT;
63
63
  }
64
- //# sourceMappingURL=commands.js.map
@@ -1,4 +1,3 @@
1
1
  export { ChannelRunner } from "./channel-runner.js";
2
2
  export { getOrCreateRunner } from "./runner-factory.js";
3
3
  export type { AgentRunner } from "./types.js";
4
- //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,2 @@
1
1
  export { ChannelRunner } from "./channel-runner.js";
2
2
  export { getOrCreateRunner } from "./runner-factory.js";
3
- //# sourceMappingURL=index.js.map
@@ -2,4 +2,3 @@ import type { ProgressEntryKind } from "./types.js";
2
2
  export declare function clipUserInput(text: string, maxChars: number): string;
3
3
  export declare function formatProgressEntry(kind: ProgressEntryKind, text: string): string;
4
4
  export declare function extractToolResultText(result: unknown): string;
5
- //# sourceMappingURL=progress-formatter.d.ts.map
@@ -50,4 +50,3 @@ export function extractToolResultText(result) {
50
50
  }
51
51
  return JSON.stringify(result);
52
52
  }
53
- //# sourceMappingURL=progress-formatter.js.map
@@ -1,6 +1,5 @@
1
- import type { SandboxConfig } from "./sandbox.js";
1
+ import type { SandboxConfig } from "../sandbox.js";
2
2
  export interface AppendSystemPromptOptions {
3
3
  subAgentList?: string;
4
4
  }
5
5
  export declare function buildAppendSystemPrompt(workspacePath: string, channelId: string, sandboxConfig: SandboxConfig, options?: AppendSystemPromptOptions): string;
6
- //# sourceMappingURL=prompt-builder.d.ts.map
@@ -143,4 +143,3 @@ Important rules:
143
143
  - Use temporary inline sub-agents only when that extra flexibility is genuinely useful`);
144
144
  return sections.join("\n\n");
145
145
  }
146
- //# sourceMappingURL=prompt-builder.js.map
@@ -5,4 +5,3 @@ export interface CreatedRunQueue {
5
5
  drain: () => Promise<void>;
6
6
  }
7
7
  export declare function createRunQueue(ctx: DingTalkContext): CreatedRunQueue;
8
- //# sourceMappingURL=run-queue.d.ts.map
@@ -24,4 +24,3 @@ export function createRunQueue(ctx) {
24
24
  },
25
25
  };
26
26
  }
27
- //# sourceMappingURL=run-queue.js.map
@@ -1,4 +1,3 @@
1
1
  import type { SandboxConfig } from "../sandbox.js";
2
2
  import type { AgentRunner } from "./types.js";
3
3
  export declare function getOrCreateRunner(sandboxConfig: SandboxConfig, channelId: string, channelDir: string): AgentRunner;
4
- //# sourceMappingURL=runner-factory.d.ts.map
@@ -8,4 +8,3 @@ export function getOrCreateRunner(sandboxConfig, channelId, channelDir) {
8
8
  channelRunners.set(channelId, runner);
9
9
  return runner;
10
10
  }
11
- //# sourceMappingURL=runner-factory.js.map
@@ -12,4 +12,3 @@ export interface SessionEventHandlerContext {
12
12
  memoryLifecycle: MemoryLifecycle;
13
13
  }
14
14
  export declare function handleSessionEvent(event: unknown, context: SessionEventHandlerContext): Promise<void>;
15
- //# sourceMappingURL=session-events.d.ts.map
@@ -213,4 +213,3 @@ export async function handleSessionEvent(event, context) {
213
213
  queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `Retrying (${event.attempt}/${event.maxAttempts})...`), false), "retry");
214
214
  }
215
215
  }
216
- //# sourceMappingURL=session-events.js.map
@@ -0,0 +1,10 @@
1
+ export declare class SessionResourceGate {
2
+ private readonly reloadSessionResources;
3
+ private activePromptCount;
4
+ private refreshPending;
5
+ private reloadChain;
6
+ constructor(reloadSessionResources: () => Promise<void>);
7
+ runPrompt<T>(operation: () => Promise<T>): Promise<T>;
8
+ requestRefresh(): Promise<void>;
9
+ private flushPendingRefresh;
10
+ }
@@ -0,0 +1,44 @@
1
+ export class SessionResourceGate {
2
+ constructor(reloadSessionResources) {
3
+ this.reloadSessionResources = reloadSessionResources;
4
+ this.activePromptCount = 0;
5
+ this.refreshPending = false;
6
+ this.reloadChain = Promise.resolve();
7
+ }
8
+ async runPrompt(operation) {
9
+ await this.reloadChain;
10
+ this.activePromptCount++;
11
+ try {
12
+ return await operation();
13
+ }
14
+ finally {
15
+ this.activePromptCount--;
16
+ await this.flushPendingRefresh();
17
+ }
18
+ }
19
+ async requestRefresh() {
20
+ this.refreshPending = true;
21
+ if (this.activePromptCount > 0) {
22
+ return;
23
+ }
24
+ await this.flushPendingRefresh();
25
+ }
26
+ async flushPendingRefresh() {
27
+ if (!this.refreshPending || this.activePromptCount > 0) {
28
+ return;
29
+ }
30
+ this.refreshPending = false;
31
+ const runReload = async () => {
32
+ if (this.activePromptCount > 0) {
33
+ this.refreshPending = true;
34
+ return;
35
+ }
36
+ await this.reloadSessionResources();
37
+ };
38
+ this.reloadChain = this.reloadChain.then(runReload, runReload);
39
+ await this.reloadChain;
40
+ if (this.refreshPending && this.activePromptCount === 0) {
41
+ await this.flushPendingRefresh();
42
+ }
43
+ }
44
+ }
@@ -20,4 +20,3 @@ export declare function isAutoCompactionEndEvent(value: unknown): value is AutoC
20
20
  export declare function isAutoRetryStartEvent(value: unknown): value is AutoRetryStartEvent;
21
21
  export declare function isSubAgentToolDetails(value: unknown): value is SubAgentToolDetails;
22
22
  export declare function extractCustomCommandResultText(message: unknown): string | null;
23
- //# sourceMappingURL=type-guards.d.ts.map
@@ -1,5 +1,5 @@
1
- import { COMMAND_RESULT_CUSTOM_TYPE } from "../command-extension.js";
2
1
  import { isRecord } from "../shared/type-guards.js";
2
+ import { COMMAND_RESULT_CUSTOM_TYPE } from "./command-extension.js";
3
3
  function isMessageWithRole(value) {
4
4
  return isRecord(value) && typeof value.role === "string";
5
5
  }
@@ -104,4 +104,3 @@ export function extractCustomCommandResultText(message) {
104
104
  const content = message.content;
105
105
  return typeof content === "string" && content.trim() ? content : null;
106
106
  }
107
- //# sourceMappingURL=type-guards.js.map
@@ -1,7 +1,7 @@
1
- import type { BuiltInCommand } from "../commands.js";
2
1
  import type { DingTalkContext } from "../runtime/dingtalk.js";
3
2
  import type { ChannelStore } from "../runtime/store.js";
4
3
  import type { UsageTotals } from "../shared/types.js";
4
+ import type { BuiltInCommand } from "./commands.js";
5
5
  export interface AgentRunner {
6
6
  run(ctx: DingTalkContext, store: ChannelStore): Promise<{
7
7
  stopReason: string;
@@ -158,4 +158,3 @@ export type AutoRetryStartEvent = Extract<SessionEvent, {
158
158
  }>;
159
159
  export type ProgressEntryKind = "tool" | "thinking" | "error" | "assistant";
160
160
  export declare const MAX_USER_MESSAGE_CHARS = 12000;
161
- //# sourceMappingURL=types.d.ts.map
@@ -20,4 +20,3 @@ export function createEmptyRunState() {
20
20
  };
21
21
  }
22
22
  export const MAX_USER_MESSAGE_CHARS = 12_000;
23
- //# sourceMappingURL=types.js.map
@@ -1,9 +1,8 @@
1
1
  /**
2
- * Configuration file loaders for pipiclaw workspace files:
3
- * SOUL.md, AGENTS.md, skills/, and API key resolution.
2
+ * Workspace resource loaders for pipiclaw:
3
+ * SOUL.md, AGENTS.md, and workspace/channel skills.
4
4
  */
5
- import type { Api, Model } from "@mariozechner/pi-ai";
6
- import { type ModelRegistry, type Skill } from "@mariozechner/pi-coding-agent";
5
+ import { type Skill } from "@mariozechner/pi-coding-agent";
7
6
  /**
8
7
  * Load SOUL.md — defines the agent's identity, personality, and communication style.
9
8
  * Only loaded from workspace root (global).
@@ -19,9 +18,3 @@ export declare function getAgentConfig(channelDir: string): string;
19
18
  * Channel-level skills override global skills with the same name.
20
19
  */
21
20
  export declare function loadPipiclawSkills(channelDir: string, workspacePath: string): Skill[];
22
- /**
23
- * Resolve an API key for the given model's provider.
24
- * Checks ModelRegistry first, then falls back to ANTHROPIC_API_KEY env var.
25
- */
26
- export declare function getApiKeyForModel(modelRegistry: ModelRegistry, model: Model<Api>): Promise<string>;
27
- //# sourceMappingURL=config-loader.d.ts.map
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Configuration file loaders for pipiclaw workspace files:
3
- * SOUL.md, AGENTS.md, skills/, and API key resolution.
2
+ * Workspace resource loaders for pipiclaw:
3
+ * SOUL.md, AGENTS.md, and workspace/channel skills.
4
4
  */
5
5
  import { loadSkillsFromDir } from "@mariozechner/pi-coding-agent";
6
6
  import { existsSync, readFileSync } from "fs";
7
7
  import { join } from "path";
8
- import * as log from "./log.js";
8
+ import * as log from "../log.js";
9
9
  /**
10
10
  * Load SOUL.md — defines the agent's identity, personality, and communication style.
11
11
  * Only loaded from workspace root (global).
@@ -72,19 +72,3 @@ export function loadPipiclawSkills(channelDir, workspacePath) {
72
72
  }
73
73
  return Array.from(skillMap.values());
74
74
  }
75
- /**
76
- * Resolve an API key for the given model's provider.
77
- * Checks ModelRegistry first, then falls back to ANTHROPIC_API_KEY env var.
78
- */
79
- export async function getApiKeyForModel(modelRegistry, model) {
80
- const key = await modelRegistry.getApiKeyForProvider(model.provider);
81
- if (key)
82
- return key;
83
- // Fallback: try anthropic env var
84
- const envKey = process.env.ANTHROPIC_API_KEY;
85
- if (envKey)
86
- return envKey;
87
- throw new Error(`No API key found for provider: ${model.provider}.\n\n` +
88
- "Configure API key in ~/.pi/agent/models.json or set ANTHROPIC_API_KEY environment variable.");
89
- }
90
- //# sourceMappingURL=config-loader.js.map
package/dist/index.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- export { type AgentRunner, getOrCreateRunner } from "./agent.js";
2
- export { COMMAND_RESULT_CUSTOM_TYPE, createCommandExtension, type PipiclawCommandExtensionOptions, } from "./command-extension.js";
3
- export { type BuiltInCommand, type BuiltInCommandName, parseBuiltInCommand, renderBuiltInHelp } from "./commands.js";
4
- export { getAgentConfig, getApiKeyForModel, getSoul, loadPipiclawSkills, } from "./config-loader.js";
5
- export { type PipiclawMemoryRecallSettings, type PipiclawSessionMemorySettings, type PipiclawSettings, PipiclawSettingsManager, } from "./context.js";
1
+ export { COMMAND_RESULT_CUSTOM_TYPE, createCommandExtension, type PipiclawCommandExtensionOptions, } from "./agent/command-extension.js";
2
+ export { type BuiltInCommand, type BuiltInCommandName, parseBuiltInCommand, renderBuiltInHelp, } from "./agent/commands.js";
3
+ export { type AgentRunner, getOrCreateRunner } from "./agent/index.js";
4
+ export { type AppendSystemPromptOptions, buildAppendSystemPrompt } from "./agent/prompt-builder.js";
5
+ export { getAgentConfig, getSoul, loadPipiclawSkills, } from "./agent/workspace-resources.js";
6
6
  export { type BuildMemoryCandidatesOptions, buildMemoryCandidates, type MemoryCandidate, } from "./memory/candidates.js";
7
7
  export { type BackgroundMaintenanceResult, type ConsolidationRunOptions, type InlineConsolidationResult, runBackgroundMaintenance, runInlineConsolidation, } from "./memory/consolidation.js";
8
8
  export { ensureChannelMemoryFiles, ensureChannelMemoryFilesSync, getChannelSessionPath, readChannelSession, rewriteChannelSession, } from "./memory/files.js";
9
9
  export { type ConsolidationReason, MemoryLifecycle, type MemoryLifecycleOptions } from "./memory/lifecycle.js";
10
10
  export { type RecalledMemory, type RecallRequest, type RecallResult, recallRelevantMemory, } from "./memory/recall.js";
11
11
  export { renderSessionMemory, type SessionMemoryState, type SessionMemoryUpdateOptions, updateChannelSessionMemory, } from "./memory/session.js";
12
- export { findExactModelReferenceMatch, formatModelList, formatModelReference, resolveInitialModel, } from "./model-utils.js";
12
+ export { runSidecarTask, type SidecarResult, type SidecarTask, } from "./memory/sidecar-worker.js";
13
+ export { getApiKeyForModel } from "./models/api-keys.js";
14
+ export { findExactModelReferenceMatch, formatModelList, formatModelReference, resolveInitialModel, } from "./models/utils.js";
13
15
  export { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, MODELS_CONFIG_PATH, SETTINGS_CONFIG_PATH, SUB_AGENTS_DIR, SUB_AGENTS_DIR_NAME, WORKSPACE_DIR, } from "./paths.js";
14
- export { type AppendSystemPromptOptions, buildAppendSystemPrompt } from "./prompt-builder.js";
15
16
  export { createDingTalkContext } from "./runtime/delivery.js";
16
17
  export { type BusyMessageMode, DingTalkBot, type DingTalkConfig, type DingTalkContext, type DingTalkEvent, type DingTalkHandler, } from "./runtime/dingtalk.js";
17
18
  export { createEventsWatcher, EventsWatcher, type ImmediateEvent, type OneShotEvent, type PeriodicEvent, type ScheduledEvent, } from "./runtime/events.js";
18
19
  export { ChannelStore, type LoggedMessage, type LoggedSubAgentRun } from "./runtime/store.js";
19
20
  export { createExecutor, type ExecOptions, type ExecResult, type Executor, parseSandboxArg, type SandboxConfig, validateSandbox, } from "./sandbox.js";
20
- export { runSidecarTask, type SidecarResult, type SidecarTask, } from "./sidecar-worker.js";
21
+ export { type PipiclawMemoryRecallSettings, type PipiclawSessionMemorySettings, type PipiclawSettings, PipiclawSettingsManager, } from "./settings.js";
21
22
  export { discoverSubAgents, formatSubAgentList, getSubAgentsDir, type ResolvedSubAgentConfig, resolveSubAgentConfig, type SubAgentConfig, type SubAgentContextMode, type SubAgentDiscoveryResult, type SubAgentInvocationOverrides, type SubAgentMemoryMode, type SubAgentToolName, } from "./subagents/discovery.js";
22
23
  export { createSubAgentTool, type SubAgentToolDetails, type SubAgentToolOptions, } from "./subagents/tool.js";
23
24
  export { type CreatePipiclawToolsOptions, createPipiclawBaseTools, createPipiclawTools, } from "./tools/index.js";
24
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,24 +1,24 @@
1
- export { getOrCreateRunner } from "./agent.js";
2
- export { COMMAND_RESULT_CUSTOM_TYPE, createCommandExtension, } from "./command-extension.js";
3
- export { parseBuiltInCommand, renderBuiltInHelp } from "./commands.js";
4
- export { getAgentConfig, getApiKeyForModel, getSoul, loadPipiclawSkills, } from "./config-loader.js";
5
- export { PipiclawSettingsManager, } from "./context.js";
1
+ export { COMMAND_RESULT_CUSTOM_TYPE, createCommandExtension, } from "./agent/command-extension.js";
2
+ export { parseBuiltInCommand, renderBuiltInHelp, } from "./agent/commands.js";
3
+ export { getOrCreateRunner } from "./agent/index.js";
4
+ export { buildAppendSystemPrompt } from "./agent/prompt-builder.js";
5
+ export { getAgentConfig, getSoul, loadPipiclawSkills, } from "./agent/workspace-resources.js";
6
6
  export { buildMemoryCandidates, } from "./memory/candidates.js";
7
7
  export { runBackgroundMaintenance, runInlineConsolidation, } from "./memory/consolidation.js";
8
8
  export { ensureChannelMemoryFiles, ensureChannelMemoryFilesSync, getChannelSessionPath, readChannelSession, rewriteChannelSession, } from "./memory/files.js";
9
9
  export { MemoryLifecycle } from "./memory/lifecycle.js";
10
10
  export { recallRelevantMemory, } from "./memory/recall.js";
11
11
  export { renderSessionMemory, updateChannelSessionMemory, } from "./memory/session.js";
12
- export { findExactModelReferenceMatch, formatModelList, formatModelReference, resolveInitialModel, } from "./model-utils.js";
12
+ export { runSidecarTask, } from "./memory/sidecar-worker.js";
13
+ export { getApiKeyForModel } from "./models/api-keys.js";
14
+ export { findExactModelReferenceMatch, formatModelList, formatModelReference, resolveInitialModel, } from "./models/utils.js";
13
15
  export { APP_HOME_DIR, APP_NAME, AUTH_CONFIG_PATH, CHANNEL_CONFIG_PATH, MODELS_CONFIG_PATH, SETTINGS_CONFIG_PATH, SUB_AGENTS_DIR, SUB_AGENTS_DIR_NAME, WORKSPACE_DIR, } from "./paths.js";
14
- export { buildAppendSystemPrompt } from "./prompt-builder.js";
15
16
  export { createDingTalkContext } from "./runtime/delivery.js";
16
17
  export { DingTalkBot, } from "./runtime/dingtalk.js";
17
18
  export { createEventsWatcher, EventsWatcher, } from "./runtime/events.js";
18
19
  export { ChannelStore } from "./runtime/store.js";
19
20
  export { createExecutor, parseSandboxArg, validateSandbox, } from "./sandbox.js";
20
- export { runSidecarTask, } from "./sidecar-worker.js";
21
+ export { PipiclawSettingsManager, } from "./settings.js";
21
22
  export { discoverSubAgents, formatSubAgentList, getSubAgentsDir, resolveSubAgentConfig, } from "./subagents/discovery.js";
22
23
  export { createSubAgentTool, } from "./subagents/tool.js";
23
24
  export { createPipiclawBaseTools, createPipiclawTools, } from "./tools/index.js";
24
- //# sourceMappingURL=index.js.map
package/dist/log.d.ts CHANGED
@@ -30,4 +30,3 @@ export declare function logUsageSummary(ctx: LogContext, usage: {
30
30
  export declare function logStartup(workingDir: string, sandbox: string): void;
31
31
  export declare function logConnected(): void;
32
32
  export declare function logDisconnected(): void;
33
- //# sourceMappingURL=log.d.ts.map
package/dist/log.js CHANGED
@@ -185,4 +185,3 @@ export function logConnected() {
185
185
  export function logDisconnected() {
186
186
  console.log("pipiclaw disconnected.");
187
187
  }
188
- //# sourceMappingURL=log.js.map
package/dist/main.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=main.d.ts.map
package/dist/main.js CHANGED
@@ -7,4 +7,3 @@ void bootstrap(process.argv).catch((error) => {
7
7
  console.error(error);
8
8
  process.exit(1);
9
9
  });
10
- //# sourceMappingURL=main.js.map
@@ -4,4 +4,3 @@ export interface FirstTurnMemoryBootstrapOptions {
4
4
  maxChars?: number;
5
5
  }
6
6
  export declare function buildFirstTurnMemoryBootstrap(options: FirstTurnMemoryBootstrapOptions): string;
7
- //# sourceMappingURL=bootstrap.d.ts.map
@@ -44,4 +44,3 @@ export function buildFirstTurnMemoryBootstrap(options) {
44
44
  sections.push("</durable_memory_snapshot>");
45
45
  return sections.join("\n");
46
46
  }
47
- //# sourceMappingURL=bootstrap.js.map
@@ -19,4 +19,3 @@ export interface MemoryCandidateCache {
19
19
  }
20
20
  export declare function createMemoryCandidateCache(): MemoryCandidateCache;
21
21
  export declare function buildMemoryCandidates(options: BuildMemoryCandidatesOptions): Promise<MemoryCandidate[]>;
22
- //# sourceMappingURL=candidates.d.ts.map
@@ -136,4 +136,3 @@ export async function buildMemoryCandidates(options) {
136
136
  options.cache.entries.set(key, pending);
137
137
  return pending;
138
138
  }
139
- //# sourceMappingURL=candidates.js.map
@@ -1,2 +1 @@
1
1
  export declare const COMMON_CHINESE_WORDS: Set<string>;
2
- //# sourceMappingURL=chinese-words.d.ts.map
@@ -131,6 +131,30 @@ export const COMMON_CHINESE_WORDS = new Set([
131
131
  "状态管理",
132
132
  "异常处理",
133
133
  "错误处理",
134
+ "管理",
135
+ "优化",
136
+ "系统",
137
+ "设计",
138
+ "开发",
139
+ "测试",
140
+ "部署",
141
+ "修改",
142
+ "创建",
143
+ "删除",
144
+ "更新",
145
+ "查询",
146
+ "提交",
147
+ "调用",
148
+ "启动",
149
+ "停止",
150
+ "迁移",
151
+ "同步",
152
+ "备份",
153
+ "分析",
154
+ "监控",
155
+ "审查",
156
+ "重构",
157
+ "封装",
134
158
  "并发控制",
135
159
  "并发请求",
136
160
  "异步任务",
@@ -154,6 +178,30 @@ export const COMMON_CHINESE_WORDS = new Set([
154
178
  "熔断机制",
155
179
  "事务处理",
156
180
  "事务回滚",
181
+ "异常",
182
+ "错误",
183
+ "日志",
184
+ "线程",
185
+ "进程",
186
+ "端口",
187
+ "协议",
188
+ "路由",
189
+ "索引",
190
+ "事务",
191
+ "连接",
192
+ "超时",
193
+ "重连",
194
+ "校验",
195
+ "加密",
196
+ "解密",
197
+ "分支",
198
+ "合并",
199
+ "冲突",
200
+ "版本",
201
+ "发布",
202
+ "构建",
203
+ "编译",
204
+ "依赖",
157
205
  "索引优化",
158
206
  "数据迁移",
159
207
  "数据同步",
@@ -200,6 +248,22 @@ export const COMMON_CHINESE_WORDS = new Set([
200
248
  "修复登录",
201
249
  "生产环境",
202
250
  "工作区",
251
+ "记忆",
252
+ "会话",
253
+ "频道",
254
+ "模型",
255
+ "提示",
256
+ "工具",
257
+ "代理",
258
+ "任务",
259
+ "调度",
260
+ "排队",
261
+ "响应",
262
+ "请求",
263
+ "回调",
264
+ "订阅",
265
+ "通知",
266
+ "触发",
203
267
  "频道记忆",
204
268
  "记忆系统",
205
269
  "记忆子系统",
@@ -207,4 +271,3 @@ export const COMMON_CHINESE_WORDS = new Set([
207
271
  "工作记忆",
208
272
  "会话记忆",
209
273
  ]);
210
- //# sourceMappingURL=chinese-words.js.map
@@ -19,4 +19,3 @@ export interface BackgroundMaintenanceResult {
19
19
  }
20
20
  export declare function runInlineConsolidation(options: ConsolidationRunOptions): Promise<InlineConsolidationResult>;
21
21
  export declare function runBackgroundMaintenance(options: ConsolidationRunOptions): Promise<BackgroundMaintenanceResult>;
22
- //# sourceMappingURL=consolidation.d.ts.map
@@ -1,10 +1,10 @@
1
1
  import { getLatestCompactionEntry, serializeConversation, } from "@mariozechner/pi-coding-agent";
2
- import { parseJsonObject } from "../llm-json.js";
2
+ import { parseJsonObject } from "../shared/llm-json.js";
3
3
  import { splitH2Sections } from "../shared/markdown-sections.js";
4
4
  import { clipText } from "../shared/text-utils.js";
5
5
  import { buildStandardMessages } from "../shared/type-guards.js";
6
- import { runSidecarTask } from "../sidecar-worker.js";
7
6
  import { appendChannelHistoryBlock, appendChannelMemoryUpdate, readChannelHistory, readChannelMemory, readChannelSession, rewriteChannelHistory, rewriteChannelMemory, } from "./files.js";
7
+ import { runSidecarTask } from "./sidecar-worker.js";
8
8
  const INLINE_TRANSCRIPT_MAX_CHARS = 28_000;
9
9
  const MEMORY_CLEANUP_LENGTH_THRESHOLD = 5_000;
10
10
  const MEMORY_UPDATE_BLOCK_THRESHOLD = 4;
@@ -226,4 +226,3 @@ export async function runBackgroundMaintenance(options) {
226
226
  const foldedHistory = await foldChannelHistory(options, currentHistory);
227
227
  return { cleanedMemory, foldedHistory };
228
228
  }
229
- //# sourceMappingURL=consolidation.js.map
@@ -19,4 +19,3 @@ export declare function rewriteChannelHistory(channelDir: string, content: strin
19
19
  export declare function rewriteChannelSession(channelDir: string, content: string): Promise<void>;
20
20
  export declare function appendChannelMemoryUpdate(channelDir: string, block: MemoryUpdateBlock): Promise<void>;
21
21
  export declare function appendChannelHistoryBlock(channelDir: string, block: HistoryBlock): Promise<void>;
22
- //# sourceMappingURL=files.d.ts.map