@oyasmi/pipiclaw 0.8.5 → 0.8.7-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +27 -10
- package/dist/agent/command-extension.d.ts +1 -0
- package/dist/agent/command-extension.js +6 -0
- package/dist/agent/commands.js +6 -0
- package/dist/agent/session-events.js +17 -5
- package/dist/agent/types.d.ts +1 -0
- package/dist/log.d.ts +12 -20
- package/dist/log.js +195 -198
- package/dist/memory/bootstrap.d.ts +5 -0
- package/dist/memory/bootstrap.js +14 -4
- package/dist/memory/candidates.d.ts +2 -0
- package/dist/memory/candidates.js +13 -3
- package/dist/memory/commands.d.ts +6 -0
- package/dist/memory/commands.js +112 -0
- package/dist/memory/consolidation.d.ts +3 -0
- package/dist/memory/consolidation.js +68 -26
- package/dist/memory/files.d.ts +13 -0
- package/dist/memory/files.js +65 -8
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +38 -7
- package/dist/memory/maintenance-jobs.js +48 -23
- package/dist/memory/metadata.d.ts +60 -0
- package/dist/memory/metadata.js +135 -0
- package/dist/memory/policy.d.ts +3 -0
- package/dist/memory/policy.js +19 -0
- package/dist/memory/post-turn-review.d.ts +11 -1
- package/dist/memory/post-turn-review.js +78 -19
- package/dist/memory/promotion.d.ts +5 -2
- package/dist/memory/promotion.js +3 -1
- package/dist/memory/recall.d.ts +3 -0
- package/dist/memory/recall.js +27 -5
- package/dist/memory/review-log.d.ts +2 -0
- package/dist/memory/review-log.js +15 -0
- package/dist/memory/session-corpus.js +11 -3
- package/dist/memory/session-search.js +8 -4
- package/dist/memory/session.d.ts +1 -0
- package/dist/memory/session.js +3 -1
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +1 -0
- package/dist/memory/source-window.d.ts +25 -0
- package/dist/memory/source-window.js +64 -0
- package/dist/memory/tombstones.d.ts +12 -0
- package/dist/memory/tombstones.js +44 -0
- package/dist/memory/transcript.js +26 -3
- package/dist/runtime/bootstrap.d.ts +1 -0
- package/dist/runtime/bootstrap.js +42 -11
- package/dist/runtime/dingtalk.js +19 -6
- package/dist/runtime/events.d.ts +2 -0
- package/dist/runtime/events.js +14 -7
- package/dist/runtime/store.d.ts +4 -6
- package/dist/runtime/store.js +44 -40
- package/dist/runtime/task-commands.js +1 -1
- package/dist/security/logger.d.ts +3 -1
- package/dist/security/logger.js +33 -10
- package/dist/settings.js +1 -1
- package/dist/shared/jsonl-appender.d.ts +27 -8
- package/dist/shared/jsonl-appender.js +128 -41
- package/dist/tasks/control.js +9 -3
- package/dist/tasks/store.d.ts +1 -0
- package/dist/tasks/store.js +11 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/edit.js +1 -1
- package/dist/tools/grep.js +1 -1
- package/dist/tools/memory-manage.d.ts +1 -1
- package/dist/tools/memory-manage.js +27 -6
- package/dist/tools/read.js +1 -1
- package/dist/tools/task-manage.js +2 -2
- package/dist/tools/write-content.js +1 -1
- package/dist/tui/app.js +17 -0
- package/dist/usage/ledger.d.ts +4 -0
- package/dist/usage/ledger.js +3 -1
- package/dist/web/client.js +3 -3
- package/package.json +1 -1
|
@@ -4,8 +4,9 @@ import { mkdir, readFile, writeFile } from "fs/promises";
|
|
|
4
4
|
import { dirname, join, resolve } from "path";
|
|
5
5
|
import { createExecutor } from "../executor.js";
|
|
6
6
|
import * as log from "../log.js";
|
|
7
|
-
import {
|
|
7
|
+
import { buildFirstTurnMemoryBootstrapResult } from "../memory/bootstrap.js";
|
|
8
8
|
import { createMemoryCandidateStore } from "../memory/candidates.js";
|
|
9
|
+
import { handleMemoryCommand } from "../memory/commands.js";
|
|
9
10
|
import { getChannelMemoryPath } from "../memory/files.js";
|
|
10
11
|
import { MemoryLifecycle } from "../memory/lifecycle.js";
|
|
11
12
|
import { applyMemoryActivityToState, updateMemoryMaintenanceState, } from "../memory/maintenance-state.js";
|
|
@@ -106,6 +107,7 @@ export class ChannelRunner {
|
|
|
106
107
|
this.memoryLifecycle = new MemoryLifecycle({
|
|
107
108
|
channelId: this.channelId,
|
|
108
109
|
channelDir: this.channelDir,
|
|
110
|
+
appHomeDir: this.appHomeDir,
|
|
109
111
|
getMessages: () => this.session.messages,
|
|
110
112
|
getSessionEntries: () => this.sessionManager.getBranch(),
|
|
111
113
|
getModel: () => this.session.model ?? this.activeModel,
|
|
@@ -190,6 +192,8 @@ export class ChannelRunner {
|
|
|
190
192
|
let recalledContextText = "";
|
|
191
193
|
let taskDigestText = "";
|
|
192
194
|
let durableMemoryBootstrapText = "";
|
|
195
|
+
let bootstrapCandidateIds = [];
|
|
196
|
+
let bootstrapPrepared = false;
|
|
193
197
|
try {
|
|
194
198
|
await this.ensureSessionReady();
|
|
195
199
|
await this.maybeRestorePrimaryModel();
|
|
@@ -208,6 +212,12 @@ export class ChannelRunner {
|
|
|
208
212
|
// Channel facts are turn-dynamic by design (spec 025 §7.3): keeping them out of the
|
|
209
213
|
// system prompt is what lets every channel in a workspace share one cached prefix.
|
|
210
214
|
promptText = `${this.renderChannelTurnContext()}\n\n<user_message>\n${promptText}\n</user_message>`;
|
|
215
|
+
if (this.firstTurnMemoryBootstrapPending) {
|
|
216
|
+
const bootstrap = await this.buildFirstTurnMemoryBootstrap();
|
|
217
|
+
durableMemoryBootstrapText = bootstrap.renderedText;
|
|
218
|
+
bootstrapCandidateIds = bootstrap.includedCandidateIds;
|
|
219
|
+
bootstrapPrepared = true;
|
|
220
|
+
}
|
|
211
221
|
const recallSettings = this.settingsManager.getMemoryRecallSettings();
|
|
212
222
|
if (recallSettings.enabled) {
|
|
213
223
|
const recall = await recallRelevantMemory({
|
|
@@ -219,6 +229,7 @@ export class ChannelRunner {
|
|
|
219
229
|
maxInjected: recallSettings.maxInjected,
|
|
220
230
|
maxChars: recallSettings.maxChars,
|
|
221
231
|
rerankWithModel: recallSettings.rerankWithModel,
|
|
232
|
+
excludedCandidateIds: bootstrapCandidateIds,
|
|
222
233
|
// Let shouldUseModelRerank's own memory-intent gate decide (it already handles
|
|
223
234
|
// Chinese phrasing) — forcing autoRerank for every Han-script message triggered a
|
|
224
235
|
// model rerank (up to 8s) on nearly every Chinese turn once memory filled up.
|
|
@@ -243,12 +254,8 @@ export class ChannelRunner {
|
|
|
243
254
|
promptText = `${taskDigestText}\n\n${promptText}`;
|
|
244
255
|
}
|
|
245
256
|
}
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
if (durableMemoryBootstrapText) {
|
|
249
|
-
promptText = `${durableMemoryBootstrapText}\n\n${promptText}`;
|
|
250
|
-
}
|
|
251
|
-
this.firstTurnMemoryBootstrapPending = false;
|
|
257
|
+
if (durableMemoryBootstrapText) {
|
|
258
|
+
promptText = `${durableMemoryBootstrapText}\n\n${promptText}`;
|
|
252
259
|
}
|
|
253
260
|
}
|
|
254
261
|
// Estimated against the fully assembled prompt (recall + task digest + bootstrap all
|
|
@@ -267,12 +274,17 @@ export class ChannelRunner {
|
|
|
267
274
|
await this.sessionResourceGate.runPrompt(async () => {
|
|
268
275
|
await this.session.prompt(text);
|
|
269
276
|
promptSubmitted = true;
|
|
277
|
+
if (bootstrapPrepared)
|
|
278
|
+
this.firstTurnMemoryBootstrapPending = false;
|
|
270
279
|
});
|
|
271
280
|
}
|
|
272
281
|
catch (err) {
|
|
273
282
|
this.runState.stopReason = "error";
|
|
274
283
|
this.runState.errorMessage = errorMessage(err);
|
|
275
|
-
log.
|
|
284
|
+
log.logEvent("error", "agent.turn.failed", "Runner failed", {
|
|
285
|
+
ctx: this.runState.logCtx ?? { channelId: this.channelId },
|
|
286
|
+
fields: { error: this.runState.errorMessage },
|
|
287
|
+
});
|
|
276
288
|
}
|
|
277
289
|
},
|
|
278
290
|
getRunError: () => ({
|
|
@@ -317,7 +329,10 @@ export class ChannelRunner {
|
|
|
317
329
|
catch (err) {
|
|
318
330
|
this.runState.stopReason = "error";
|
|
319
331
|
this.runState.errorMessage = errorMessage(err);
|
|
320
|
-
log.
|
|
332
|
+
log.logEvent("error", "agent.turn.failed", "Runner failed", {
|
|
333
|
+
ctx: this.runState.logCtx ?? { channelId: this.channelId },
|
|
334
|
+
fields: { error: this.runState.errorMessage },
|
|
335
|
+
});
|
|
321
336
|
}
|
|
322
337
|
finally {
|
|
323
338
|
this.turn.phase = "finishing";
|
|
@@ -457,6 +472,7 @@ export class ChannelRunner {
|
|
|
457
472
|
errorMessage: this.runState.errorMessage,
|
|
458
473
|
usage: { ...this.runState.totalUsage, cost: { ...this.runState.totalUsage.cost } },
|
|
459
474
|
durationMs: Date.now() - startedAt,
|
|
475
|
+
silent: this.runState.finalOutcome.kind === "silent",
|
|
460
476
|
};
|
|
461
477
|
}
|
|
462
478
|
async handleBuiltinCommand(ctx, command) {
|
|
@@ -882,6 +898,7 @@ export class ChannelRunner {
|
|
|
882
898
|
refreshSessionResources: async () => {
|
|
883
899
|
await this.refreshSessionResources();
|
|
884
900
|
},
|
|
901
|
+
runMemoryCommand: async (args) => handleMemoryCommand({ channelDir: this.channelDir, args }),
|
|
885
902
|
}),
|
|
886
903
|
],
|
|
887
904
|
// Pipiclaw owns the base prompt: with a custom prompt present, pi emits no
|
|
@@ -1028,7 +1045,7 @@ export class ChannelRunner {
|
|
|
1028
1045
|
readOptionalFile(getChannelMemoryPath(this.channelDir)),
|
|
1029
1046
|
readOptionalFile(join(this.workspaceDir, "MEMORY.md")),
|
|
1030
1047
|
]);
|
|
1031
|
-
return
|
|
1048
|
+
return buildFirstTurnMemoryBootstrapResult({
|
|
1032
1049
|
channelMemory,
|
|
1033
1050
|
workspaceMemory,
|
|
1034
1051
|
});
|
|
@@ -10,5 +10,6 @@ export interface PipiclawCommandExtensionOptions {
|
|
|
10
10
|
getLastResponseModel?: () => string | undefined;
|
|
11
11
|
switchModel: (model: Model<Api>) => Promise<void>;
|
|
12
12
|
refreshSessionResources: () => Promise<void>;
|
|
13
|
+
runMemoryCommand: (args: string) => Promise<string>;
|
|
13
14
|
}
|
|
14
15
|
export declare function createCommandExtension(options: PipiclawCommandExtensionOptions): ExtensionFactory;
|
|
@@ -41,6 +41,12 @@ function sendCommandResult(sender, text) {
|
|
|
41
41
|
}
|
|
42
42
|
export function createCommandExtension(options) {
|
|
43
43
|
return (pi) => {
|
|
44
|
+
pi.registerCommand("memory", {
|
|
45
|
+
description: sessionCommandDescription("memory"),
|
|
46
|
+
handler: async (args) => {
|
|
47
|
+
sendCommandResult(pi, await options.runMemoryCommand(args));
|
|
48
|
+
},
|
|
49
|
+
});
|
|
44
50
|
pi.registerCommand("session", {
|
|
45
51
|
description: sessionCommandDescription("session"),
|
|
46
52
|
handler: async () => {
|
package/dist/agent/commands.js
CHANGED
|
@@ -87,6 +87,12 @@ export const BUILT_IN_COMMANDS = [
|
|
|
87
87
|
* extension registration in `command-extension.ts`.
|
|
88
88
|
*/
|
|
89
89
|
export const SESSION_COMMANDS = [
|
|
90
|
+
{
|
|
91
|
+
name: "memory",
|
|
92
|
+
argumentHint: "[status|list|show <id>|pending]",
|
|
93
|
+
description: "Inspect active memory, metadata, recall statistics, tombstones, and pending suggestions",
|
|
94
|
+
examples: ["/memory status", "/memory list", "/memory show m-1234abcd", "/memory pending"],
|
|
95
|
+
},
|
|
90
96
|
{
|
|
91
97
|
name: "session",
|
|
92
98
|
description: "Show current session state, message stats, token usage, and model info",
|
|
@@ -251,7 +251,10 @@ export async function handleSessionEvent(event, context) {
|
|
|
251
251
|
}
|
|
252
252
|
if (isAutoCompactionStartEvent(event)) {
|
|
253
253
|
const label = "Compacting context...";
|
|
254
|
-
log.
|
|
254
|
+
log.logEvent("info", "agent.compaction.started", "Compaction started", {
|
|
255
|
+
ctx: logCtx,
|
|
256
|
+
fields: { reason: event.reason },
|
|
257
|
+
});
|
|
255
258
|
if (showProgress) {
|
|
256
259
|
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", label), false), "compaction start");
|
|
257
260
|
}
|
|
@@ -260,14 +263,20 @@ export async function handleSessionEvent(event, context) {
|
|
|
260
263
|
if (isAutoCompactionEndEvent(event)) {
|
|
261
264
|
if (event.result) {
|
|
262
265
|
runState.lastCompactionError = undefined;
|
|
263
|
-
log.
|
|
266
|
+
log.logEvent("info", "agent.compaction.finished", "Compaction completed", {
|
|
267
|
+
ctx: logCtx,
|
|
268
|
+
fields: { tokensBefore: event.result.tokensBefore },
|
|
269
|
+
});
|
|
264
270
|
}
|
|
265
271
|
else if (event.aborted) {
|
|
266
|
-
log.
|
|
272
|
+
log.logEvent("info", "agent.compaction.aborted", "Compaction aborted", { ctx: logCtx });
|
|
267
273
|
}
|
|
268
274
|
else if (event.errorMessage) {
|
|
269
275
|
runState.lastCompactionError = event.errorMessage;
|
|
270
|
-
log.
|
|
276
|
+
log.logEvent("warn", "agent.compaction.failed", "Compaction failed", {
|
|
277
|
+
ctx: logCtx,
|
|
278
|
+
fields: { error: event.errorMessage },
|
|
279
|
+
});
|
|
271
280
|
if (showProgress) {
|
|
272
281
|
queue.enqueue(() => ctx.respond(formatProgressEntry("error", truncate(event.errorMessage ?? "Compaction failed", 200)), false), "compaction error");
|
|
273
282
|
}
|
|
@@ -275,7 +284,10 @@ export async function handleSessionEvent(event, context) {
|
|
|
275
284
|
return;
|
|
276
285
|
}
|
|
277
286
|
if (isAutoRetryStartEvent(event)) {
|
|
278
|
-
log.
|
|
287
|
+
log.logEvent("warn", "agent.retrying", "Retrying model request", {
|
|
288
|
+
ctx: logCtx,
|
|
289
|
+
fields: { attempt: event.attempt, maxAttempts: event.maxAttempts, error: event.errorMessage },
|
|
290
|
+
});
|
|
279
291
|
if (showProgress) {
|
|
280
292
|
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `Retrying (${event.attempt}/${event.maxAttempts})...`), false), "retry");
|
|
281
293
|
}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export interface AgentRunner {
|
|
|
38
38
|
errorMessage?: string;
|
|
39
39
|
usage?: UsageTotals;
|
|
40
40
|
durationMs?: number;
|
|
41
|
+
silent?: boolean;
|
|
41
42
|
}>;
|
|
42
43
|
handleBuiltinCommand(ctx: ChannelContext, command: RunnerBuiltInCommand): Promise<void>;
|
|
43
44
|
/** True if `text` is a slash command the runtime or session layer can handle. */
|
package/dist/log.d.ts
CHANGED
|
@@ -4,16 +4,6 @@ export interface LogContext {
|
|
|
4
4
|
channelName?: string;
|
|
5
5
|
}
|
|
6
6
|
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
7
|
-
export interface LogRecord {
|
|
8
|
-
ts: string;
|
|
9
|
-
level: LogLevel;
|
|
10
|
-
event: string;
|
|
11
|
-
channelId?: string;
|
|
12
|
-
userName?: string;
|
|
13
|
-
message: string;
|
|
14
|
-
details?: string;
|
|
15
|
-
fields?: Record<string, unknown>;
|
|
16
|
-
}
|
|
17
7
|
export interface LoggingConfig {
|
|
18
8
|
level: LogLevel;
|
|
19
9
|
file: {
|
|
@@ -22,24 +12,26 @@ export interface LoggingConfig {
|
|
|
22
12
|
maxFiles: number;
|
|
23
13
|
};
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
export interface LogOptions {
|
|
16
|
+
ctx?: LogContext;
|
|
17
|
+
details?: string;
|
|
18
|
+
fields?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/** Configure both console filtering and the optional structured file sink. */
|
|
29
21
|
export declare function configureLogging(config: LoggingConfig): void;
|
|
30
|
-
/**
|
|
31
|
-
* Toggle the human-readable console sink. The TUI disables it so structured
|
|
32
|
-
* logging does not corrupt the pi-tui frame (which owns stdout); the file sink
|
|
33
|
-
* is unaffected, so logs are still captured when file logging is enabled.
|
|
34
|
-
*/
|
|
22
|
+
/** The TUI owns stdout, so its runtime logs are file-only. */
|
|
35
23
|
export declare function setConsoleLoggingEnabled(enabled: boolean): void;
|
|
24
|
+
/** Wait for structured logs accepted so far to reach disk. */
|
|
25
|
+
export declare function flushLogging(): Promise<void>;
|
|
26
|
+
/** Emit one consistently formatted runtime event to stdout and the JSONL sink. */
|
|
27
|
+
export declare function logEvent(level: LogLevel, event: string, message: string, options?: LogOptions): void;
|
|
36
28
|
export declare function logToolStart(ctx: LogContext, toolName: string, label: string, args: Record<string, unknown>): void;
|
|
37
29
|
export declare function logToolSuccess(ctx: LogContext, toolName: string, durationMs: number, result: string): void;
|
|
38
30
|
export declare function logToolError(ctx: LogContext, toolName: string, durationMs: number, error: string): void;
|
|
39
31
|
export declare function logResponseStart(ctx: LogContext): void;
|
|
40
32
|
export declare function logThinking(ctx: LogContext, thinking: string): void;
|
|
41
33
|
export declare function logResponse(ctx: LogContext, text: string): void;
|
|
42
|
-
export declare function logInfo(message: string): void;
|
|
34
|
+
export declare function logInfo(message: string, details?: string): void;
|
|
43
35
|
export declare function logWarning(message: string, details?: string): void;
|
|
44
36
|
export declare function logModelFallback(ctx: LogContext, from: string, to: string, error: string): void;
|
|
45
37
|
export declare function logUsageSummary(ctx: LogContext, usage: {
|