@oyasmi/pipiclaw 0.9.0-beta.8 → 0.9.0
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 +8 -0
- package/dist/agent/channel-runner.js +73 -10
- package/dist/agent/commands.d.ts +1 -1
- package/dist/agent/commands.js +9 -0
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/job-manager.d.ts +23 -3
- package/dist/agent/job-manager.js +14 -1
- package/dist/agent/runner-factory.d.ts +16 -4
- package/dist/agent/runner-factory.js +9 -23
- package/dist/agent/turn-recovery.d.ts +72 -0
- package/dist/agent/turn-recovery.js +193 -0
- package/dist/agent/types.d.ts +9 -1
- package/dist/agent/types.js +3 -16
- package/dist/playbooks/agent-delegation.md +3 -3
- package/dist/playbooks/runtime-orientation.md +5 -0
- package/dist/runtime/active-session-store.d.ts +42 -0
- package/dist/runtime/active-session-store.js +100 -0
- package/dist/runtime/bootstrap.d.ts +10 -2
- package/dist/runtime/bootstrap.js +122 -53
- package/dist/runtime/channel-event.d.ts +41 -0
- package/dist/runtime/channel-event.js +1 -0
- package/dist/runtime/delivery.d.ts +3 -2
- package/dist/runtime/dingtalk.d.ts +9 -31
- package/dist/runtime/dingtalk.js +2 -1
- package/dist/runtime/durable-dispatch.d.ts +3 -2
- package/dist/runtime/events.d.ts +3 -2
- package/dist/runtime/events.js +2 -3
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +112 -0
- package/dist/runtime/project-scope-store.d.ts +31 -0
- package/dist/runtime/project-scope-store.js +102 -0
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +7 -7
- package/dist/runtime/task-driver.js +1 -4
- package/dist/runtime/task-migration.js +1 -1
- package/dist/runtime/task-wake.d.ts +4 -4
- package/dist/security/config.js +10 -0
- package/dist/security/path-guard.js +34 -9
- package/dist/security/project-scope.d.ts +45 -0
- package/dist/security/project-scope.js +107 -0
- package/dist/security/types.d.ts +20 -2
- package/dist/settings.d.ts +0 -106
- package/dist/settings.js +0 -224
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +10 -1
- package/dist/subagents/external/run.js +2 -8
- package/dist/subagents/runs.d.ts +3 -3
- package/dist/subagents/runs.js +2 -12
- package/dist/subagents/tool.d.ts +13 -4
- package/dist/subagents/tool.js +9 -15
- package/dist/tasks/ledger.js +1 -1
- package/dist/{shared → tasks}/task-schedule.js +1 -1
- package/dist/tools/bash.js +4 -4
- package/dist/tools/edit.js +3 -3
- package/dist/tools/event-manage.js +1 -4
- package/dist/tools/grep.js +5 -6
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +7 -2
- package/dist/tools/job.js +5 -5
- package/dist/tools/memory-manage.js +3 -6
- package/dist/tools/read.js +3 -3
- package/dist/tools/registry.js +1 -1
- package/dist/tools/send-media.js +2 -2
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-manage.js +3 -3
- package/dist/tools/subagent-manage.js +3 -3
- package/dist/tools/task-manage/shared.js +2 -2
- package/dist/tools/task-manage.js +1 -4
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tools/write-content.js +3 -3
- package/dist/tui/app.js +50 -4
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +2 -0
- package/dist/tui/turn-controller.d.ts +1 -0
- package/dist/tui/turn-controller.js +1 -0
- package/package.json +1 -1
- /package/dist/{shared → tasks}/task-events.d.ts +0 -0
- /package/dist/{shared → tasks}/task-events.js +0 -0
- /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
package/dist/subagents/tool.js
CHANGED
|
@@ -15,6 +15,7 @@ import { splitH1Sections } from "../shared/markdown-sections.js";
|
|
|
15
15
|
import { clipTextByPromptUnits, countPromptUnits } from "../shared/prompt-units.js";
|
|
16
16
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
17
17
|
import { clipText, errorMessage, extractAssistantText, extractLabelFromArgs } from "../shared/text-utils.js";
|
|
18
|
+
import { createEmptyUsageTotals } from "../shared/types.js";
|
|
18
19
|
import { workspaceSubjectHash } from "../tasks/artifact-subject.js";
|
|
19
20
|
import { readStoredTask } from "../tasks/store.js";
|
|
20
21
|
import { writeVerificationAttestation } from "../tasks/verification.js";
|
|
@@ -137,6 +138,11 @@ function resolveRunWorkingDirectory(requested, options) {
|
|
|
137
138
|
if (!existsSync(target) || !statSync(target).isDirectory()) {
|
|
138
139
|
throw new RecoverableToolError(`workingDirectory "${requested}" is not an existing directory.`);
|
|
139
140
|
}
|
|
141
|
+
// D6.2: under `boundary: "project"`, an explicit workingDirectory must stay within the parent's
|
|
142
|
+
// ProjectRoot — `resolve(base, trimmed)` alone lets an absolute `trimmed` escape `base` entirely.
|
|
143
|
+
if (options.projectBoundary === "project" && target !== base && !target.startsWith(`${base}/`)) {
|
|
144
|
+
throw new RecoverableToolError(`workingDirectory "${requested}" must be inside the project root (${base}).`);
|
|
145
|
+
}
|
|
140
146
|
return target;
|
|
141
147
|
}
|
|
142
148
|
async function prepareRunContext(runId, params, options) {
|
|
@@ -157,16 +163,6 @@ async function gitWorkspaceState(executor) {
|
|
|
157
163
|
const result = await executor.exec("git status --porcelain=v1 --untracked-files=all", { timeout: 30 });
|
|
158
164
|
return result.code === 0 ? result.stdout : undefined;
|
|
159
165
|
}
|
|
160
|
-
function createEmptyUsageTotals() {
|
|
161
|
-
return {
|
|
162
|
-
input: 0,
|
|
163
|
-
output: 0,
|
|
164
|
-
cacheRead: 0,
|
|
165
|
-
cacheWrite: 0,
|
|
166
|
-
total: 0,
|
|
167
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
166
|
function isAssistantMessage(message) {
|
|
171
167
|
return typeof message === "object" && message !== null && "role" in message && message.role === "assistant";
|
|
172
168
|
}
|
|
@@ -270,8 +266,9 @@ function buildSubagentTools(executor, bashTimeoutSec, options, runContext) {
|
|
|
270
266
|
executor,
|
|
271
267
|
securityConfig,
|
|
272
268
|
securityContext: {
|
|
273
|
-
|
|
274
|
-
|
|
269
|
+
agentWorkspaceDir: options.workspaceDir,
|
|
270
|
+
projectRoot: runContext.workingDirectory,
|
|
271
|
+
boundary: options.projectBoundary,
|
|
275
272
|
},
|
|
276
273
|
channelId: options.runtimeContext.channelId,
|
|
277
274
|
channelDir: options.channelDir,
|
|
@@ -428,7 +425,6 @@ function filterToolsByName(allTools, names) {
|
|
|
428
425
|
}
|
|
429
426
|
function createDetails(config, runContext, usage, turns, toolCalls, durationMs, failed, failureReason, verificationVerdict, extras) {
|
|
430
427
|
return {
|
|
431
|
-
kind: "subagent",
|
|
432
428
|
agent: config.name,
|
|
433
429
|
source: config.source,
|
|
434
430
|
model: formatModelReference(config.model),
|
|
@@ -594,7 +590,6 @@ export function createSubAgentTool(options) {
|
|
|
594
590
|
},
|
|
595
591
|
],
|
|
596
592
|
details: {
|
|
597
|
-
kind: "subagent",
|
|
598
593
|
agent: config.name,
|
|
599
594
|
source: config.source,
|
|
600
595
|
model: config.externalModelRef ?? "unknown",
|
|
@@ -970,7 +965,6 @@ export function createSubAgentTool(options) {
|
|
|
970
965
|
},
|
|
971
966
|
],
|
|
972
967
|
details: {
|
|
973
|
-
kind: "subagent",
|
|
974
968
|
agent: config.name,
|
|
975
969
|
source: config.source,
|
|
976
970
|
model: formatModelReference(config.model),
|
package/dist/tasks/ledger.js
CHANGED
|
@@ -2,8 +2,8 @@ import { readdir, readFile, stat } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
4
4
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
5
|
-
import { nextTaskWake } from "../shared/task-schedule.js";
|
|
6
5
|
import { createDefaultTaskControl, parseTaskControl, taskPriorityRank } from "./control.js";
|
|
6
|
+
import { nextTaskWake } from "./task-schedule.js";
|
|
7
7
|
import { normalizeStoredStatus, wasLegacyEscalated } from "./transitions.js";
|
|
8
8
|
const FRONTMATTER_FIELDS = [
|
|
9
9
|
"status",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cron } from "croner";
|
|
2
|
-
import { errorMessage } from "
|
|
2
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
3
3
|
/**
|
|
4
4
|
* The cron cadence of a recurring task lives in its `schedule` frontmatter key.
|
|
5
5
|
* Cron is always interpreted in the host timezone — tasks (and events) follow the
|
package/dist/tools/bash.js
CHANGED
|
@@ -90,8 +90,8 @@ function formatCommandBlockMessage(command, category, reason, matchedText) {
|
|
|
90
90
|
export function createBashTool(executor, options = {}) {
|
|
91
91
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
92
92
|
const securityContext = options.securityContext ?? {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
agentWorkspaceDir: process.cwd(),
|
|
94
|
+
projectRoot: process.cwd(),
|
|
95
95
|
};
|
|
96
96
|
return {
|
|
97
97
|
name: "bash",
|
|
@@ -102,7 +102,7 @@ export function createBashTool(executor, options = {}) {
|
|
|
102
102
|
if (securityConfig.enabled && securityConfig.commandGuard.enabled) {
|
|
103
103
|
const guardResult = guardCommand(command, securityConfig.commandGuard);
|
|
104
104
|
if (!guardResult.allowed) {
|
|
105
|
-
await logSecurityEvent(securityContext.
|
|
105
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
106
106
|
type: "command",
|
|
107
107
|
tool: "bash",
|
|
108
108
|
channelId: options.channelId,
|
|
@@ -152,7 +152,7 @@ export function createBashTool(executor, options = {}) {
|
|
|
152
152
|
: "It runs off-turn and will NOT wake you when it finishes; check it with the job tool (op:poll/list)."),
|
|
153
153
|
},
|
|
154
154
|
],
|
|
155
|
-
details: {
|
|
155
|
+
details: { async: { state: "running", jobId: job.id } },
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
const result = await executor.exec(effectiveCommand, { timeout: effectiveTimeout, signal });
|
package/dist/tools/edit.js
CHANGED
|
@@ -111,8 +111,8 @@ function clampDiffForEcho(diff) {
|
|
|
111
111
|
export function createEditTool(executor, options = {}) {
|
|
112
112
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
113
113
|
const securityContext = options.securityContext ?? {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
agentWorkspaceDir: process.cwd(),
|
|
115
|
+
projectRoot: process.cwd(),
|
|
116
116
|
};
|
|
117
117
|
// Per-tool-instance counter of consecutive byte-identical no-op edits, keyed by the exact
|
|
118
118
|
// (path, oldText, newText) payload. A model stuck re-issuing the same no-op edit is chasing a
|
|
@@ -128,7 +128,7 @@ export function createEditTool(executor, options = {}) {
|
|
|
128
128
|
if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
|
|
129
129
|
const readGuard = guardPath(path, "read", { ...securityContext, config: securityConfig.pathGuard });
|
|
130
130
|
if (!readGuard.allowed) {
|
|
131
|
-
await logSecurityEvent(securityContext.
|
|
131
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
132
132
|
type: "path",
|
|
133
133
|
tool: "edit",
|
|
134
134
|
channelId: options.channelId,
|
|
@@ -170,10 +170,7 @@ export function createEventManageTool(options) {
|
|
|
170
170
|
});
|
|
171
171
|
return {
|
|
172
172
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
173
|
-
details: {
|
|
174
|
-
kind: "event_manage",
|
|
175
|
-
...result,
|
|
176
|
-
},
|
|
173
|
+
details: { ...result },
|
|
177
174
|
};
|
|
178
175
|
},
|
|
179
176
|
};
|
package/dist/tools/grep.js
CHANGED
|
@@ -134,8 +134,8 @@ function renderFileGroup(file, entries, perFileMatchCap) {
|
|
|
134
134
|
export function createGrepTool(executor, options = {}) {
|
|
135
135
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
136
136
|
const securityContext = options.securityContext ?? {
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
agentWorkspaceDir: process.cwd(),
|
|
138
|
+
projectRoot: process.cwd(),
|
|
139
139
|
};
|
|
140
140
|
return {
|
|
141
141
|
name: "grep",
|
|
@@ -152,7 +152,7 @@ export function createGrepTool(executor, options = {}) {
|
|
|
152
152
|
if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
|
|
153
153
|
const guardResult = guardPath(searchPath, "read", { ...securityContext, config: securityConfig.pathGuard });
|
|
154
154
|
if (!guardResult.allowed) {
|
|
155
|
-
await logSecurityEvent(securityContext.
|
|
155
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
156
156
|
type: "path",
|
|
157
157
|
tool: "grep",
|
|
158
158
|
channelId: options.channelId,
|
|
@@ -203,7 +203,7 @@ export function createGrepTool(executor, options = {}) {
|
|
|
203
203
|
text: `No matches found in ${scope}. Try a broader pattern, drop the glob, or widen the path.`,
|
|
204
204
|
},
|
|
205
205
|
],
|
|
206
|
-
details: {
|
|
206
|
+
details: { matchCount: 0, fileCount: 0 },
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
files.sort((a, b) => a[0].localeCompare(b[0]));
|
|
@@ -219,7 +219,7 @@ export function createGrepTool(executor, options = {}) {
|
|
|
219
219
|
text: `No more matching files (skip=${startOffset} is past the last of ${files.length}).`,
|
|
220
220
|
},
|
|
221
221
|
],
|
|
222
|
-
details: {
|
|
222
|
+
details: { matchCount: 0, fileCount: files.length },
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
const blocks = [];
|
|
@@ -249,7 +249,6 @@ export function createGrepTool(executor, options = {}) {
|
|
|
249
249
|
return {
|
|
250
250
|
content: [{ type: "text", text: outputText }],
|
|
251
251
|
details: {
|
|
252
|
-
kind: "grep",
|
|
253
252
|
matchCount: shownMatchCount,
|
|
254
253
|
fileCount: files.length,
|
|
255
254
|
shownFileCount: page.length,
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Api, Model } from "@earendil-works/pi-ai";
|
|
|
3
3
|
import type { Executor } from "../executor.js";
|
|
4
4
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
5
5
|
import type { MediaSender } from "../runtime/channel-context.js";
|
|
6
|
+
import type { ProjectScope } from "../security/project-scope.js";
|
|
6
7
|
import type { SecurityConfig } from "../security/types.js";
|
|
7
8
|
import type { PipiclawMemoryRecallSettings, PipiclawSessionSearchSettings } from "../settings.js";
|
|
8
9
|
import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
@@ -13,6 +14,8 @@ export interface CreatePipiclawToolsOptions {
|
|
|
13
14
|
getAvailableModels: () => Model<Api>[];
|
|
14
15
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
15
16
|
workspaceDir: string;
|
|
17
|
+
/** Frozen for this runner generation; bounds generic file tools and sets the shell/subagent cwd (spec 043, D4.2). */
|
|
18
|
+
projectScope: ProjectScope;
|
|
16
19
|
channelDir: string;
|
|
17
20
|
channelId: string;
|
|
18
21
|
getSubAgentDiscovery: () => SubAgentDiscoveryResult;
|
package/dist/tools/index.js
CHANGED
|
@@ -13,8 +13,9 @@ export function createPipiclawTools(options) {
|
|
|
13
13
|
const securityConfig = withSubAgentsDirWriteDeny(options.securityConfig ?? loadSecurityConfig(APP_HOME_DIR), options.workspaceDir);
|
|
14
14
|
const toolsConfig = options.toolsConfig ?? loadToolsConfig(APP_HOME_DIR);
|
|
15
15
|
const securityContext = {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
agentWorkspaceDir: options.workspaceDir,
|
|
17
|
+
projectRoot: options.projectScope.projectRoot,
|
|
18
|
+
boundary: options.projectScope.boundary,
|
|
18
19
|
};
|
|
19
20
|
// The leaf tools (files, web, memory, skills) come from the single declarative
|
|
20
21
|
// registry so this set, the sub-agent set, and the prompt hints share one source.
|
|
@@ -49,6 +50,10 @@ export function createPipiclawTools(options) {
|
|
|
49
50
|
getAvailableModels: options.getAvailableModels,
|
|
50
51
|
resolveApiKey: options.resolveApiKey,
|
|
51
52
|
workspaceDir: options.workspaceDir,
|
|
53
|
+
// D6.2: an internal sub-agent defaults to the parent's ProjectRoot; a model-requested
|
|
54
|
+
// explicit workingDirectory is validated (in subagents/tool.ts) to stay within it.
|
|
55
|
+
workingDirectory: options.projectScope.projectRoot,
|
|
56
|
+
projectBoundary: options.projectScope.boundary,
|
|
52
57
|
channelDir: options.channelDir,
|
|
53
58
|
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
54
59
|
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
package/dist/tools/job.js
CHANGED
|
@@ -49,7 +49,7 @@ export function createJobTool(options) {
|
|
|
49
49
|
const text = outcomes.map((outcome) => `- [${outcome.id}] ${outcome.status}`).join("\n");
|
|
50
50
|
return {
|
|
51
51
|
content: [{ type: "text", text: `Cancel results:\n${text}` }],
|
|
52
|
-
details: {
|
|
52
|
+
details: { op: "cancel", outcomes },
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
if (op === "list") {
|
|
@@ -57,12 +57,12 @@ export function createJobTool(options) {
|
|
|
57
57
|
if (jobs.length === 0) {
|
|
58
58
|
return {
|
|
59
59
|
content: [{ type: "text", text: "No background jobs." }],
|
|
60
|
-
details: {
|
|
60
|
+
details: { op: "list", jobs },
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
return {
|
|
64
64
|
content: [{ type: "text", text: jobs.map(formatJobLine).join("\n") }],
|
|
65
|
-
details: {
|
|
65
|
+
details: { op: "list", jobs },
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
// poll
|
|
@@ -70,7 +70,7 @@ export function createJobTool(options) {
|
|
|
70
70
|
if (jobs.length === 0) {
|
|
71
71
|
return {
|
|
72
72
|
content: [{ type: "text", text: "No matching running jobs to wait for." }],
|
|
73
|
-
details: {
|
|
73
|
+
details: { op: "poll", jobs },
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
const finished = jobs.filter((job) => job.status !== "running");
|
|
@@ -85,7 +85,7 @@ export function createJobTool(options) {
|
|
|
85
85
|
}
|
|
86
86
|
return {
|
|
87
87
|
content: [{ type: "text", text: parts.join("\n\n") }],
|
|
88
|
-
details: {
|
|
88
|
+
details: { op: "poll", jobs },
|
|
89
89
|
};
|
|
90
90
|
},
|
|
91
91
|
};
|
|
@@ -83,7 +83,7 @@ export function createMemoryManageTool(options) {
|
|
|
83
83
|
rejectMissingArgument("save", "content", args);
|
|
84
84
|
}
|
|
85
85
|
if (containsSecret(trimmed)) {
|
|
86
|
-
return textResult("This content looks like a credential or secret, so it was not saved. Store the secret in an approved secret manager and remember only its location.", {
|
|
86
|
+
return textResult("This content looks like a credential or secret, so it was not saved. Store the secret in an approved secret manager and remember only its location.", { op: "save", saved: false, blockedReason: "secret" });
|
|
87
87
|
}
|
|
88
88
|
// Serialize through the shared channel memory queue so this never races with background
|
|
89
89
|
// consolidation/maintenance on the same channel's files.
|
|
@@ -105,7 +105,6 @@ export function createMemoryManageTool(options) {
|
|
|
105
105
|
? `Saved to channel memory${kind ? ` (${kind})` : ""}.`
|
|
106
106
|
: "That memory is already present; no duplicate was added.";
|
|
107
107
|
return textResult(message, {
|
|
108
|
-
kind: "memory_manage",
|
|
109
108
|
op: "save",
|
|
110
109
|
saved: result.added > 0 || result.skippedDuplicate > 0,
|
|
111
110
|
});
|
|
@@ -134,13 +133,12 @@ export function createMemoryManageTool(options) {
|
|
|
134
133
|
candidateStore: options.memoryCandidateStore,
|
|
135
134
|
});
|
|
136
135
|
if (items.length === 0) {
|
|
137
|
-
return textResult(`No stored memory matched "${trimmed}". Try a broader query, or the fact may not be saved yet.`, {
|
|
136
|
+
return textResult(`No stored memory matched "${trimmed}". Try a broader query, or the fact may not be saved yet.`, { op: "search", resultCount: 0 });
|
|
138
137
|
}
|
|
139
138
|
const rendered = items
|
|
140
139
|
.map((item, index) => `${index + 1}. [${item.source}/${item.title}] ${item.content}`)
|
|
141
140
|
.join("\n");
|
|
142
141
|
return textResult(`Found ${items.length} stored memory entr${items.length === 1 ? "y" : "ies"}:\n\n${rendered}`, {
|
|
143
|
-
kind: "memory_manage",
|
|
144
142
|
op: "search",
|
|
145
143
|
resultCount: items.length,
|
|
146
144
|
});
|
|
@@ -157,7 +155,6 @@ export function createMemoryManageTool(options) {
|
|
|
157
155
|
const matches = entries.filter((entry) => entry.content === trimmed || entry.content.toLowerCase().includes(needle));
|
|
158
156
|
if (matches.length === 0) {
|
|
159
157
|
return textResult(`No stored memory entry matched "${trimmed}"; nothing was removed.`, {
|
|
160
|
-
kind: "memory_manage",
|
|
161
158
|
op: "forget",
|
|
162
159
|
forgotten: false,
|
|
163
160
|
});
|
|
@@ -180,7 +177,7 @@ export function createMemoryManageTool(options) {
|
|
|
180
177
|
}).catch((error) => {
|
|
181
178
|
log.logWarning(`Failed to append memory review log for channel ${options.channelId}`, errorMessage(error));
|
|
182
179
|
});
|
|
183
|
-
return textResult("Removed the entry from active channel memory. Its exact content and source transcript window are tombstoned against automatic replay; if the fact is stated again later, it may be learned as new. Original session history and retention backups are unchanged.", {
|
|
180
|
+
return textResult("Removed the entry from active channel memory. Its exact content and source transcript window are tombstoned against automatic replay; if the fact is stated again later, it may be learned as new. Original session history and retention backups are unchanged.", { op: "forget", forgotten: true, entryId: removed.id });
|
|
184
181
|
}
|
|
185
182
|
return {
|
|
186
183
|
name: "memory_manage",
|
package/dist/tools/read.js
CHANGED
|
@@ -93,8 +93,8 @@ function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
|
93
93
|
export function createReadTool(executor, options = {}) {
|
|
94
94
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
95
95
|
const securityContext = options.securityContext ?? {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
agentWorkspaceDir: process.cwd(),
|
|
97
|
+
projectRoot: process.cwd(),
|
|
98
98
|
};
|
|
99
99
|
return {
|
|
100
100
|
name: "read",
|
|
@@ -105,7 +105,7 @@ export function createReadTool(executor, options = {}) {
|
|
|
105
105
|
if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
|
|
106
106
|
const guardResult = guardPath(path, "read", { ...securityContext, config: securityConfig.pathGuard });
|
|
107
107
|
if (!guardResult.allowed) {
|
|
108
|
-
await logSecurityEvent(securityContext.
|
|
108
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
109
109
|
type: "path",
|
|
110
110
|
tool: "read",
|
|
111
111
|
channelId: options.channelId,
|
package/dist/tools/registry.js
CHANGED
|
@@ -152,7 +152,7 @@ export const TOOL_REGISTRY = [
|
|
|
152
152
|
workspaceDir: ctx.workspaceDir,
|
|
153
153
|
channelDir: ctx.channelDir,
|
|
154
154
|
channelId: ctx.channelId,
|
|
155
|
-
workingDirectory: ctx.securityContext.
|
|
155
|
+
workingDirectory: ctx.securityContext.projectRoot,
|
|
156
156
|
dispatchVerification: ctx.dispatchVerification,
|
|
157
157
|
}),
|
|
158
158
|
},
|
package/dist/tools/send-media.js
CHANGED
|
@@ -29,7 +29,7 @@ function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
|
29
29
|
*/
|
|
30
30
|
export function createSendMediaTool(executor, options) {
|
|
31
31
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
32
|
-
const securityContext = options.securityContext ?? {
|
|
32
|
+
const securityContext = options.securityContext ?? { agentWorkspaceDir: process.cwd(), projectRoot: process.cwd() };
|
|
33
33
|
return {
|
|
34
34
|
name: "send_media",
|
|
35
35
|
label: "send_media",
|
|
@@ -41,7 +41,7 @@ export function createSendMediaTool(executor, options) {
|
|
|
41
41
|
if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
|
|
42
42
|
const guardResult = guardPath(path, "read", { ...securityContext, config: securityConfig.pathGuard });
|
|
43
43
|
if (!guardResult.allowed) {
|
|
44
|
-
await logSecurityEvent(securityContext.
|
|
44
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
45
45
|
type: "path",
|
|
46
46
|
tool: "send_media",
|
|
47
47
|
channelId: options.channelId,
|
|
@@ -190,7 +190,7 @@ async function viewWorkspaceSkill(options, name, filePath) {
|
|
|
190
190
|
}
|
|
191
191
|
return {
|
|
192
192
|
content: [{ type: "text", text: `Skill: ${name}\nPath: ${targetPath}\n\n${body}` }],
|
|
193
|
-
details: {
|
|
193
|
+
details: { action: "view", name, path: targetPath, truncated: truncation.truncated },
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
export function createSkillManageTool(options) {
|
|
@@ -205,7 +205,7 @@ export function createSkillManageTool(options) {
|
|
|
205
205
|
const skills = await listWorkspaceSkills(options);
|
|
206
206
|
return {
|
|
207
207
|
content: [{ type: "text", text: JSON.stringify({ skills }) }],
|
|
208
|
-
details: {
|
|
208
|
+
details: { action: "list", count: skills.length },
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
211
|
if (!args.name) {
|
|
@@ -224,7 +224,7 @@ export function createSkillManageTool(options) {
|
|
|
224
224
|
});
|
|
225
225
|
return {
|
|
226
226
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
227
|
-
details: {
|
|
227
|
+
details: { ...result },
|
|
228
228
|
};
|
|
229
229
|
},
|
|
230
230
|
};
|
|
@@ -67,7 +67,7 @@ export function createSubAgentManageTool(options) {
|
|
|
67
67
|
}
|
|
68
68
|
return {
|
|
69
69
|
content: [{ type: "text", text: lines.join("\n") }],
|
|
70
|
-
details: {
|
|
70
|
+
details: { op, runs },
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
if (!runId) {
|
|
@@ -85,7 +85,7 @@ export function createSubAgentManageTool(options) {
|
|
|
85
85
|
const status = await manager().cancel(resolvedRunId);
|
|
86
86
|
return {
|
|
87
87
|
content: [{ type: "text", text: `Cancel requested for run ${resolvedRunId}: ${status}` }],
|
|
88
|
-
details: {
|
|
88
|
+
details: { op, runId: resolvedRunId, status },
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
// follow_up
|
|
@@ -238,7 +238,7 @@ export function createSubAgentManageTool(options) {
|
|
|
238
238
|
text: `Follow-up dispatched as runId=${newRunId} (resuming ${resolvedRunId}). This channel will be woken when it finishes.`,
|
|
239
239
|
},
|
|
240
240
|
],
|
|
241
|
-
details: {
|
|
241
|
+
details: { op, runId: newRunId, resumedFrom: resolvedRunId },
|
|
242
242
|
};
|
|
243
243
|
},
|
|
244
244
|
};
|
|
@@ -4,11 +4,11 @@ import { join } from "node:path";
|
|
|
4
4
|
import * as log from "../../log.js";
|
|
5
5
|
import { parseScheduledEventContent } from "../../runtime/events.js";
|
|
6
6
|
import { formatLocalTime, parseWakeInput } from "../../shared/local-time.js";
|
|
7
|
-
import { taskEventPrefix } from "../../shared/task-events.js";
|
|
8
|
-
import { nextTaskWake, validateTaskSchedule } from "../../shared/task-schedule.js";
|
|
9
7
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
10
8
|
import { applyTaskControlPatch, createDefaultTaskControl } from "../../tasks/control.js";
|
|
11
9
|
import { normalizeTaskFields, parseTaskFrontmatter, renderStandardTaskBody, renderTaskDocument, taskBody, upsertCurrentCycleCompletionEvidence, } from "../../tasks/ledger.js";
|
|
10
|
+
import { taskEventPrefix } from "../../tasks/task-events.js";
|
|
11
|
+
import { nextTaskWake, validateTaskSchedule } from "../../tasks/task-schedule.js";
|
|
12
12
|
import { isSettableTaskStatus } from "../../tasks/transitions.js";
|
|
13
13
|
import { RecoverableToolError } from "../tool-details.js";
|
|
14
14
|
import { SETTABLE_STATUSES } from "./schema.js";
|
package/dist/tools/web-fetch.js
CHANGED
|
@@ -15,13 +15,13 @@ export async function writeContent(executor, path, content, signal, options) {
|
|
|
15
15
|
const createParentDir = options?.createParentDir ?? false;
|
|
16
16
|
const securityConfig = options?.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
17
17
|
const securityContext = options?.securityContext ?? {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
agentWorkspaceDir: process.cwd(),
|
|
19
|
+
projectRoot: process.cwd(),
|
|
20
20
|
};
|
|
21
21
|
if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
|
|
22
22
|
const guardResult = guardPath(path, "write", { ...securityContext, config: securityConfig.pathGuard });
|
|
23
23
|
if (!guardResult.allowed) {
|
|
24
|
-
await logSecurityEvent(securityContext.
|
|
24
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
25
25
|
type: "path",
|
|
26
26
|
tool: options?.toolName ?? "write",
|
|
27
27
|
channelId: options?.channelId,
|
package/dist/tui/app.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { userInfo } from "node:os";
|
|
10
10
|
import { renderBuiltInHelp } from "../agent/commands.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { createRunner } from "../agent/index.js";
|
|
12
|
+
import { channelRunningJobLines } from "../agent/job-manager.js";
|
|
13
13
|
import * as log from "../log.js";
|
|
14
14
|
import { ensureChannelMemoryFilesSync } from "../memory/files.js";
|
|
15
15
|
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../runtime/app-home.js";
|
|
@@ -17,10 +17,12 @@ import { prepareAppServices } from "../runtime/bootstrap.js";
|
|
|
17
17
|
import { ensureChannelDir } from "../runtime/channel-paths.js";
|
|
18
18
|
import { finalDeliveryOf, progressStyleOf } from "../runtime/dingtalk.js";
|
|
19
19
|
import { handleEventsCommand } from "../runtime/event-commands.js";
|
|
20
|
+
import { handleProjectCommand } from "../runtime/project-commands.js";
|
|
20
21
|
import { ChannelStore } from "../runtime/store.js";
|
|
21
22
|
import { handleSubagentsCommand } from "../runtime/subagent-commands.js";
|
|
22
23
|
import { handleTasksCommand } from "../runtime/task-commands.js";
|
|
23
24
|
import { flushSecurityLogs } from "../security/logger.js";
|
|
25
|
+
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
24
26
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
25
27
|
import { parseUsageMode, renderUsageReport } from "../usage/render.js";
|
|
26
28
|
import { TUI_SLASH_COMMANDS } from "./commands.js";
|
|
@@ -43,6 +45,28 @@ async function waitForStorageFlush(task) {
|
|
|
43
45
|
});
|
|
44
46
|
});
|
|
45
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* A replaceable `AgentRunner` reference (spec 043, D4.2): `TurnController` holds a single
|
|
50
|
+
* `AgentRunner` for the process's lifetime, but `/project set|reset` needs to dispose the runner
|
|
51
|
+
* built under the old scope and hand the next turn a fresh one built under the new scope. The
|
|
52
|
+
* proxy forwards every call to whichever runner is current, so `TurnController` never needs to
|
|
53
|
+
* know the reference changed.
|
|
54
|
+
*/
|
|
55
|
+
function createRunnerSlot(initial) {
|
|
56
|
+
let current = initial;
|
|
57
|
+
const runner = new Proxy({}, {
|
|
58
|
+
get(_target, prop, _receiver) {
|
|
59
|
+
const value = Reflect.get(current, prop);
|
|
60
|
+
return typeof value === "function" ? value.bind(current) : value;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
runner,
|
|
65
|
+
replace(next) {
|
|
66
|
+
current = next;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
46
70
|
export function resolveChannelId(raw, io = console) {
|
|
47
71
|
const channel = raw?.trim() || DEFAULT_CHANNEL_ID;
|
|
48
72
|
if (!CHANNEL_ID_PATTERN.test(channel)) {
|
|
@@ -78,12 +102,15 @@ export async function runTuiApp(options) {
|
|
|
78
102
|
const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
|
|
79
103
|
ensureChannelMemoryFilesSync(channelDir);
|
|
80
104
|
const store = new ChannelStore({ workingDir: paths.workspaceDir });
|
|
81
|
-
const
|
|
105
|
+
const buildRunner = () => createRunner(channelId, channelDir, {
|
|
82
106
|
appHomeDir: paths.appHomeDir,
|
|
83
107
|
authConfigPath: paths.authConfigPath,
|
|
84
108
|
modelsConfigPath: paths.modelsConfigPath,
|
|
109
|
+
settingsManager,
|
|
85
110
|
mediaSender: createTerminalMediaSender(io),
|
|
86
111
|
});
|
|
112
|
+
const runnerSlot = createRunnerSlot(buildRunner());
|
|
113
|
+
const runner = runnerSlot.runner;
|
|
87
114
|
const tuiSettings = settingsManager.getTuiSettings();
|
|
88
115
|
const traits = {
|
|
89
116
|
progressStyle: progressStyleOf(tuiSettings.responseMode),
|
|
@@ -114,6 +141,25 @@ export async function runTuiApp(options) {
|
|
|
114
141
|
channelId,
|
|
115
142
|
}),
|
|
116
143
|
runSubagents: (args) => handleSubagentsCommand({ args, channelId, discovery: runner.getSubAgentDiscoverySnapshot() }),
|
|
144
|
+
runProject: (args) => handleProjectCommand({
|
|
145
|
+
args,
|
|
146
|
+
channelId,
|
|
147
|
+
channelDir,
|
|
148
|
+
appHomeDir: paths.appHomeDir,
|
|
149
|
+
actor: "tui-command",
|
|
150
|
+
isBusy: () => runner.isBusy(),
|
|
151
|
+
listActiveBlockers: () => [
|
|
152
|
+
...getSubAgentRunManager(channelId)
|
|
153
|
+
.list()
|
|
154
|
+
.filter((record) => record.status === "running")
|
|
155
|
+
.map((record) => `subagent run \`${record.runId}\` (${record.agent})`),
|
|
156
|
+
...channelRunningJobLines(channelId),
|
|
157
|
+
],
|
|
158
|
+
onScopeChanged: async () => {
|
|
159
|
+
await runner.dispose();
|
|
160
|
+
runnerSlot.replace(buildRunner());
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
117
163
|
statusInfo: { version: readCliVersion(), startedAt: Date.now() },
|
|
118
164
|
});
|
|
119
165
|
try {
|
|
@@ -125,7 +171,7 @@ export async function runTuiApp(options) {
|
|
|
125
171
|
}
|
|
126
172
|
}
|
|
127
173
|
finally {
|
|
128
|
-
|
|
174
|
+
await runner.dispose();
|
|
129
175
|
await waitForStorageFlush(Promise.allSettled([store.close(), getUsageLedger().flush?.() ?? Promise.resolve(), flushSecurityLogs()]));
|
|
130
176
|
await waitForStorageFlush(log.flushLogging());
|
|
131
177
|
}
|
package/dist/tui/commands.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface DispatchDeps {
|
|
|
40
40
|
runEvents(args: string): Promise<string>;
|
|
41
41
|
runTasks(args: string): Promise<string>;
|
|
42
42
|
runSubagents(args: string): Promise<string>;
|
|
43
|
+
runProject(args: string): Promise<string>;
|
|
43
44
|
}
|
|
44
45
|
export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
|
|
45
46
|
/**
|
package/dist/tui/commands.js
CHANGED
|
@@ -41,6 +41,8 @@ export async function dispatch(input, deps) {
|
|
|
41
41
|
return { kind: "reply", text: await deps.runTasks(command.args) };
|
|
42
42
|
case "subagents":
|
|
43
43
|
return { kind: "reply", text: await deps.runSubagents(command.args) };
|
|
44
|
+
case "project":
|
|
45
|
+
return { kind: "reply", text: await deps.runProject(command.args) };
|
|
44
46
|
case "stop":
|
|
45
47
|
return { kind: "stop" };
|
|
46
48
|
case "steer":
|
|
@@ -23,6 +23,7 @@ export interface TurnControllerDeps {
|
|
|
23
23
|
runEvents: (args: string) => Promise<string>;
|
|
24
24
|
runTasks: (args: string) => Promise<string>;
|
|
25
25
|
runSubagents: (args: string) => Promise<string>;
|
|
26
|
+
runProject: (args: string) => Promise<string>;
|
|
26
27
|
/** Static bits the status renderer needs alongside the live run state. */
|
|
27
28
|
statusInfo: {
|
|
28
29
|
version: string;
|
|
@@ -36,6 +36,7 @@ export class TurnController {
|
|
|
36
36
|
runEvents: deps.runEvents,
|
|
37
37
|
runTasks: deps.runTasks,
|
|
38
38
|
runSubagents: deps.runSubagents,
|
|
39
|
+
runProject: deps.runProject,
|
|
39
40
|
renderContext: (args) => this.deps.runner.renderContextReport(args),
|
|
40
41
|
renderStatus: () => renderStatus({
|
|
41
42
|
runner: this.deps.runner,
|