@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.2-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 +9 -1
- package/dist/agent/channel-runner.js +51 -18
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +6 -7
- package/dist/agent/prompt/sections.js +9 -5
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/status-render.js +12 -12
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +28 -0
- package/dist/executor.js +120 -18
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +35 -38
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +31 -12
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +16 -38
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +19 -0
- package/dist/memory/recall.js +116 -24
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +15 -22
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +34 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +15 -15
- package/dist/playbooks/memory-and-learning.md +30 -23
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +36 -38
- package/dist/playbooks/task-planning.md +21 -21
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +16 -7
- package/dist/runtime/bootstrap.js +54 -13
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +30 -15
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +55 -56
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +37 -0
- package/dist/runtime/task-commands.js +108 -66
- package/dist/runtime/task-driver.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +61 -12
- package/dist/security/types.d.ts +9 -0
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +51 -19
- package/dist/subagents/discovery.js +93 -98
- package/dist/subagents/external/claude-code.js +40 -2
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +1 -1
- package/dist/subagents/runs.js +10 -9
- package/dist/subagents/tool.d.ts +31 -18
- package/dist/subagents/tool.js +592 -562
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -2
- package/dist/tools/bash.js +99 -76
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +276 -75
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +60 -44
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +54 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +3 -9
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +21 -8
- package/dist/tools/memory-manage.js +114 -103
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +100 -120
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +21 -43
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +1 -25
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +47 -47
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +49 -56
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +4 -4
- package/dist/tools/task-manage/verification.js +6 -8
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +9 -2
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -41
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/app.js +1 -1
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/tui/turn-controller.js +14 -4
- package/dist/usage/ledger.js +7 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -231
|
@@ -8,6 +8,7 @@ import type { RunnerFactoryPaths } from "./runner-factory.js";
|
|
|
8
8
|
import { type AgentRunner, type RunnerStatusSnapshot, type TurnStatus } from "./types.js";
|
|
9
9
|
export declare class ChannelRunner implements AgentRunner {
|
|
10
10
|
private readonly executor;
|
|
11
|
+
private readonly fileStore;
|
|
11
12
|
private readonly channelId;
|
|
12
13
|
private readonly channelDir;
|
|
13
14
|
private readonly appHomeDir;
|
|
@@ -113,6 +114,13 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
113
114
|
* often the larger half), and the last turn's dynamic context.
|
|
114
115
|
*/
|
|
115
116
|
renderContextReport(args?: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* `/help` — the static per-command listing from `commands.ts`, plus (top-level only) the
|
|
119
|
+
* workspace skills and prompt templates this session can actually invoke via `/skill:name` and
|
|
120
|
+
* `/<template-name>`. Neither list is knowable to `renderBuiltInHelp` itself (it is a pure
|
|
121
|
+
* function with no session state), so the runner appends it here (review 2026-08-24 §1.9).
|
|
122
|
+
*/
|
|
123
|
+
private renderHelpWithDiscovery;
|
|
116
124
|
/** `/subagents list`'s role-directory health tail — whatever this runner already discovered. */
|
|
117
125
|
getSubAgentDiscoverySnapshot(): SubAgentDiscoveryResult;
|
|
118
126
|
/**
|
|
@@ -206,7 +214,7 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
206
214
|
*/
|
|
207
215
|
private setSessionBaseToolsOverride;
|
|
208
216
|
private subscribeToSessionEvents;
|
|
209
|
-
/** Gated by the same master autonomy switch as
|
|
217
|
+
/** Gated by the same master autonomy switch as the task_* tools and the TaskDriver. */
|
|
210
218
|
private buildTaskDigestForTurn;
|
|
211
219
|
private buildFirstTurnMemoryBootstrap;
|
|
212
220
|
}
|
|
@@ -4,6 +4,7 @@ import { AgentSession, AgentSessionRuntime, convertToLlm, createExtensionRuntime
|
|
|
4
4
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
5
5
|
import { dirname, join, resolve } from "path";
|
|
6
6
|
import { createExecutor } from "../executor.js";
|
|
7
|
+
import { createFileStore } from "../file-store.js";
|
|
7
8
|
import * as log from "../log.js";
|
|
8
9
|
import { buildFirstTurnMemoryBootstrapResult, FIRST_TURN_BOOTSTRAP_MAX_UNITS, } from "../memory/bootstrap.js";
|
|
9
10
|
import { createMemoryCandidateStore } from "../memory/candidates.js";
|
|
@@ -11,7 +12,7 @@ import { handleMemoryCommand } from "../memory/commands.js";
|
|
|
11
12
|
import { getChannelMemoryPath } from "../memory/files.js";
|
|
12
13
|
import { MemoryLifecycle } from "../memory/lifecycle.js";
|
|
13
14
|
import { createMemoryActivityRecorder, } from "../memory/maintenance-state.js";
|
|
14
|
-
import { MEMORY_RECALL_MAX_UNITS, recallRelevantMemory } from "../memory/recall.js";
|
|
15
|
+
import { findPreviousUserText, MEMORY_RECALL_MAX_UNITS, recallRelevantMemory } from "../memory/recall.js";
|
|
15
16
|
import { buildTaskDigest, TASK_AGENDA_MAX_UNITS } from "../memory/task-digest.js";
|
|
16
17
|
import { getApiKeyForModel } from "../models/api-keys.js";
|
|
17
18
|
import { createModelRuntime, defaultModel, findExactModelReferenceMatch, formatModelReference, hasKnownModelPricing, resolveInitialModel, wrapModelRegistry, } from "../models/utils.js";
|
|
@@ -21,7 +22,7 @@ import { resolveProjectScope } from "../runtime/project-scope-store.js";
|
|
|
21
22
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
22
23
|
import { resolveProjectAccessPolicy } from "../security/project-scope.js";
|
|
23
24
|
import { formatConfigDiagnostic } from "../shared/config-diagnostic.js";
|
|
24
|
-
import { formatLocalTime, localStampForFilename } from "../shared/local-time.js";
|
|
25
|
+
import { formatLocalTime, localStampForFilename, parseLocalTime } from "../shared/local-time.js";
|
|
25
26
|
import { countPromptUnits } from "../shared/prompt-units.js";
|
|
26
27
|
import { errorMessage } from "../shared/text-utils.js";
|
|
27
28
|
import { isRecord } from "../shared/type-guards.js";
|
|
@@ -111,6 +112,7 @@ export class ChannelRunner {
|
|
|
111
112
|
this.mediaSender = paths.mediaSender;
|
|
112
113
|
const executor = createExecutor();
|
|
113
114
|
this.executor = executor;
|
|
115
|
+
this.fileStore = createFileStore();
|
|
114
116
|
this.workspaceDir = resolve(dirname(channelDir));
|
|
115
117
|
// Resolve and freeze this generation's ProjectScope (spec 043, D2/D3/D4.2). A channel with
|
|
116
118
|
// no persisted selection gets the app default, materialized as its first selection right
|
|
@@ -298,6 +300,7 @@ export class ChannelRunner {
|
|
|
298
300
|
if (recallSettings.enabled) {
|
|
299
301
|
const recall = await recallRelevantMemory({
|
|
300
302
|
query: clippedInput,
|
|
303
|
+
contextQuery: findPreviousUserText(this.session.messages),
|
|
301
304
|
channelId: this.channelId,
|
|
302
305
|
workspaceDir: this.workspaceDir,
|
|
303
306
|
channelDir: this.channelDir,
|
|
@@ -588,26 +591,27 @@ export class ChannelRunner {
|
|
|
588
591
|
try {
|
|
589
592
|
switch (command.name) {
|
|
590
593
|
case "help":
|
|
591
|
-
await this.sendCommandReply(ctx,
|
|
594
|
+
await this.sendCommandReply(ctx, this.renderHelpWithDiscovery(command.args), "help");
|
|
592
595
|
return;
|
|
593
596
|
case "context":
|
|
594
|
-
await this.sendCommandReply(ctx, this.renderContextReport(command.args));
|
|
597
|
+
await this.sendCommandReply(ctx, this.renderContextReport(command.args), "context");
|
|
595
598
|
return;
|
|
596
599
|
case "stop":
|
|
597
|
-
await this.sendCommandReply(ctx, "当前没有运行中的回合,`/stop` 只在回合进行中有意义。");
|
|
600
|
+
await this.sendCommandReply(ctx, "当前没有运行中的回合,`/stop` 只在回合进行中有意义。", "stop");
|
|
598
601
|
return;
|
|
599
602
|
case "steer":
|
|
600
603
|
this.requireQueuedMessage(command.args, "steer");
|
|
601
|
-
await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可,不用 `/steer`。");
|
|
604
|
+
await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可,不用 `/steer`。", "steer");
|
|
602
605
|
return;
|
|
603
606
|
case "followup":
|
|
604
607
|
this.requireQueuedMessage(command.args, "followup");
|
|
605
|
-
await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可;`/followup` 用于回合进行中排队。");
|
|
608
|
+
await this.sendCommandReply(ctx, "当前没有运行中的回合,直接发消息即可;`/followup` 用于回合进行中排队。", "followup");
|
|
606
609
|
return;
|
|
607
610
|
default: {
|
|
608
|
-
// The
|
|
609
|
-
//
|
|
610
|
-
// narrowed parameter type makes that a
|
|
611
|
+
// The stateless report commands (events/tasks/status/usage/subagents/project — see
|
|
612
|
+
// `BUILT_IN_COMMANDS`'s `runnerHandled: false` entries) are routed to their own
|
|
613
|
+
// handlers upstream and never reach here; the narrowed parameter type makes that a
|
|
614
|
+
// compile-time guarantee.
|
|
611
615
|
const _exhaustive = command.name;
|
|
612
616
|
throw new Error(`Unhandled built-in command: ${String(_exhaustive)}`);
|
|
613
617
|
}
|
|
@@ -616,7 +620,7 @@ export class ChannelRunner {
|
|
|
616
620
|
catch (err) {
|
|
617
621
|
const errMsg = errorMessage(err);
|
|
618
622
|
log.logWarning(`[${this.channelId}] Built-in command failed`, errMsg);
|
|
619
|
-
await this.sendCommandReply(ctx, `命令执行失败:${errMsg}
|
|
623
|
+
await this.sendCommandReply(ctx, `命令执行失败:${errMsg}`, command.name);
|
|
620
624
|
}
|
|
621
625
|
}
|
|
622
626
|
/**
|
|
@@ -631,7 +635,7 @@ export class ChannelRunner {
|
|
|
631
635
|
if (!name) {
|
|
632
636
|
return false;
|
|
633
637
|
}
|
|
634
|
-
if (isKnownCommandName(name)) {
|
|
638
|
+
if (isKnownCommandName(name, this.currentSkills.skills.map((skill) => skill.name.toLowerCase()))) {
|
|
635
639
|
return true;
|
|
636
640
|
}
|
|
637
641
|
return this.session.promptTemplates.some((template) => template.name.toLowerCase() === name);
|
|
@@ -754,6 +758,30 @@ export class ChannelRunner {
|
|
|
754
758
|
detail: args.trim().toLowerCase() === "detail",
|
|
755
759
|
});
|
|
756
760
|
}
|
|
761
|
+
/**
|
|
762
|
+
* `/help` — the static per-command listing from `commands.ts`, plus (top-level only) the
|
|
763
|
+
* workspace skills and prompt templates this session can actually invoke via `/skill:name` and
|
|
764
|
+
* `/<template-name>`. Neither list is knowable to `renderBuiltInHelp` itself (it is a pure
|
|
765
|
+
* function with no session state), so the runner appends it here (review 2026-08-24 §1.9).
|
|
766
|
+
*/
|
|
767
|
+
renderHelpWithDiscovery(args) {
|
|
768
|
+
const help = renderBuiltInHelp(args);
|
|
769
|
+
if (args.trim()) {
|
|
770
|
+
return help;
|
|
771
|
+
}
|
|
772
|
+
const sections = [help];
|
|
773
|
+
if (this.currentSkills.skills.length > 0) {
|
|
774
|
+
sections.push(`**Workspace skills** · 用 \`/skill:<名称>\` 调用\n\n${this.currentSkills.skills
|
|
775
|
+
.map((skill) => `- \`/skill:${skill.name}\` — ${skill.description}`)
|
|
776
|
+
.join("\n")}`);
|
|
777
|
+
}
|
|
778
|
+
if (this.session.promptTemplates.length > 0) {
|
|
779
|
+
sections.push(`**Prompt templates**\n\n${this.session.promptTemplates
|
|
780
|
+
.map((template) => `- \`/${template.name}\``)
|
|
781
|
+
.join("\n")}`);
|
|
782
|
+
}
|
|
783
|
+
return sections.join("\n\n");
|
|
784
|
+
}
|
|
757
785
|
/** `/subagents list`'s role-directory health tail — whatever this runner already discovered. */
|
|
758
786
|
getSubAgentDiscoverySnapshot() {
|
|
759
787
|
return this.subAgentDiscovery;
|
|
@@ -772,8 +800,11 @@ export class ChannelRunner {
|
|
|
772
800
|
"</runtime_turn_context>",
|
|
773
801
|
].join("\n");
|
|
774
802
|
}
|
|
775
|
-
async sendCommandReply(ctx, text) {
|
|
776
|
-
|
|
803
|
+
async sendCommandReply(ctx, text, commandName) {
|
|
804
|
+
// Command echoes are ephemeral control-plane traffic, not conversation: keep them out of
|
|
805
|
+
// log.jsonl so they are never re-consumed as memory-extraction input (review 2026-08-24 §1.2).
|
|
806
|
+
const title = commandName ? `/${commandName}` : undefined;
|
|
807
|
+
const delivered = await ctx.respondPlain(text, false, title);
|
|
777
808
|
if (!delivered) {
|
|
778
809
|
await ctx.replaceMessage(text);
|
|
779
810
|
await ctx.flush();
|
|
@@ -786,9 +817,9 @@ export class ChannelRunner {
|
|
|
786
817
|
*/
|
|
787
818
|
recordMemoryActivity(event) {
|
|
788
819
|
const maintenanceSettings = this.settingsManager.getMemoryMaintenanceSettings();
|
|
789
|
-
const eventTime =
|
|
790
|
-
const eligibleAfter =
|
|
791
|
-
? new Date(eventTime + Math.max(0, maintenanceSettings.minIdleMinutesBeforeLlmWork) * 60_000)
|
|
820
|
+
const eventTime = parseLocalTime(event.timestamp);
|
|
821
|
+
const eligibleAfter = eventTime !== undefined
|
|
822
|
+
? formatLocalTime(new Date(eventTime + Math.max(0, maintenanceSettings.minIdleMinutesBeforeLlmWork) * 60_000))
|
|
792
823
|
: undefined;
|
|
793
824
|
this.memoryActivityRecorder.record({ ...event, eligibleAfter });
|
|
794
825
|
}
|
|
@@ -1245,6 +1276,7 @@ export class ChannelRunner {
|
|
|
1245
1276
|
this.tasksEnabled = toolsLoad.config.tools.tasks.enabled;
|
|
1246
1277
|
const tools = createPipiclawTools({
|
|
1247
1278
|
executor: this.executor,
|
|
1279
|
+
fileStore: this.fileStore,
|
|
1248
1280
|
getCurrentModel: () => this.activeModel,
|
|
1249
1281
|
getAvailableModels: () => this.modelRegistry.getAvailable(),
|
|
1250
1282
|
resolveApiKey: async (model) => getApiKeyForModel(this.modelRegistry, model),
|
|
@@ -1328,12 +1360,13 @@ export class ChannelRunner {
|
|
|
1328
1360
|
refreshSessionResources: async () => {
|
|
1329
1361
|
await this.refreshSessionResources();
|
|
1330
1362
|
},
|
|
1363
|
+
skillsDir: join(this.workspaceDir, "skills"),
|
|
1331
1364
|
}).catch((err) => {
|
|
1332
1365
|
log.logWarning(`[${this.channelId}] session event handler failed`, errorMessage(err));
|
|
1333
1366
|
});
|
|
1334
1367
|
});
|
|
1335
1368
|
}
|
|
1336
|
-
/** Gated by the same master autonomy switch as
|
|
1369
|
+
/** Gated by the same master autonomy switch as the task_* tools and the TaskDriver. */
|
|
1337
1370
|
buildTaskDigestForTurn() {
|
|
1338
1371
|
const taskDigestSettings = this.settingsManager.getTaskDigestSettings();
|
|
1339
1372
|
return buildTaskDigest({
|
|
@@ -9,19 +9,16 @@ function buildSessionText(stats, currentModel, thinkingLevel, lastResponseModel)
|
|
|
9
9
|
? ` (actual: \`${lastResponseModel}\`)`
|
|
10
10
|
: "";
|
|
11
11
|
const sessionFile = stats.sessionFile ? `\`${basename(stats.sessionFile)}\`` : "(none)";
|
|
12
|
-
return
|
|
12
|
+
return `**会话**
|
|
13
13
|
|
|
14
|
-
- Session ID
|
|
15
|
-
- Session file
|
|
16
|
-
-
|
|
17
|
-
- Thinking level
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- Total messages: \`${stats.totalMessages}\`
|
|
23
|
-
- Tokens: \`${stats.tokens.total}\` (input \`${stats.tokens.input}\`, output \`${stats.tokens.output}\`, cache read \`${stats.tokens.cacheRead}\`, cache write \`${stats.tokens.cacheWrite}\`)
|
|
24
|
-
- Cost: \`$${stats.cost.toFixed(4)}\``;
|
|
14
|
+
- Session ID:\`${stats.sessionId}\`
|
|
15
|
+
- Session file:${sessionFile}
|
|
16
|
+
- 模型:${modelText}${actualText}
|
|
17
|
+
- Thinking level:\`${thinkingLevel}\`
|
|
18
|
+
- 消息:用户 \`${stats.userMessages}\` · 助手 \`${stats.assistantMessages}\` · 共 \`${stats.totalMessages}\`
|
|
19
|
+
- 工具调用:\`${stats.toolCalls}\` · 工具结果:\`${stats.toolResults}\`
|
|
20
|
+
- Tokens:\`${stats.tokens.total}\`(input \`${stats.tokens.input}\`,output \`${stats.tokens.output}\`,cache read \`${stats.tokens.cacheRead}\`,cache write \`${stats.tokens.cacheWrite}\`)
|
|
21
|
+
- Cost:\`$${stats.cost.toFixed(4)}\``;
|
|
25
22
|
}
|
|
26
23
|
async function runCompact(ctx, customInstructions) {
|
|
27
24
|
return await new Promise((resolve, reject) => {
|
|
@@ -40,12 +37,12 @@ function sendCommandResult(sender, text) {
|
|
|
40
37
|
});
|
|
41
38
|
}
|
|
42
39
|
function buildThinkingText(current, available) {
|
|
43
|
-
return
|
|
40
|
+
return `**Thinking**
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
- 当前档位:\`${current}\`
|
|
43
|
+
- 可用档位:${available.map((level) => `\`${level}\``).join(", ")}
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
用 \`/thinking <level>\` 设置档位,或 \`/thinking cycle\` 切到下一个支持的档位。`;
|
|
49
46
|
}
|
|
50
47
|
export function createCommandExtension(options) {
|
|
51
48
|
return (pi) => {
|
|
@@ -98,13 +95,13 @@ export function createCommandExtension(options) {
|
|
|
98
95
|
if (!args.trim()) {
|
|
99
96
|
const current = currentModel ? `\`${formatModelReference(currentModel)}\`` : "(none)";
|
|
100
97
|
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel) : "- (none)";
|
|
101
|
-
sendCommandResult(pi,
|
|
98
|
+
sendCommandResult(pi, `**模型**
|
|
102
99
|
|
|
103
|
-
|
|
100
|
+
当前模型:${current}
|
|
104
101
|
|
|
105
|
-
|
|
102
|
+
用 \`/model <provider/modelId>\`、\`/model <modelId>\` 或任意能唯一匹配的子串切换。
|
|
106
103
|
|
|
107
|
-
|
|
104
|
+
可用模型:
|
|
108
105
|
${available}`);
|
|
109
106
|
return;
|
|
110
107
|
}
|
|
@@ -112,19 +109,19 @@ ${available}`);
|
|
|
112
109
|
const available = availableModels.length > 0 ? formatModelList(availableModels, currentModel, 10) : "- (none)";
|
|
113
110
|
if (match.match) {
|
|
114
111
|
await options.switchModel(match.match);
|
|
115
|
-
sendCommandResult(pi, `已切换模型到 \`${formatModelReference(match.match)}
|
|
112
|
+
sendCommandResult(pi, `已切换模型到 \`${formatModelReference(match.match)}\``);
|
|
116
113
|
return;
|
|
117
114
|
}
|
|
118
115
|
if (match.ambiguous) {
|
|
119
116
|
sendCommandResult(pi, `未切换模型:\`${args.trim()}\` 匹配到多个模型。请提供更精确的 \`provider/modelId\`、\`modelId\` 或更长的片段。
|
|
120
117
|
|
|
121
|
-
|
|
118
|
+
可用模型:
|
|
122
119
|
${available}`);
|
|
123
120
|
return;
|
|
124
121
|
}
|
|
125
122
|
sendCommandResult(pi, `未找到模型 \`${args.trim()}\`。请使用精确的 \`provider/modelId\`、唯一的 \`modelId\`,或能唯一命中的片段字符串。
|
|
126
123
|
|
|
127
|
-
|
|
124
|
+
可用模型:
|
|
128
125
|
${available}`);
|
|
129
126
|
},
|
|
130
127
|
});
|
|
@@ -136,7 +133,7 @@ ${available}`);
|
|
|
136
133
|
withSession: async (nextCtx) => {
|
|
137
134
|
sentFromReplacement = true;
|
|
138
135
|
await options.refreshSessionResources();
|
|
139
|
-
await sendCommandResult(nextCtx, `已开启新会话。\n\nSession ID
|
|
136
|
+
await sendCommandResult(nextCtx, `已开启新会话。\n\nSession ID:\`${nextCtx.sessionManager.getSessionId()}\``);
|
|
140
137
|
},
|
|
141
138
|
});
|
|
142
139
|
if (result.cancelled) {
|
|
@@ -144,7 +141,7 @@ ${available}`);
|
|
|
144
141
|
}
|
|
145
142
|
else if (!sentFromReplacement) {
|
|
146
143
|
await options.refreshSessionResources();
|
|
147
|
-
sendCommandResult(pi, `已开启新会话。\n\nSession ID
|
|
144
|
+
sendCommandResult(pi, `已开启新会话。\n\nSession ID:\`${ctx.sessionManager.getSessionId()}\``);
|
|
148
145
|
}
|
|
149
146
|
},
|
|
150
147
|
});
|
|
@@ -155,8 +152,8 @@ ${available}`);
|
|
|
155
152
|
const result = await runCompact(ctx, customInstructions);
|
|
156
153
|
sendCommandResult(pi, `已压缩当前会话上下文。
|
|
157
154
|
|
|
158
|
-
-
|
|
159
|
-
-
|
|
155
|
+
- 压缩前 tokens:\`${result.tokensBefore}\`
|
|
156
|
+
- 摘要:
|
|
160
157
|
|
|
161
158
|
\`\`\`text
|
|
162
159
|
${result.summary}
|
package/dist/agent/commands.d.ts
CHANGED
|
@@ -16,10 +16,25 @@ export interface BuiltInCommand {
|
|
|
16
16
|
export type RunnerBuiltInCommand = BuiltInCommand & {
|
|
17
17
|
name: RunnerBuiltInCommandName;
|
|
18
18
|
};
|
|
19
|
+
/** One subcommand entry, as broadcast by `/help <name>` and consumed by `renderSubcommandUsage`. */
|
|
20
|
+
export interface CommandSubSpec {
|
|
21
|
+
name: string;
|
|
22
|
+
/** Argument syntax after the subcommand name, e.g. `<id>` or `<id> <wake|next|deadline> <值>`. */
|
|
23
|
+
args?: string;
|
|
24
|
+
description: string;
|
|
25
|
+
/** A concrete invocation; omitted only for the bare "no args" form. */
|
|
26
|
+
example?: string;
|
|
27
|
+
}
|
|
19
28
|
/**
|
|
20
29
|
* Single source of truth for a slash command's metadata. `HELP_TEXT`, the TUI
|
|
21
30
|
* autocomplete list, the busy-time hint, and the known-command set are all
|
|
22
31
|
* derived from these tables — do not hand-maintain those in parallel.
|
|
32
|
+
*
|
|
33
|
+
* `subcommands`, where present, is *also* the single source for that command's own `usage()`
|
|
34
|
+
* text (via `renderSubcommandUsage`) and for `/help <name>`'s detail view — see
|
|
35
|
+
* `test/commands-subcommands.test.ts`, which feeds every `subcommands[].example` back into the
|
|
36
|
+
* matching parser so the broadcast list and the parser can never drift apart again (review
|
|
37
|
+
* 2026-08-24 §1.1).
|
|
23
38
|
*/
|
|
24
39
|
export interface CommandSpec {
|
|
25
40
|
name: string;
|
|
@@ -27,10 +42,19 @@ export interface CommandSpec {
|
|
|
27
42
|
argumentHint?: string;
|
|
28
43
|
/** One-line description; used for `/help` and for editor autocomplete. */
|
|
29
44
|
description: string;
|
|
30
|
-
/** Concrete invocations shown under the command in `/help
|
|
45
|
+
/** Concrete invocations shown under the command in `/help`; only used when `subcommands` is absent. */
|
|
31
46
|
examples?: string[];
|
|
32
47
|
/** Whether the command is accepted while a task is streaming. */
|
|
33
48
|
availableWhileBusy?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* True for the built-ins `ChannelRunner.handleBuiltinCommand` handles directly (help/stop/
|
|
51
|
+
* steer/followup/context); false for the stateless runtime reports (events/tasks/status/
|
|
52
|
+
* usage/subagents/project) dispatched through `runRuntimeCommand`. Meaningful only within
|
|
53
|
+
* `BUILT_IN_COMMANDS`.
|
|
54
|
+
*/
|
|
55
|
+
runnerHandled?: boolean;
|
|
56
|
+
/** Broadcast list of this command's subcommands, for commands with a `/<name> <action> ...` shape. */
|
|
57
|
+
subcommands?: CommandSubSpec[];
|
|
34
58
|
}
|
|
35
59
|
/**
|
|
36
60
|
* Transport commands: handled directly by the runtime layer (never sent to the
|
|
@@ -46,19 +70,39 @@ export declare const SESSION_COMMANDS: readonly CommandSpec[];
|
|
|
46
70
|
/** Look up the shared description for a session command (used by the SDK extension). */
|
|
47
71
|
export declare function sessionCommandDescription(name: string): string;
|
|
48
72
|
export declare function isBuiltInCommandName(name: string): name is BuiltInCommandName;
|
|
73
|
+
/** True for a session-layer command name (`/model`, `/compact`, …) — needs the idle session layer. */
|
|
74
|
+
export declare function isSessionCommandName(name: string): boolean;
|
|
49
75
|
/** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
|
|
50
76
|
export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command is RunnerBuiltInCommand;
|
|
51
77
|
/** Comma-separated list of commands usable while a task is streaming (names only). */
|
|
52
78
|
export declare function formatBusyCommandList(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
|
|
81
|
+
* `event-commands.ts`, `subagent-commands.ts`, `project-commands.ts`, and `memory/commands.ts` call
|
|
82
|
+
* on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
|
|
83
|
+
*/
|
|
84
|
+
export declare function renderSubcommandUsage(name: string): string;
|
|
85
|
+
/** `/help <name>`'s content, or `undefined` for an unknown command name. */
|
|
86
|
+
export declare function renderCommandHelp(name: string): string | undefined;
|
|
53
87
|
/** Extract the lower-cased command name from a slash input, or `null` if not a slash command. */
|
|
54
88
|
export declare function slashCommandName(text: string): string | null;
|
|
55
89
|
/**
|
|
56
|
-
* True if `text` is a slash command the runtime or session layer knows how to
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
90
|
+
* True if `text` is a slash command the runtime or session layer knows how to handle: a built-in
|
|
91
|
+
* transport command, a session command, or a skill invocation (`/skill:name`) naming a skill
|
|
92
|
+
* actually present in `knownSkillNames`. Prompt-template names are resolved separately by the
|
|
93
|
+
* runner, which has the session's live template list.
|
|
94
|
+
*
|
|
95
|
+
* `knownSkillNames` used to be unchecked — any `/skill:<anything>` counted as known and got a full
|
|
96
|
+
* LLM turn, bypassing the "unknown command never reaches the model" guarantee this function exists
|
|
97
|
+
* to provide (review 2026-08-24 §1.9). Omitting `knownSkillNames` (no roster available) rejects
|
|
98
|
+
* every `skill:` name rather than trusting it.
|
|
60
99
|
*/
|
|
61
|
-
export declare function isKnownCommandName(name: string): boolean;
|
|
100
|
+
export declare function isKnownCommandName(name: string, knownSkillNames?: Iterable<string>): boolean;
|
|
62
101
|
export declare function formatUnknownCommandMessage(name: string): string;
|
|
63
102
|
export declare function parseBuiltInCommand(text: string): BuiltInCommand | null;
|
|
64
|
-
|
|
103
|
+
/**
|
|
104
|
+
* `/help` (top-level command listing) or `/help <name>` (that command's subcommands/examples) —
|
|
105
|
+
* two-level help so the top level stays scannable instead of the ~40-line wall of every example
|
|
106
|
+
* (review 2026-08-24 §2.2.1). `args` is the raw text after `/help`.
|
|
107
|
+
*/
|
|
108
|
+
export declare function renderBuiltInHelp(args?: string): string;
|