@keyou007/agent-bot 0.1.20-alpha.0 → 0.1.20

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +18 -1
  3. package/README.zh.md +9 -0
  4. package/dist/cli/AgentPrerequisites.js +11 -47
  5. package/dist/cli/AgentPrerequisites.js.map +1 -1
  6. package/dist/cli/DefaultAgentSelection.js +1 -1
  7. package/dist/cli/DefaultAgentSelection.js.map +1 -1
  8. package/dist/cli.js +15 -0
  9. package/dist/cli.js.map +1 -1
  10. package/dist/codex/CodexLocalActivityDetector.js +32 -10
  11. package/dist/codex/CodexLocalActivityDetector.js.map +1 -1
  12. package/dist/codex/CodexProcessManager.js +53 -7
  13. package/dist/codex/CodexProcessManager.js.map +1 -1
  14. package/dist/codex/CodexRuntime.js +225 -164
  15. package/dist/codex/CodexRuntime.js.map +1 -1
  16. package/dist/codex/CodexVersion.js +18 -0
  17. package/dist/codex/CodexVersion.js.map +1 -0
  18. package/dist/codex/ProviderSwitch.js +32 -0
  19. package/dist/codex/ProviderSwitch.js.map +1 -0
  20. package/dist/config/AgentExecutionDefaultsStore.js +1 -1
  21. package/dist/config/AgentExecutionDefaultsStore.js.map +1 -1
  22. package/dist/feishu/CardRenderer.js +36 -11
  23. package/dist/feishu/CardRenderer.js.map +1 -1
  24. package/dist/feishu/FeishuConnector.js +17 -5
  25. package/dist/feishu/FeishuConnector.js.map +1 -1
  26. package/dist/feishu/InboundText.js +11 -0
  27. package/dist/feishu/InboundText.js.map +1 -1
  28. package/dist/feishu/MergedForwardMessage.js +17 -5
  29. package/dist/feishu/MergedForwardMessage.js.map +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/local-files/LocalFileViewerServer.js +25 -7
  33. package/dist/local-files/LocalFileViewerServer.js.map +1 -1
  34. package/dist/local-files/MarkdownFileLinks.js +65 -0
  35. package/dist/local-files/MarkdownFileLinks.js.map +1 -0
  36. package/dist/proxy/ProxySessionController.js +400 -259
  37. package/dist/proxy/ProxySessionController.js.map +1 -1
  38. package/dist/state/StateStore.js +99 -65
  39. package/dist/state/StateStore.js.map +1 -1
  40. package/dist/utils/semanticVersion.js +39 -0
  41. package/dist/utils/semanticVersion.js.map +1 -0
  42. package/docs/technical-reference.md +5 -3
  43. package/docs/technical-reference.zh.md +5 -3
  44. package/npm-shrinkwrap.json +2 -2
  45. package/package.json +1 -1
  46. package/skills/agent-bot/SKILL.md +7 -1
  47. package/src/cli/AgentPrerequisites.ts +14 -40
  48. package/src/cli/DefaultAgentSelection.ts +1 -1
  49. package/src/cli.ts +13 -0
  50. package/src/codex/CodexLocalActivityDetector.ts +41 -9
  51. package/src/codex/CodexProcessManager.ts +44 -7
  52. package/src/codex/CodexRuntime.ts +244 -195
  53. package/src/codex/CodexVersion.ts +18 -0
  54. package/src/codex/ProviderSwitch.ts +36 -0
  55. package/src/config/AgentExecutionDefaultsStore.ts +1 -1
  56. package/src/feishu/CardRenderer.ts +37 -27
  57. package/src/feishu/FeishuConnector.ts +15 -5
  58. package/src/feishu/InboundText.ts +11 -0
  59. package/src/feishu/MergedForwardMessage.ts +15 -5
  60. package/src/index.ts +1 -1
  61. package/src/local-files/LocalFileViewerServer.ts +26 -7
  62. package/src/local-files/MarkdownFileLinks.ts +64 -0
  63. package/src/proxy/ProxySessionController.ts +370 -240
  64. package/src/runtime/types.ts +15 -2
  65. package/src/state/StateStore.ts +117 -90
  66. package/src/utils/semanticVersion.ts +28 -0
@@ -113,6 +113,11 @@ export interface RemoteCompletedTurnSummary {
113
113
  completedAt?: number;
114
114
  }
