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,312 +0,0 @@
|
|
|
1
|
-
import { createSpaceKey, normalizeSpaceId } from "../create/space/spaceKeys";
|
|
2
|
-
import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
|
|
3
|
-
import { parseUserIdFromAuthToken, readOption, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
|
|
4
|
-
import { readSpaceRecordWithFallback } from "./spaceMutationHelpers";
|
|
5
|
-
|
|
6
|
-
type SpaceMembership = Record<string, any> & {
|
|
7
|
-
spaceId?: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
spaceName?: string;
|
|
10
|
-
title?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type DeleteTarget = {
|
|
14
|
-
spaceId: string;
|
|
15
|
-
name: string;
|
|
16
|
-
spaceKey: string;
|
|
17
|
-
memberKeys: string[];
|
|
18
|
-
contentCount: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type SkippedTarget = {
|
|
22
|
-
spaceId: string;
|
|
23
|
-
name: string;
|
|
24
|
-
reason: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function usage() {
|
|
28
|
-
return [
|
|
29
|
-
"Usage:",
|
|
30
|
-
" nolo space delete --name-prefix <prefix> [--yes] [--json]",
|
|
31
|
-
" nolo space delete --name <exact-name> [--yes] [--json]",
|
|
32
|
-
" nolo space delete --space <spaceId|spaceKey|spaceUrl> [--yes] [--json]",
|
|
33
|
-
"",
|
|
34
|
-
].join("\n");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function displayName(membership: SpaceMembership) {
|
|
38
|
-
return String(
|
|
39
|
-
membership.spaceName ??
|
|
40
|
-
membership.name ??
|
|
41
|
-
membership.title ??
|
|
42
|
-
membership.spaceTitle ??
|
|
43
|
-
""
|
|
44
|
-
).trim();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function matchesMembership(args: string[], membership: SpaceMembership) {
|
|
48
|
-
const requestedSpace = readOption(args, "--space");
|
|
49
|
-
if (requestedSpace) {
|
|
50
|
-
return normalizeSpaceId(String(membership.spaceId ?? "")) === normalizeSpaceId(requestedSpace);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const name = displayName(membership);
|
|
54
|
-
const exactName = readOption(args, "--name");
|
|
55
|
-
if (exactName) return name === exactName;
|
|
56
|
-
|
|
57
|
-
const prefix = readOption(args, "--name-prefix");
|
|
58
|
-
if (prefix) return name.startsWith(prefix);
|
|
59
|
-
|
|
60
|
-
throw new Error("space delete requires --space, --name, or --name-prefix");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function listMemberKeys(spaceRecord: Record<string, any>, userId: string, spaceId: string) {
|
|
64
|
-
const memberIds = new Set<string>();
|
|
65
|
-
memberIds.add(userId);
|
|
66
|
-
|
|
67
|
-
const members = spaceRecord.members;
|
|
68
|
-
if (Array.isArray(members)) {
|
|
69
|
-
for (const memberId of members) {
|
|
70
|
-
if (typeof memberId === "string" && memberId.trim()) {
|
|
71
|
-
memberIds.add(memberId.trim());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} else if (members && typeof members === "object") {
|
|
75
|
-
for (const memberId of Object.keys(members)) {
|
|
76
|
-
if (memberId.trim()) memberIds.add(memberId.trim());
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return Array.from(memberIds).map((memberId) => createSpaceKey.member(memberId, spaceId));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function fetchMemberships(args: {
|
|
84
|
-
authToken: string;
|
|
85
|
-
fetchImpl: typeof fetch;
|
|
86
|
-
serverUrl: string;
|
|
87
|
-
userId: string;
|
|
88
|
-
}) {
|
|
89
|
-
const response = await args.fetchImpl(`${args.serverUrl}/rpc/getUserSpaceMemberships`, {
|
|
90
|
-
method: "POST",
|
|
91
|
-
headers: {
|
|
92
|
-
Authorization: `Bearer ${args.authToken}`,
|
|
93
|
-
"Content-Type": "application/json",
|
|
94
|
-
},
|
|
95
|
-
body: JSON.stringify({ userId: args.userId }),
|
|
96
|
-
});
|
|
97
|
-
const data = await response.json().catch(() => ({}));
|
|
98
|
-
if (!response.ok || !Array.isArray(data)) {
|
|
99
|
-
throw new Error(`failed to list memberships (${response.status}): ${JSON.stringify(data)}`);
|
|
100
|
-
}
|
|
101
|
-
return data as SpaceMembership[];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function buildTarget(args: {
|
|
105
|
-
authToken: string;
|
|
106
|
-
db: Awaited<ReturnType<typeof getReadableCliDb>>;
|
|
107
|
-
fallbackFetchImpl?: typeof fetch;
|
|
108
|
-
fetchImpl: typeof fetch;
|
|
109
|
-
membership: SpaceMembership;
|
|
110
|
-
serverUrl: string;
|
|
111
|
-
userId: string;
|
|
112
|
-
}): Promise<DeleteTarget | SkippedTarget> {
|
|
113
|
-
const spaceId = normalizeSpaceId(String(args.membership.spaceId ?? ""));
|
|
114
|
-
const name = displayName(args.membership) || spaceId;
|
|
115
|
-
if (!spaceId) {
|
|
116
|
-
return { spaceId: "", name, reason: "membership has no spaceId" };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let spaceRecord: Record<string, any>;
|
|
120
|
-
try {
|
|
121
|
-
spaceRecord = await readSpaceRecordWithFallback({
|
|
122
|
-
authToken: args.authToken,
|
|
123
|
-
db: args.db,
|
|
124
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
125
|
-
fetchImpl: args.fetchImpl,
|
|
126
|
-
serverCandidates: [args.serverUrl],
|
|
127
|
-
spaceId,
|
|
128
|
-
});
|
|
129
|
-
} catch (error) {
|
|
130
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
131
|
-
return { spaceId, name, reason: `failed to read space record: ${message}` };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const ownerId = typeof spaceRecord.ownerId === "string" ? spaceRecord.ownerId : "";
|
|
135
|
-
if (ownerId && ownerId !== args.userId) {
|
|
136
|
-
return { spaceId, name, reason: `current user is not owner (${ownerId})` };
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const contents = spaceRecord.contents;
|
|
140
|
-
return {
|
|
141
|
-
spaceId,
|
|
142
|
-
name: displayName(args.membership) || String(spaceRecord.name ?? spaceRecord.title ?? spaceId),
|
|
143
|
-
spaceKey: createSpaceKey.space(spaceId),
|
|
144
|
-
memberKeys: listMemberKeys(spaceRecord, args.userId, spaceId),
|
|
145
|
-
contentCount: contents && typeof contents === "object" ? Object.keys(contents).length : 0,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function deleteKey(args: {
|
|
150
|
-
authToken: string;
|
|
151
|
-
fetchImpl: typeof fetch;
|
|
152
|
-
key: string;
|
|
153
|
-
serverUrl: string;
|
|
154
|
-
}) {
|
|
155
|
-
const response = await args.fetchImpl(
|
|
156
|
-
`${args.serverUrl}/api/v1/db/delete/${encodeURIComponent(args.key)}`,
|
|
157
|
-
{
|
|
158
|
-
method: "DELETE",
|
|
159
|
-
headers: {
|
|
160
|
-
Authorization: `Bearer ${args.authToken}`,
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
const text = await response.text();
|
|
165
|
-
let data: any = {};
|
|
166
|
-
if (text) {
|
|
167
|
-
try {
|
|
168
|
-
data = JSON.parse(text);
|
|
169
|
-
} catch {
|
|
170
|
-
data = {};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (!response.ok) {
|
|
174
|
-
throw new Error(`delete ${args.key} failed (${response.status}): ${JSON.stringify(data)}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export async function runSpaceDeleteCommand(
|
|
179
|
-
args: string[],
|
|
180
|
-
deps: AgentCommandDeps = {}
|
|
181
|
-
) {
|
|
182
|
-
const env = deps.env ?? process.env;
|
|
183
|
-
const output = deps.output ?? process.stdout;
|
|
184
|
-
|
|
185
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
186
|
-
output.write(`${usage()}\n`);
|
|
187
|
-
return 0;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const requestedSpace = readOption(args, "--space");
|
|
191
|
-
const exactName = readOption(args, "--name");
|
|
192
|
-
const prefix = readOption(args, "--name-prefix");
|
|
193
|
-
if (!requestedSpace && !exactName && !prefix) {
|
|
194
|
-
output.write(`${usage()}\n`);
|
|
195
|
-
return 1;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const authToken = resolveAuthToken(args, env);
|
|
199
|
-
const userId = parseUserIdFromAuthToken(authToken);
|
|
200
|
-
if (!authToken || !userId) {
|
|
201
|
-
output.write("[nolo] space delete requires an auth token with userId. Run `nolo login`.\n");
|
|
202
|
-
return 1;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const shouldDelete = args.includes("--yes");
|
|
206
|
-
const wantJson = args.includes("--json");
|
|
207
|
-
const db = deps.db ?? await getReadableCliDb(output);
|
|
208
|
-
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
209
|
-
const fallbackFetchImpl = deps.fallbackFetchImpl;
|
|
210
|
-
const serverUrl = resolveServerUrl(args, env);
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
const memberships = await fetchMemberships({
|
|
214
|
-
authToken,
|
|
215
|
-
fetchImpl,
|
|
216
|
-
serverUrl,
|
|
217
|
-
userId,
|
|
218
|
-
});
|
|
219
|
-
const matchingMemberships = memberships.filter((membership) => matchesMembership(args, membership));
|
|
220
|
-
const inspected = await Promise.all(
|
|
221
|
-
matchingMemberships.map((membership) =>
|
|
222
|
-
buildTarget({
|
|
223
|
-
authToken,
|
|
224
|
-
db,
|
|
225
|
-
fallbackFetchImpl,
|
|
226
|
-
fetchImpl,
|
|
227
|
-
membership,
|
|
228
|
-
serverUrl,
|
|
229
|
-
userId,
|
|
230
|
-
})
|
|
231
|
-
)
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const targets = inspected.filter((item): item is DeleteTarget => "spaceKey" in item);
|
|
235
|
-
const skipped = inspected.filter((item): item is SkippedTarget => !("spaceKey" in item));
|
|
236
|
-
const deletedKeys: string[] = [];
|
|
237
|
-
|
|
238
|
-
if (shouldDelete) {
|
|
239
|
-
for (const target of targets) {
|
|
240
|
-
for (const memberKey of target.memberKeys) {
|
|
241
|
-
await deleteKey({
|
|
242
|
-
authToken,
|
|
243
|
-
fetchImpl,
|
|
244
|
-
key: memberKey,
|
|
245
|
-
serverUrl,
|
|
246
|
-
});
|
|
247
|
-
deletedKeys.push(memberKey);
|
|
248
|
-
}
|
|
249
|
-
await deleteKey({
|
|
250
|
-
authToken,
|
|
251
|
-
fetchImpl,
|
|
252
|
-
key: target.spaceKey,
|
|
253
|
-
serverUrl,
|
|
254
|
-
});
|
|
255
|
-
deletedKeys.push(target.spaceKey);
|
|
256
|
-
await db.batch([
|
|
257
|
-
...target.memberKeys.map((key) => ({ type: "del" as const, key })),
|
|
258
|
-
{ type: "del" as const, key: target.spaceKey },
|
|
259
|
-
]);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const result = {
|
|
264
|
-
baseUrl: serverUrl,
|
|
265
|
-
userId,
|
|
266
|
-
dryRun: !shouldDelete,
|
|
267
|
-
totalMemberships: memberships.length,
|
|
268
|
-
matchCount: matchingMemberships.length,
|
|
269
|
-
deletableCount: targets.length,
|
|
270
|
-
skipped,
|
|
271
|
-
targets: targets.map((target) => ({
|
|
272
|
-
spaceId: target.spaceId,
|
|
273
|
-
name: target.name,
|
|
274
|
-
spaceKey: target.spaceKey,
|
|
275
|
-
memberKeys: target.memberKeys,
|
|
276
|
-
contentCount: target.contentCount,
|
|
277
|
-
})),
|
|
278
|
-
deletedKeys,
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
if (wantJson) {
|
|
282
|
-
output.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
283
|
-
return 0;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
output.write(`Base: ${result.baseUrl}\n`);
|
|
287
|
-
output.write(`User: ${result.userId}\n`);
|
|
288
|
-
output.write(`Matched spaces: ${result.matchCount}\n`);
|
|
289
|
-
for (const target of result.targets) {
|
|
290
|
-
output.write(`- ${target.name} (${target.spaceId})\n`);
|
|
291
|
-
output.write(` space key: ${target.spaceKey}\n`);
|
|
292
|
-
output.write(` member keys: ${target.memberKeys.join(", ") || "(none)"}\n`);
|
|
293
|
-
output.write(` contents preserved: ${target.contentCount}\n`);
|
|
294
|
-
}
|
|
295
|
-
for (const item of skipped) {
|
|
296
|
-
output.write(`- skipped ${item.name || item.spaceId}: ${item.reason}\n`);
|
|
297
|
-
}
|
|
298
|
-
output.write(
|
|
299
|
-
shouldDelete
|
|
300
|
-
? `Deleted keys: ${deletedKeys.length}\n`
|
|
301
|
-
: "Dry-run only. Add --yes to delete the matched spaces.\n"
|
|
302
|
-
);
|
|
303
|
-
return 0;
|
|
304
|
-
} catch (error) {
|
|
305
|
-
output.write(
|
|
306
|
-
`[nolo] space delete failed: ${
|
|
307
|
-
error instanceof Error ? error.message : String(error)
|
|
308
|
-
}\n`
|
|
309
|
-
);
|
|
310
|
-
return 1;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createEnvCommand } from "./cliCommandFactories";
|
|
2
|
-
import type { CommandEntry } from "./cliCommandTypes";
|
|
3
|
-
import { runSpaceAttachAgentCommand } from "./spaceAttachCommands";
|
|
4
|
-
import {
|
|
5
|
-
runSpaceCategoryCommand,
|
|
6
|
-
runSpaceContentCategoryCommand,
|
|
7
|
-
} from "./spaceCategoryCommands";
|
|
8
|
-
import { runSpaceDeleteCommand } from "./spaceDeleteCommands";
|
|
9
|
-
import { runSpaceListCommand } from "./spaceCommands";
|
|
10
|
-
import { runSpaceReadCommand } from "./spaceReadCommands";
|
|
11
|
-
|
|
12
|
-
export function getSpaceInternalCommandEntries(): CommandEntry[] {
|
|
13
|
-
return [
|
|
14
|
-
createEnvCommand(["space", "list"], "List joined spaces", runSpaceListCommand),
|
|
15
|
-
createEnvCommand(["space", "read"], "Read a space", runSpaceReadCommand),
|
|
16
|
-
createEnvCommand(["space", "attach-agent"], "Attach an existing agent to a space", runSpaceAttachAgentCommand),
|
|
17
|
-
createEnvCommand(["space", "category"], "Create or update a space category", runSpaceCategoryCommand),
|
|
18
|
-
createEnvCommand(["space", "content-category"], "Move content into a space category", runSpaceContentCategoryCommand),
|
|
19
|
-
createEnvCommand(["space", "delete"], "Delete spaces by safe filters", runSpaceDeleteCommand),
|
|
20
|
-
];
|
|
21
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { createSpaceKey, normalizeSpaceId } from "../create/space/spaceKeys";
|
|
2
|
-
import type { CliKvDb } from "./client/hybridRecordStore";
|
|
3
|
-
import { readDbRecord, writeDbRecord } from "./agentRecordHelpers";
|
|
4
|
-
|
|
5
|
-
export function parseSpaceIdFromInput(raw: string): string {
|
|
6
|
-
const trimmed = raw.trim();
|
|
7
|
-
if (!trimmed) {
|
|
8
|
-
throw new Error("Space id/url is empty.");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
|
|
12
|
-
const url = new URL(trimmed);
|
|
13
|
-
const fromQuery = url.searchParams.get("spaceId");
|
|
14
|
-
if (fromQuery) {
|
|
15
|
-
return normalizeSpaceId(fromQuery);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const parts = url.pathname.split("/").filter(Boolean);
|
|
19
|
-
const spaceIndex = parts.findIndex((part) => part === "space");
|
|
20
|
-
if (spaceIndex >= 0 && parts[spaceIndex + 1]) {
|
|
21
|
-
return normalizeSpaceId(parts[spaceIndex + 1]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
throw new Error(`Unsupported space URL: ${trimmed}`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return normalizeSpaceId(trimmed);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function readSpaceRecordWithFallback(args: {
|
|
31
|
-
authToken: string;
|
|
32
|
-
db: CliKvDb;
|
|
33
|
-
fallbackFetchImpl?: typeof fetch;
|
|
34
|
-
fetchImpl: typeof fetch;
|
|
35
|
-
serverCandidates: string[];
|
|
36
|
-
spaceId: string;
|
|
37
|
-
}) {
|
|
38
|
-
const spaceKey = createSpaceKey.space(args.spaceId);
|
|
39
|
-
try {
|
|
40
|
-
return await args.db.get(spaceKey);
|
|
41
|
-
} catch {
|
|
42
|
-
let lastError: Error | null = null;
|
|
43
|
-
for (const serverUrl of args.serverCandidates) {
|
|
44
|
-
try {
|
|
45
|
-
return await readDbRecord({
|
|
46
|
-
authToken: args.authToken,
|
|
47
|
-
dbKey: spaceKey,
|
|
48
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
49
|
-
fetchImpl: args.fetchImpl,
|
|
50
|
-
serverUrl,
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
throw lastError ?? new Error(`Failed to read ${spaceKey}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function writeSpaceRecord(args: {
|
|
61
|
-
authToken: string;
|
|
62
|
-
db: CliKvDb;
|
|
63
|
-
fallbackFetchImpl?: typeof fetch;
|
|
64
|
-
fetchImpl: typeof fetch;
|
|
65
|
-
record: Record<string, any>;
|
|
66
|
-
serverUrl: string;
|
|
67
|
-
spaceId: string;
|
|
68
|
-
userId: string;
|
|
69
|
-
}) {
|
|
70
|
-
const spaceKey = createSpaceKey.space(args.spaceId);
|
|
71
|
-
await writeDbRecord({
|
|
72
|
-
authToken: args.authToken,
|
|
73
|
-
dbKey: spaceKey,
|
|
74
|
-
fallbackFetchImpl: args.fallbackFetchImpl,
|
|
75
|
-
fetchImpl: args.fetchImpl,
|
|
76
|
-
record: args.record,
|
|
77
|
-
serverUrl: args.serverUrl,
|
|
78
|
-
userId: args.userId,
|
|
79
|
-
});
|
|
80
|
-
await args.db.put(spaceKey, args.record);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function buildTableAttachedSpaceRecord(args: {
|
|
84
|
-
categoryId?: string;
|
|
85
|
-
contentKey: string;
|
|
86
|
-
existingSpaceRecord: Record<string, any>;
|
|
87
|
-
spaceId: string;
|
|
88
|
-
title: string;
|
|
89
|
-
}) {
|
|
90
|
-
const { categoryId, contentKey, existingSpaceRecord, spaceId, title } = args;
|
|
91
|
-
const now = Date.now();
|
|
92
|
-
const existingContent = existingSpaceRecord?.contents?.[contentKey];
|
|
93
|
-
const categoryIdForStorage =
|
|
94
|
-
categoryId && existingSpaceRecord?.categories?.[categoryId] ? categoryId : undefined;
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
...existingSpaceRecord,
|
|
98
|
-
dbKey: createSpaceKey.space(spaceId),
|
|
99
|
-
updatedAt: now,
|
|
100
|
-
contents: {
|
|
101
|
-
...(existingSpaceRecord?.contents ?? {}),
|
|
102
|
-
[contentKey]: {
|
|
103
|
-
...(existingContent ?? {}),
|
|
104
|
-
title,
|
|
105
|
-
type: "table",
|
|
106
|
-
contentKey,
|
|
107
|
-
...(categoryIdForStorage ? { categoryId: categoryIdForStorage } : {}),
|
|
108
|
-
updatedAt: now,
|
|
109
|
-
createdAt: existingContent?.createdAt ?? now,
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function parseContentKeys(args: string[]) {
|
|
116
|
-
const keys = new Set<string>();
|
|
117
|
-
const singleIndex = args.indexOf("--content-key");
|
|
118
|
-
if (singleIndex >= 0 && args[singleIndex + 1]?.trim()) {
|
|
119
|
-
keys.add(args[singleIndex + 1].trim());
|
|
120
|
-
}
|
|
121
|
-
const listIndex = args.indexOf("--content-keys");
|
|
122
|
-
if (listIndex >= 0) {
|
|
123
|
-
const raw = args[listIndex + 1];
|
|
124
|
-
const parsed = JSON.parse(raw ?? "null");
|
|
125
|
-
if (!Array.isArray(parsed)) {
|
|
126
|
-
throw new Error("--content-keys must be a JSON array.");
|
|
127
|
-
}
|
|
128
|
-
for (const item of parsed) {
|
|
129
|
-
if (typeof item === "string" && item.trim()) {
|
|
130
|
-
keys.add(item.trim());
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return Array.from(keys);
|
|
135
|
-
}
|