@kingsoftcloud/agentkit-harness-node 0.0.28 → 0.0.30
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/engine-view.html +29 -15
- package/package.json +2 -2
- package/src/native/engine-runtime.mjs +10 -7
- package/src/native/engine-server.mjs +4 -0
- package/src/native/engine-service.mjs +4 -1
- package/src/native/local-command-state.mjs +10 -2
- package/src/native/native-terminal-failure.mjs +3 -0
- package/src/native/windows-private-state.mjs +41 -0
- package/src/native/workspace-state.mjs +3 -3
- package/src/native/workspace-tools.mjs +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone Native Harness Node adapters: a durable SQLite run store, a one-request model HTTP port, and a minimal versioned JSON-RPC 2.0 over NDJSON process entry. Reuses the shared Native adapter implementations and externalizes @kingsoftcloud/agentkit-harness-core; depends on no Studio/DSH code at runtime.",
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"src/package-integrity.mjs"
|
|
155
155
|
],
|
|
156
156
|
"dependencies": {
|
|
157
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
157
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.30",
|
|
158
158
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
159
159
|
"parse5": "7.3.0",
|
|
160
160
|
"playwright-core": "1.58.2",
|
|
@@ -19,6 +19,7 @@ import { validateMediaBlock } from './model-media.mjs';
|
|
|
19
19
|
import { admitProviderCompatibilityPolicy } from './model-provider-compat.mjs';
|
|
20
20
|
import { isProviderCompatibilityRule } from './model-inline-reasoning.mjs';
|
|
21
21
|
import { bindNativeContext, nativeContextDefaults } from './context-profile.mjs';
|
|
22
|
+
import { privateDirectory } from './local-command-state.mjs';
|
|
22
23
|
import { createEngineDeliveryJournal, engineDeliveryEvidence } from './engine-delivery-evidence.mjs';
|
|
23
24
|
import { createNativeWorkspaceTools } from './workspace-tools.mjs';
|
|
24
25
|
import { createNativeLocalCommandTools } from './local-command-tools.mjs';
|
|
@@ -215,6 +216,8 @@ export async function createEngineRuntime({ workspaceRoot, stateDir, sessionId,
|
|
|
215
216
|
&& scope && ['tenantId', 'workspaceId', 'userId', 'agentId'].every(key => text(scope[key])), 'engine_runtime_invalid');
|
|
216
217
|
const root = realpathSync(resolve(workspaceRoot));
|
|
217
218
|
mkdirSync(stateDir, { recursive: true });
|
|
219
|
+
const windows = process.platform === 'win32';
|
|
220
|
+
if (windows) privateDirectory(realpathSync(stateDir));
|
|
218
221
|
const description = admitEngineModel(model);
|
|
219
222
|
const roles = nativeChildRoles({ subAgents });
|
|
220
223
|
const supportsImages = description.input.includes('image');
|
|
@@ -230,7 +233,7 @@ export async function createEngineRuntime({ workspaceRoot, stateDir, sessionId,
|
|
|
230
233
|
const local = execution.localExecution(executionOptions);
|
|
231
234
|
const workspace = createNativeWorkspaceTools({ workspaceRoot: root, stateDir: join(stateDir, 'workspace'), sessionId, authorize: decide });
|
|
232
235
|
const deliveries = createEngineDeliveryJournal(join(stateDir, 'delivery'), () => workspace.captureDelivery());
|
|
233
|
-
const commands = createNativeLocalCommandTools({ workspaceRoot: root, stateRoot: join(stateDir, 'commands'), sessionId,
|
|
236
|
+
const commands = windows ? null : createNativeLocalCommandTools({ workspaceRoot: root, stateRoot: join(stateDir, 'commands'), sessionId,
|
|
234
237
|
settings: local.settings, sourceEnv: local.environment, outputPolicy: local.outputPolicy, environmentPolicy: local.environmentPolicy,
|
|
235
238
|
shellPolicy: commandSandbox,
|
|
236
239
|
artifacts, authorize: (request, info) => decide(request, true, info?.readOnlyCommand),
|
|
@@ -241,7 +244,7 @@ export async function createEngineRuntime({ workspaceRoot, stateDir, sessionId,
|
|
|
241
244
|
// Do not advertise a search which can only return provider_not_configured.
|
|
242
245
|
// Public page fetching remains available independently of search credentials.
|
|
243
246
|
if (!search.configured) web.definitions = web.definitions.filter(tool => tool.name !== 'web_search');
|
|
244
|
-
const owners = [workspace, commands, web];
|
|
247
|
+
const owners = [workspace, ...(commands ? [commands] : []), web];
|
|
245
248
|
const route = new Map(owners.flatMap(port => port.definitions.map(definition => [definition.name, port])));
|
|
246
249
|
// Anything a Run advertises that the engine does not own was admitted as a host tool.
|
|
247
250
|
const hostPort = {
|
|
@@ -330,17 +333,17 @@ export async function createEngineRuntime({ workspaceRoot, stateDir, sessionId,
|
|
|
330
333
|
const modelSurface = bindNativeModelSurface({ environment: execution.executionEnvironment(executionOptions), description });
|
|
331
334
|
const modelPort = createNativeModelPort({ fetchImpl, resolveProfile: async () => ({ protocol: description.protocol, baseUrl: description.baseUrl,
|
|
332
335
|
apiKey: await model.apiKey(), model: description.modelName, parameters: description.parameters }) });
|
|
333
|
-
const background = createBackgroundCommandPort({ scope, store, readers: { local_process: commands.reader } });
|
|
336
|
+
const background = createBackgroundCommandPort({ scope, store, readers: commands ? { local_process: commands.reader } : {} });
|
|
334
337
|
const lifetime = new AbortController();
|
|
335
338
|
const childDefinitions = [];
|
|
336
339
|
let children;
|
|
337
340
|
if (roles.length) {
|
|
338
341
|
try {
|
|
339
|
-
const childTools = [...workspace.definitions, ...commands
|
|
342
|
+
const childTools = [...workspace.definitions, ...(commands?.definitions ?? [])].map(tool => tool.readOnly
|
|
340
343
|
? tool : { ...tool, approvalPolicy: DURABLE_APPROVAL });
|
|
341
344
|
const fileWorkspaces = createStudioNativeChildWorkspaces({ workspaceRoot: root, stateDir });
|
|
342
|
-
const commandResource = childCommandResource({ ...local.binding,
|
|
343
|
-
controls: { ...local.binding.controls, shellPolicy: commandSandbox ?? local.binding.controls.shellPolicy } });
|
|
345
|
+
const commandResource = commands ? childCommandResource({ ...local.binding,
|
|
346
|
+
controls: { ...local.binding.controls, shellPolicy: commandSandbox ?? local.binding.controls.shellPolicy } }) : null;
|
|
344
347
|
children = await createNativeChildren({ roles, scope, sessionId, store, tools: childTools, fileWorkspaces,
|
|
345
348
|
commandResource, isClosed: () => lifetime.signal.aborted, detachSignal: lifetime.signal,
|
|
346
349
|
restrictTools: (tools, parent) => tools.flatMap(tool => {
|
|
@@ -360,7 +363,7 @@ export async function createEngineRuntime({ workspaceRoot, stateDir, sessionId,
|
|
|
360
363
|
const childState = join(stateDir, 'children', digest({ childScope, childSession }));
|
|
361
364
|
const files = createNativeWorkspaceTools({ workspaceRoot: childRoot, stateDir: join(childState, 'workspace'),
|
|
362
365
|
sessionId: childSession, authorize: decide });
|
|
363
|
-
const command = executionResource ? createNativeLocalCommandTools({ workspaceRoot: childRoot,
|
|
366
|
+
const command = commands && executionResource ? createNativeLocalCommandTools({ workspaceRoot: childRoot,
|
|
364
367
|
stateRoot: join(childState, 'commands'), sessionId: childSession, settings: local.settings, sourceEnv: local.environment,
|
|
365
368
|
outputPolicy: local.outputPolicy, environmentPolicy: local.environmentPolicy, shellPolicy: commandSandbox,
|
|
366
369
|
authorize: decide, captureWorkspace: request => files.capture(request),
|
|
@@ -113,6 +113,8 @@ export function projectEngineEvent(event, requiredVerification = false, thinking
|
|
|
113
113
|
case 'model.retry_scheduled':
|
|
114
114
|
return { ...base, category: 'model', title: 'waiting',
|
|
115
115
|
...(Number.isSafeInteger(payload.retryAt) && payload.retryAt > 0 ? { retryAt: payload.retryAt } : {}),
|
|
116
|
+
...(Number.isSafeInteger(payload.attempt) && payload.attempt > 0 ? { attempt: payload.attempt } : {}),
|
|
117
|
+
...(payload.purpose === 'compaction' ? { purpose: 'compaction' } : {}),
|
|
116
118
|
...(Number.isSafeInteger(payload.failure?.httpStatus) ? { httpStatus: payload.failure.httpStatus } : {}) };
|
|
117
119
|
case 'context.summary_completed':
|
|
118
120
|
case 'completion.delivery_review_completed':
|
|
@@ -142,6 +144,8 @@ export function projectEngineEvent(event, requiredVerification = false, thinking
|
|
|
142
144
|
case 'model.retry_exhausted': return { ...base, category: 'model', reason: 'provider_unavailable',
|
|
143
145
|
modelError: nativeModelStopMessage('provider_unavailable') };
|
|
144
146
|
case 'run.started': return { ...base, category: 'run', title: 'started' };
|
|
147
|
+
case 'run.paused': return { ...base, category: 'run', title: 'paused', reason: payload.reason,
|
|
148
|
+
...modelStopFields(payload.reason) };
|
|
145
149
|
case 'run.terminal': return { ...base, category: 'run', title: payload.phase, status: payload.outcome,
|
|
146
150
|
...(requiredVerification ? { requiredVerification: true } : {}),
|
|
147
151
|
...(payload.reason ? { reason: payload.reason } : {}),
|
|
@@ -10,6 +10,8 @@ import { PassThrough } from 'node:stream';
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
import { engineStartupFromArgs, engineView, serveEngine } from './engine-server.mjs';
|
|
12
12
|
import { ENGINE_EXECUTION_POLICY } from './engine-runtime.mjs';
|
|
13
|
+
import { privateDirectory } from './local-command-state.mjs';
|
|
14
|
+
import { isInside } from './workspace-paths.mjs';
|
|
13
15
|
import { createEngineViewStore } from './engine-view-store.mjs';
|
|
14
16
|
import { ENGINE_TOOL_POLICY } from './engine-tool-policy.mjs';
|
|
15
17
|
import { ENGINE_CONTEXT } from './engine-context.mjs';
|
|
@@ -187,8 +189,9 @@ export function createEngineService({ startup, token, env = process.env, fetchIm
|
|
|
187
189
|
mkdirSync(startup.stateDir, { recursive: true, mode: 0o700 });
|
|
188
190
|
const stateDir = realpathSync(startup.stateDir);
|
|
189
191
|
const workspace = realpathSync(startup.workspace);
|
|
190
|
-
if (workspace
|
|
192
|
+
if (isInside(workspace, stateDir) || isInside(stateDir, workspace))
|
|
191
193
|
throw new Error('engine_service_workspace_state_overlap');
|
|
194
|
+
if (process.platform === 'win32') privateDirectory(stateDir);
|
|
192
195
|
if (startup.commandSandbox !== undefined) {
|
|
193
196
|
if (startup.commandSandbox !== ISOLATED_COMMAND_SHELL) throw new Error('engine_service_sandbox_invalid');
|
|
194
197
|
const [command, ...args] = shellCommandArgv(':', startup.commandSandbox, { workspaceRoot: workspace, cwd: workspace });
|
|
@@ -4,6 +4,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
4
4
|
import { constants, closeSync, existsSync, fstatSync, fsyncSync, lstatSync, mkdirSync,
|
|
5
5
|
openSync, readFileSync, readSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import { dirname, join, resolve } from 'node:path';
|
|
7
|
+
import { verifyWindowsPrivateState } from './windows-private-state.mjs';
|
|
7
8
|
import { validCommandEvidence } from './local-command-evidence.mjs';
|
|
8
9
|
|
|
9
10
|
export const LOCAL_BACKGROUND_CONTRACT = 'agentkit.local-background-command/v1';
|
|
@@ -24,6 +25,10 @@ function noSymlinks(path) {
|
|
|
24
25
|
if (dirname(part) === part) break;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
function hasPrivatePermissions(path, stat) {
|
|
29
|
+
return process.platform === 'win32' ? verifyWindowsPrivateState(resolve(path), stat)
|
|
30
|
+
: stat.uid === process.getuid() && (stat.mode & 0o077) === 0;
|
|
31
|
+
}
|
|
27
32
|
export function privateDirectory(path, create = false) {
|
|
28
33
|
noSymlinks(path);
|
|
29
34
|
if (create) {
|
|
@@ -33,12 +38,12 @@ export function privateDirectory(path, create = false) {
|
|
|
33
38
|
for (const part of missing.reverse()) { syncDirectory(part); syncDirectory(dirname(part)); }
|
|
34
39
|
}
|
|
35
40
|
const stat = lstatSync(path);
|
|
36
|
-
check(stat.isDirectory() &&
|
|
41
|
+
check(stat.isDirectory() && hasPrivatePermissions(path, stat), 'background_state_not_private');
|
|
37
42
|
}
|
|
38
43
|
export function privateFile(path, allowMissing = false) {
|
|
39
44
|
try {
|
|
40
45
|
const stat = lstatSync(path);
|
|
41
|
-
check(stat.isFile() &&
|
|
46
|
+
check(stat.isFile() && hasPrivatePermissions(path, stat),
|
|
42
47
|
'background_state_not_private');
|
|
43
48
|
// Atomic publication can unlink the inode while lstat is observing it.
|
|
44
49
|
// It is never usable evidence; read-only callers may retry the new inode.
|
|
@@ -66,6 +71,9 @@ export function openPrivate(path, flags) {
|
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
export function syncDirectory(directory) {
|
|
74
|
+
// Node opens directory handles read-only on Windows. File data is still
|
|
75
|
+
// flushed before rename, and SQLite journals use their native Windows VFS.
|
|
76
|
+
if (process.platform === 'win32') return;
|
|
69
77
|
const fd = openSync(directory, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
70
78
|
try { fsyncSync(fd); } finally { closeSync(fd); }
|
|
71
79
|
}
|
|
@@ -19,6 +19,8 @@ const messages = Object.freeze({
|
|
|
19
19
|
context_finalization_budget_unavailable: '剩余上下文预算不足以完成任务收尾。',
|
|
20
20
|
repeated_tool_error_no_progress: '工具连续失败且任务没有进展,请检查工具配置或输入。',
|
|
21
21
|
verification_report_missing: '任务验证没有返回结果,无法确认完成。',
|
|
22
|
+
delivery_no_progress: '验收待办仍未完成,继续执行后没有观察到进展。任务已暂停,可补充信息后继续。',
|
|
23
|
+
delivery_repair_budget_exhausted: '验收待办仍未完成,本轮可用的修复预算已用完。任务已暂停。',
|
|
22
24
|
child_owner_unavailable: '子任务执行端不可用,请核对原子任务状态。',
|
|
23
25
|
child_receipt_unavailable: '子任务结果尚未确认,请核对原子任务。',
|
|
24
26
|
background_children_unsettled: '后台子任务尚未结算,请核对后继续。',
|
|
@@ -51,6 +53,7 @@ function modelFailureMessage(value, retriesExhausted = false) {
|
|
|
51
53
|
}
|
|
52
54
|
export function nativeModelStopMessage(reason, modelFailure) {
|
|
53
55
|
if (reason === 'provider_unavailable') return '模型服务暂不可用,自动重试次数已用完。任务已暂停,可稍后继续。';
|
|
56
|
+
if (reason === 'delivery_no_progress' || reason === 'delivery_repair_budget_exhausted') return messages[reason];
|
|
54
57
|
if (!modelReasons.has(reason)) return null;
|
|
55
58
|
if (reason.endsWith('_retry_exhausted')) {
|
|
56
59
|
const detail = modelFailureMessage(modelFailure, true);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Windows mode bits and uid do not describe NTFS access. Resolve security
|
|
5
|
+
// identifiers directly so the check does not depend on localized account names.
|
|
6
|
+
const checkAcl = Buffer.from(String.raw`
|
|
7
|
+
$ErrorActionPreference = 'Stop'
|
|
8
|
+
$sidType = [System.Security.Principal.SecurityIdentifier]
|
|
9
|
+
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
|
10
|
+
$trusted = @($user, 'S-1-5-18', 'S-1-5-32-544')
|
|
11
|
+
$acl = Microsoft.PowerShell.Security\Get-Acl -LiteralPath $env:AGENTKIT_WINDOWS_PRIVATE_STATE_PATH
|
|
12
|
+
if ($acl.GetOwner($sidType).Value -notin $trusted) { exit 2 }
|
|
13
|
+
foreach ($entry in $acl.GetAccessRules($true, $true, $sidType)) {
|
|
14
|
+
if ($entry.AccessControlType -ne 'Allow') { continue }
|
|
15
|
+
$principal = $entry.IdentityReference.Value
|
|
16
|
+
if ($principal -in $trusted) { continue }
|
|
17
|
+
$inheritOnly = $entry.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly
|
|
18
|
+
if ($principal -eq 'S-1-3-0' -and $inheritOnly) { continue }
|
|
19
|
+
exit 2
|
|
20
|
+
}
|
|
21
|
+
`, 'utf16le').toString('base64');
|
|
22
|
+
|
|
23
|
+
const verified = new Map();
|
|
24
|
+
|
|
25
|
+
export function verifyWindowsPrivateState(path, stat) {
|
|
26
|
+
const identity = [stat.dev, stat.ino, stat.birthtimeMs, stat.ctimeMs].join(':');
|
|
27
|
+
if (verified.get(path) === identity) return true;
|
|
28
|
+
const root = process.env.SystemRoot;
|
|
29
|
+
if (!root) return false;
|
|
30
|
+
const executable = join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
31
|
+
const result = spawnSync(executable, ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', checkAcl], {
|
|
32
|
+
env: { SystemRoot: root, AGENTKIT_WINDOWS_PRIVATE_STATE_PATH: path },
|
|
33
|
+
stdio: 'ignore', windowsHide: true, timeout: 5000,
|
|
34
|
+
});
|
|
35
|
+
if (result.status !== 0 || result.error) return false;
|
|
36
|
+
// Only the accepted principals can change an accepted ACL. File replacement
|
|
37
|
+
// or metadata changes require a fresh check.
|
|
38
|
+
if (verified.size >= 1024) verified.clear();
|
|
39
|
+
verified.set(path, identity);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* JSON files for audit/inspection only.
|
|
22
22
|
*/
|
|
23
23
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
24
|
-
import { isAbsolute, join } from 'node:path';
|
|
24
|
+
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
25
25
|
import { createHash, randomUUID } from 'node:crypto';
|
|
26
26
|
|
|
27
27
|
const READ_STATE_VERSION = 'native-workspace-read-state/v1';
|
|
@@ -244,9 +244,9 @@ export class WorkspaceStateStore {
|
|
|
244
244
|
|
|
245
245
|
/** Write JSON atomically (temp sibling + rename) to avoid torn reads on restart. */
|
|
246
246
|
export function atomicWriteJson(dest, value) {
|
|
247
|
-
const dir =
|
|
247
|
+
const dir = dirname(dest);
|
|
248
248
|
mkdirSync(dir, { recursive: true });
|
|
249
|
-
const tmp = join(dir, `.${dest
|
|
249
|
+
const tmp = join(dir, `.${basename(dest)}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`);
|
|
250
250
|
writeFileSync(tmp, JSON.stringify(value), 'utf-8');
|
|
251
251
|
renameSync(tmp, dest);
|
|
252
252
|
}
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
readFileSync, readlinkSync, readSync, realpathSync, rmdirSync, statSync,
|
|
23
23
|
unlinkSync,
|
|
24
24
|
} from 'node:fs';
|
|
25
|
-
import { join } from 'node:path';
|
|
25
|
+
import { basename, join } from 'node:path';
|
|
26
26
|
import { checkPythonSyntax, NATIVE_PYTHON_SYNTAX } from './python-syntax.mjs';
|
|
27
27
|
import { acquireWorkspaceMutationLock, workspaceMutationGuard } from './workspace-mutation-lock.mjs';
|
|
28
28
|
import { budgetWorkspaceSourcePage, validateSourcePageBudget } from './source-page.mjs';
|
|
@@ -247,7 +247,7 @@ export function createNativeWorkspaceTools({
|
|
|
247
247
|
const items = []; // {abs, name}
|
|
248
248
|
const targetInfo = lstatSync(target, { bigint: true });
|
|
249
249
|
if (targetInfo.isFile()) {
|
|
250
|
-
items.push({ abs: target, name: target
|
|
250
|
+
items.push({ abs: target, name: basename(target) });
|
|
251
251
|
} else if (targetInfo.isDirectory()) {
|
|
252
252
|
const stack = [target];
|
|
253
253
|
while (stack.length) {
|
|
@@ -918,7 +918,7 @@ export function createNativeWorkspaceTools({
|
|
|
918
918
|
if (glob) {
|
|
919
919
|
filtered = candidates.filter((c) => {
|
|
920
920
|
const rel = relativeOf(c);
|
|
921
|
-
return fnmatch(rel, glob) || fnmatch(c
|
|
921
|
+
return fnmatch(rel, glob) || fnmatch(basename(c), glob);
|
|
922
922
|
});
|
|
923
923
|
}
|
|
924
924
|
let pattern;
|