nolo-cli 0.1.32 → 0.1.33
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/README.md +0 -6
- package/agent-runtime/agentRecordConfig.ts +2 -0
- package/agent-runtime/hostAdapter.ts +1 -0
- package/agent-runtime/index.ts +0 -21
- package/agent-runtime/localToolPolicy.ts +6 -13
- package/agent-runtime/localWorkspaceTools.ts +30 -333
- package/agent-runtime/platformChatProvider.ts +1 -4
- package/agent-runtime/runtimeToolPolicy.ts +47 -32
- package/agentAliases.ts +14 -83
- package/agentCommandSupport.ts +3 -6
- package/agentInternalCommandEntries.ts +2 -13
- package/agentListCommands.ts +19 -28
- package/agentMachineCommands.ts +40 -336
- package/agentPullCommand.ts +36 -56
- package/agentRecordCommands.ts +3 -5
- package/agentRecordHelpers.ts +22 -189
- package/agentRunCommand.ts +438 -107
- package/agentRuntimeLocal.ts +0 -10
- package/ai/agent/cliExecutor.ts +19 -323
- package/authCommands.ts +2 -36
- package/cli/agentAliases.ts +14 -83
- package/cli/agentCommandSupport.ts +3 -6
- package/cli/agentInternalCommandEntries.ts +2 -13
- package/cli/agentListCommands.ts +19 -28
- package/cli/agentMachineCommands.ts +40 -336
- package/cli/agentPullCommand.ts +36 -56
- package/cli/agentRecordCommands.ts +3 -5
- package/cli/agentRecordHelpers.ts +22 -189
- package/cli/agentRunCommand.ts +438 -107
- package/cli/agentRuntimeLocal.ts +0 -10
- package/cli/authCommands.ts +2 -36
- package/cli/cliEnvHelpers.ts +21 -162
- package/cli/client/agentRun.ts +853 -57
- package/cli/client/localRuntimeAdapter.ts +22 -159
- package/cli/client/streamingOutput.ts +3 -1
- package/cli/client/taskRunPrompt.ts +24 -7
- package/cli/commandRegistry.ts +2 -3
- package/cli/connectorRunArtifact.ts +10 -34
- package/cli/connectorWebSocketTarget.ts +6 -10
- package/cli/internalCommandEntries.ts +0 -8
- package/cli/localRuntimeDb.ts +2 -39
- package/cli/machineCommands.ts +189 -190
- package/cli/machineDaemonCommands.ts +165 -9
- package/cli/machineHeartbeatCommands.ts +2 -1
- package/cli/machineStatusCommands.ts +13 -5
- package/cli/machineWatchCommands.ts +1 -1
- package/cli/machineWsRunDispatch.ts +14 -48
- package/cli/machineWsSession.ts +0 -2
- package/cli/offlineMarxistsAgentCommand.ts +314 -0
- package/cli/runtimeDoctorCommands.ts +69 -18
- package/cli/scriptCommandEntries.ts +45 -5
- package/cli/tableCommands.ts +133 -33
- package/cli/taskRunCommand.ts +211 -16
- package/cli/tui/session.ts +372 -43
- package/cli/workflowInternalCommandEntries.ts +0 -20
- package/cliEnvHelpers.ts +21 -162
- package/client/agentConfigResolver.test.ts +2 -0
- package/client/agentRun.test.ts +12 -208
- package/client/agentRun.ts +853 -57
- package/client/localRuntimeAdapter.test.ts +9 -168
- package/client/localRuntimeAdapter.ts +22 -159
- package/client/localToolPolicy.test.ts +4 -28
- package/client/streamingOutput.ts +3 -1
- package/client/taskRunPrompt.ts +24 -7
- package/commandRegistry.ts +2 -3
- package/connectorRunArtifact.ts +10 -34
- package/connectorWebSocketTarget.ts +6 -10
- package/database/server/db.ts +34 -15
- package/internalCommandEntries.ts +0 -8
- package/localRuntimeDb.ts +2 -39
- package/machineCommands.ts +189 -190
- package/machineDaemonCommands.ts +165 -9
- package/machineHeartbeatCommands.ts +2 -1
- package/machineStatusCommands.ts +13 -5
- package/machineWatchCommands.ts +1 -1
- package/machineWsRunDispatch.ts +14 -48
- package/machineWsSession.ts +0 -2
- package/offlineMarxistsAgentCommand.ts +314 -0
- package/package.json +49 -193
- package/runtimeDoctorCommands.ts +69 -18
- package/scriptCommandEntries.ts +45 -5
- package/tableCommands.ts +133 -33
- package/taskRunCommand.ts +211 -16
- package/tui/session.ts +372 -43
- package/workflowInternalCommandEntries.ts +0 -20
- package/agent-runtime/dialogStatus.ts +0 -139
- package/agent-runtime/hostRuntimeConfig.ts +0 -86
- package/agentCreateCustomCommands.ts +0 -278
- package/agentDialogsCommands.ts +0 -227
- package/agentDoctorCommands.ts +0 -203
- package/agentRunLocalWorkspace.ts +0 -182
- package/agentRunParsing.ts +0 -298
- package/agentSuperviseCommands.ts +0 -8
- package/agentUnpublishCommands.ts +0 -113
- package/ai/agent/agentRunDialogLineage.ts +0 -56
- package/ai/policy/types.ts +0 -64
- package/ai/skills/skillSummaryMarker.ts +0 -26
- package/app/types.ts +0 -358
- package/build.ts +0 -16
- package/buildPublish.ts +0 -138
- package/buildPublishArtifactAssembly.ts +0 -724
- package/buildPublishImportAnalysis.ts +0 -242
- package/chat/messages/fetchMessages.ts +0 -84
- package/chat/messages/types.ts +0 -185
- package/cli/agentCreateCustomCommands.ts +0 -278
- package/cli/agentDialogsCommands.ts +0 -227
- package/cli/agentDoctorCommands.ts +0 -203
- package/cli/agentRunLocalWorkspace.ts +0 -182
- package/cli/agentRunParsing.ts +0 -298
- package/cli/agentSuperviseCommands.ts +0 -8
- package/cli/agentUnpublishCommands.ts +0 -113
- package/cli/buildPublish.ts +0 -138
- package/cli/buildPublishArtifactAssembly.ts +0 -724
- package/cli/buildPublishImportAnalysis.ts +0 -242
- package/cli/cliIoTypes.ts +0 -3
- package/cli/cliRuntimeDoctorReport.ts +0 -193
- package/cli/client/agentRunInput.ts +0 -10
- package/cli/client/agentRunLocalExecution.ts +0 -124
- package/cli/client/agentRunLocalExecutor.ts +0 -179
- package/cli/client/agentRunRuntimeSelection.ts +0 -145
- package/cli/client/agentRunServerTransport.ts +0 -397
- package/cli/client/agentRunTaskRunRecorder.ts +0 -176
- package/cli/customCodingAgentFlow.ts +0 -208
- package/cli/customCodingAgentRecord.ts +0 -179
- package/cli/dialogDataAccess.ts +0 -186
- package/cli/dialogInternalCommandEntries.ts +0 -11
- package/cli/dialogReadCommands.ts +0 -180
- package/cli/dialogReadHelpers.ts +0 -226
- package/cli/dialogStatusCommands.ts +0 -123
- package/cli/docInternalCommandEntries.ts +0 -20
- package/cli/hybridReadHelpers.ts +0 -109
- package/cli/machineCommandPrompts.ts +0 -79
- package/cli/machineCommandResolution.ts +0 -43
- package/cli/noloReadBridgePrompt.ts +0 -16
- package/cli/pageCreateCommands.ts +0 -219
- package/cli/pageDeleteCommands.ts +0 -167
- package/cli/pageReadCommands.ts +0 -151
- package/cli/pageUpdateCommands.ts +0 -249
- package/cli/pageWriteHelpers.ts +0 -209
- package/cli/publishPackage.ts +0 -36
- package/cli/runtimeInternalCommandEntries.ts +0 -15
- package/cli/runtimePassthroughCommands.ts +0 -22
- package/cli/scriptPassthroughHelpers.ts +0 -28
- package/cli/secretScanHelpers.ts +0 -31
- package/cli/spaceAttachCommands.ts +0 -134
- package/cli/spaceCategoryCommands.ts +0 -263
- package/cli/spaceCommands.ts +0 -295
- package/cli/spaceDeleteCommands.ts +0 -312
- package/cli/spaceInternalCommandEntries.ts +0 -21
- package/cli/spaceMutationHelpers.ts +0 -135
- package/cli/spaceReadCommands.ts +0 -323
- package/cli/tableDataOutput.ts +0 -41
- package/cli/tableDataSafety.ts +0 -26
- package/cli/tableMetaCommands.ts +0 -307
- package/cli/tableMutationCommands.ts +0 -266
- package/cli/tableQueryParsing.ts +0 -90
- package/cli/tableQueryRequest.ts +0 -53
- package/cli/taskRunActions.ts +0 -122
- package/cli/taskRunParsing.ts +0 -86
- package/cli/taskRunPromptShared.ts +0 -55
- package/cli/tui/tuiCatalog.ts +0 -22
- package/cli/tui/tuiCommandInterpreter.ts +0 -253
- package/cli/tui/tuiPresentation.ts +0 -146
- package/cliIoTypes.ts +0 -3
- package/cliRuntimeDoctorReport.ts +0 -193
- package/client/agentRunInput.ts +0 -10
- package/client/agentRunLocalExecution.test.ts +0 -123
- package/client/agentRunLocalExecution.ts +0 -124
- package/client/agentRunLocalExecutor.ts +0 -179
- package/client/agentRunRuntimeSelection.test.ts +0 -159
- package/client/agentRunRuntimeSelection.ts +0 -145
- package/client/agentRunServerTransport.ts +0 -397
- package/client/agentRunTaskRunRecorder.ts +0 -176
- package/connector-experimental/daemonLauncher.ts +0 -223
- package/create/space/spaceKeys.ts +0 -65
- package/create/types.ts +0 -21
- package/customCodingAgentFlow.ts +0 -208
- package/customCodingAgentRecord.ts +0 -179
- package/database/keys.ts +0 -765
- package/database/server/authorityStoreTypes.ts +0 -31
- package/database/server/legacyServerDb.ts +0 -58
- package/database/server/levelAuthorityStore.ts +0 -75
- package/database/server/memoryAuthorityStore.ts +0 -133
- package/database/server/serverStoreFactory.ts +0 -124
- package/database/tombstones.ts +0 -52
- package/database/utils/ulid.ts +0 -1
- package/dialogDataAccess.ts +0 -186
- package/dialogInternalCommandEntries.ts +0 -11
- package/dialogReadCommands.ts +0 -180
- package/dialogReadHelpers.ts +0 -226
- package/dialogStatusCommands.ts +0 -123
- package/docInternalCommandEntries.ts +0 -20
- package/hybridReadHelpers.ts +0 -109
- package/machineCommandPrompts.ts +0 -79
- package/machineCommandResolution.ts +0 -43
- package/noloReadBridgePrompt.ts +0 -16
- package/pageCreateCommands.ts +0 -219
- package/pageDeleteCommands.ts +0 -167
- package/pageReadCommands.ts +0 -151
- package/pageUpdateCommands.ts +0 -249
- package/pageWriteHelpers.ts +0 -209
- package/publishPackage.ts +0 -36
- package/runtimeInternalCommandEntries.ts +0 -15
- package/runtimePassthroughCommands.ts +0 -22
- package/scriptPassthroughHelpers.ts +0 -28
- package/secretScanHelpers.ts +0 -31
- package/share/helpers.ts +0 -302
- package/share/keys.ts +0 -243
- package/share/types.ts +0 -100
- package/spaceAttachCommands.ts +0 -134
- package/spaceCategoryCommands.ts +0 -263
- package/spaceCommands.ts +0 -295
- package/spaceDeleteCommands.ts +0 -312
- package/spaceInternalCommandEntries.ts +0 -21
- package/spaceMutationHelpers.ts +0 -135
- package/spaceReadCommands.ts +0 -323
- package/tableDataOutput.ts +0 -41
- package/tableDataSafety.ts +0 -26
- package/tableMetaCommands.ts +0 -307
- package/tableMutationCommands.ts +0 -266
- package/tableQueryParsing.ts +0 -90
- package/tableQueryRequest.ts +0 -53
- package/taskRunActions.ts +0 -122
- package/taskRunParsing.ts +0 -86
- package/taskRunPromptShared.ts +0 -55
- package/tui/tuiCatalog.ts +0 -22
- package/tui/tuiCommandInterpreter.test.ts +0 -169
- package/tui/tuiCommandInterpreter.ts +0 -253
- package/tui/tuiPresentation.test.ts +0 -154
- package/tui/tuiPresentation.ts +0 -146
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import type { LocalAgentToolEvent } from "../agent-runtime/localLoop";
|
|
4
|
-
import {
|
|
5
|
-
classifyTaskRunReviewStatus,
|
|
6
|
-
formatToolTraceEvent,
|
|
7
|
-
nextLocalToolRoundLimit,
|
|
8
|
-
parseLocalToolRoundLimitError,
|
|
9
|
-
resolveLocalToolRoundRetryLimit,
|
|
10
|
-
shouldCollectLocalToolEvidence,
|
|
11
|
-
shouldTraceLocalTools,
|
|
12
|
-
summarizeLocalToolEvidence,
|
|
13
|
-
} from "./agentRunLocalExecution";
|
|
14
|
-
|
|
15
|
-
function makeToolEvent(
|
|
16
|
-
overrides: Partial<LocalAgentToolEvent> & Pick<LocalAgentToolEvent, "type">
|
|
17
|
-
): LocalAgentToolEvent {
|
|
18
|
-
return {
|
|
19
|
-
type: overrides.type,
|
|
20
|
-
round: overrides.round ?? 0,
|
|
21
|
-
toolCallId: overrides.toolCallId ?? "call-1",
|
|
22
|
-
toolName: overrides.toolName ?? "readWorkspaceFile",
|
|
23
|
-
message: overrides.message,
|
|
24
|
-
metadata: overrides.metadata,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("agentRunLocalExecution", () => {
|
|
29
|
-
test("traces local tools from explicit option or env flag", () => {
|
|
30
|
-
expect(shouldTraceLocalTools({ traceTools: true, env: {} })).toBe(true);
|
|
31
|
-
expect(shouldTraceLocalTools({ traceTools: false, env: { NOLO_TRACE_TOOLS: "1" } })).toBe(
|
|
32
|
-
true
|
|
33
|
-
);
|
|
34
|
-
expect(shouldTraceLocalTools({ env: {} })).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("collects local tool evidence only when task-run row key exists", () => {
|
|
38
|
-
expect(shouldCollectLocalToolEvidence({ taskRunContext: { rowDbKey: "row-1" } })).toBe(true);
|
|
39
|
-
expect(shouldCollectLocalToolEvidence({ taskRunContext: {} })).toBe(false);
|
|
40
|
-
expect(shouldCollectLocalToolEvidence({})).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("summarizes tool evidence with unique tools and event counts", () => {
|
|
44
|
-
const events: LocalAgentToolEvent[] = [
|
|
45
|
-
makeToolEvent({ type: "tool-call", toolName: "readWorkspaceFile", toolCallId: "call-1" }),
|
|
46
|
-
makeToolEvent({ type: "tool-result", toolName: "readWorkspaceFile", toolCallId: "call-1" }),
|
|
47
|
-
makeToolEvent({ type: "tool-call", round: 1, toolName: "execShell", toolCallId: "call-2" }),
|
|
48
|
-
makeToolEvent({ type: "tool-error", round: 1, toolName: "execShell", toolCallId: "call-2" }),
|
|
49
|
-
makeToolEvent({ type: "tool-call", round: 1, toolName: "readWorkspaceFile", toolCallId: "call-3" }),
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
expect(summarizeLocalToolEvidence(events)).toEqual({
|
|
53
|
-
toolsUsed: ["readWorkspaceFile", "execShell"],
|
|
54
|
-
summary: {
|
|
55
|
-
callCount: 3,
|
|
56
|
-
resultCount: 1,
|
|
57
|
-
errorCount: 1,
|
|
58
|
-
rounds: 2,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
expect(summarizeLocalToolEvidence([])).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("parses local tool round limit errors only from matching messages", () => {
|
|
65
|
-
expect(parseLocalToolRoundLimitError(new Error("Local agent exceeded max tool rounds: 256"))).toBe(
|
|
66
|
-
256
|
|
67
|
-
);
|
|
68
|
-
expect(parseLocalToolRoundLimitError("Local agent exceeded max tool rounds: 4")).toBe(4);
|
|
69
|
-
expect(parseLocalToolRoundLimitError(new Error("other failure"))).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("resolves retry limit from env positive integers and falls back to default", () => {
|
|
73
|
-
expect(resolveLocalToolRoundRetryLimit({ env: { NOLO_LOCAL_MAX_TOOL_ROUNDS_LIMIT: "64" } })).toBe(
|
|
74
|
-
64
|
|
75
|
-
);
|
|
76
|
-
expect(resolveLocalToolRoundRetryLimit({ env: { NOLO_LOCAL_MAX_TOOL_ROUNDS_LIMIT: "0" } })).toBe(
|
|
77
|
-
512
|
|
78
|
-
);
|
|
79
|
-
expect(resolveLocalToolRoundRetryLimit({ env: { NOLO_LOCAL_MAX_TOOL_ROUNDS_LIMIT: "abc" } })).toBe(
|
|
80
|
-
512
|
|
81
|
-
);
|
|
82
|
-
expect(resolveLocalToolRoundRetryLimit({ env: {} })).toBe(512);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("increments next local tool round limit by doubling positive values", () => {
|
|
86
|
-
expect(nextLocalToolRoundLimit(0)).toBe(1);
|
|
87
|
-
expect(nextLocalToolRoundLimit(-1)).toBe(1);
|
|
88
|
-
expect(nextLocalToolRoundLimit(8)).toBe(16);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("formats tool trace events for calls, results, and errors", () => {
|
|
92
|
-
expect(
|
|
93
|
-
formatToolTraceEvent(
|
|
94
|
-
makeToolEvent({ type: "tool-call", round: 0, toolName: "readWorkspaceFile", toolCallId: "call-1" })
|
|
95
|
-
)
|
|
96
|
-
).toBe("[nolo:tool] round 1 -> readWorkspaceFile (call-1)\n");
|
|
97
|
-
expect(
|
|
98
|
-
formatToolTraceEvent(
|
|
99
|
-
makeToolEvent({ type: "tool-result", round: 1, toolName: "readWorkspaceFile", toolCallId: "call-1" })
|
|
100
|
-
)
|
|
101
|
-
).toBe("[nolo:tool] round 2 <- readWorkspaceFile (call-1)\n");
|
|
102
|
-
expect(
|
|
103
|
-
formatToolTraceEvent(
|
|
104
|
-
makeToolEvent({
|
|
105
|
-
type: "tool-error",
|
|
106
|
-
round: 1,
|
|
107
|
-
toolName: "execShell",
|
|
108
|
-
toolCallId: "call-2",
|
|
109
|
-
message: "timed out",
|
|
110
|
-
})
|
|
111
|
-
)
|
|
112
|
-
).toBe("[nolo:tool] round 2 !! execShell: timed out\n");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("classifies review status only from explicit or strong signals", () => {
|
|
116
|
-
expect(classifyTaskRunReviewStatus("Review decision: passed")).toBe("passed");
|
|
117
|
-
expect(classifyTaskRunReviewStatus("Changes requested for missing test coverage")).toBe(
|
|
118
|
-
"needs_changes"
|
|
119
|
-
);
|
|
120
|
-
expect(classifyTaskRunReviewStatus("无法审查,存在阻塞")).toBe("blocked");
|
|
121
|
-
expect(classifyTaskRunReviewStatus("I looked at the diff and have notes")).toBeUndefined();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import type { LocalAgentToolEvent } from "../agent-runtime/localLoop";
|
|
2
|
-
import type { EnvLike } from "../cliEnvHelpers";
|
|
3
|
-
|
|
4
|
-
type TaskRunReviewStatus = "passed" | "needs_changes" | "blocked";
|
|
5
|
-
|
|
6
|
-
export type TaskRunToolEvidence = {
|
|
7
|
-
toolsUsed: string[];
|
|
8
|
-
summary: {
|
|
9
|
-
callCount: number;
|
|
10
|
-
resultCount: number;
|
|
11
|
-
errorCount: number;
|
|
12
|
-
rounds: number;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type TraceLocalToolOptions = {
|
|
17
|
-
traceTools?: boolean;
|
|
18
|
-
env: EnvLike;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type CollectLocalToolEvidenceOptions = {
|
|
22
|
-
taskRunContext?: {
|
|
23
|
-
rowDbKey?: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type ResolveLocalToolRoundRetryLimitOptions = {
|
|
28
|
-
env: EnvLike;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const DEFAULT_LOCAL_AGENT_TOOL_ROUND_RETRY_LIMIT = 512;
|
|
32
|
-
|
|
33
|
-
function parsePositiveInteger(value: string | undefined) {
|
|
34
|
-
if (!value) return null;
|
|
35
|
-
const parsed = Number(value);
|
|
36
|
-
if (!Number.isInteger(parsed) || parsed <= 0) return null;
|
|
37
|
-
return parsed;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function shouldTraceLocalTools(options: TraceLocalToolOptions) {
|
|
41
|
-
return Boolean(options.traceTools || options.env.NOLO_TRACE_TOOLS === "1");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function shouldCollectLocalToolEvidence(options: CollectLocalToolEvidenceOptions) {
|
|
45
|
-
return Boolean(options.taskRunContext?.rowDbKey);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function summarizeLocalToolEvidence(
|
|
49
|
-
events: LocalAgentToolEvent[]
|
|
50
|
-
): TaskRunToolEvidence | undefined {
|
|
51
|
-
if (events.length === 0) return undefined;
|
|
52
|
-
const toolsUsed = [
|
|
53
|
-
...new Set(
|
|
54
|
-
events
|
|
55
|
-
.filter((event) => event.type === "tool-call")
|
|
56
|
-
.map((event) => event.toolName)
|
|
57
|
-
.filter(Boolean)
|
|
58
|
-
),
|
|
59
|
-
];
|
|
60
|
-
const rounds = new Set(events.map((event) => event.round)).size;
|
|
61
|
-
return {
|
|
62
|
-
toolsUsed,
|
|
63
|
-
summary: {
|
|
64
|
-
callCount: events.filter((event) => event.type === "tool-call").length,
|
|
65
|
-
resultCount: events.filter((event) => event.type === "tool-result").length,
|
|
66
|
-
errorCount: events.filter((event) => event.type === "tool-error").length,
|
|
67
|
-
rounds,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function parseLocalToolRoundLimitError(error: unknown) {
|
|
73
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
74
|
-
const match = message.match(/Local agent exceeded max tool rounds:\s*(\d+)/);
|
|
75
|
-
if (!match) return null;
|
|
76
|
-
return Number(match[1]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function resolveLocalToolRoundRetryLimit(
|
|
80
|
-
options: ResolveLocalToolRoundRetryLimitOptions
|
|
81
|
-
) {
|
|
82
|
-
return (
|
|
83
|
-
parsePositiveInteger(options.env.NOLO_LOCAL_MAX_TOOL_ROUNDS_LIMIT) ??
|
|
84
|
-
DEFAULT_LOCAL_AGENT_TOOL_ROUND_RETRY_LIMIT
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function nextLocalToolRoundLimit(current: number) {
|
|
89
|
-
return current <= 0 ? 1 : current * 2;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function formatToolTraceEvent(event: LocalAgentToolEvent) {
|
|
93
|
-
const round = event.round + 1;
|
|
94
|
-
if (event.type === "tool-call") {
|
|
95
|
-
return `[nolo:tool] round ${round} -> ${event.toolName} (${event.toolCallId})\n`;
|
|
96
|
-
}
|
|
97
|
-
if (event.type === "tool-error") {
|
|
98
|
-
return `[nolo:tool] round ${round} !! ${event.toolName}: ${event.message ?? "failed"}\n`;
|
|
99
|
-
}
|
|
100
|
-
return `[nolo:tool] round ${round} <- ${event.toolName} (${event.toolCallId})\n`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function classifyTaskRunReviewStatus(summary?: string): TaskRunReviewStatus | undefined {
|
|
104
|
-
const normalized = summary?.toLowerCase().trim();
|
|
105
|
-
if (!normalized) return undefined;
|
|
106
|
-
|
|
107
|
-
const explicit = normalized.match(/review\s+decision\s*:\s*(passed|needs_changes|blocked)/);
|
|
108
|
-
if (explicit?.[1]) return explicit[1] as TaskRunReviewStatus;
|
|
109
|
-
|
|
110
|
-
if (/\b(blocked|cannot review|unable to review)\b|无法审查|阻塞/.test(normalized)) {
|
|
111
|
-
return "blocked";
|
|
112
|
-
}
|
|
113
|
-
if (
|
|
114
|
-
/\b(needs changes|request changes|changes requested|not approved)\b|需要修改|需修改|发现问题/.test(
|
|
115
|
-
normalized
|
|
116
|
-
)
|
|
117
|
-
) {
|
|
118
|
-
return "needs_changes";
|
|
119
|
-
}
|
|
120
|
-
if (/\b(approved|lgtm|no issues|passed)\b|通过|无问题/.test(normalized)) {
|
|
121
|
-
return "passed";
|
|
122
|
-
}
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { runLocalAgentTurn, resolveHostRuntimeConfigFromEnv } from "../agentRuntimeLocal";
|
|
2
|
-
import { LOCAL_AGENT_CONFIG_MISSING_CODE } from "../agent-runtime/localLoop";
|
|
3
|
-
import type { LocalAgentToolEvent } from "../agent-runtime/localLoop";
|
|
4
|
-
import { buildUserInputContent } from "./agentRunInput";
|
|
5
|
-
import { createCliLocalRuntimeAdapter } from "./localRuntimeAdapter";
|
|
6
|
-
import { prependTaskRunPrompt } from "./taskRunPrompt";
|
|
7
|
-
import { recordTaskRunOutcome } from "./agentRunTaskRunRecorder";
|
|
8
|
-
import {
|
|
9
|
-
formatToolTraceEvent,
|
|
10
|
-
nextLocalToolRoundLimit,
|
|
11
|
-
parseLocalToolRoundLimitError,
|
|
12
|
-
resolveLocalToolRoundRetryLimit,
|
|
13
|
-
shouldCollectLocalToolEvidence,
|
|
14
|
-
shouldTraceLocalTools,
|
|
15
|
-
summarizeLocalToolEvidence,
|
|
16
|
-
} from "./agentRunLocalExecution";
|
|
17
|
-
import type { RunAgentTurnOptions } from "./agentRun";
|
|
18
|
-
|
|
19
|
-
export type LocalAgentTurnResult = {
|
|
20
|
-
exitCode: number;
|
|
21
|
-
dialogId?: string;
|
|
22
|
-
localError?: unknown;
|
|
23
|
-
toolEvidence?: ReturnType<typeof summarizeLocalToolEvidence>;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function buildDefaultLocalRuntimeAdapter(options: RunAgentTurnOptions) {
|
|
27
|
-
return createCliLocalRuntimeAdapter({
|
|
28
|
-
env: options.env,
|
|
29
|
-
hostRuntimeConfig: resolveHostRuntimeConfigFromEnv({
|
|
30
|
-
env: options.env,
|
|
31
|
-
surface: "cli-local",
|
|
32
|
-
workspaceBinding: "explicit-cwd",
|
|
33
|
-
}),
|
|
34
|
-
fetchImpl: options.fetchImpl,
|
|
35
|
-
cwd: options.localRuntimeCwd,
|
|
36
|
-
output: options.output,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function resolveLocalRuntimeAdapter(options: RunAgentTurnOptions) {
|
|
41
|
-
return (
|
|
42
|
-
options.localRuntimeAdapter ||
|
|
43
|
-
options.localRuntimeAdapterFactory?.(options.env, { cwd: options.localRuntimeCwd }) ||
|
|
44
|
-
buildDefaultLocalRuntimeAdapter(options)
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function isMissingLocalAgentConfigError(error: unknown, agentRef: string) {
|
|
49
|
-
return Boolean(
|
|
50
|
-
error &&
|
|
51
|
-
typeof error === "object" &&
|
|
52
|
-
"code" in error &&
|
|
53
|
-
(error as { code?: string; agentRef?: string }).code === LOCAL_AGENT_CONFIG_MISSING_CODE &&
|
|
54
|
-
(error as { code?: string; agentRef?: string }).agentRef === agentRef
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export async function runInjectedLocalAgentTurn(options: RunAgentTurnOptions) {
|
|
59
|
-
return runLocalAgentTurnWithAutoRoundExpansion(options, { reportFailure: true });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export async function refreshMissingLocalAgentConfig(options: RunAgentTurnOptions) {
|
|
63
|
-
const adapter = resolveLocalRuntimeAdapter(options);
|
|
64
|
-
if (!adapter) return false;
|
|
65
|
-
const agentConfig = await adapter.loadAgentConfig(options.agentKey);
|
|
66
|
-
return Boolean(agentConfig);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function runLocalAgentTurnWithAutoRoundExpansion(
|
|
70
|
-
options: RunAgentTurnOptions,
|
|
71
|
-
settings: { reportFailure: boolean }
|
|
72
|
-
) {
|
|
73
|
-
const maxRetryLimit = resolveLocalToolRoundRetryLimit(options);
|
|
74
|
-
let currentMaxToolRounds = options.maxToolRounds;
|
|
75
|
-
let lastResult: Awaited<ReturnType<typeof runLocalAgentTurnForCli>> | null = null;
|
|
76
|
-
|
|
77
|
-
while (true) {
|
|
78
|
-
const attemptOptions = {
|
|
79
|
-
...options,
|
|
80
|
-
...(typeof currentMaxToolRounds === "number" ? { maxToolRounds: currentMaxToolRounds } : {}),
|
|
81
|
-
};
|
|
82
|
-
const result = await runLocalAgentTurnForCli(attemptOptions, { reportFailure: false });
|
|
83
|
-
lastResult = result;
|
|
84
|
-
if (result.exitCode === 0) return result;
|
|
85
|
-
|
|
86
|
-
const exhaustedRounds = parseLocalToolRoundLimitError(result.localError);
|
|
87
|
-
if (exhaustedRounds === null) break;
|
|
88
|
-
|
|
89
|
-
const nextMaxToolRounds = nextLocalToolRoundLimit(exhaustedRounds);
|
|
90
|
-
if (nextMaxToolRounds > maxRetryLimit) break;
|
|
91
|
-
|
|
92
|
-
options.output.write(
|
|
93
|
-
`[nolo] Local agent used all ${exhaustedRounds} tool rounds; retrying with ${nextMaxToolRounds}.\n`
|
|
94
|
-
);
|
|
95
|
-
currentMaxToolRounds = nextMaxToolRounds;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (settings.reportFailure && lastResult?.localError) {
|
|
99
|
-
options.output.write(
|
|
100
|
-
`[nolo] Local agent run failed: ${
|
|
101
|
-
lastResult.localError instanceof Error ? lastResult.localError.message : String(lastResult.localError)
|
|
102
|
-
}\n`
|
|
103
|
-
);
|
|
104
|
-
await recordTaskRunOutcome({
|
|
105
|
-
options,
|
|
106
|
-
status: "failed",
|
|
107
|
-
errorCode: "LOCAL_AGENT_FAILED",
|
|
108
|
-
resultSummary:
|
|
109
|
-
lastResult.localError instanceof Error ? lastResult.localError.message : String(lastResult.localError),
|
|
110
|
-
toolEvidence: lastResult.toolEvidence,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return lastResult ?? { exitCode: 1 };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export async function runLocalAgentTurnForCli(
|
|
117
|
-
options: RunAgentTurnOptions,
|
|
118
|
-
settings: { reportFailure: boolean }
|
|
119
|
-
): Promise<LocalAgentTurnResult> {
|
|
120
|
-
const adapter = resolveLocalRuntimeAdapter(options);
|
|
121
|
-
if (!adapter) {
|
|
122
|
-
options.output.write("[nolo] Local runtime was requested but no local runtime adapter is available.\n");
|
|
123
|
-
return { exitCode: 1 };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
options.output.write(`\n${options.agentName} -> working locally...\n`);
|
|
127
|
-
const toolEvents: LocalAgentToolEvent[] = [];
|
|
128
|
-
try {
|
|
129
|
-
const traceLocalTools = shouldTraceLocalTools(options);
|
|
130
|
-
const collectToolEvidence = shouldCollectLocalToolEvidence(options);
|
|
131
|
-
const result = await runLocalAgentTurn({
|
|
132
|
-
adapter,
|
|
133
|
-
agentRef: options.agentKey,
|
|
134
|
-
input: buildUserInputContent(
|
|
135
|
-
prependTaskRunPrompt(options.message, options.taskRunContext),
|
|
136
|
-
options.imageUrls
|
|
137
|
-
),
|
|
138
|
-
continueDialogId: options.continueDialogId,
|
|
139
|
-
spaceId: options.spaceId,
|
|
140
|
-
category: options.category,
|
|
141
|
-
inheritedFromDialogKey: options.inheritedFromDialogKey,
|
|
142
|
-
parentDialogId: options.parentDialogId,
|
|
143
|
-
background: options.background,
|
|
144
|
-
noStream: options.noStream,
|
|
145
|
-
maxToolRounds: options.maxToolRounds,
|
|
146
|
-
...(traceLocalTools || collectToolEvidence
|
|
147
|
-
? {
|
|
148
|
-
onToolEvent: (event) => {
|
|
149
|
-
if (collectToolEvidence) toolEvents.push(event);
|
|
150
|
-
if (traceLocalTools) options.output.write(formatToolTraceEvent(event));
|
|
151
|
-
},
|
|
152
|
-
}
|
|
153
|
-
: {}),
|
|
154
|
-
});
|
|
155
|
-
const content = result.content.trim();
|
|
156
|
-
if (content) {
|
|
157
|
-
options.output.write(`\n${options.agentName} > ${content}\n`);
|
|
158
|
-
} else {
|
|
159
|
-
options.output.write(`\n${options.agentName} > (no text response)\n`);
|
|
160
|
-
}
|
|
161
|
-
await recordTaskRunOutcome({
|
|
162
|
-
options,
|
|
163
|
-
status: options.background ? "running" : "completed",
|
|
164
|
-
dialogId: result.dialogId,
|
|
165
|
-
...(!options.background && content ? { resultSummary: content } : {}),
|
|
166
|
-
toolEvidence: summarizeLocalToolEvidence(toolEvents),
|
|
167
|
-
});
|
|
168
|
-
return { exitCode: 0, dialogId: result.dialogId };
|
|
169
|
-
} catch (error) {
|
|
170
|
-
if (settings.reportFailure) {
|
|
171
|
-
options.output.write(
|
|
172
|
-
`[nolo] Local agent run failed: ${
|
|
173
|
-
error instanceof Error ? error.message : String(error)
|
|
174
|
-
}\n`
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
return { exitCode: 1, localError: error, toolEvidence: summarizeLocalToolEvidence(toolEvents) };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
findServerPlatformTools,
|
|
5
|
-
isKnownServerPlatformAgent,
|
|
6
|
-
normalizeAgentRef,
|
|
7
|
-
resolveRequestedRuntimeMode,
|
|
8
|
-
resolveServerPlatformToolNames,
|
|
9
|
-
shouldAttemptAutoLocal,
|
|
10
|
-
shouldShowUsage,
|
|
11
|
-
shouldSkipAutoLocalForServerPlatformTools,
|
|
12
|
-
shouldUseScriptBridge,
|
|
13
|
-
type OutputLike,
|
|
14
|
-
} from "./agentRunRuntimeSelection";
|
|
15
|
-
|
|
16
|
-
class CaptureOutput implements OutputLike {
|
|
17
|
-
chunks: string[] = [];
|
|
18
|
-
|
|
19
|
-
write(chunk: string) {
|
|
20
|
-
this.chunks.push(chunk);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
text() {
|
|
24
|
-
return this.chunks.join("");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("agentRunRuntimeSelection", () => {
|
|
29
|
-
test("uses the repo script bridge only when no auth token is available", () => {
|
|
30
|
-
expect(shouldUseScriptBridge({ hasAuthToken: false, scriptPathExists: true })).toBe(true);
|
|
31
|
-
expect(shouldUseScriptBridge({ hasAuthToken: true, scriptPathExists: true })).toBe(false);
|
|
32
|
-
expect(shouldUseScriptBridge({ hasAuthToken: false, scriptPathExists: false })).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("identifies server platform tools that local runtime cannot provide", () => {
|
|
36
|
-
expect(findServerPlatformTools(["readWorkspaceFile", "queryTableRows", "updateTableRow"])).toEqual([
|
|
37
|
-
"queryTableRows",
|
|
38
|
-
"updateTableRow",
|
|
39
|
-
]);
|
|
40
|
-
expect(findServerPlatformTools(["readWorkspaceFile", "execShell"])).toEqual([]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("merges server platform tool declarations from toolNames and runtime policy", () => {
|
|
44
|
-
expect(
|
|
45
|
-
resolveServerPlatformToolNames({
|
|
46
|
-
toolNames: ["queryTableRows", "readWorkspaceFile"],
|
|
47
|
-
runtimeToolPolicy: { agentTools: ["taskRun", "execShell", "updateTableRow"] },
|
|
48
|
-
})
|
|
49
|
-
).toEqual(["queryTableRows", "taskRun", "updateTableRow"]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("normalizes agent refs before alias matching", () => {
|
|
53
|
-
expect(normalizeAgentRef(" Nolo Fullstack ")).toBe("nolo fullstack");
|
|
54
|
-
expect(isKnownServerPlatformAgent({ agentKey: " Nolo Fullstack " })).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("detects known server platform agents by canonical key", () => {
|
|
58
|
-
expect(isKnownServerPlatformAgent({ agentKey: "agent-b2e06f801f-01NOLOFULLSTK00000001J740Q" })).toBe(true);
|
|
59
|
-
expect(isKnownServerPlatformAgent({ agentKey: "agent-user-1-01FRONTENDAG0000000115N4E1" })).toBe(true);
|
|
60
|
-
expect(isKnownServerPlatformAgent({ agentKey: "agent-user-1-custom" })).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("shows usage only when debug or usage env is enabled", () => {
|
|
64
|
-
expect(shouldShowUsage({})).toBe(false);
|
|
65
|
-
expect(shouldShowUsage({ NOLO_DEBUG: "1" })).toBe(true);
|
|
66
|
-
expect(shouldShowUsage({ NOLO_SHOW_USAGE: "1" })).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("resolves requested runtime mode from explicit option before env", () => {
|
|
70
|
-
expect(resolveRequestedRuntimeMode({ runtimeMode: "local", env: { NOLO_RUNTIME_MODE: "server" } })).toBe(
|
|
71
|
-
"local"
|
|
72
|
-
);
|
|
73
|
-
expect(resolveRequestedRuntimeMode({ env: { NOLO_RUNTIME_MODE: "server" } })).toBe("server");
|
|
74
|
-
expect(resolveRequestedRuntimeMode({ env: { NOLO_RUNTIME_MODE: "weird" } })).toBe("auto");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("attempts auto-local when an adapter/factory exists or local env is configured", () => {
|
|
78
|
-
expect(shouldAttemptAutoLocal({ env: {}, localRuntimeAdapter: { loadAgentConfig: async () => undefined } })).toBe(
|
|
79
|
-
true
|
|
80
|
-
);
|
|
81
|
-
expect(shouldAttemptAutoLocal({ env: {}, localRuntimeAdapterFactory: {} })).toBe(true);
|
|
82
|
-
expect(shouldAttemptAutoLocal({ env: { OPENAI_API_KEY: "key-1" } })).toBe(true);
|
|
83
|
-
expect(shouldAttemptAutoLocal({ env: { NOLO_LOCAL_AGENT_KEY: "agent-1" } })).toBe(true);
|
|
84
|
-
expect(shouldAttemptAutoLocal({ env: {} })).toBe(false);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("skips auto-local immediately for known server platform agents", async () => {
|
|
88
|
-
const output = new CaptureOutput();
|
|
89
|
-
|
|
90
|
-
await expect(
|
|
91
|
-
shouldSkipAutoLocalForServerPlatformTools({
|
|
92
|
-
agentKey: "agent-b2e06f801f-01NOLOFULLSTK00000001J740Q",
|
|
93
|
-
env: {},
|
|
94
|
-
output,
|
|
95
|
-
})
|
|
96
|
-
).resolves.toBe(true);
|
|
97
|
-
|
|
98
|
-
expect(output.text()).toContain("known platform agent");
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test("skips auto-local when loaded agent config declares server platform tools", async () => {
|
|
102
|
-
const output = new CaptureOutput();
|
|
103
|
-
|
|
104
|
-
await expect(
|
|
105
|
-
shouldSkipAutoLocalForServerPlatformTools({
|
|
106
|
-
agentKey: "agent-user-1-tools",
|
|
107
|
-
env: {},
|
|
108
|
-
output,
|
|
109
|
-
localRuntimeAdapter: {
|
|
110
|
-
loadAgentConfig: async () => ({
|
|
111
|
-
toolNames: ["queryTableRows", "readWorkspaceFile"],
|
|
112
|
-
runtimeToolPolicy: { agentTools: ["addTableRow", "execShell"] },
|
|
113
|
-
}),
|
|
114
|
-
},
|
|
115
|
-
})
|
|
116
|
-
).resolves.toBe(true);
|
|
117
|
-
|
|
118
|
-
expect(output.text()).toContain("queryTableRows, addTableRow");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("does not skip auto-local when no adapter exists, loading fails, or no server tools are declared", async () => {
|
|
122
|
-
const output = new CaptureOutput();
|
|
123
|
-
|
|
124
|
-
await expect(
|
|
125
|
-
shouldSkipAutoLocalForServerPlatformTools({
|
|
126
|
-
agentKey: "agent-user-1-none",
|
|
127
|
-
env: {},
|
|
128
|
-
output,
|
|
129
|
-
})
|
|
130
|
-
).resolves.toBe(false);
|
|
131
|
-
|
|
132
|
-
await expect(
|
|
133
|
-
shouldSkipAutoLocalForServerPlatformTools({
|
|
134
|
-
agentKey: "agent-user-1-error",
|
|
135
|
-
env: {},
|
|
136
|
-
output,
|
|
137
|
-
localRuntimeAdapter: {
|
|
138
|
-
loadAgentConfig: async () => {
|
|
139
|
-
throw new Error("load failed");
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
).resolves.toBe(false);
|
|
144
|
-
|
|
145
|
-
await expect(
|
|
146
|
-
shouldSkipAutoLocalForServerPlatformTools({
|
|
147
|
-
agentKey: "agent-user-1-local",
|
|
148
|
-
env: {},
|
|
149
|
-
output,
|
|
150
|
-
resolveLocalRuntimeAdapter: () => ({
|
|
151
|
-
loadAgentConfig: async () => ({
|
|
152
|
-
toolNames: ["readWorkspaceFile"],
|
|
153
|
-
runtimeToolPolicy: { agentTools: ["execShell"] },
|
|
154
|
-
}),
|
|
155
|
-
}),
|
|
156
|
-
})
|
|
157
|
-
).resolves.toBe(false);
|
|
158
|
-
});
|
|
159
|
-
});
|