codeksei 0.1.0 → 0.1.1
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/LICENSE +661 -661
- package/README.en.md +109 -47
- package/README.md +79 -58
- package/bin/cyberboss.js +1 -1
- package/package.json +86 -86
- package/scripts/open_shared_wechat_thread.sh +77 -77
- package/scripts/open_wechat_thread.sh +108 -108
- package/scripts/shared-common.js +144 -144
- package/scripts/shared-open.js +14 -14
- package/scripts/shared-start.js +5 -5
- package/scripts/shared-status.js +27 -27
- package/scripts/show_shared_status.sh +45 -45
- package/scripts/start_shared_app_server.sh +52 -52
- package/scripts/start_shared_wechat.sh +94 -94
- package/scripts/timeline-screenshot.sh +14 -14
- package/src/adapters/channel/weixin/account-store.js +99 -99
- package/src/adapters/channel/weixin/api-v2.js +50 -50
- package/src/adapters/channel/weixin/api.js +169 -169
- package/src/adapters/channel/weixin/context-token-store.js +84 -84
- package/src/adapters/channel/weixin/index.js +618 -604
- package/src/adapters/channel/weixin/legacy.js +579 -566
- package/src/adapters/channel/weixin/media-mime.js +22 -22
- package/src/adapters/channel/weixin/media-receive.js +370 -370
- package/src/adapters/channel/weixin/media-send.js +102 -102
- package/src/adapters/channel/weixin/message-utils-v2.js +282 -282
- package/src/adapters/channel/weixin/message-utils.js +199 -199
- package/src/adapters/channel/weixin/redact.js +41 -41
- package/src/adapters/channel/weixin/reminder-queue-store.js +101 -101
- package/src/adapters/channel/weixin/sync-buffer-store.js +35 -35
- package/src/adapters/runtime/codex/events.js +215 -215
- package/src/adapters/runtime/codex/index.js +109 -104
- package/src/adapters/runtime/codex/message-utils.js +95 -95
- package/src/adapters/runtime/codex/model-catalog.js +106 -106
- package/src/adapters/runtime/codex/protocol-leak-monitor.js +75 -75
- package/src/adapters/runtime/codex/rpc-client.js +339 -339
- package/src/adapters/runtime/codex/session-store.js +286 -286
- package/src/app/channel-send-file-cli.js +57 -57
- package/src/app/diary-write-cli.js +236 -88
- package/src/app/note-sync-cli.js +2 -2
- package/src/app/reminder-write-cli.js +215 -210
- package/src/app/review-cli.js +7 -5
- package/src/app/system-checkin-poller.js +64 -64
- package/src/app/system-send-cli.js +129 -129
- package/src/app/timeline-event-cli.js +28 -25
- package/src/app/timeline-screenshot-cli.js +103 -100
- package/src/core/app.js +1763 -1763
- package/src/core/branding.js +2 -1
- package/src/core/command-registry.js +381 -369
- package/src/core/config.js +30 -14
- package/src/core/default-targets.js +163 -163
- package/src/core/durable-note-schema.js +9 -8
- package/src/core/instructions-template.js +17 -16
- package/src/core/note-sync.js +8 -7
- package/src/core/path-utils.js +54 -0
- package/src/core/project-radar.js +11 -10
- package/src/core/review.js +48 -50
- package/src/core/stream-delivery.js +1162 -983
- package/src/core/system-message-dispatcher.js +68 -68
- package/src/core/system-message-queue-store.js +128 -128
- package/src/core/thread-state-store.js +96 -96
- package/src/core/timeline-screenshot-queue-store.js +134 -134
- package/src/core/timezone.js +436 -0
- package/src/core/workspace-bootstrap.js +9 -1
- package/src/index.js +148 -146
- package/src/integrations/timeline/index.js +130 -74
- package/src/integrations/timeline/state-sync.js +240 -0
- package/templates/weixin-instructions.md +12 -38
- package/templates/weixin-operations.md +29 -31
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { normalizeAccountId } = require("./account-store");
|
|
4
|
-
|
|
5
|
-
function ensureSyncBufferDir(config) {
|
|
6
|
-
fs.mkdirSync(config.syncBufferDir, { recursive: true });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function resolveSyncBufferPath(config, accountId) {
|
|
10
|
-
ensureSyncBufferDir(config);
|
|
11
|
-
return path.join(config.syncBufferDir, `${normalizeAccountId(accountId)}.txt`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function loadSyncBuffer(config, accountId) {
|
|
15
|
-
try {
|
|
16
|
-
const filePath = resolveSyncBufferPath(config, accountId);
|
|
17
|
-
if (!fs.existsSync(filePath)) {
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
return fs.readFileSync(filePath, "utf8").trim();
|
|
21
|
-
} catch {
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function saveSyncBuffer(config, accountId, buffer) {
|
|
27
|
-
const filePath = resolveSyncBufferPath(config, accountId);
|
|
28
|
-
fs.writeFileSync(filePath, String(buffer || ""), "utf8");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
loadSyncBuffer,
|
|
33
|
-
resolveSyncBufferPath,
|
|
34
|
-
saveSyncBuffer,
|
|
35
|
-
};
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { normalizeAccountId } = require("./account-store");
|
|
4
|
+
|
|
5
|
+
function ensureSyncBufferDir(config) {
|
|
6
|
+
fs.mkdirSync(config.syncBufferDir, { recursive: true });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function resolveSyncBufferPath(config, accountId) {
|
|
10
|
+
ensureSyncBufferDir(config);
|
|
11
|
+
return path.join(config.syncBufferDir, `${normalizeAccountId(accountId)}.txt`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function loadSyncBuffer(config, accountId) {
|
|
15
|
+
try {
|
|
16
|
+
const filePath = resolveSyncBufferPath(config, accountId);
|
|
17
|
+
if (!fs.existsSync(filePath)) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
return fs.readFileSync(filePath, "utf8").trim();
|
|
21
|
+
} catch {
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function saveSyncBuffer(config, accountId, buffer) {
|
|
27
|
+
const filePath = resolveSyncBufferPath(config, accountId);
|
|
28
|
+
fs.writeFileSync(filePath, String(buffer || ""), "utf8");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
loadSyncBuffer,
|
|
33
|
+
resolveSyncBufferPath,
|
|
34
|
+
saveSyncBuffer,
|
|
35
|
+
};
|
|
@@ -5,54 +5,54 @@ const {
|
|
|
5
5
|
extractThreadIdFromParams,
|
|
6
6
|
extractTurnIdFromParams,
|
|
7
7
|
} = require("./message-utils");
|
|
8
|
-
|
|
9
|
-
function mapCodexMessageToRuntimeEvent(message) {
|
|
10
|
-
if (message?.type === "event_msg" && message?.payload?.type === "token_count") {
|
|
11
|
-
return {
|
|
12
|
-
type: "runtime.usage.updated",
|
|
13
|
-
payload: normalizeUsagePayload(message.payload),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const method = normalizeString(message?.method);
|
|
17
|
-
const params = message?.params || {};
|
|
18
|
-
const threadId = extractThreadIdFromParams(params);
|
|
19
|
-
const turnId = extractTurnIdFromParams(params);
|
|
20
|
-
|
|
21
|
-
if (!method) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (method === "turn/started" || method === "turn/start") {
|
|
26
|
-
return {
|
|
27
|
-
type: "runtime.turn.started",
|
|
28
|
-
payload: {
|
|
29
|
-
threadId,
|
|
30
|
-
turnId,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (method === "turn/completed") {
|
|
36
|
-
return {
|
|
37
|
-
type: "runtime.turn.completed",
|
|
38
|
-
payload: {
|
|
39
|
-
threadId,
|
|
40
|
-
turnId,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (method === "turn/failed") {
|
|
46
|
-
return {
|
|
47
|
-
type: "runtime.turn.failed",
|
|
48
|
-
payload: {
|
|
49
|
-
threadId,
|
|
50
|
-
turnId,
|
|
51
|
-
text: extractFailureText(params),
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
8
|
+
|
|
9
|
+
function mapCodexMessageToRuntimeEvent(message) {
|
|
10
|
+
if (message?.type === "event_msg" && message?.payload?.type === "token_count") {
|
|
11
|
+
return {
|
|
12
|
+
type: "runtime.usage.updated",
|
|
13
|
+
payload: normalizeUsagePayload(message.payload),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const method = normalizeString(message?.method);
|
|
17
|
+
const params = message?.params || {};
|
|
18
|
+
const threadId = extractThreadIdFromParams(params);
|
|
19
|
+
const turnId = extractTurnIdFromParams(params);
|
|
20
|
+
|
|
21
|
+
if (!method) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (method === "turn/started" || method === "turn/start") {
|
|
26
|
+
return {
|
|
27
|
+
type: "runtime.turn.started",
|
|
28
|
+
payload: {
|
|
29
|
+
threadId,
|
|
30
|
+
turnId,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (method === "turn/completed") {
|
|
36
|
+
return {
|
|
37
|
+
type: "runtime.turn.completed",
|
|
38
|
+
payload: {
|
|
39
|
+
threadId,
|
|
40
|
+
turnId,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (method === "turn/failed") {
|
|
46
|
+
return {
|
|
47
|
+
type: "runtime.turn.failed",
|
|
48
|
+
payload: {
|
|
49
|
+
threadId,
|
|
50
|
+
turnId,
|
|
51
|
+
text: extractFailureText(params),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
56
|
if (method === "item/agentMessage/delta") {
|
|
57
57
|
const text = extractAssistantText(params);
|
|
58
58
|
const phase = extractAssistantPhase(params);
|
|
@@ -61,8 +61,8 @@ function mapCodexMessageToRuntimeEvent(message) {
|
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
63
63
|
type: "runtime.reply.delta",
|
|
64
|
-
payload: {
|
|
65
|
-
threadId,
|
|
64
|
+
payload: {
|
|
65
|
+
threadId,
|
|
66
66
|
turnId,
|
|
67
67
|
itemId: normalizeString(params?.itemId || params?.item?.id),
|
|
68
68
|
text,
|
|
@@ -85,168 +85,168 @@ function mapCodexMessageToRuntimeEvent(message) {
|
|
|
85
85
|
},
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
if (isApprovalRequestMethod(method)) {
|
|
90
|
-
return {
|
|
91
|
-
type: "runtime.approval.requested",
|
|
92
|
-
payload: {
|
|
93
|
-
threadId,
|
|
94
|
-
requestId: message?.id ?? null,
|
|
95
|
-
reason: normalizeString(params?.reason),
|
|
96
|
-
command: extractApprovalDisplayCommand(params),
|
|
97
|
-
commandTokens: extractApprovalCommandTokens(params),
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function normalizeUsagePayload(payload) {
|
|
106
|
-
const info = payload?.info || {};
|
|
107
|
-
const total = info?.total_token_usage || {};
|
|
108
|
-
const last = info?.last_token_usage || {};
|
|
109
|
-
const rateLimits = payload?.rate_limits || {};
|
|
110
|
-
return {
|
|
111
|
-
totalInputTokens: numberOrZero(total.input_tokens),
|
|
112
|
-
totalCachedInputTokens: numberOrZero(total.cached_input_tokens),
|
|
113
|
-
totalOutputTokens: numberOrZero(total.output_tokens),
|
|
114
|
-
totalReasoningTokens: numberOrZero(total.reasoning_output_tokens),
|
|
115
|
-
totalTokens: numberOrZero(total.total_tokens),
|
|
116
|
-
lastInputTokens: numberOrZero(last.input_tokens),
|
|
117
|
-
lastCachedInputTokens: numberOrZero(last.cached_input_tokens),
|
|
118
|
-
lastOutputTokens: numberOrZero(last.output_tokens),
|
|
119
|
-
lastReasoningTokens: numberOrZero(last.reasoning_output_tokens),
|
|
120
|
-
lastTotalTokens: numberOrZero(last.total_tokens),
|
|
121
|
-
modelContextWindow: numberOrZero(info?.model_context_window),
|
|
122
|
-
primaryUsedPercent: numberOrZero(rateLimits?.primary?.used_percent),
|
|
123
|
-
secondaryUsedPercent: numberOrZero(rateLimits?.secondary?.used_percent),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function isApprovalRequestMethod(method) {
|
|
128
|
-
return typeof method === "string" && method.endsWith("requestApproval");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function extractApprovalDisplayCommand(params) {
|
|
132
|
-
const commandTokens = extractApprovalCommandTokens(params);
|
|
133
|
-
const direct = params?.command;
|
|
134
|
-
if (typeof direct === "string" && direct.trim()) {
|
|
135
|
-
return direct.trim();
|
|
136
|
-
}
|
|
137
|
-
if (Array.isArray(direct)) {
|
|
138
|
-
const normalized = normalizeCommandTokens(direct);
|
|
139
|
-
if (normalized.length) {
|
|
140
|
-
return buildApprovalCommandPreview(normalized);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return buildApprovalCommandPreview(commandTokens);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function extractApprovalCommandTokens(params) {
|
|
147
|
-
return normalizeCommandTokens(extractTokens(params));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function extractTokens(value) {
|
|
151
|
-
if (!value) {
|
|
152
|
-
return [];
|
|
153
|
-
}
|
|
154
|
-
if (Array.isArray(value)) {
|
|
155
|
-
return value.every((entry) => typeof entry === "string")
|
|
156
|
-
? value.map((entry) => entry.trim()).filter(Boolean)
|
|
157
|
-
: [];
|
|
158
|
-
}
|
|
159
|
-
if (typeof value === "string") {
|
|
160
|
-
return splitCommandLine(value);
|
|
161
|
-
}
|
|
162
|
-
if (typeof value !== "object") {
|
|
163
|
-
return [];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
for (const key of ["proposedExecpolicyAmendment", "argv", "args", "command", "cmd", "exec", "shellCommand", "script"]) {
|
|
167
|
-
const tokens = extractTokens(value[key]);
|
|
168
|
-
if (tokens.length) {
|
|
169
|
-
return tokens;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
174
|
-
const normalizedKey = key.toLowerCase();
|
|
175
|
-
if (normalizedKey.includes("execpolicy") || normalizedKey.includes("exec_policy")) {
|
|
176
|
-
const tokens = extractTokens(nested);
|
|
177
|
-
if (tokens.length) {
|
|
178
|
-
return tokens;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function splitCommandLine(input) {
|
|
187
|
-
const tokens = [];
|
|
188
|
-
let current = "";
|
|
189
|
-
let quote = null;
|
|
190
|
-
let escaped = false;
|
|
191
|
-
|
|
192
|
-
for (const char of String(input || "")) {
|
|
193
|
-
if (escaped) {
|
|
194
|
-
current += char;
|
|
195
|
-
escaped = false;
|
|
196
|
-
continue;
|
|
197
|
-
}
|
|
198
|
-
if (char === "\\") {
|
|
199
|
-
escaped = true;
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
if (quote) {
|
|
203
|
-
if (char === quote) {
|
|
204
|
-
quote = null;
|
|
205
|
-
} else {
|
|
206
|
-
current += char;
|
|
207
|
-
}
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (char === "\"" || char === "'") {
|
|
211
|
-
quote = char;
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
if (/\s/.test(char)) {
|
|
215
|
-
if (current) {
|
|
216
|
-
tokens.push(current);
|
|
217
|
-
current = "";
|
|
218
|
-
}
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
current += char;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (current) {
|
|
225
|
-
tokens.push(current);
|
|
226
|
-
}
|
|
227
|
-
return tokens;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function buildApprovalCommandPreview(tokens) {
|
|
231
|
-
const normalized = normalizeCommandTokens(tokens);
|
|
232
|
-
if (!normalized.length) {
|
|
233
|
-
return "";
|
|
234
|
-
}
|
|
235
|
-
return normalized.map((token) => (token.includes(" ") ? JSON.stringify(token) : token)).join(" ");
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function normalizeCommandTokens(tokens) {
|
|
239
|
-
return Array.isArray(tokens)
|
|
240
|
-
? tokens.map((part) => normalizeString(part)).filter(Boolean)
|
|
241
|
-
: [];
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function normalizeString(value) {
|
|
245
|
-
return typeof value === "string" ? value.trim() : "";
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function numberOrZero(value) {
|
|
249
|
-
return Number.isFinite(Number(value)) ? Number(value) : 0;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
module.exports = { mapCodexMessageToRuntimeEvent };
|
|
88
|
+
|
|
89
|
+
if (isApprovalRequestMethod(method)) {
|
|
90
|
+
return {
|
|
91
|
+
type: "runtime.approval.requested",
|
|
92
|
+
payload: {
|
|
93
|
+
threadId,
|
|
94
|
+
requestId: message?.id ?? null,
|
|
95
|
+
reason: normalizeString(params?.reason),
|
|
96
|
+
command: extractApprovalDisplayCommand(params),
|
|
97
|
+
commandTokens: extractApprovalCommandTokens(params),
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function normalizeUsagePayload(payload) {
|
|
106
|
+
const info = payload?.info || {};
|
|
107
|
+
const total = info?.total_token_usage || {};
|
|
108
|
+
const last = info?.last_token_usage || {};
|
|
109
|
+
const rateLimits = payload?.rate_limits || {};
|
|
110
|
+
return {
|
|
111
|
+
totalInputTokens: numberOrZero(total.input_tokens),
|
|
112
|
+
totalCachedInputTokens: numberOrZero(total.cached_input_tokens),
|
|
113
|
+
totalOutputTokens: numberOrZero(total.output_tokens),
|
|
114
|
+
totalReasoningTokens: numberOrZero(total.reasoning_output_tokens),
|
|
115
|
+
totalTokens: numberOrZero(total.total_tokens),
|
|
116
|
+
lastInputTokens: numberOrZero(last.input_tokens),
|
|
117
|
+
lastCachedInputTokens: numberOrZero(last.cached_input_tokens),
|
|
118
|
+
lastOutputTokens: numberOrZero(last.output_tokens),
|
|
119
|
+
lastReasoningTokens: numberOrZero(last.reasoning_output_tokens),
|
|
120
|
+
lastTotalTokens: numberOrZero(last.total_tokens),
|
|
121
|
+
modelContextWindow: numberOrZero(info?.model_context_window),
|
|
122
|
+
primaryUsedPercent: numberOrZero(rateLimits?.primary?.used_percent),
|
|
123
|
+
secondaryUsedPercent: numberOrZero(rateLimits?.secondary?.used_percent),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isApprovalRequestMethod(method) {
|
|
128
|
+
return typeof method === "string" && method.endsWith("requestApproval");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function extractApprovalDisplayCommand(params) {
|
|
132
|
+
const commandTokens = extractApprovalCommandTokens(params);
|
|
133
|
+
const direct = params?.command;
|
|
134
|
+
if (typeof direct === "string" && direct.trim()) {
|
|
135
|
+
return direct.trim();
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(direct)) {
|
|
138
|
+
const normalized = normalizeCommandTokens(direct);
|
|
139
|
+
if (normalized.length) {
|
|
140
|
+
return buildApprovalCommandPreview(normalized);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return buildApprovalCommandPreview(commandTokens);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function extractApprovalCommandTokens(params) {
|
|
147
|
+
return normalizeCommandTokens(extractTokens(params));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function extractTokens(value) {
|
|
151
|
+
if (!value) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(value)) {
|
|
155
|
+
return value.every((entry) => typeof entry === "string")
|
|
156
|
+
? value.map((entry) => entry.trim()).filter(Boolean)
|
|
157
|
+
: [];
|
|
158
|
+
}
|
|
159
|
+
if (typeof value === "string") {
|
|
160
|
+
return splitCommandLine(value);
|
|
161
|
+
}
|
|
162
|
+
if (typeof value !== "object") {
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (const key of ["proposedExecpolicyAmendment", "argv", "args", "command", "cmd", "exec", "shellCommand", "script"]) {
|
|
167
|
+
const tokens = extractTokens(value[key]);
|
|
168
|
+
if (tokens.length) {
|
|
169
|
+
return tokens;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
174
|
+
const normalizedKey = key.toLowerCase();
|
|
175
|
+
if (normalizedKey.includes("execpolicy") || normalizedKey.includes("exec_policy")) {
|
|
176
|
+
const tokens = extractTokens(nested);
|
|
177
|
+
if (tokens.length) {
|
|
178
|
+
return tokens;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function splitCommandLine(input) {
|
|
187
|
+
const tokens = [];
|
|
188
|
+
let current = "";
|
|
189
|
+
let quote = null;
|
|
190
|
+
let escaped = false;
|
|
191
|
+
|
|
192
|
+
for (const char of String(input || "")) {
|
|
193
|
+
if (escaped) {
|
|
194
|
+
current += char;
|
|
195
|
+
escaped = false;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (char === "\\") {
|
|
199
|
+
escaped = true;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (quote) {
|
|
203
|
+
if (char === quote) {
|
|
204
|
+
quote = null;
|
|
205
|
+
} else {
|
|
206
|
+
current += char;
|
|
207
|
+
}
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (char === "\"" || char === "'") {
|
|
211
|
+
quote = char;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (/\s/.test(char)) {
|
|
215
|
+
if (current) {
|
|
216
|
+
tokens.push(current);
|
|
217
|
+
current = "";
|
|
218
|
+
}
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
current += char;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (current) {
|
|
225
|
+
tokens.push(current);
|
|
226
|
+
}
|
|
227
|
+
return tokens;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function buildApprovalCommandPreview(tokens) {
|
|
231
|
+
const normalized = normalizeCommandTokens(tokens);
|
|
232
|
+
if (!normalized.length) {
|
|
233
|
+
return "";
|
|
234
|
+
}
|
|
235
|
+
return normalized.map((token) => (token.includes(" ") ? JSON.stringify(token) : token)).join(" ");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function normalizeCommandTokens(tokens) {
|
|
239
|
+
return Array.isArray(tokens)
|
|
240
|
+
? tokens.map((part) => normalizeString(part)).filter(Boolean)
|
|
241
|
+
: [];
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function normalizeString(value) {
|
|
245
|
+
return typeof value === "string" ? value.trim() : "";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function numberOrZero(value) {
|
|
249
|
+
return Number.isFinite(Number(value)) ? Number(value) : 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
module.exports = { mapCodexMessageToRuntimeEvent };
|