@kingsoftcloud/agentkit-harness-node 0.0.6 → 0.0.8
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/package.json +2 -2
- package/src/native/workspace-tools.mjs +25 -14
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.8",
|
|
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.",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"src/package-integrity.mjs"
|
|
138
138
|
],
|
|
139
139
|
"dependencies": {
|
|
140
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
140
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.8",
|
|
141
141
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
142
142
|
"parse5": "7.3.0",
|
|
143
143
|
"playwright-core": "1.58.2",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { publicErrorMessage, publicErrorCode } from '@kingsoftcloud/agentkit-harness-core/error-presentation';
|
|
1
|
+
import { publicErrorMessage, publicErrorCode, publicFailureContent } from '@kingsoftcloud/agentkit-harness-core/error-presentation';
|
|
2
2
|
/**
|
|
3
3
|
* Native Node workspace tools for the AgentKit Harness.
|
|
4
4
|
*
|
|
@@ -476,7 +476,7 @@ export function createNativeWorkspaceTools({
|
|
|
476
476
|
if (e.code === 'EEXIST') {
|
|
477
477
|
return { ok: false, path: rel, error_type: 'file_exists', error_message: 'workspace file was created before publication', suggested_action: 'Read the new file before proposing an overwrite.' };
|
|
478
478
|
}
|
|
479
|
-
return { ok: false, path: rel, error_type: e.code
|
|
479
|
+
return { ok: false, path: rel, error_type: typeof e.code === 'string' && e.code.startsWith('checkpoint_') ? publicErrorCode(e, 'publish_failed') : 'publish_failed', error_message: publicErrorMessage(e) };
|
|
480
480
|
}
|
|
481
481
|
const stat = statSync(t, { bigint: true });
|
|
482
482
|
refreshReadState(rel, stat, content, t);
|
|
@@ -790,7 +790,7 @@ export function createNativeWorkspaceTools({
|
|
|
790
790
|
try {
|
|
791
791
|
publish(target, Buffer.from(updated, 'utf-8'));
|
|
792
792
|
} catch (e) {
|
|
793
|
-
return { stat: null, error: { ok: false, path: rel, error_type: e.code
|
|
793
|
+
return { stat: null, error: { ok: false, path: rel, error_type: typeof e.code === 'string' && e.code.startsWith('checkpoint_') ? publicErrorCode(e, 'publish_failed') : 'publish_failed', error_message: publicErrorMessage(e) } };
|
|
794
794
|
}
|
|
795
795
|
const stat = statSync(target, { bigint: true });
|
|
796
796
|
refreshReadState(rel, stat, updated, target);
|
|
@@ -832,7 +832,7 @@ export function createNativeWorkspaceTools({
|
|
|
832
832
|
try {
|
|
833
833
|
JSON.parse(text ?? '');
|
|
834
834
|
} catch (e) {
|
|
835
|
-
issues.push({ severity: 'error', ...jsonErrorPosition(e.message, text), message: e
|
|
835
|
+
issues.push({ severity: 'error', ...jsonErrorPosition(e.message, text), message: publicErrorMessage(e) });
|
|
836
836
|
}
|
|
837
837
|
} else {
|
|
838
838
|
genericTextChecks(text, issues);
|
|
@@ -923,7 +923,7 @@ export function createNativeWorkspaceTools({
|
|
|
923
923
|
try {
|
|
924
924
|
pattern = new RegExp(isRegex ? needle : escapeRegex(needle), caseSensitive ? '' : 'i');
|
|
925
925
|
} catch (e) {
|
|
926
|
-
return { ok: false, error_code: 'invalid_search_pattern', error_message: e
|
|
926
|
+
return { ok: false, error_code: 'invalid_search_pattern', error_message: publicErrorMessage(e) };
|
|
927
927
|
}
|
|
928
928
|
const limit = Math.max(1, Math.min(maxResults || 100, 5000));
|
|
929
929
|
const contextLimit = Math.max(0, Math.min(contextLines || 0, 20));
|
|
@@ -983,7 +983,7 @@ export function createNativeWorkspaceTools({
|
|
|
983
983
|
}
|
|
984
984
|
activeMutations?.add(relativeOf(target));
|
|
985
985
|
} catch (e) {
|
|
986
|
-
return { ok: false, error_message: `workspace delete failed: ${e
|
|
986
|
+
return { ok: false, error_message: `workspace delete failed: ${publicErrorMessage(e)}` };
|
|
987
987
|
}
|
|
988
988
|
return { ok: true, deleted: relativeOf(target) };
|
|
989
989
|
}
|
|
@@ -1047,7 +1047,18 @@ export function createNativeWorkspaceTools({
|
|
|
1047
1047
|
|
|
1048
1048
|
// ---- execute --------------------------------------------------------------
|
|
1049
1049
|
|
|
1050
|
-
|
|
1050
|
+
// One public failure boundary also covers helper results and parser diagnostics.
|
|
1051
|
+
// Successful file/media data and Host effect evidence must not be rewritten.
|
|
1052
|
+
async function execute(request, options) {
|
|
1053
|
+
try {
|
|
1054
|
+
const result = await executeWorkspace(request, options);
|
|
1055
|
+
return result.status === 'ok' ? result : { ...result, content: publicFailureContent(result.content) };
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
throw Object.assign(new Error(publicErrorMessage(error)), { code: publicErrorCode(error, 'internal_error') });
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
async function executeWorkspace(request, { assertCurrent, checkpointCommitted } = {}) {
|
|
1051
1062
|
if (!request || typeof request !== 'object') {
|
|
1052
1063
|
return { status: 'error', content: { code: 'invalid_request', message: 'request object required' } };
|
|
1053
1064
|
}
|
|
@@ -1072,7 +1083,7 @@ export function createNativeWorkspaceTools({
|
|
|
1072
1083
|
try { checkRootBoundary(); }
|
|
1073
1084
|
catch (e) {
|
|
1074
1085
|
if (e instanceof RootBoundaryError) {
|
|
1075
|
-
return { status: 'error', content: { code: e
|
|
1086
|
+
return { status: 'error', content: { code: publicErrorCode(e, 'workspace_root_changed'), message: publicErrorMessage(e) } };
|
|
1076
1087
|
}
|
|
1077
1088
|
throw e;
|
|
1078
1089
|
}
|
|
@@ -1085,14 +1096,14 @@ export function createNativeWorkspaceTools({
|
|
|
1085
1096
|
} else {
|
|
1086
1097
|
let decision;
|
|
1087
1098
|
try { decision = await authorizeFn(request); } catch (e) {
|
|
1088
|
-
return { status: 'error', content: { code: 'authorize_failed', message: e
|
|
1099
|
+
return { status: 'error', content: { code: 'authorize_failed', message: publicErrorMessage(e) } };
|
|
1089
1100
|
}
|
|
1090
1101
|
// Re-check the boundary after the authorization await: the root could
|
|
1091
1102
|
// have been swapped while the caller was deciding approval.
|
|
1092
1103
|
try { checkRootBoundary(); }
|
|
1093
1104
|
catch (e) {
|
|
1094
1105
|
if (e instanceof RootBoundaryError) {
|
|
1095
|
-
return { status: 'error', content: { code: e
|
|
1106
|
+
return { status: 'error', content: { code: publicErrorCode(e, 'workspace_root_changed'), message: publicErrorMessage(e) } };
|
|
1096
1107
|
}
|
|
1097
1108
|
throw e;
|
|
1098
1109
|
}
|
|
@@ -1178,19 +1189,19 @@ export function createNativeWorkspaceTools({
|
|
|
1178
1189
|
try {
|
|
1179
1190
|
compensateRewind(preparedRewind, publications, checkpoint, guard);
|
|
1180
1191
|
return { status: 'error', workspaceChangedPaths: [...mutations], content: { ok: false,
|
|
1181
|
-
error_type: 'checkpoint_rewind_compensated', cause: e
|
|
1192
|
+
error_type: 'checkpoint_rewind_compensated', cause: publicErrorCode(e, 'rewind_failed'), compensated: true, executed: true, paths: [...mutations] } };
|
|
1182
1193
|
} catch (error) { compensationError = error; }
|
|
1183
1194
|
}
|
|
1184
1195
|
if (checkpoint && !mutations.size) { try { checkpoint.fail(); } catch {} }
|
|
1185
1196
|
if (signal?.aborted && !mutations.size) return canceled();
|
|
1186
1197
|
if (e instanceof WorkspacePathError && !mutations.size) {
|
|
1187
|
-
return { status: 'error', content: { ok: false, error_type: 'path_escape', error_message: e
|
|
1198
|
+
return { status: 'error', content: { ok: false, error_type: 'path_escape', error_message: publicErrorMessage(e) } };
|
|
1188
1199
|
}
|
|
1189
1200
|
if (mutations.size) return { status: 'uncertain', workspaceChangedPaths: [...mutations],
|
|
1190
1201
|
content: { ok: false, error_type: compensationError ? 'checkpoint_compensation_incomplete'
|
|
1191
1202
|
: name === 'apply_workspace_patch' ? 'patch_publication_incomplete' : 'state_persist_failed',
|
|
1192
|
-
...(compensationError ? { compensation_reason: compensationError
|
|
1193
|
-
return { status: 'error', content: { ok: false, error_type: e
|
|
1203
|
+
...(compensationError ? { compensation_reason: publicErrorCode(compensationError, 'compensation_failed') } : {}), executed: true, paths: [...mutations] } };
|
|
1204
|
+
return { status: 'error', content: { ok: false, error_type: publicErrorCode(e, 'internal_error'), error_message: publicErrorMessage(e) } };
|
|
1194
1205
|
} finally { activeMutations = previousMutations; activeGuard = previousGuard; activeCheckpoint = previousCheckpoint; activeDisplayChanges = previousDisplayChanges;
|
|
1195
1206
|
activePublications = previousPublications; activeReads = previousReads; release?.(); }
|
|
1196
1207
|
// The only asynchronous implementation parses captured read-only bytes.
|