@oyasmi/pipiclaw 0.8.2 → 0.8.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.
@@ -25,10 +25,7 @@ export function createPipiclawTools(options) {
25
25
  webConfig: toolsConfig.tools.web,
26
26
  toolsConfig,
27
27
  rtkEnabled: toolsConfig.tools.rtk.enabled,
28
- // Background jobs are opt-in; when off, bash `async` errors and the job tool is not registered.
29
- jobManager: toolsConfig.tools.jobs.enabled
30
- ? getChannelJobManager(options.channelId, options.executor)
31
- : undefined,
28
+ jobManager: getChannelJobManager(options.channelId, options.executor),
32
29
  getCurrentModel: options.getCurrentModel,
33
30
  getAvailableModels: options.getAvailableModels,
34
31
  resolveApiKey: options.resolveApiKey,
@@ -24,15 +24,15 @@ export interface ToolBuildContext {
24
24
  workspaceDir: string;
25
25
  /** Main set: `toolsConfig.tools.web`; sub-agent set: the sub-agent's own webConfig. */
26
26
  webConfig?: PipiclawWebToolsConfig;
27
- /** Present only on the main path; gates session_search / memory_manage / skills. */
27
+ /** Present only on the main path; gates task_manage and the bash interceptor. */
28
28
  toolsConfig?: PipiclawToolsConfig;
29
29
  /** Sub-agent set passes its per-invocation bash timeout; the main set relies on the built-in default. */
30
30
  bashDefaultTimeoutSeconds?: number;
31
31
  /** Gates the bash tool's rtk command optimizer (`tools.rtk.enabled`). Threaded to both sets. */
32
32
  rtkEnabled?: boolean;
33
33
  /**
34
- * Present only on the main path when `tools.jobs.enabled` is on. Enables bash `async` and the
35
- * `job` tool. The sub-agent set never supplies it, so sub-agents get neither.
34
+ * Present only on the main path. Enables bash `async` and the `job` tool.
35
+ * The sub-agent set never supplies it, so sub-agents get neither.
36
36
  */
37
37
  jobManager?: ChannelJobManager;
38
38
  getCurrentModel?: () => Model<Api>;
@@ -64,7 +64,6 @@ export const TOOL_REGISTRY = [
64
64
  name: "grep",
65
65
  promptHint: "Search file contents with a regex; grouped, paginated, token-bounded — prefer over bash grep",
66
66
  availableToSubagents: true,
67
- enabledBy: (ctx) => ctx.toolsConfig?.tools.grep.enabled !== false,
68
67
  create: (ctx) => createGrepTool(ctx.executor, fileToolOptions(ctx)),
69
68
  },
70
69
  {
@@ -102,7 +101,6 @@ export const TOOL_REGISTRY = [
102
101
  name: "session_search",
103
102
  promptHint: "Search current-channel cold transcript storage for older conversation details",
104
103
  availableToSubagents: false,
105
- enabledBy: (ctx) => ctx.toolsConfig?.tools.memory.sessionSearch.enabled !== false,
106
104
  create: (ctx) => createSessionSearchTool({
107
105
  channelId: ctx.channelId,
108
106
  channelDir: ctx.channelDir,
@@ -115,7 +113,6 @@ export const TOOL_REGISTRY = [
115
113
  name: "memory_manage",
116
114
  promptHint: "Save a durable fact, search stored memory on demand, or forget an entry — when the user asks",
117
115
  availableToSubagents: false,
118
- enabledBy: (ctx) => ctx.toolsConfig?.tools.memory.save.enabled !== false,
119
116
  create: (ctx) => createMemoryManageTool({
120
117
  channelId: ctx.channelId,
121
118
  channelDir: ctx.channelDir,
@@ -129,14 +126,12 @@ export const TOOL_REGISTRY = [
129
126
  name: "skill_manage",
130
127
  promptHint: "List, view, create, or maintain workspace-level procedural memory in skills/",
131
128
  availableToSubagents: false,
132
- enabledBy: (ctx) => ctx.toolsConfig?.tools.skills.manage.enabled !== false,
133
129
  create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir }),
134
130
  },
135
131
  {
136
132
  name: "event_manage",
137
133
  promptHint: "Create/update/delete validated one-shot reminders, periodic cadences, and preAction-gated sensors",
138
134
  availableToSubagents: false,
139
- enabledBy: (ctx) => ctx.toolsConfig?.tools.events.enabled !== false,
140
135
  create: (ctx) => createEventManageTool({
141
136
  workspaceDir: ctx.workspaceDir,
142
137
  channelId: ctx.channelId,
@@ -147,6 +142,8 @@ export const TOOL_REGISTRY = [
147
142
  name: "task_manage",
148
143
  promptHint: "Create, checkpoint, govern, verify, complete, cancel, or list persistent tasks",
149
144
  availableToSubagents: false,
145
+ // tools.tasks is the master switch for the whole autonomous long-running task
146
+ // mechanism; the TaskDriver and per-turn task digest honor the same flag.
150
147
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
151
148
  create: (ctx) => createTaskManageTool({
152
149
  workspaceDir: ctx.workspaceDir,
@@ -159,7 +156,8 @@ export const TOOL_REGISTRY = [
159
156
  name: "job",
160
157
  promptHint: "Inspect/poll/cancel background bash jobs started with bash async:true",
161
158
  availableToSubagents: false,
162
- // Present only when a job manager was supplied (tools.jobs.enabled on the main path).
159
+ // Present only when a job manager was supplied (always on the main path,
160
+ // never for sub-agents).
163
161
  enabledBy: (ctx) => ctx.jobManager !== undefined,
164
162
  create: (ctx) => createJobTool({ jobManager: req(ctx.jobManager, "jobManager") }),
165
163
  },
@@ -34,8 +34,6 @@ export declare class TurnController {
34
34
  private readonly deps;
35
35
  private readonly now;
36
36
  private readonly dispatchDeps;
37
- private running;
38
- private currentTaskText;
39
37
  private currentTurn;
40
38
  private readonly followups;
41
39
  private submitChain;
@@ -54,7 +52,7 @@ export declare class TurnController {
54
52
  * too, instead of falling through to the model as a plain message.
55
53
  */
56
54
  runOnce(prompt?: string): Promise<void>;
57
- /** Test/observability hook. */
55
+ /** Test/observability hook. Turn state is owned by the runner. */
58
56
  isRunning(): boolean;
59
57
  submit(text: string): void;
60
58
  private processSubmit;
@@ -19,7 +19,6 @@ const SHUTDOWN_ABORT_WAIT_MS = 5000;
19
19
  const SHUTDOWN_FLUSH_WAIT_MS = 20_000;
20
20
  export class TurnController {
21
21
  constructor(deps) {
22
- this.running = false;
23
22
  this.currentTurn = Promise.resolve();
24
23
  this.followups = [];
25
24
  this.submitChain = Promise.resolve();
@@ -36,7 +35,7 @@ export class TurnController {
36
35
  runEvents: deps.runEvents,
37
36
  runTasks: deps.runTasks,
38
37
  renderStatus: () => renderStatus({
39
- state: { running: this.running, currentTaskText: this.currentTaskText, runner: this.deps.runner },
38
+ runner: this.deps.runner,
40
39
  version: deps.statusInfo.version,
41
40
  uptimeMs: this.now() - deps.statusInfo.startedAt,
42
41
  }),
@@ -70,9 +69,9 @@ export class TurnController {
70
69
  }
71
70
  await this.shutdown();
72
71
  }
73
- /** Test/observability hook. */
72
+ /** Test/observability hook. Turn state is owned by the runner. */
74
73
  isRunning() {
75
- return this.running;
74
+ return this.deps.runner.isBusy();
76
75
  }
77
76
  submit(text) {
78
77
  this.submitChain = this.submitChain
@@ -99,7 +98,7 @@ export class TurnController {
99
98
  this.requestExit();
100
99
  return;
101
100
  case "stop":
102
- if (this.running) {
101
+ if (this.deps.runner.isBusy()) {
103
102
  void this.deps.runner.abort();
104
103
  this.deps.frontend.showNotice("Stopping…");
105
104
  }
@@ -126,7 +125,7 @@ export class TurnController {
126
125
  }
127
126
  /** A plain message or /steer: steer the in-flight turn, else start a fresh one. */
128
127
  async applyText(text) {
129
- if (this.running) {
128
+ if (this.deps.runner.isBusy()) {
130
129
  try {
131
130
  await this.deps.runner.queueSteer(text, this.deps.userName);
132
131
  this.deps.frontend.showNotice("Queued as steer.");
@@ -139,7 +138,7 @@ export class TurnController {
139
138
  this.beginTurn(text);
140
139
  }
141
140
  applyFollowup(text) {
142
- if (this.running) {
141
+ if (this.deps.runner.isBusy()) {
143
142
  this.followups.push(text);
144
143
  this.deps.frontend.showNotice("Queued as follow-up.");
145
144
  return;
@@ -147,10 +146,10 @@ export class TurnController {
147
146
  this.beginTurn(text);
148
147
  }
149
148
  beginTurn(text) {
150
- if (this.running || this.exiting)
149
+ if (this.deps.runner.isBusy() || this.exiting)
151
150
  return;
152
- this.running = true;
153
- this.currentTaskText = text;
151
+ // Reserve the turn synchronously; the runner is the single owner of busy state.
152
+ this.deps.runner.beginTurn(text);
154
153
  this.deps.frontend.setBusy(true);
155
154
  this.updateStatus();
156
155
  this.currentTurn = (async () => {
@@ -165,8 +164,7 @@ export class TurnController {
165
164
  }
166
165
  finally {
167
166
  await ctx.close();
168
- this.running = false;
169
- this.currentTaskText = undefined;
167
+ this.deps.runner.endTurn();
170
168
  this.deps.frontend.setBusy(false);
171
169
  this.updateStatus();
172
170
  }
@@ -175,12 +173,12 @@ export class TurnController {
175
173
  // method failing); drain either way and never leak an unhandled rejection.
176
174
  void this.currentTurn.then(() => this.drainFollowups(), (err) => {
177
175
  log.logWarning(`[${this.deps.channelId}] TUI turn finalizer failed`, errorMessage(err));
178
- this.running = false;
176
+ this.deps.runner.endTurn();
179
177
  this.drainFollowups();
180
178
  });
181
179
  }
182
180
  drainFollowups() {
183
- if (this.exiting || this.running)
181
+ if (this.exiting || this.deps.runner.isBusy())
184
182
  return;
185
183
  const next = this.followups.shift();
186
184
  if (next !== undefined)
@@ -211,7 +209,7 @@ export class TurnController {
211
209
  }
212
210
  }
213
211
  handleInterrupt() {
214
- if (this.running) {
212
+ if (this.deps.runner.isBusy()) {
215
213
  void this.deps.runner.abort();
216
214
  this.deps.frontend.showNotice("Stopping…");
217
215
  return;
@@ -256,18 +254,18 @@ export class TurnController {
256
254
  if (snapshot.contextTokens !== undefined && snapshot.contextWindow > 0) {
257
255
  line += ` · ctx ${((snapshot.contextTokens / snapshot.contextWindow) * 100).toFixed(0)}%`;
258
256
  }
259
- line += this.running ? " · running" : " · idle";
257
+ line += this.deps.runner.isBusy() ? " · running" : " · idle";
260
258
  this.deps.frontend.setStatus(`${this.deps.channelId} · ${line}`);
261
259
  }
262
260
  catch {
263
- this.deps.frontend.setStatus(`${this.deps.channelId} · ${this.running ? "running" : "ready"}`);
261
+ this.deps.frontend.setStatus(`${this.deps.channelId} · ${this.deps.runner.isBusy() ? "running" : "ready"}`);
264
262
  }
265
263
  }
266
264
  async shutdown() {
267
265
  if (this.exiting)
268
266
  return;
269
267
  this.exiting = true;
270
- if (this.running) {
268
+ if (this.deps.runner.isBusy()) {
271
269
  await this.deps.runner.abort().catch(() => { });
272
270
  // Never let a rejected turn (e.g. ctx.close() throwing in the turn's finally)
273
271
  // escape the race — that would skip frontend.stop() and strand the terminal in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true }); require('node:fs').rmSync('coverage', { recursive: true, force: true });\"",
25
- "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src = 'src/playbooks', dst = 'dist/playbooks'; fs.rmSync(dst, { recursive: true, force: true }); fs.mkdirSync(dst, { recursive: true }); for (const f of fs.readdirSync(src)) if (f.endsWith('.md')) fs.copyFileSync(src + '/' + f, dst + '/' + f); fs.chmodSync('dist/main.js', 0o755)\"",
25
+ "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src = 'src/playbooks', dst = 'dist/playbooks'; fs.mkdirSync(dst, { recursive: true }); for (const f of fs.readdirSync(src)) if (f.endsWith('.md')) fs.copyFileSync(src + '/' + f, dst + '/' + f); fs.chmodSync('dist/main.js', 0o755)\"",
26
26
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
27
27
  "lint": "biome check .",
28
28
  "typecheck": "tsc --noEmit -p tsconfig.json",