@agentbean/daemon 0.1.10 → 0.1.12

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.
@@ -2,7 +2,7 @@ import { logger } from './log.js';
2
2
  import { uploadArtifact } from './uploader.js';
3
3
  import { postProcess } from './post-process.js';
4
4
  import { generateSandboxProfile, getWorkspaceDir, isSandboxAvailable } from './sandbox.js';
5
- import { archiveOutputFiles, beginAgentWorkspaceRun, finishAgentWorkspaceRun, workspaceEnv, } from './workspace-manager.js';
5
+ import { archiveOutputFiles, beginAgentWorkspaceRun, finishAgentWorkspaceRun, formatWorkspaceReply, workspaceEnv, } from './workspace-manager.js';
6
6
  function errorMessage(err) {
7
7
  if (err instanceof Error && err.message)
8
8
  return err.message;
@@ -72,7 +72,8 @@ export class AgentInstance {
72
72
  outputDirs: [run.outputDir, run.intermediateDir],
73
73
  });
74
74
  archivedFiles = archiveOutputFiles(run, processed.outputFiles);
75
- finishAgentWorkspaceRun(run, { replyText: processed.replyText, files: archivedFiles, status: 'completed' });
75
+ const replyText = formatWorkspaceReply(rawBody, archivedFiles);
76
+ finishAgentWorkspaceRun(run, { replyText, files: archivedFiles, status: 'completed' });
76
77
  const artifactIds = [];
77
78
  if (archivedFiles.length > 0) {
78
79
  for (const file of archivedFiles) {
@@ -92,7 +93,6 @@ export class AgentInstance {
92
93
  deviceId: deviceId ?? null,
93
94
  pathKind: file.pathKind,
94
95
  relativePath: file.relativePath,
95
- originalPath: file.originalPath,
96
96
  sha256: file.sha256,
97
97
  }),
98
98
  });
@@ -107,7 +107,7 @@ export class AgentInstance {
107
107
  socket.emit('reply', {
108
108
  agentId: this.id,
109
109
  channelId: req.channelId,
110
- body: processed.replyText,
110
+ body: replyText,
111
111
  requestId: req.requestId,
112
112
  artifactIds: artifactIds.length > 0 ? artifactIds : undefined,
113
113
  });
@@ -2,7 +2,7 @@ import { io } from 'socket.io-client';
2
2
  import { logger } from './log.js';
3
3
  import { uploadArtifact } from './uploader.js';
4
4
  import { postProcess } from './post-process.js';
5
- import { archiveOutputFiles, beginAgentWorkspaceRun, finishAgentWorkspaceRun, workspaceEnv, } from './workspace-manager.js';
5
+ import { archiveOutputFiles, beginAgentWorkspaceRun, finishAgentWorkspaceRun, formatWorkspaceReply, workspaceEnv, } from './workspace-manager.js';
6
6
  function errorMessage(err) {
7
7
  if (err instanceof Error && err.message)
8
8
  return err.message;
@@ -80,7 +80,8 @@ export function createConnection(cfg, adapter) {
80
80
  outputDirs: [run.outputDir, run.intermediateDir],
81
81
  });
82
82
  archivedFiles = archiveOutputFiles(run, processed.outputFiles);
83
- finishAgentWorkspaceRun(run, { replyText: processed.replyText, files: archivedFiles, status: 'completed' });
83
+ const replyText = formatWorkspaceReply(rawBody, archivedFiles);
84
+ finishAgentWorkspaceRun(run, { replyText, files: archivedFiles, status: 'completed' });
84
85
  const artifactIds = [];
85
86
  if (archivedFiles.length > 0) {
86
87
  const httpBase = cfg.server.url.replace(/\/agent$/, '');
@@ -100,7 +101,6 @@ export function createConnection(cfg, adapter) {
100
101
  runId: req.requestId,
101
102
  pathKind: file.pathKind,
102
103
  relativePath: file.relativePath,
103
- originalPath: file.originalPath,
104
104
  sha256: file.sha256,
105
105
  }),
106
106
  });
@@ -114,7 +114,7 @@ export function createConnection(cfg, adapter) {
114
114
  }
115
115
  currentSocket.emit('reply', {
116
116
  channelId: req.channelId,
117
- body: processed.replyText,
117
+ body: replyText,
118
118
  requestId: req.requestId,
119
119
  artifactIds: artifactIds.length > 0 ? artifactIds : undefined,
120
120
  });
@@ -94,9 +94,9 @@ function canonicalPath(path) {
94
94
  return path;
95
95
  }
96
96
  }
97
- function resolveOutputRoots(workspace, outputDirs = []) {
97
+ function resolveOutputRoots(workspace, outputDirs = [], includeWorkspace = false) {
98
98
  const roots = new Set();
99
- if (workspace)
99
+ if (workspace && includeWorkspace)
100
100
  roots.add(resolve(workspace));
101
101
  for (const raw of [...outputDirs, ...outputDirsFromEnv()]) {
102
102
  const expanded = raw.replace(/^~(?=$|\/)/, homedir());
@@ -153,7 +153,7 @@ export async function postProcess(reply, workspace, kind, dispatchStart, options
153
153
  for (const filePath of extractMentionedFiles(reply, workspace, dispatchStart)) {
154
154
  outputFiles.add(canonicalPath(filePath));
155
155
  }
156
- for (const filePath of collectRecentOutputFiles(resolveOutputRoots(workspace, options.outputDirs), dispatchStart)) {
156
+ for (const filePath of collectRecentOutputFiles(resolveOutputRoots(workspace, options.outputDirs, options.scanWorkspace), dispatchStart)) {
157
157
  outputFiles.add(filePath);
158
158
  }
159
159
  // Extract code blocks for logging but do NOT auto-execute (security)
@@ -34,6 +34,14 @@ function uniqueDestination(dir, filename) {
34
34
  }
35
35
  return candidate;
36
36
  }
37
+ function escapeRegExp(value) {
38
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
39
+ }
40
+ function replaceAllLiteral(value, search, replacement) {
41
+ if (!search || search === replacement)
42
+ return value;
43
+ return value.replace(new RegExp(escapeRegExp(search), 'g'), replacement);
44
+ }
37
45
  export function beginAgentWorkspaceRun(input) {
38
46
  const teamId = safeSegment(input.teamId);
39
47
  const agentId = safeSegment(input.agentId);
@@ -112,6 +120,20 @@ export function archiveOutputFiles(run, files) {
112
120
  }
113
121
  return archived;
114
122
  }
123
+ export function formatWorkspaceReply(reply, files) {
124
+ let body = reply;
125
+ for (const file of files) {
126
+ body = replaceAllLiteral(body, `file://${file.originalPath}`, `file://${file.archivedPath}`);
127
+ body = replaceAllLiteral(body, file.originalPath, file.archivedPath);
128
+ }
129
+ const missingPaths = files
130
+ .map((file) => file.archivedPath)
131
+ .filter((path) => !body.includes(path));
132
+ if (missingPaths.length > 0) {
133
+ body += '\n\n已生成文件:\n' + missingPaths.map((path) => `- ${path}`).join('\n');
134
+ }
135
+ return body;
136
+ }
115
137
  export function finishAgentWorkspaceRun(run, input) {
116
138
  if (input.replyText !== undefined) {
117
139
  writeFileSync(join(run.runDir, 'response.md'), input.replyText);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentbean/daemon",
3
3
  "private": false,
4
- "version": "0.1.10",
4
+ "version": "0.1.12",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "bin": {