@oyasmi/pipiclaw 0.8.8-beta.2 → 0.8.8

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.
@@ -12,6 +12,7 @@ export declare class ChannelRunner implements AgentRunner {
12
12
  private readonly appHomeDir;
13
13
  private readonly authConfigPath;
14
14
  private readonly modelsConfigPath;
15
+ private readonly onSessionEvent?;
15
16
  private readonly workspaceDir;
16
17
  private session;
17
18
  private agent;
@@ -74,6 +74,7 @@ export class ChannelRunner {
74
74
  this.appHomeDir = paths.appHomeDir;
75
75
  this.authConfigPath = paths.authConfigPath;
76
76
  this.modelsConfigPath = paths.modelsConfigPath;
77
+ this.onSessionEvent = paths.onSessionEvent;
77
78
  const executor = createExecutor();
78
79
  this.executor = executor;
79
80
  this.workspaceDir = resolve(dirname(channelDir));
@@ -1028,6 +1029,13 @@ export class ChannelRunner {
1028
1029
  subscribeToSessionEvents() {
1029
1030
  this.sessionUnsubscribe?.();
1030
1031
  this.sessionUnsubscribe = this.session.subscribe((event) => {
1032
+ // Observation is deliberately before our consumer and must never alter a turn.
1033
+ try {
1034
+ this.onSessionEvent?.(event, this.channelId);
1035
+ }
1036
+ catch (err) {
1037
+ log.logWarning(`[${this.channelId}] session observer failed`, errorMessage(err));
1038
+ }
1031
1039
  if (isRecord(event) && event.type === "message_start" && this.turn.phase === "preparing") {
1032
1040
  this.turn.phase = "streaming";
1033
1041
  }
@@ -3,6 +3,8 @@ export interface RunnerFactoryPaths {
3
3
  appHomeDir: string;
4
4
  authConfigPath: string;
5
5
  modelsConfigPath: string;
6
+ /** Optional, side-effect-free observer used by the behavior-eval harness. */
7
+ onSessionEvent?: (event: unknown, channelId: string) => void;
6
8
  }
7
9
  export declare function getOrCreateRunner(channelId: string, channelDir: string, paths: RunnerFactoryPaths): AgentRunner;
8
10
  export declare function resetRunner(channelId: string, paths?: RunnerFactoryPaths, channelDir?: string): void;
@@ -1,6 +1,6 @@
1
1
  import { type Executor } from "../executor.js";
2
2
  import { PipiclawSettingsManager } from "../settings.js";
3
- import { DingTalkBot, type DingTalkConfig, type DingTalkHandler } from "./dingtalk.js";
3
+ import { DingTalkBot, type DingTalkConfig, type DingTalkEvent, type DingTalkHandler } from "./dingtalk.js";
4
4
  import { ChannelStore } from "./store.js";
5
5
  export interface BootstrapPaths {
6
6
  appName: string;
@@ -37,6 +37,13 @@ export interface AppContext {
37
37
  export interface RuntimeContext {
38
38
  handler: DingTalkHandler;
39
39
  store: ChannelStore;
40
+ /** Production driver instance, exposed so evals can invoke the real scan path. */
41
+ taskDriver: {
42
+ start(): void;
43
+ stop(): void;
44
+ nudge?(): void;
45
+ runOnce?: (now?: Date) => Promise<void>;
46
+ };
40
47
  shutdown: (reason?: NodeJS.Signals | "manual") => Promise<void>;
41
48
  }
42
49
  export declare const DEFAULT_BOOTSTRAP_PATHS: BootstrapPaths;
@@ -70,6 +77,10 @@ interface RuntimeContextOptions {
70
77
  stop(): void;
71
78
  nudge?(): void;
72
79
  };
80
+ /** Receives raw SDK session events after subscription, without changing runtime handling. */
81
+ observer?: (event: unknown, channelId: string) => void;
82
+ /** Receives TaskDriver dispatch outcomes; used only by isolated evaluation workers. */
83
+ onTaskDriverDispatch?: (event: DingTalkEvent, accepted: boolean) => void;
73
84
  startServices?: boolean;
74
85
  registerSignalHandlers?: boolean;
75
86
  }
@@ -423,6 +423,7 @@ export function createRuntimeContext(options) {
423
423
  appHomeDir: options.paths.appHomeDir,
424
424
  authConfigPath: options.paths.authConfigPath,
425
425
  modelsConfigPath: options.paths.modelsConfigPath,
426
+ onSessionEvent: options.observer,
426
427
  });
427
428
  channelRunners.set(channelId, runner);
428
429
  }
@@ -714,6 +715,7 @@ export function createRuntimeContext(options) {
714
715
  getKnownChannelIds: () => channelRunners.keys(),
715
716
  isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
716
717
  dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
718
+ onDispatch: options.onTaskDriverDispatch,
717
719
  getSettings: () => {
718
720
  runtimeSettingsManager.reload();
719
721
  return runtimeSettingsManager.getTaskDriverSettings();
@@ -772,6 +774,7 @@ export function createRuntimeContext(options) {
772
774
  appHomeDir: options.paths.appHomeDir,
773
775
  authConfigPath: options.paths.authConfigPath,
774
776
  modelsConfigPath: options.paths.modelsConfigPath,
777
+ onSessionEvent: options.observer,
775
778
  }, channelDir);
776
779
  }
777
780
  const storageFlushes = [
@@ -811,6 +814,7 @@ export function createRuntimeContext(options) {
811
814
  handler,
812
815
  store,
813
816
  bot,
817
+ taskDriver,
814
818
  shutdown: shutdownWithReason,
815
819
  };
816
820
  }
@@ -6,6 +6,8 @@ export interface TaskDriverOptions {
6
6
  getKnownChannelIds?: () => Iterable<string>;
7
7
  isChannelActive: (channelId: string) => boolean;
8
8
  dispatch: (event: DingTalkEvent) => boolean | Promise<boolean>;
9
+ /** Optional observability hook. It runs after every production dispatch attempt. */
10
+ onDispatch?: (event: DingTalkEvent, accepted: boolean) => void;
9
11
  getSettings: () => PipiclawTaskDriverSettings;
10
12
  /** Master autonomy switch (`tools.tasks.enabled`); re-read every tick. Defaults to on. */
11
13
  isEnabled?: () => boolean;
@@ -49,6 +51,7 @@ export declare class TaskDriver {
49
51
  */
50
52
  private readonly lastDispatchedTaskId;
51
53
  constructor(options: TaskDriverOptions);
54
+ private observeDispatch;
52
55
  start(): void;
53
56
  stop(): void;
54
57
  /**
@@ -92,7 +92,8 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
92
92
  text: `[TASK_DRIVER:${entry.id}] Resume task ${entry.id}. ${capsule}${repair} ` +
93
93
  `Open tasks/${entry.id}.md and read ${join(PLAYBOOKS_DIR, "task-driving.md")} before acting. ` +
94
94
  "Advance the next concrete step under the task's current control, acceptance, approval, and verification state. " +
95
- `If complete or waiting, use the matching task_manage lifecycle/checkpoint action from the playbook.${verificationInstruction}`,
95
+ `If complete or waiting, use the matching task_manage lifecycle/checkpoint action from the playbook.${verificationInstruction} ` +
96
+ "If the task explicitly says there is no change and no tool action is needed, do not call task_manage; respond with exactly [SILENT]. Otherwise, if this wake produces no user-visible change or result, respond with exactly [SILENT].",
96
97
  ts: String(nowMs),
97
98
  conversationId: "",
98
99
  conversationType: channelId.startsWith("group_") ? "2" : "1",
@@ -178,6 +179,14 @@ export class TaskDriver {
178
179
  */
179
180
  this.lastDispatchedTaskId = new Map();
180
181
  }
182
+ observeDispatch(event, accepted) {
183
+ try {
184
+ this.options.onDispatch?.(event, accepted);
185
+ }
186
+ catch (error) {
187
+ log.logWarning("Task driver dispatch observer failed", errorMessage(error));
188
+ }
189
+ }
181
190
  start() {
182
191
  if (this.loopActive)
183
192
  return;
@@ -320,7 +329,9 @@ export class TaskDriver {
320
329
  if (!escalationReason)
321
330
  continue;
322
331
  governanceHandled = true;
323
- const accepted = await this.options.dispatch(taskEscalationEvent(channelId, candidate, escalationReason, nowMs));
332
+ const escalationEvent = taskEscalationEvent(channelId, candidate, escalationReason, nowMs);
333
+ const accepted = await this.options.dispatch(escalationEvent);
334
+ this.observeDispatch(escalationEvent, accepted);
324
335
  if (accepted && (await escalateTask(channelDir, candidate.id, escalationReason))) {
325
336
  dispatched++;
326
337
  lastDispatchOffset = offset;
@@ -380,6 +391,7 @@ export class TaskDriver {
380
391
  ? createCycleStartEvent(channelId, entry, nowMs)
381
392
  : createTaskDriverEvent(channelId, entry, nowMs);
382
393
  const accepted = await this.options.dispatch(event);
394
+ this.observeDispatch(event, accepted);
383
395
  if (!accepted && claim)
384
396
  await releaseTaskAttemptClaim(channelDir, entry.id, claim, now);
385
397
  this.attempts.set(key, { fingerprint, atMs: nowMs, accepted });
@@ -161,7 +161,9 @@ function isDeniedSystemPath(path) {
161
161
  return SYSTEM_DENY_PREFIXES.some((prefix) => startsWithPathPrefix(path, normalize(prefix)));
162
162
  }
163
163
  function matchesConfiguredPath(path, entries, ctx) {
164
- return entries.map((entry) => resolveConfiguredPath(entry, ctx)).some((entry) => startsWithPathPrefix(path, entry));
164
+ return entries
165
+ .map((entry) => resolveForGuard(resolveConfiguredPath(entry, ctx), ctx))
166
+ .some((entry) => startsWithPathPrefix(path, entry));
165
167
  }
166
168
  function pathAllowedByDefaults(path, ctx) {
167
169
  const homeDir = ctx.homeDir ?? homedir();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.8-beta.2",
3
+ "version": "0.8.8",
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": {
@@ -29,6 +29,10 @@
29
29
  "deadcode": "knip",
30
30
  "test": "vitest --run",
31
31
  "test:e2e": "vitest --run --config vitest.config.e2e.ts",
32
+ "eval:build": "tsc -p tsconfig.evals.json && node -e \"const fs=require('node:fs'); fs.cpSync('src/playbooks','dist-evals/src/playbooks',{recursive:true})\"",
33
+ "eval": "npm run eval:build && node dist-evals/evals/harness/run.js",
34
+ "eval:diff": "npm run eval:build && node dist-evals/evals/harness/diff.js",
35
+ "eval:promote": "npm run eval:build && node dist-evals/evals/harness/promote.js",
32
36
  "test:coverage": "vitest --run --coverage",
33
37
  "check": "npm run lint && npm run typecheck && npm run deadcode && npm run test",
34
38
  "prepublishOnly": "npm run clean && npm run build && npm run check"