@lark-codem/codem-cli 0.1.267 → 0.1.269-meego-ai-integration.100103555663.0.gda51474
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/package.json +9 -10
- package/profile/credential-errors.js +1 -4
- package/profile/runtime-logs.js +8 -98
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-codem/codem-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
4
4
|
"codemServiceManagementProtocol": 3,
|
|
5
5
|
"codemProfileProtocol": 1,
|
|
6
6
|
"type": "module",
|
|
@@ -29,17 +29,16 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@lark-codem/codem-core": "0.8.
|
|
33
|
-
"zod": "3.25.76"
|
|
34
|
-
"@lark-codem/lark-cli": "0.1.1"
|
|
32
|
+
"@lark-codem/codem-core": "0.8.86-meego-ai-integration.100103555251.0.g9fb420c",
|
|
33
|
+
"zod": "3.25.76"
|
|
35
34
|
},
|
|
36
35
|
"optionalDependencies": {
|
|
37
|
-
"@lark-codem/codem-cli-darwin-arm64": "0.1.
|
|
38
|
-
"@lark-codem/codem-cli-darwin-x64": "0.1.
|
|
39
|
-
"@lark-codem/codem-cli-linux-arm64": "0.1.
|
|
40
|
-
"@lark-codem/codem-cli-linux-x64": "0.1.
|
|
41
|
-
"@lark-codem/codem-cli-win32-arm64": "0.1.
|
|
42
|
-
"@lark-codem/codem-cli-win32-x64": "0.1.
|
|
36
|
+
"@lark-codem/codem-cli-darwin-arm64": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
37
|
+
"@lark-codem/codem-cli-darwin-x64": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
38
|
+
"@lark-codem/codem-cli-linux-arm64": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
39
|
+
"@lark-codem/codem-cli-linux-x64": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
40
|
+
"@lark-codem/codem-cli-win32-arm64": "0.1.269-meego-ai-integration.100103555663.0.gda51474",
|
|
41
|
+
"@lark-codem/codem-cli-win32-x64": "0.1.269-meego-ai-integration.100103555663.0.gda51474"
|
|
43
42
|
},
|
|
44
43
|
"engines": {
|
|
45
44
|
"node": ">=18"
|
|
@@ -30,8 +30,5 @@ export class CredentialStorageError extends Error {
|
|
|
30
30
|
|
|
31
31
|
export function isRecoverableCredentialState(error) {
|
|
32
32
|
return error?.code === "credential_storage_rotation_pending"
|
|
33
|
-
|| error?.code === "credential_storage_rotation_unknown"
|
|
34
|
-
// A missing OAuth record permits reauthorization with the existing device,
|
|
35
|
-
// never use of its stale plaintext mirror or another credential kind.
|
|
36
|
-
|| (error?.code === "credential_storage_missing" && error.kind === "oauth");
|
|
33
|
+
|| error?.code === "credential_storage_rotation_unknown";
|
|
37
34
|
}
|
package/profile/runtime-logs.js
CHANGED
|
@@ -10,59 +10,21 @@ const CAPACITY = 256;
|
|
|
10
10
|
const BATCH_SIZE = 32;
|
|
11
11
|
const INTERVAL_MS = 10_000;
|
|
12
12
|
const REQUEST_TIMEOUT_MS = 3_000;
|
|
13
|
-
const TRUSTED_DEVICE_EVENTS = new Set(["host_identity_collection", "host_identity_command", "host_session_attempt", "host_session_expired", "trusted_device_admission_blocked", "trusted_device_admission_recovered"]);
|
|
14
|
-
const TRUSTED_DEVICE_PHASES = ["auth", "identity", "provider", "host_key", "activation_state", "activation_apply", "activation_sign", "activation_complete", "credential_resolve", "session_apply", "session_sign", "session_complete", "trusted_device"];
|
|
15
|
-
const TRUSTED_DEVICE_DIMENSIONS = {
|
|
16
|
-
phase: TRUSTED_DEVICE_PHASES,
|
|
17
|
-
operation: ["create", "renew", "recovery", "platform_identity", "network_interfaces", "network_ports"],
|
|
18
|
-
outcome: ["success", "partial", "failed", "ready", "not_registered", "no_auth", "reset", "blocked", "invalid", "verified", "not_required", "absent", "expired"],
|
|
19
|
-
failure_kind: ["none", "timeout", "exec_failed", "invalid_json", "empty_identity", "read_failed", "authorization", "unknown"]
|
|
20
|
-
};
|
|
21
|
-
const OBSERVATION_EVENTS = new Set(["command_delivery_observed", "command_admission", "runtime_capability_probe", "command_ack", "command_observation_closed", "diagnostic_reporter_health", ...TRUSTED_DEVICE_EVENTS]);
|
|
22
|
-
const OBSERVATION_DIMENSIONS = {
|
|
23
|
-
phase: ["resolve_binary", "build_env", "host_capabilities", "parse_capabilities", "strict_resume", "verify_binding", "prepare", "persist_state", "trusted_device", "request", "validate_response", "apply_response"],
|
|
24
|
-
reason: ["runtime_unavailable", "runtime_environment_failed", "capability_probe_failed", "runtime_binary_changed", "strict_resume_unsupported", "turn_context_unsupported", "active_run_protocol_mismatch", "trusted_device_blocked", "shutting_down_handoff", "handoff_target_not_active", "duplicate_inflight", "handler_inflight", "prepare_exception_unknown", "capacity", "stopped", "replaced", "scope_changed", "queue_removed", "local_rejected"],
|
|
25
|
-
command_type: ["agent.run", "agent.steer", "agent.stop", "task.assign", "task.stop", "artifact.relay.read", "artifact.convert_to_lark_resource", "artifact.download", "directory.list", "git.preview", "workflow.preview"],
|
|
26
|
-
actor_type: ["device", "sandbox"],
|
|
27
|
-
ack_status: ["accepted", "ignored_duplicate", "rejected"],
|
|
28
|
-
ack_outcome: ["accepted", "duplicate", "rejected", "conflicting"],
|
|
29
|
-
readback_scope: ["command", "delivery", "unmatched"],
|
|
30
|
-
timing_origin: ["observed", "restored_unknown"]
|
|
31
|
-
};
|
|
32
|
-
const OBSERVATION_METRICS = {
|
|
33
|
-
host_identity_collection: ["duration_ms", "field_error_count"],
|
|
34
|
-
host_identity_command: ["duration_ms", "timeout_ms"],
|
|
35
|
-
host_session_attempt: ["elapsed_ms", "next_retry_ms", "consecutive_failures", "session_remaining_ms", ...TRUSTED_DEVICE_PHASES.map(phase => `${phase}_duration_ms`)],
|
|
36
|
-
host_session_expired: ["expired_for_ms", "consecutive_failures", "next_retry_ms"],
|
|
37
|
-
trusted_device_admission_blocked: ["elapsed_ms", "blocked_response_count"],
|
|
38
|
-
trusted_device_admission_recovered: ["elapsed_ms", "blocked_response_count"],
|
|
39
|
-
command_delivery_observed: ["attempt_delta", "suppressed_count"],
|
|
40
|
-
command_admission: ["attempt_delta", "suppressed_count", "deferred_age_ms", "deferred_duration_ms"],
|
|
41
|
-
runtime_capability_probe: ["probe_duration_ms"],
|
|
42
|
-
command_ack: ["attempt_delta", "suppressed_count", "ack_queue_wait_ms", "ack_settle_duration_ms", "pending_ack_age_ms", "pending_command_ack_count", "pending_ack_unknown_age_count"],
|
|
43
|
-
command_observation_closed: ["omitted_detail_count", "pending_command_ack_count", "deferred_count"],
|
|
44
|
-
diagnostic_reporter_health: ["dropped_delta", "upload_failure_delta", "pending_event_count"]
|
|
45
|
-
};
|
|
46
|
-
const EXTRA_FIELDS = ["observation_id", "runtime_client_instance_id", "command_id", "delivery_id", "probe_id", "sync_id", "transport_request_id", "attempt_id"];
|
|
47
13
|
const STRING_FIELDS = new Set([
|
|
48
|
-
...EXTRA_FIELDS, "command_type", "ack_status", "ack_outcome", "readback_scope", "timing_origin", "required_capability",
|
|
49
14
|
"request_id", "command_id", "session_id", "task_id", "dispatch_id", "event_id", "sync_id",
|
|
50
15
|
"process_instance_id", "run_id", "stage", "phase", "status", "outcome", "reason", "action",
|
|
51
16
|
"error_class", "error_code", "error_kind", "error_type", "code", "signal", "stop_reason",
|
|
52
17
|
"terminal_event", "event_type", "actor_type", "source", "trigger", "hook_id", "hook_event",
|
|
53
18
|
"target_version", "cli_version", "core_version", "version", "previous_state", "state",
|
|
54
|
-
"failure_kind", "failure_impact", "failure_type", "failure_subtype", "failure_code", "failure_status", "delay_source", "mode", "provider", "name", "termination", "interaction_id", "interaction_kind", "owner_state", "artifact_id", "resource_type", "delivery_mode", "host", "scheme", "tool_call_id", "tool_name", "background_task_id", "model", "artifact_kind", "codem_user_id", "device_id", "operation", "foreground_error_code"
|
|
55
|
-
"operation_id", "entrypoint"
|
|
19
|
+
"failure_kind", "failure_impact", "failure_type", "failure_subtype", "failure_code", "failure_status", "delay_source", "mode", "provider", "name", "termination", "interaction_id", "interaction_kind", "owner_state", "artifact_id", "resource_type", "delivery_mode", "host", "scheme", "tool_call_id", "tool_name", "background_task_id", "model", "artifact_kind", "codem_user_id", "device_id", "operation", "foreground_error_code"
|
|
56
20
|
]);
|
|
57
21
|
const VALUE_FIELDS = new Set([
|
|
58
|
-
"session_retained",
|
|
59
|
-
...new Set(Object.values(OBSERVATION_METRICS).flat()),
|
|
60
22
|
"pid", "exit_code", "duration_ms", "elapsed_ms", "wait_ms", "run_ms", "total_ms", "took_ms",
|
|
61
23
|
"attempt", "attempts", "attempt_count", "retryable", "http_status", "active_task_count",
|
|
62
24
|
"pending_event_count", "pending_command_ack_count", "next_retry_ms", "consecutive_failures",
|
|
63
25
|
"outage_duration_ms", "startup_duration_ms", "failed_attempts", "active_runs", "completed",
|
|
64
26
|
"delivered", "result_delivered", "queued_behind_existing", "expected", "timed_out",
|
|
65
|
-
"force_exit_ms", "teardown_ceiling_ms", "recovered", "count", "ms_since_process_start", "owner_pid", "consumed", "delivery_attempt", "ack_deadline_ms", "command_to_bridge_ms", "size_bytes", "
|
|
27
|
+
"force_exit_ms", "teardown_ceiling_ms", "recovered", "count", "ms_since_process_start", "owner_pid", "consumed", "delivery_attempt", "ack_deadline_ms", "command_to_bridge_ms", "size_bytes", "before", "after", "omitted_detail_count", "opened", "selected", "foreground"
|
|
66
28
|
]);
|
|
67
29
|
|
|
68
30
|
function token(value) {
|
|
@@ -78,16 +40,6 @@ function optional(read) {
|
|
|
78
40
|
try { return read(); } catch { return undefined; }
|
|
79
41
|
}
|
|
80
42
|
|
|
81
|
-
function metricProjection(event, fields = {}) {
|
|
82
|
-
return { count: 1, ...Object.fromEntries((OBSERVATION_METRICS[event] ?? [])
|
|
83
|
-
.filter(key => typeof fields?.[key] === "number" && Number.isFinite(fields[key]) && fields[key] >= 0)
|
|
84
|
-
.map(key => [key, fields[key]])) };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function extraProjection(fields = {}) {
|
|
88
|
-
return Object.fromEntries(EXTRA_FIELDS.filter(key => token(fields?.[key])).map(key => [key, token(fields[key])]));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
43
|
function projectFields(input) {
|
|
92
44
|
const result = {};
|
|
93
45
|
for (const [key, value] of Object.entries(input ?? {}).slice(0, 100)) {
|
|
@@ -100,8 +52,6 @@ function projectFields(input) {
|
|
|
100
52
|
}
|
|
101
53
|
}
|
|
102
54
|
const error = input?.error ?? input?.terminalError;
|
|
103
|
-
const fingerprint = input?.error_fingerprint ?? input?.errorFingerprint;
|
|
104
|
-
if (typeof fingerprint === "string" && /^[a-f0-9]{24}$/u.test(fingerprint)) result.error_fingerprint = fingerprint;
|
|
105
55
|
const terminal = input?.terminalError ?? error?.terminalError;
|
|
106
56
|
if (terminal && typeof terminal === "object") {
|
|
107
57
|
if (token(terminal.code)) result.error_code = token(terminal.code);
|
|
@@ -140,10 +90,6 @@ export class RuntimeLogReporter {
|
|
|
140
90
|
#timer;
|
|
141
91
|
#closed = false;
|
|
142
92
|
#dropped = 0;
|
|
143
|
-
#uploadFailures = 0;
|
|
144
|
-
#reportedDrops = 0;
|
|
145
|
-
#reportedFailures = 0;
|
|
146
|
-
#lastHealthAt = Date.now();
|
|
147
93
|
#send;
|
|
148
94
|
#role;
|
|
149
95
|
#version;
|
|
@@ -198,7 +144,7 @@ export class RuntimeLogReporter {
|
|
|
198
144
|
if (fs.lstatSync(file).isSymbolicLink() || fs.statSync(file).size > 65536) continue;
|
|
199
145
|
const entry = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
200
146
|
if (entry?.record?.category?.reporter !== "codem_js" || entry?.record?.log_type !== "log" || !entry.header) continue;
|
|
201
|
-
this.#replay.queue.push({ header: entry.header, record: entry.record,
|
|
147
|
+
this.#replay.queue.push({ header: entry.header, record: entry.record, attempts: 0, crashFile: file });
|
|
202
148
|
} catch { /* A partial crash write cannot prevent startup. */ }
|
|
203
149
|
}
|
|
204
150
|
} catch { /* First startup or unavailable storage. */ }
|
|
@@ -223,14 +169,12 @@ export class RuntimeLogReporter {
|
|
|
223
169
|
|
|
224
170
|
get pendingCount() { return this.#live.queue.length + this.#replay.queue.length; }
|
|
225
171
|
get droppedCount() { return this.#dropped; }
|
|
226
|
-
get identityKey() { return JSON.stringify([this.#instanceId, this.#role, this.#identity.deviceId, this.#identity.userId, this.#identity.tenantId]); }
|
|
227
172
|
|
|
228
173
|
record(level, component, event, fields = {}) {
|
|
229
174
|
try {
|
|
230
175
|
if (this.#closed) return false;
|
|
231
176
|
let safeFields;
|
|
232
177
|
try { safeFields = projectFields(fields); } catch { safeFields = {}; }
|
|
233
|
-
if (OBSERVATION_EVENTS.has(event)) safeFields.observation_id = randomUUID();
|
|
234
178
|
const severity = ["info", "warn", "error", "fatal"].includes(level) ? level : "info";
|
|
235
179
|
const identity = { ...this.#identity };
|
|
236
180
|
const category = {
|
|
@@ -242,14 +186,6 @@ export class RuntimeLogReporter {
|
|
|
242
186
|
...(identity.serverEnvironment ? { server_environment: identity.serverEnvironment } : {}),
|
|
243
187
|
...Object.fromEntries(["stage", "error_class", "error_code", "error_kind", "outcome"].filter((key) => safeFields[key]).map((key) => [key, safeFields[key]]))
|
|
244
188
|
};
|
|
245
|
-
if (OBSERVATION_EVENTS.has(category.event)) {
|
|
246
|
-
const trustedDevice = TRUSTED_DEVICE_EVENTS.has(category.event);
|
|
247
|
-
// Keep arbitrary upstream error codes in logs, not metric dimensions.
|
|
248
|
-
if (trustedDevice) for (const key of ["stage", "error_class", "error_code", "error_kind", "outcome"]) delete category[key];
|
|
249
|
-
for (const [key, values] of Object.entries(trustedDevice ? TRUSTED_DEVICE_DIMENSIONS : OBSERVATION_DIMENSIONS)) {
|
|
250
|
-
if (safeFields[key]) category[key] = values.includes(safeFields[key]) ? safeFields[key] : "unknown";
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
189
|
const header = {
|
|
254
190
|
aid: SLARDAR_PC_AID,
|
|
255
191
|
device_id: identity.deviceId ?? this.#instanceId,
|
|
@@ -271,39 +207,17 @@ export class RuntimeLogReporter {
|
|
|
271
207
|
log_type: "log", log_level: severity === "fatal" ? "error" : severity,
|
|
272
208
|
log_content: `CodeM diagnostic ${severity} ${category.component}/${category.event}\n${JSON.stringify(payload)}`
|
|
273
209
|
};
|
|
274
|
-
const priority = severity === "fatal" ? 3 :
|
|
275
|
-
["resumed", "settled"].includes(safeFields.stage) || (severity === "error" && !safeFields.suppressed_count) ? 2 :
|
|
276
|
-
severity === "info" ? 0 : 1;
|
|
277
210
|
if (this.#live.queue.length >= CAPACITY) {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
const expendable = this.#live.queue.findIndex(entry => (entry.priority ?? (entry.record.log_level === "info" ? 0 : 1)) === minimum);
|
|
281
|
-
this.#live.queue.splice(expendable, 1);
|
|
211
|
+
const expendable = this.#live.queue.findIndex((entry) => entry.record.log_level === "info");
|
|
212
|
+
this.#live.queue.splice(expendable >= 0 ? expendable : 0, 1);
|
|
282
213
|
this.#dropped += 1;
|
|
283
214
|
}
|
|
284
|
-
this.#live.queue.push({ header, record,
|
|
215
|
+
this.#live.queue.push({ header, record, attempts: 0 });
|
|
285
216
|
return true;
|
|
286
217
|
} catch { return false; }
|
|
287
218
|
}
|
|
288
219
|
|
|
289
220
|
async flush({ timeoutMs = REQUEST_TIMEOUT_MS } = {}) {
|
|
290
|
-
// Counters only in the failure path: never recursively log an upload error.
|
|
291
|
-
if (Date.now() - this.#lastHealthAt >= 60_000 && (this.#dropped !== this.#reportedDrops || this.#uploadFailures !== this.#reportedFailures)) {
|
|
292
|
-
this.#lastHealthAt = Date.now();
|
|
293
|
-
const dropped = this.#dropped;
|
|
294
|
-
const failures = this.#uploadFailures;
|
|
295
|
-
const queued = this.record("warn", "runtime-post", "diagnostic_reporter_health", {
|
|
296
|
-
dropped_delta: dropped - this.#reportedDrops,
|
|
297
|
-
upload_failure_delta: failures - this.#reportedFailures,
|
|
298
|
-
pending_event_count: this.pendingCount
|
|
299
|
-
});
|
|
300
|
-
// The health record can itself evict an entry or be refused by a full
|
|
301
|
-
// higher-priority queue. Neither loss has been included in this snapshot.
|
|
302
|
-
if (queued) {
|
|
303
|
-
this.#reportedDrops = dropped;
|
|
304
|
-
this.#reportedFailures = failures;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
221
|
const deadline = Date.now() + timeoutMs;
|
|
308
222
|
const live = this.#flushLane(this.#live, timeoutMs).then(() => {
|
|
309
223
|
// Cover records added after drain's last queue check but before its
|
|
@@ -348,10 +262,10 @@ export class RuntimeLogReporter {
|
|
|
348
262
|
const key = JSON.stringify(first.header);
|
|
349
263
|
const batch = [];
|
|
350
264
|
while (batch.length < BATCH_SIZE && lane.queue.length && JSON.stringify(lane.queue[0].header) === key && Boolean(lane.queue[0].crashFile) === Boolean(first.crashFile)) batch.push(lane.queue.shift());
|
|
351
|
-
const data = batch.flatMap(({ record
|
|
265
|
+
const data = batch.flatMap(({ record }) => [record, {
|
|
352
266
|
app_version: record.app_version, app_minor_version: "", build_id: "",
|
|
353
267
|
process_type: record.process_type, session_id: "", timestamp: record.timestamp,
|
|
354
|
-
log_type: "flexible", event_name: "codem_runtime_diagnostic", category: record.category, metrics:
|
|
268
|
+
log_type: "flexible", event_name: "codem_runtime_diagnostic", category: record.category, metrics: { count: 1 }
|
|
355
269
|
}]);
|
|
356
270
|
try {
|
|
357
271
|
await Promise.race([Promise.resolve().then(() => this.#send({ header: first.header, data }, { signal: controller.signal })), deadline]);
|
|
@@ -359,7 +273,6 @@ export class RuntimeLogReporter {
|
|
|
359
273
|
if (entry.crashFile) { try { fs.unlinkSync(entry.crashFile); } catch { /* Replay may duplicate after a crash or concurrent startup. */ } }
|
|
360
274
|
}
|
|
361
275
|
} catch {
|
|
362
|
-
this.#uploadFailures += 1;
|
|
363
276
|
// One later retry, on the regular interval. Bound both memory and work;
|
|
364
277
|
// an unavailable collector must not create a retry loop or block exit.
|
|
365
278
|
for (const entry of batch) {
|
|
@@ -390,9 +303,6 @@ export class RuntimeLogReporter {
|
|
|
390
303
|
|
|
391
304
|
let active;
|
|
392
305
|
|
|
393
|
-
export function runtimeLogsEnabled() { return Boolean(active); }
|
|
394
|
-
export function runtimeLogIdentityKey() { return active?.identityKey; }
|
|
395
|
-
|
|
396
306
|
export function startRuntimeLogs({ role, version, env = process.env, send } = {}) {
|
|
397
307
|
try {
|
|
398
308
|
if (active || /^(1|true|yes)$/iu.test(env.CODEM_TELEMETRY_DISABLED ?? "") || env.NODE_TEST_CONTEXT) return;
|