115
115
 
116
+ export interface RemoteTurnPage {
117
+ turns: RemoteCompletedTurnSummary[];
118
+ nextCursor?: string;
119
+ }
120
+
116
121
  export interface RemoteSessionSummary {
117
122
  id: string;
118
123
  title?: string;
@@ -163,6 +168,8 @@ export interface RuntimeSession {
163
168
  reasoningEffort?: string;
164
169
  permissionMode: PermissionMode;
165
170
  activeTurnId?: string;
171
+ // Returned by reconciliation so status callers can reuse the same observation.
172
+ remoteSummary?: RemoteSessionSummary;
166
173
  }
167
174
 
168
175
  export interface CreateRuntimeSessionInput {
@@ -229,8 +236,9 @@ export interface AgentRuntime {
229
236
  getSession(localSessionId: string): RuntimeSession | undefined;
230
237
  readSessionMetadata(remoteSessionId: string): Promise<RuntimeSessionMetadata>;
231
238
  listRemoteSessions?(input?: { searchTerm?: string; cursor?: string; limit?: number }): Promise<RemoteSessionPage>;
232
- readRemoteSession?(remoteSessionId: string): Promise<RemoteSessionSummary>;
239
+ readRemoteSession?(remoteSessionId: string, view?: "metadata" | "latest" | "latest-full"): Promise<RemoteSessionSummary>;
233
240
  readRemoteForkSource?(remoteSessionId: string): Promise<RemoteSessionSummary>;
241
+ listRemoteTurnSummaries?(remoteSessionId: string, input: { cursor?: string; limit: number }): Promise<RemoteTurnPage>;
234
242
  inspectRemoteSessionActivity?(remoteSessionId: string): Promise<RemoteSessionActivity>;
235
243
  synchronizeSession(sessionId: string): Promise<RuntimeSession>;
236
244
  startTurn(sessionId: string, prompt: RuntimePrompt): Promise<string>;
@@ -246,7 +254,12 @@ export interface AgentRuntime {
246
254
  setModel(sessionId: string, model: string): Promise<void>;
247
255
  setReasoningEffort(sessionId: string, effort: string): Promise<void>;
248
256
  setPermissionMode(sessionId: string, mode: PermissionMode): Promise<void>;
249
- setExecutionSettings?(sessionId: string, settings: RuntimeExecutionSettings): Promise<RuntimeSession>;
257
+ setExecutionSettings?(
258
+ sessionId: string,
259
+ settings: RuntimeExecutionSettings,
260
+ // Called after remote verification, before releasing the task's operation lock.
261
+ persist?: (session: RuntimeSession) => Promise<void>,
262
+ ): Promise<RuntimeSession>;
250
263
  respondToApproval(sessionId: string, requestId: string, decision: ApprovalDecision): Promise<void>;
251
264
  listModels(): Promise<ModelOption[]>;
252
265
  listModelProviders?(): Promise<ModelProviderOption[]>;
@@ -95,6 +95,21 @@ export interface CompletedTurnSnapshotRecord {
95
95
  updatedAt: string;
96
96
  }
97
97
 
98
+ export interface CompletedTurnIndexRecord {
99
+ turnId: string;
100
+ parentTurnId?: string;
101
+ timestamp: number;
102
+ updatedAt: string;
103
+ }
104
+
105
+ export interface TurnPromptSummary {
106
+ status?: string;
107
+ prompt?: string;
108
+ taskTitle?: string;
109
+ startedAt?: number;
110
+ completedAt?: number;
111
+ }
112
+
98
113
  export interface ImportedCompletedTurnRecord {
99
114
  turnId: string;
100
115
  snapshot: unknown;
@@ -1032,6 +1047,21 @@ export class StateStore {
1032
1047
  return row ? JSON.parse(row.snapshot_json) : undefined;
1033
1048
  }
1034
1049
 
1050
+ getTurnPromptSummary(turnId: string): TurnPromptSummary | undefined {
1051
+ const row = this.db.prepare(`SELECT
1052
+ json_extract(snapshot_json, '$.status') AS status,
1053
+ json_extract(snapshot_json, '$.prompt') AS prompt,
1054
+ json_extract(snapshot_json, '$.taskTitle') AS taskTitle,
1055
+ json_extract(snapshot_json, '$.startedAt') AS startedAt,
1056
+ json_extract(snapshot_json, '$.completedAt') AS completedAt
1057
+ FROM turn_snapshots WHERE turn_id = ?`).get(turnId) as TurnPromptSummary | undefined;
1058
+ return row ? {
1059
+ status: row.status ?? undefined, prompt: row.prompt ?? undefined,
1060
+ taskTitle: row.taskTitle ?? undefined, startedAt: row.startedAt ?? undefined,
1061
+ completedAt: row.completedAt ?? undefined,
1062
+ } : undefined;
1063
+ }
1064
+
1035
1065
  findLatestTurnSnapshotForSession(localSessionId: string): PersistedTurnSnapshotRecord | undefined {
1036
1066
  const row = this.db.prepare(`
1037
1067
  SELECT turn_id, local_session_id, context_key, snapshot_json, updated_at
@@ -1096,16 +1126,16 @@ export class StateStore {
1096
1126
  : undefined;
1097
1127
  }
1098
1128
 
1099
- saveTurnParent(turnId: string, localSessionId: string, parentTurnId?: string): void {
1129
+ saveTurnParent(turnId: string, localSessionId: string, parentTurnId?: string, replaceExisting = false): void {
1100
1130
  this.db.prepare(`
1101
1131
  INSERT INTO turn_parent_links (
1102
1132
  turn_id, local_session_id, parent_turn_id, created_at
1103
1133
  ) VALUES (?, ?, ?, ?)
1104
1134
  ON CONFLICT(turn_id) DO UPDATE SET
1105
1135
  parent_turn_id = excluded.parent_turn_id
1106
- WHERE turn_parent_links.parent_turn_id IS NULL
1136
+ WHERE (turn_parent_links.parent_turn_id IS NULL OR ?)
1107
1137
  AND excluded.parent_turn_id IS NOT NULL
1108
- `).run(turnId, localSessionId, parentTurnId ?? null, new Date().toISOString());
1138
+ `).run(turnId, localSessionId, parentTurnId ?? null, new Date().toISOString(), Number(replaceExisting));
1109
1139
  }
1110
1140
 
1111
1141
  importCompletedTurnHistory(input: {
@@ -1114,6 +1144,7 @@ export class StateStore {
1114
1144
  agentName: string;
1115
1145
  remoteSessionId: string;
1116
1146
  turns: ImportedCompletedTurnRecord[];
1147
+ replaceParents?: boolean;
1117
1148
  }): void {
1118
1149
  const importHistory = this.db.transaction(() => {
1119
1150
  let parentTurnId: string | undefined;
@@ -1140,7 +1171,7 @@ export class StateStore {
1140
1171
  input.remoteSessionId,
1141
1172
  turn.updatedAt,
1142
1173
  );
1143
- this.saveTurnParent(turn.turnId, input.localSessionId, parentTurnId);
1174
+ this.saveTurnParent(turn.turnId, input.localSessionId, parentTurnId, input.replaceParents);
1144
1175
  parentTurnId = turn.turnId;
1145
1176
  }
1146
1177
  });
@@ -1156,13 +1187,13 @@ export class StateStore {
1156
1187
  return row?.parent_turn_id ?? undefined;
1157
1188
  }
1158
1189
 
1159
- findLatestCompletedTurnId(localSessionId: string, contextKey: string): string | undefined {
1190
+ findLatestCompletedTurnId(localSessionId: string, contextKey?: string): string | undefined {
1160
1191
  const row = this.db
1161
1192
  .prepare(`
1162
1193
  SELECT turn_id
1163
1194
  FROM turn_snapshots
1164
1195
  WHERE local_session_id = ?
1165
- AND context_key = ?
1196
+ AND (? IS NULL OR context_key = ?)
1166
1197
  AND json_extract(snapshot_json, '$.status') = 'completed'
1167
1198
  ORDER BY
1168
1199
  coalesce(
@@ -1173,7 +1204,7 @@ export class StateStore {
1173
1204
  updated_at DESC
1174
1205
  LIMIT 1
1175
1206
  `)
1176
- .get(localSessionId, contextKey) as { turn_id: string } | undefined;
1207
+ .get(localSessionId, contextKey ?? null, contextKey ?? null) as { turn_id: string } | undefined;
1177
1208
  return row?.turn_id;
1178
1209
  }
1179
1210
 
@@ -1255,24 +1286,92 @@ export class StateStore {
1255
1286
  }));
1256
1287
  }
1257
1288
 
1289
+ hasTaskHistoryTurn(localSessionId: string, turnId: string): boolean {
1290
+ const readParent = this.db.prepare(`
1291
+ SELECT ts.local_session_id, tpl.parent_turn_id
1292
+ FROM turn_snapshots ts
1293
+ LEFT JOIN turn_parent_links tpl ON tpl.turn_id = ts.turn_id
1294
+ WHERE ts.turn_id = ?
1295
+ AND json_extract(ts.snapshot_json, '$.status') = 'completed'
1296
+ `);
1297
+ type ParentRow = { local_session_id: string; parent_turn_id: string | null };
1298
+ const target = readParent.get(turnId) as ParentRow | undefined;
1299
+ if (!target) return false;
1300
+ if (target.local_session_id === localSessionId) return true;
1301
+
1302
+ const backfilledSessions = new Set<string>();
1303
+ let ancestorTurnId = this.findForkSourceTurnId(localSessionId);
1304
+ if (!ancestorTurnId) {
1305
+ // Reset-only legacy tasks may have partially saved cross-session links.
1306
+ this.backfillTurnParents(localSessionId);
1307
+ backfilledSessions.add(localSessionId);
1308
+ ancestorTurnId = this.findCrossSessionParentTurnId(localSessionId);
1309
+ }
1310
+ const visited = new Set<string>();
1311
+ while (ancestorTurnId && !visited.has(ancestorTurnId)) {
1312
+ if (ancestorTurnId === turnId) return true;
1313
+ visited.add(ancestorTurnId);
1314
+ const ancestor = readParent.get(ancestorTurnId) as ParentRow | undefined;
1315
+ if (!ancestor) return false;
1316
+ let parentTurnId = ancestor.parent_turn_id;
1317
+ // Older snapshots may lack parent links. Repair each owner at most once,
1318
+ // without loading full snapshots or rebuilding already linked ancestry.
1319
+ if (!parentTurnId && !backfilledSessions.has(ancestor.local_session_id)) {
1320
+ this.backfillTurnParents(ancestor.local_session_id);
1321
+ backfilledSessions.add(ancestor.local_session_id);
1322
+ parentTurnId = (readParent.get(ancestorTurnId) as ParentRow | undefined)?.parent_turn_id ?? null;
1323
+ }
1324
+ ancestorTurnId = parentTurnId ?? undefined;
1325
+ }
1326
+ return false;
1327
+ }
1328
+
1258
1329
  listTaskTurnGraph(localSessionId: string): CompletedTurnSnapshotRecord[] {
1259
- this.backfillTurnParents(localSessionId);
1260
- const records = new Map(
1261
- this.listCompletedTurnGraphRows(localSessionId).map((record) => [record.turnId, record]),
1262
- );
1330
+ return this.listTaskTurnGraphIndex(localSessionId).map((record) => ({
1331
+ ...record, snapshot: this.getTurnSnapshot(record.turnId),
1332
+ }));
1333
+ }
1334
+
1335
+ listTaskTurnGraphIndex(localSessionId: string): CompletedTurnIndexRecord[] {
1336
+ const backfilled = new Set<string>();
1337
+ const backfill = (id: string): void => {
1338
+ if (backfilled.has(id)) return;
1339
+ this.backfillTurnParents(id);
1340
+ backfilled.add(id);
1341
+ };
1342
+ backfill(localSessionId);
1343
+ const projection = `SELECT ts.turn_id AS turnId, tpl.parent_turn_id AS parentTurnId,
1344
+ ts.local_session_id AS localSessionId, ts.updated_at AS updatedAt,
1345
+ coalesce(json_extract(ts.snapshot_json, '$.completedAt'),
1346
+ json_extract(ts.snapshot_json, '$.startedAt'),
1347
+ cast(strftime('%s', ts.updated_at) AS INTEGER) * 1000, 0) AS timestamp
1348
+ FROM turn_snapshots ts LEFT JOIN turn_parent_links tpl ON tpl.turn_id = ts.turn_id
1349
+ WHERE json_extract(ts.snapshot_json, '$.status') = 'completed'`;
1350
+ type Row = CompletedTurnIndexRecord & { localSessionId: string; parentTurnId: string | undefined };
1351
+ const normalize = (row: Row): CompletedTurnIndexRecord => ({
1352
+ turnId: row.turnId, parentTurnId: row.parentTurnId ?? undefined,
1353
+ timestamp: row.timestamp, updatedAt: row.updatedAt,
1354
+ });
1355
+ const own = this.db.prepare(`${projection} AND ts.local_session_id = ?`).all(localSessionId) as Row[];
1356
+ const read = this.db.prepare(`${projection} AND ts.turn_id = ?`);
1357
+ const records = new Map(own.map((row) => [row.turnId, normalize(row)]));
1263
1358
  let ancestorTurnId = this.findForkSourceTurnId(localSessionId)
1264
1359
  ?? this.findCrossSessionParentTurnId(localSessionId);
1265
1360
  const visited = new Set<string>();
1266
1361
 
1267
1362
  while (ancestorTurnId && !visited.has(ancestorTurnId)) {
1268
1363
  visited.add(ancestorTurnId);
1269
- const ancestor = this.getCompletedTurnGraphRecord(ancestorTurnId);
1364
+ let ancestor = read.get(ancestorTurnId) as Row | undefined;
1270
1365
  if (!ancestor) break;
1271
- records.set(ancestor.turnId, ancestor);
1366
+ if (!backfilled.has(ancestor.localSessionId)) {
1367
+ backfill(ancestor.localSessionId);
1368
+ ancestor = read.get(ancestorTurnId) as Row;
1369
+ }
1370
+ records.set(ancestor.turnId, normalize(ancestor));
1272
1371
  ancestorTurnId = ancestor.parentTurnId;
1273
1372
  }
1274
1373
 
1275
- return [...records.values()].sort(compareCompletedTurnSnapshots);
1374
+ return [...records.values()].sort((a, b) => b.timestamp - a.timestamp || b.updatedAt.localeCompare(a.updatedAt));
1276
1375
  }
1277
1376
 
1278
1377
  getForkHistorySource(localSessionId: string): ForkHistorySourceRecord | undefined {
@@ -1300,54 +1399,16 @@ export class StateStore {
1300
1399
  };
1301
1400
  }
1302
1401
 
1303
- hasImportedForkTurnHistory(localSessionId: string): boolean {
1402
+ hasImportedForkTurnHistory(localSessionId: string, sourceRemoteSessionId?: string, sourceTurnId?: string): boolean {
1304
1403
  return Boolean(this.db.prepare(`
1305
1404
  SELECT 1
1306
1405
  FROM audit_events
1307
1406
  WHERE event_type = 'fork_turn_history_imported'
1308
1407
  AND json_extract(payload_json, '$.forkedLocalSessionId') = ?
1408
+ AND (? IS NULL OR json_extract(payload_json, '$.sourceRemoteSessionId') = ?)
1409
+ AND (? IS NULL OR json_extract(payload_json, '$.sourceTurnId') = ?)
1309
1410
  LIMIT 1
1310
- `).get(localSessionId));
1311
- }
1312
-
1313
- private listCompletedTurnGraphRows(localSessionId: string): CompletedTurnSnapshotRecord[] {
1314
- const rows = this.db.prepare(`
1315
- SELECT ts.turn_id, tpl.parent_turn_id, ts.snapshot_json, ts.updated_at
1316
- FROM turn_snapshots ts
1317
- LEFT JOIN turn_parent_links tpl ON tpl.turn_id = ts.turn_id
1318
- WHERE ts.local_session_id = ?
1319
- AND json_extract(ts.snapshot_json, '$.status') = 'completed'
1320
- `).all(localSessionId) as Array<{
1321
- turn_id: string;
1322
- parent_turn_id: string | null;
1323
- snapshot_json: string;
1324
- updated_at: string;
1325
- }>;
1326
- return rows.map(mapCompletedTurnSnapshot);
1327
- }
1328
-
1329
- private getCompletedTurnGraphRecord(turnId: string): CompletedTurnSnapshotRecord | undefined {
1330
- const owner = this.db.prepare(`
1331
- SELECT local_session_id
1332
- FROM turn_snapshots
1333
- WHERE turn_id = ?
1334
- AND json_extract(snapshot_json, '$.status') = 'completed'
1335
- `).get(turnId) as { local_session_id: string } | undefined;
1336
- if (!owner) return undefined;
1337
- this.backfillTurnParents(owner.local_session_id);
1338
- const row = this.db.prepare(`
1339
- SELECT ts.turn_id, tpl.parent_turn_id, ts.snapshot_json, ts.updated_at
1340
- FROM turn_snapshots ts
1341
- LEFT JOIN turn_parent_links tpl ON tpl.turn_id = ts.turn_id
1342
- WHERE ts.turn_id = ?
1343
- AND json_extract(ts.snapshot_json, '$.status') = 'completed'
1344
- `).get(turnId) as {
1345
- turn_id: string;
1346
- parent_turn_id: string | null;
1347
- snapshot_json: string;
1348
- updated_at: string;
1349
- } | undefined;
1350
- return row ? mapCompletedTurnSnapshot(row) : undefined;
1411
+ `).get(localSessionId, sourceRemoteSessionId ?? null, sourceRemoteSessionId ?? null, sourceTurnId ?? null, sourceTurnId ?? null));
1351
1412
  }
1352
1413
 
1353
1414
  private findForkSourceTurnId(localSessionId: string): string | undefined {
@@ -2249,40 +2310,6 @@ function mapTurnAttempt(row: TurnAttemptRow): TurnAttemptRecord {
2249
2310
  };
2250
2311
  }
2251
2312
 
2252
- function mapCompletedTurnSnapshot(row: {
2253
- turn_id: string;
2254
- parent_turn_id: string | null;
2255
- snapshot_json: string;
2256
- updated_at: string;
2257
- }): CompletedTurnSnapshotRecord {
2258
- return {
2259
- turnId: row.turn_id,
2260
- parentTurnId: row.parent_turn_id ?? undefined,
2261
- snapshot: JSON.parse(row.snapshot_json),
2262
- updatedAt: row.updated_at,
2263
- };
2264
- }
2265
-
2266
- function compareCompletedTurnSnapshots(
2267
- left: CompletedTurnSnapshotRecord,
2268
- right: CompletedTurnSnapshotRecord,
2269
- ): number {
2270
- const timeDifference = completedTurnTimestamp(right) - completedTurnTimestamp(left);
2271
- return timeDifference || right.updatedAt.localeCompare(left.updatedAt);
2272
- }
2273
-
2274
- function completedTurnTimestamp(record: CompletedTurnSnapshotRecord): number {
2275
- const snapshot = record.snapshot && typeof record.snapshot === "object"
2276
- ? record.snapshot as { completedAt?: unknown; startedAt?: unknown }
2277
- : undefined;
2278
- const timestamp = typeof snapshot?.completedAt === "number"
2279
- ? snapshot.completedAt
2280
- : typeof snapshot?.startedAt === "number"
2281
- ? snapshot.startedAt
2282
- : Date.parse(record.updatedAt);
2283
- return Number.isFinite(timestamp) ? timestamp : 0;
2284
- }
2285
-
2286
2313
  function stringValue(value: unknown): string | undefined {
2287
2314
  return typeof value === "string" && value.trim() ? value.trim() : undefined;
2288
2315
  }
@@ -0,0 +1,28 @@
1
+ export function compareSemanticVersions(left: string, right: string): number {
2
+ const parse = (value: string) => /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/u.exec(value);
3
+ const a = parse(left);
4
+ const b = parse(right);
5
+ if (!a || !b) return 0;
6
+ for (let i = 1; i <= 3; i += 1) {
7
+ const difference = Number(a[i]) - Number(b[i]);
8
+ if (difference) return difference;
9
+ }
10
+ if (!a[4] && !b[4]) return 0;
11
+ if (!a[4]) return 1;
12
+ if (!b[4]) return -1;
13
+ const aParts = a[4].split(".");
14
+ const bParts = b[4].split(".");
15
+ for (let i = 0; i < Math.max(aParts.length, bParts.length); i += 1) {
16
+ const x = aParts[i];
17
+ const y = bParts[i];
18
+ if (x === undefined) return -1;
19
+ if (y === undefined) return 1;
20
+ if (x === y) continue;
21
+ const nx = /^\d+$/u.test(x);
22
+ const ny = /^\d+$/u.test(y);
23
+ if (nx && ny) return Number(x) - Number(y);
24
+ if (nx !== ny) return nx ? -1 : 1;
25
+ return x.localeCompare(y);
26
+ }
27
+ return 0;
28
+ }