nolo-cli 0.1.32 → 0.1.34
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 +4 -10
- package/agent-runtime/agentRecordConfig.ts +10 -0
- package/agent-runtime/hostAdapter.ts +10 -1
- package/agent-runtime/index.ts +9 -20
- package/agent-runtime/localLoop.ts +49 -2
- package/agent-runtime/localToolPolicy.ts +76 -34
- package/agent-runtime/localWorkspaceTools.ts +30 -333
- package/agent-runtime/openAiCompatibleProvider.ts +7 -3
- package/agent-runtime/openAiCompatibleProviderConfig.ts +15 -26
- package/agent-runtime/platformChatProvider.ts +47 -73
- package/agent-runtime/providerResolution.ts +244 -0
- package/agent-runtime/runtimeToolPolicy.ts +77 -29
- package/agent-runtime/shellCommandPolicy.ts +120 -0
- package/agentAliases.ts +14 -83
- package/agentCommandSupport.ts +3 -6
- package/agentInternalCommandEntries.ts +4 -13
- package/agentListCommands.ts +18 -27
- package/agentMachineCommands.ts +40 -336
- package/agentPullCommand.ts +30 -55
- package/agentRecordCommands.ts +84 -1
- package/agentRecordHelpers.ts +102 -186
- package/agentRunCommand.ts +438 -107
- package/agentRuntimeLocal.ts +2 -9
- package/ai/agent/cliExecutor.ts +19 -323
- package/ai/tools/toolNameAliases.ts +70 -0
- package/authCommands.ts +2 -36
- package/cli/agentAliases.ts +14 -83
- package/cli/agentCommandSupport.ts +3 -6
- package/cli/agentInternalCommandEntries.ts +4 -13
- package/cli/agentListCommands.ts +18 -27
- package/cli/agentMachineCommands.ts +40 -336
- package/cli/agentPullCommand.ts +30 -55
- package/cli/agentRecordCommands.ts +84 -1
- package/cli/agentRecordHelpers.ts +102 -186
- package/cli/agentRunCommand.ts +438 -107
- package/cli/agentRuntimeLocal.ts +2 -9
- package/cli/authCommands.ts +2 -36
- package/cli/cliCommandDispatch.ts +2 -2
- package/cli/cliEnvHelpers.ts +34 -107
- package/cli/client/agentRun.ts +854 -57
- package/cli/client/localRuntimeAdapter.ts +59 -159
- package/cli/client/streamingOutput.ts +3 -1
- package/cli/client/taskRunPrompt.ts +24 -7
- package/cli/commandRegistry.ts +4 -5
- 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 +30 -44
- package/cli/machineWsSession.ts +0 -2
- package/cli/offlineMarxistsAgentCommand.ts +314 -0
- package/cli/runtimeDoctorCommands.ts +72 -15
- 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/cliCommandDispatch.ts +2 -2
- package/cliEnvHelpers.ts +34 -107
- package/client/agentConfigResolver.test.ts +2 -0
- package/client/agentRun.test.ts +12 -208
- package/client/agentRun.ts +854 -57
- package/client/localProviderResolver.test.ts +26 -2
- package/client/localRuntimeAdapter.test.ts +296 -171
- package/client/localRuntimeAdapter.ts +59 -159
- package/client/localToolPolicy.test.ts +4 -28
- package/client/streamingOutput.ts +3 -1
- package/client/taskRunPrompt.ts +24 -7
- package/commandRegistry.ts +4 -5
- package/connectorRunArtifact.ts +10 -34
- package/connectorWebSocketTarget.ts +6 -10
- package/database/server/serverStoreFactory.ts +2 -8
- 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 +30 -44
- package/machineWsSession.ts +0 -2
- package/offlineMarxistsAgentCommand.ts +314 -0
- package/package.json +52 -188
- package/runtimeDoctorCommands.ts +72 -15
- 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/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
package/database/tombstones.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const getRecordTimestamp = (record: any): number => {
|
|
2
|
-
if (!record || typeof record !== "object") return 0;
|
|
3
|
-
|
|
4
|
-
const candidates = [
|
|
5
|
-
record.updatedAt,
|
|
6
|
-
record.updated_at,
|
|
7
|
-
record.createdAt,
|
|
8
|
-
record.created,
|
|
9
|
-
record?.meta?.createdAt,
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
for (const candidate of candidates) {
|
|
13
|
-
if (typeof candidate === "number" && Number.isFinite(candidate) && candidate > 0) {
|
|
14
|
-
return candidate;
|
|
15
|
-
}
|
|
16
|
-
if (typeof candidate === "string" && candidate.trim()) {
|
|
17
|
-
const timestamp = Date.parse(candidate);
|
|
18
|
-
if (Number.isFinite(timestamp) && timestamp > 0) {
|
|
19
|
-
return timestamp;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return 0;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const isTombstoneRecord = (record: any): boolean => {
|
|
28
|
-
if (!record || typeof record !== "object") return false;
|
|
29
|
-
const deletedAt = record.deletedAt;
|
|
30
|
-
if (typeof deletedAt === "string") return deletedAt.trim().length > 0;
|
|
31
|
-
return Boolean(deletedAt);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const shouldReplaceWithNextRecord = (
|
|
35
|
-
nextRecord: any,
|
|
36
|
-
currentRecord: any
|
|
37
|
-
): boolean => {
|
|
38
|
-
const nextTs = getRecordTimestamp(nextRecord);
|
|
39
|
-
const currentTs = getRecordTimestamp(currentRecord);
|
|
40
|
-
|
|
41
|
-
if (nextTs !== currentTs) return nextTs > currentTs;
|
|
42
|
-
return isTombstoneRecord(nextRecord) && !isTombstoneRecord(currentRecord);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const buildTombstoneRecord = <T extends Record<string, any>>(
|
|
46
|
-
record: T,
|
|
47
|
-
nowIso: string
|
|
48
|
-
): T & { deletedAt: string; updatedAt: string } => ({
|
|
49
|
-
...record,
|
|
50
|
-
deletedAt: nowIso,
|
|
51
|
-
updatedAt: nowIso,
|
|
52
|
-
});
|
package/database/utils/ulid.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ulid } from "ulid";
|
package/dialogDataAccess.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { fetchMessages } from "./chat/messages/fetchMessages";
|
|
2
|
-
import { getReadableCliDb } from "./agentCommandSupport";
|
|
3
|
-
import type { DialogHttpAttempt, DialogReadSource } from "./dialogReadHelpers";
|
|
4
|
-
|
|
5
|
-
export function isLocalBaseUrl(baseUrl: string) {
|
|
6
|
-
try {
|
|
7
|
-
const hostname = new URL(baseUrl).hostname;
|
|
8
|
-
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
9
|
-
} catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function fetchJsonWithFallback(
|
|
15
|
-
url: string,
|
|
16
|
-
init: RequestInit,
|
|
17
|
-
fetchImpl: typeof fetch,
|
|
18
|
-
fallbackFetchImpl?: typeof fetch
|
|
19
|
-
) {
|
|
20
|
-
try {
|
|
21
|
-
return await fetchImpl(url, init);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
if (!fallbackFetchImpl) throw error;
|
|
24
|
-
return fallbackFetchImpl(url, init);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function readDialogOverHttp(args: {
|
|
29
|
-
authToken: string;
|
|
30
|
-
base: string;
|
|
31
|
-
dialogId: string;
|
|
32
|
-
dialogKey: string;
|
|
33
|
-
fetchImpl: typeof fetch;
|
|
34
|
-
fallbackFetchImpl?: typeof fetch;
|
|
35
|
-
limit: number;
|
|
36
|
-
}) {
|
|
37
|
-
const authHeaders = {
|
|
38
|
-
...(args.authToken ? { Authorization: `Bearer ${args.authToken}` } : {}),
|
|
39
|
-
"Content-Type": "application/json",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const readViaBridge = async () => {
|
|
43
|
-
const bridgeRes = await fetchJsonWithFallback(
|
|
44
|
-
`${args.base}/api/dialog-read`,
|
|
45
|
-
{
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: authHeaders,
|
|
48
|
-
body: JSON.stringify({
|
|
49
|
-
dialogKey: args.dialogKey,
|
|
50
|
-
dialogId: args.dialogId,
|
|
51
|
-
limit: args.limit,
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
args.fetchImpl,
|
|
55
|
-
args.fallbackFetchImpl
|
|
56
|
-
);
|
|
57
|
-
if (!bridgeRes.ok) {
|
|
58
|
-
throw Object.assign(new Error(`dialog read bridge failed: HTTP ${bridgeRes.status}`), {
|
|
59
|
-
status: bridgeRes.status,
|
|
60
|
-
base: args.base,
|
|
61
|
-
stage: "bridge",
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
const payload = await bridgeRes.json();
|
|
65
|
-
if (!payload?.ok) {
|
|
66
|
-
throw Object.assign(
|
|
67
|
-
new Error(`dialog read bridge failed: ${payload?.error ?? "unknown error"}`),
|
|
68
|
-
{
|
|
69
|
-
status: 500,
|
|
70
|
-
base: args.base,
|
|
71
|
-
stage: "bridge",
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
meta: payload.meta,
|
|
77
|
-
msgs: payload.msgs,
|
|
78
|
-
source: "http" as DialogReadSource,
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const metaRes = await fetchJsonWithFallback(
|
|
83
|
-
`${args.base}/api/v1/db/read/${encodeURIComponent(args.dialogKey)}`,
|
|
84
|
-
{
|
|
85
|
-
headers: args.authToken ? { Authorization: `Bearer ${args.authToken}` } : {},
|
|
86
|
-
},
|
|
87
|
-
args.fetchImpl,
|
|
88
|
-
args.fallbackFetchImpl
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
if (!metaRes.ok) {
|
|
92
|
-
if (metaRes.status === 401 || metaRes.status === 403) {
|
|
93
|
-
return readViaBridge();
|
|
94
|
-
}
|
|
95
|
-
throw Object.assign(new Error(`read dialog meta failed: HTTP ${metaRes.status}`), {
|
|
96
|
-
status: metaRes.status,
|
|
97
|
-
base: args.base,
|
|
98
|
-
stage: "meta",
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const metaPayload = await metaRes.json().catch(() => ({}));
|
|
103
|
-
const meta = metaPayload?.data ?? metaPayload;
|
|
104
|
-
|
|
105
|
-
const msgsRes = await fetchJsonWithFallback(
|
|
106
|
-
`${args.base}/rpc/getConvMsgs`,
|
|
107
|
-
{
|
|
108
|
-
method: "POST",
|
|
109
|
-
headers: authHeaders,
|
|
110
|
-
body: JSON.stringify({ dialogId: args.dialogId, limit: args.limit }),
|
|
111
|
-
},
|
|
112
|
-
args.fetchImpl,
|
|
113
|
-
args.fallbackFetchImpl
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
if (!msgsRes.ok) {
|
|
117
|
-
if (msgsRes.status === 401 || msgsRes.status === 403) {
|
|
118
|
-
return readViaBridge();
|
|
119
|
-
}
|
|
120
|
-
throw Object.assign(new Error(`read dialog messages failed: HTTP ${msgsRes.status}`), {
|
|
121
|
-
status: msgsRes.status,
|
|
122
|
-
base: args.base,
|
|
123
|
-
stage: "messages",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const msgs = await msgsRes.json();
|
|
128
|
-
return {
|
|
129
|
-
meta,
|
|
130
|
-
msgs,
|
|
131
|
-
source: "http" as DialogReadSource,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function tryHttpDialogCandidates(args: {
|
|
136
|
-
authToken: string;
|
|
137
|
-
bases: string[];
|
|
138
|
-
dialogId: string;
|
|
139
|
-
dialogKey: string;
|
|
140
|
-
fetchImpl: typeof fetch;
|
|
141
|
-
fallbackFetchImpl?: typeof fetch;
|
|
142
|
-
limit: number;
|
|
143
|
-
}) {
|
|
144
|
-
const attempts: DialogHttpAttempt[] = [];
|
|
145
|
-
for (const base of args.bases) {
|
|
146
|
-
try {
|
|
147
|
-
const result = await readDialogOverHttp({
|
|
148
|
-
authToken: args.authToken,
|
|
149
|
-
base,
|
|
150
|
-
dialogId: args.dialogId,
|
|
151
|
-
dialogKey: args.dialogKey,
|
|
152
|
-
fetchImpl: args.fetchImpl,
|
|
153
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
154
|
-
limit: args.limit,
|
|
155
|
-
});
|
|
156
|
-
attempts.push({ base, ok: true });
|
|
157
|
-
return { ...result, resolvedBase: base, attempts };
|
|
158
|
-
} catch (error) {
|
|
159
|
-
const status =
|
|
160
|
-
typeof error === "object" && error !== null && "status" in error
|
|
161
|
-
? Number((error as any).status)
|
|
162
|
-
: undefined;
|
|
163
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
164
|
-
attempts.push({ base, ok: false, status, message });
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
throw Object.assign(new Error("All HTTP dialog reads failed"), { attempts });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export async function readDialogFromLocalDb(args: {
|
|
171
|
-
db: Awaited<ReturnType<typeof getReadableCliDb>>;
|
|
172
|
-
dialogId: string;
|
|
173
|
-
dialogKey: string;
|
|
174
|
-
limit: number;
|
|
175
|
-
}) {
|
|
176
|
-
const meta = await args.db.get(args.dialogKey);
|
|
177
|
-
const msgs = await fetchMessages(args.db, args.dialogId, {
|
|
178
|
-
limit: args.limit,
|
|
179
|
-
throwOnError: true,
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
meta,
|
|
183
|
-
msgs,
|
|
184
|
-
source: "local-db-fallback" as DialogReadSource,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createEnvCommand } from "./cliCommandFactories";
|
|
2
|
-
import type { CommandEntry } from "./cliCommandTypes";
|
|
3
|
-
import { runDialogReadCommand } from "./dialogReadCommands";
|
|
4
|
-
import { runDialogStatusCommand } from "./dialogStatusCommands";
|
|
5
|
-
|
|
6
|
-
export function getDialogInternalCommandEntries(): CommandEntry[] {
|
|
7
|
-
return [
|
|
8
|
-
createEnvCommand(["dialog", "read"], "Read a dialog", runDialogReadCommand),
|
|
9
|
-
createEnvCommand(["dialog", "status"], "Read compact dialog status", runDialogStatusCommand),
|
|
10
|
-
];
|
|
11
|
-
}
|
package/dialogReadCommands.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
|
|
2
|
-
import {
|
|
3
|
-
resolveAuthToken,
|
|
4
|
-
resolveServerCandidates,
|
|
5
|
-
} from "./cliEnvHelpers";
|
|
6
|
-
import {
|
|
7
|
-
isLocalBaseUrl,
|
|
8
|
-
readDialogFromLocalDb,
|
|
9
|
-
tryHttpDialogCandidates,
|
|
10
|
-
} from "./dialogDataAccess";
|
|
11
|
-
import {
|
|
12
|
-
buildDialogReadResult,
|
|
13
|
-
parseDialogInputForCli,
|
|
14
|
-
type DialogHttpAttempt,
|
|
15
|
-
type DialogReadSource,
|
|
16
|
-
} from "./dialogReadHelpers";
|
|
17
|
-
|
|
18
|
-
function usage() {
|
|
19
|
-
return [
|
|
20
|
-
"Usage:",
|
|
21
|
-
" nolo dialog read <dialogId|dialogUrl> [limit]",
|
|
22
|
-
"",
|
|
23
|
-
].join("\n");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isHelpArg(value?: string) {
|
|
27
|
-
return value === "-h" || value === "--help";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function parseArgs(args: string[]) {
|
|
31
|
-
const rawInput = args[0]?.trim();
|
|
32
|
-
if (!rawInput || isHelpArg(rawInput)) return { help: true as const };
|
|
33
|
-
const rawLimit = args[1]?.trim() || "50";
|
|
34
|
-
if (!/^\d+$/.test(rawLimit)) {
|
|
35
|
-
throw new Error("limit must be a number");
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
help: false as const,
|
|
39
|
-
rawInput,
|
|
40
|
-
limit: Number(rawLimit),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function runDialogReadCommand(
|
|
45
|
-
args: string[],
|
|
46
|
-
deps: AgentCommandDeps = {}
|
|
47
|
-
) {
|
|
48
|
-
const env = deps.env ?? process.env;
|
|
49
|
-
const output = deps.output ?? process.stdout;
|
|
50
|
-
let parsedArgs: ReturnType<typeof parseArgs>;
|
|
51
|
-
try {
|
|
52
|
-
parsedArgs = parseArgs(args);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
output.write(`[nolo] dialog read failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
55
|
-
return 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (parsedArgs.help) {
|
|
59
|
-
output.write(`${usage()}\n`);
|
|
60
|
-
return args[0] ? 0 : 1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const authToken = resolveAuthToken(args, env);
|
|
64
|
-
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
65
|
-
const fallbackFetchImpl = deps.fallbackFetchImpl;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
const { base, dialogId, userId, spaceId } = parseDialogInputForCli(parsedArgs.rawInput, env);
|
|
69
|
-
const dialogKey = `dialog-${userId}-${dialogId}`;
|
|
70
|
-
const candidateBases = resolveServerCandidates(
|
|
71
|
-
args,
|
|
72
|
-
{
|
|
73
|
-
...env,
|
|
74
|
-
BASE_URL: env.READ_DIALOG_BASE?.trim() || base || env.BASE_URL,
|
|
75
|
-
},
|
|
76
|
-
base
|
|
77
|
-
);
|
|
78
|
-
let meta: any;
|
|
79
|
-
let msgs: any;
|
|
80
|
-
let source: DialogReadSource;
|
|
81
|
-
let resolvedBase = base;
|
|
82
|
-
let attempts: DialogHttpAttempt[] = [];
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
({ meta, msgs, source, resolvedBase, attempts } = await tryHttpDialogCandidates({
|
|
86
|
-
authToken,
|
|
87
|
-
bases: candidateBases,
|
|
88
|
-
dialogId,
|
|
89
|
-
dialogKey,
|
|
90
|
-
fetchImpl,
|
|
91
|
-
fallbackFetchImpl,
|
|
92
|
-
limit: parsedArgs.limit,
|
|
93
|
-
}));
|
|
94
|
-
} catch (error) {
|
|
95
|
-
attempts =
|
|
96
|
-
typeof error === "object" && error !== null && "attempts" in error
|
|
97
|
-
? ((error as any).attempts as DialogHttpAttempt[])
|
|
98
|
-
: attempts;
|
|
99
|
-
const statuses = attempts
|
|
100
|
-
.map((attempt) => attempt.status)
|
|
101
|
-
.filter((status): status is number => typeof status === "number");
|
|
102
|
-
const all404 =
|
|
103
|
-
attempts.length > 0 &&
|
|
104
|
-
statuses.length === attempts.length &&
|
|
105
|
-
statuses.every((status) => status === 404);
|
|
106
|
-
const any401 = statuses.includes(401);
|
|
107
|
-
const localhostCandidate = candidateBases.find(isLocalBaseUrl);
|
|
108
|
-
|
|
109
|
-
if (!localhostCandidate) {
|
|
110
|
-
if (any401) {
|
|
111
|
-
throw new Error(
|
|
112
|
-
`read dialog failed across candidates (${candidateBases.join(", ")}). Hint: set AUTH_TOKEN to a current login token.`
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
throw new Error(
|
|
116
|
-
`read dialog failed across candidates: ${attempts
|
|
117
|
-
.map((attempt) => `${attempt.base} -> ${attempt.status ?? attempt.message}`)
|
|
118
|
-
.join("; ")}`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (all404) {
|
|
123
|
-
throw new Error(
|
|
124
|
-
`read dialog failed: dialog not found on tried servers. Tried: ${candidateBases.join(", ")}`
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const db = deps.db ?? await getReadableCliDb(output);
|
|
130
|
-
({ meta, msgs, source } = await readDialogFromLocalDb({
|
|
131
|
-
db,
|
|
132
|
-
dialogId,
|
|
133
|
-
dialogKey,
|
|
134
|
-
limit: parsedArgs.limit,
|
|
135
|
-
}));
|
|
136
|
-
resolvedBase = localhostCandidate;
|
|
137
|
-
} catch (fallbackError) {
|
|
138
|
-
const fallbackMessage =
|
|
139
|
-
fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
140
|
-
if (any401) {
|
|
141
|
-
throw new Error(
|
|
142
|
-
`read dialog failed: HTTP auth was rejected, and local DB fallback is unavailable (${fallbackMessage}). Hint: set AUTH_TOKEN to a current login token.`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
throw new Error(
|
|
146
|
-
`read dialog failed: HTTP candidates were ${attempts
|
|
147
|
-
.map((attempt) => `${attempt.base} -> ${attempt.status ?? attempt.message}`)
|
|
148
|
-
.join("; ")}; local DB fallback also failed (${fallbackMessage})`
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
output.write(
|
|
154
|
-
`${JSON.stringify(
|
|
155
|
-
buildDialogReadResult({
|
|
156
|
-
source,
|
|
157
|
-
resolvedBase,
|
|
158
|
-
candidateBases,
|
|
159
|
-
attempts,
|
|
160
|
-
spaceId,
|
|
161
|
-
dialogId,
|
|
162
|
-
dialogKey,
|
|
163
|
-
userId,
|
|
164
|
-
meta,
|
|
165
|
-
msgs,
|
|
166
|
-
}),
|
|
167
|
-
null,
|
|
168
|
-
2
|
|
169
|
-
)}\n`
|
|
170
|
-
);
|
|
171
|
-
return 0;
|
|
172
|
-
} catch (error) {
|
|
173
|
-
output.write(
|
|
174
|
-
`[nolo] dialog read failed: ${
|
|
175
|
-
error instanceof Error ? error.message : String(error)
|
|
176
|
-
}\n`
|
|
177
|
-
);
|
|
178
|
-
return 1;
|
|
179
|
-
}
|
|
180
|
-
}
|
package/dialogReadHelpers.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { normalizeSpaceId } from "./create/space/spaceKeys";
|
|
2
|
-
import { parseUserIdFromAuthToken, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
|
|
3
|
-
|
|
4
|
-
export type DialogReadSource = "http" | "local-db-fallback";
|
|
5
|
-
|
|
6
|
-
export type DialogHttpAttempt = {
|
|
7
|
-
base: string;
|
|
8
|
-
ok: boolean;
|
|
9
|
-
status?: number;
|
|
10
|
-
message?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type ParsedDialogInput = {
|
|
14
|
-
base: string;
|
|
15
|
-
dialogId: string;
|
|
16
|
-
userId: string;
|
|
17
|
-
spaceId?: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const DIALOG_PATH_RE = /^\/dialog-(.+)-([0-9A-HJKMNP-TV-Z]{26})$/i;
|
|
21
|
-
const SPACE_DIALOG_PATH_RE =
|
|
22
|
-
/^\/space\/([^/]+)\/dialog-(.+)-([0-9A-HJKMNP-TV-Z]{26})$/i;
|
|
23
|
-
|
|
24
|
-
function normalizeBaseUrl(base: string) {
|
|
25
|
-
return base.trim().replace(/\/+$/, "");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function toToolName(value: unknown) {
|
|
29
|
-
return typeof value === "string" ? value.trim() : "";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function countByName(values: string[]) {
|
|
33
|
-
return values.reduce<Record<string, number>>((acc, value) => {
|
|
34
|
-
acc[value] = (acc[value] ?? 0) + 1;
|
|
35
|
-
return acc;
|
|
36
|
-
}, {});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function uniq(values: string[]) {
|
|
40
|
-
return [...new Set(values.filter(Boolean))];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function parseJsonObject(raw: unknown): Record<string, any> | null {
|
|
44
|
-
if (typeof raw !== "string" || !raw.trim()) return null;
|
|
45
|
-
try {
|
|
46
|
-
const parsed = JSON.parse(raw);
|
|
47
|
-
return parsed && typeof parsed === "object" ? parsed : null;
|
|
48
|
-
} catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function deriveWrittenFiles(toolMessages: any[]) {
|
|
54
|
-
const writeToolNames = new Set([
|
|
55
|
-
"applyEdit",
|
|
56
|
-
"applyLineEdits",
|
|
57
|
-
"writeFile",
|
|
58
|
-
"createDoc",
|
|
59
|
-
"updateDoc",
|
|
60
|
-
]);
|
|
61
|
-
const files: string[] = [];
|
|
62
|
-
for (const message of toolMessages) {
|
|
63
|
-
const toolName = toToolName(message?.toolName ?? message?.name);
|
|
64
|
-
if (!writeToolNames.has(toolName)) continue;
|
|
65
|
-
const payload = message?.toolPayload ?? {};
|
|
66
|
-
const content = parseJsonObject(message?.content);
|
|
67
|
-
const candidates = [
|
|
68
|
-
payload?.input?.filePath,
|
|
69
|
-
payload?.response?.filePath,
|
|
70
|
-
content?.filePath,
|
|
71
|
-
];
|
|
72
|
-
for (const candidate of candidates) {
|
|
73
|
-
const normalized = typeof candidate === "string" ? candidate.trim() : "";
|
|
74
|
-
if (normalized) files.push(normalized);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return uniq(files);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function deriveToolErrors(toolMessages: any[]) {
|
|
81
|
-
const errors: string[] = [];
|
|
82
|
-
for (const message of toolMessages) {
|
|
83
|
-
const toolName = toToolName(message?.toolName ?? message?.name);
|
|
84
|
-
const payload = message?.toolPayload ?? {};
|
|
85
|
-
const content = parseJsonObject(message?.content);
|
|
86
|
-
if (payload?.status === "failed") {
|
|
87
|
-
errors.push(toolName || "unknown-tool");
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (content?.ok === false || content?.applied === false || content?.success === false) {
|
|
91
|
-
errors.push(toolName || "unknown-tool");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return uniq(errors);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function parseDialogInputForCli(
|
|
98
|
-
rawInput: string,
|
|
99
|
-
env: Record<string, string | undefined>
|
|
100
|
-
): ParsedDialogInput {
|
|
101
|
-
const authUserId = parseUserIdFromAuthToken(resolveAuthToken(env));
|
|
102
|
-
const envUserId = env.USER_ID?.trim() || authUserId;
|
|
103
|
-
const fallbackBase = normalizeBaseUrl(env.READ_DIALOG_BASE || resolveServerUrl(env));
|
|
104
|
-
|
|
105
|
-
if (!(rawInput.startsWith("http://") || rawInput.startsWith("https://"))) {
|
|
106
|
-
if (!envUserId) {
|
|
107
|
-
throw new Error("dialog read could not resolve userId; set AUTH_TOKEN or USER_ID.");
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
base: fallbackBase,
|
|
111
|
-
dialogId: rawInput.trim(),
|
|
112
|
-
userId: envUserId,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const url = new URL(rawInput);
|
|
117
|
-
const spaceMatch = url.pathname.match(SPACE_DIALOG_PATH_RE);
|
|
118
|
-
if (spaceMatch) {
|
|
119
|
-
const [, spaceIdFromPath, userIdFromPath, dialogId] = spaceMatch;
|
|
120
|
-
return {
|
|
121
|
-
base: normalizeBaseUrl(env.READ_DIALOG_BASE || url.origin),
|
|
122
|
-
dialogId,
|
|
123
|
-
userId: env.USER_ID?.trim() || userIdFromPath || envUserId,
|
|
124
|
-
spaceId: normalizeSpaceId(spaceIdFromPath),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const match = url.pathname.match(DIALOG_PATH_RE);
|
|
129
|
-
if (!match) {
|
|
130
|
-
throw new Error(`Unsupported dialog URL path: ${url.pathname}`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const [, userIdFromPath, dialogId] = match;
|
|
134
|
-
return {
|
|
135
|
-
base: normalizeBaseUrl(env.READ_DIALOG_BASE || url.origin),
|
|
136
|
-
dialogId,
|
|
137
|
-
userId: env.USER_ID?.trim() || userIdFromPath || envUserId,
|
|
138
|
-
spaceId: url.searchParams.get("spaceId") ?? undefined,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function buildDialogReadResult(args: {
|
|
143
|
-
source: DialogReadSource;
|
|
144
|
-
resolvedBase: string;
|
|
145
|
-
candidateBases: string[];
|
|
146
|
-
attempts: DialogHttpAttempt[];
|
|
147
|
-
spaceId?: string;
|
|
148
|
-
dialogId: string;
|
|
149
|
-
dialogKey: string;
|
|
150
|
-
userId: string;
|
|
151
|
-
meta: any;
|
|
152
|
-
msgs: any;
|
|
153
|
-
}) {
|
|
154
|
-
const orderedMsgs = Array.isArray(args.msgs) ? [...args.msgs].reverse() : args.msgs;
|
|
155
|
-
const lastAssistantMessage = Array.isArray(orderedMsgs)
|
|
156
|
-
? [...orderedMsgs].reverse().find(
|
|
157
|
-
(message) => message?.role === "assistant" || message?.authorRole === "assistant"
|
|
158
|
-
)
|
|
159
|
-
: null;
|
|
160
|
-
const toolMessages = Array.isArray(orderedMsgs)
|
|
161
|
-
? orderedMsgs.filter((message) => message?.role === "tool" || message?.authorRole === "tool")
|
|
162
|
-
: [];
|
|
163
|
-
const toolNamesFromMessages = toolMessages
|
|
164
|
-
.map((message) => toToolName(message?.toolName ?? message?.name))
|
|
165
|
-
.filter(Boolean);
|
|
166
|
-
const toolsUsed =
|
|
167
|
-
Array.isArray(args.meta?.toolsUsed) && args.meta.toolsUsed.length > 0
|
|
168
|
-
? args.meta.toolsUsed.map((tool: unknown) => toToolName(tool)).filter(Boolean)
|
|
169
|
-
: uniq(toolNamesFromMessages);
|
|
170
|
-
const writtenFiles =
|
|
171
|
-
Array.isArray(args.meta?.writtenFiles) && args.meta.writtenFiles.length > 0
|
|
172
|
-
? uniq(
|
|
173
|
-
args.meta.writtenFiles
|
|
174
|
-
.map((value: unknown) => (typeof value === "string" ? value.trim() : ""))
|
|
175
|
-
.filter(Boolean)
|
|
176
|
-
)
|
|
177
|
-
: deriveWrittenFiles(toolMessages);
|
|
178
|
-
const toolErrors =
|
|
179
|
-
Array.isArray(args.meta?.toolErrors) && args.meta.toolErrors.length > 0
|
|
180
|
-
? uniq(
|
|
181
|
-
args.meta.toolErrors
|
|
182
|
-
.map((value: unknown) => (typeof value === "string" ? value.trim() : ""))
|
|
183
|
-
.filter(Boolean)
|
|
184
|
-
)
|
|
185
|
-
: deriveToolErrors(toolMessages);
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
source: args.source,
|
|
189
|
-
base: args.resolvedBase,
|
|
190
|
-
triedBases: args.candidateBases,
|
|
191
|
-
httpAttempts: args.attempts,
|
|
192
|
-
spaceId: args.spaceId,
|
|
193
|
-
dialogId: args.dialogId,
|
|
194
|
-
dialogKey: args.dialogKey,
|
|
195
|
-
userId: args.userId,
|
|
196
|
-
title: args.meta?.title ?? null,
|
|
197
|
-
cybots: Array.isArray(args.meta?.cybots) ? args.meta.cybots : [],
|
|
198
|
-
category: args.meta?.category ?? null,
|
|
199
|
-
inheritedFromDialogKey: args.meta?.inheritedFromDialogKey ?? null,
|
|
200
|
-
inheritedFromDialogTitle: args.meta?.inheritedFromDialogTitle ?? null,
|
|
201
|
-
parentDialogId: args.meta?.parentDialogId ?? null,
|
|
202
|
-
rootDialogId: args.meta?.rootDialogId ?? null,
|
|
203
|
-
status: args.meta?.status,
|
|
204
|
-
errorMessage: args.meta?.errorMessage ?? null,
|
|
205
|
-
runtimeCheckpoint: args.meta?.runtimeCheckpoint ?? null,
|
|
206
|
-
durationMs: args.meta?.durationMs,
|
|
207
|
-
finishedAt: args.meta?.finishedAt,
|
|
208
|
-
createdAt: args.meta?.createdAt,
|
|
209
|
-
updatedAt: args.meta?.updatedAt,
|
|
210
|
-
artifacts: args.meta?.artifacts ?? null,
|
|
211
|
-
writtenFiles,
|
|
212
|
-
toolsUsed,
|
|
213
|
-
toolErrors,
|
|
214
|
-
toolSummary: {
|
|
215
|
-
metaToolsCount: toolsUsed.length,
|
|
216
|
-
metaToolsUnique: [...new Set(toolsUsed)],
|
|
217
|
-
toolMessageCount: toolMessages.length,
|
|
218
|
-
toolNamesFromMessages: [...new Set(toolNamesFromMessages)],
|
|
219
|
-
toolMessageCountsByName: countByName(toolNamesFromMessages),
|
|
220
|
-
},
|
|
221
|
-
agentReply: args.meta?.agentReply ?? null,
|
|
222
|
-
messagesCount: Array.isArray(orderedMsgs) ? orderedMsgs.length : 0,
|
|
223
|
-
lastAssistantMessage,
|
|
224
|
-
messages: orderedMsgs,
|
|
225
|
-
};
|
|
226
|
-
}
|