omo-ai 5.1.45 → 5.1.47
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/bin/lib/child-process.js +37 -3
- package/bin/lib/doctor-reflection-lock.js +52 -0
- package/bin/lib/doctor.js +2 -2
- package/bin/lib/launcher.js +4 -9
- package/bin/lib/reflection-lock.generated.js +2 -0
- package/bin/lib/self-update.js +96 -13
- package/bin/lib/service-auth.generated.js +2 -2
- package/bin/lib/update-lock.js +113 -0
- package/package.json +1 -1
- package/plugin/CHANGELOG.md +82 -9
- package/plugin/extensions/dream-persona.md +1 -1
- package/plugin/extensions/facts-persona.md +2 -2
- package/plugin/extensions/gateway-store-worker.mjs +2 -2
- package/plugin/extensions/memory-run-supervisor.mjs +3 -3
- package/plugin/extensions/omo-claim-receipt.js +1 -1
- package/plugin/extensions/omo-computer-use.js +2 -2
- package/plugin/extensions/omo-device-account.js +2 -2
- package/plugin/extensions/omo-feedback.js +2 -2
- package/plugin/extensions/omo-init-deep-advisor.js +1 -1
- package/plugin/extensions/omo-member.js +2 -2
- package/plugin/extensions/omo-memory-commands.js +3 -3
- package/plugin/extensions/omo-memory-doctor.js +3 -3
- package/plugin/extensions/omo-memory-memfs.js +3 -3
- package/plugin/extensions/omo-memory-palace.js +3 -3
- package/plugin/extensions/omo-memory-sync.js +1 -1
- package/plugin/extensions/omo-onboarding-scan.js +3 -3
- package/plugin/extensions/omo-recall-store.js +1 -1
- package/plugin/extensions/omo-session-history.js +1 -1
- package/plugin/extensions/omo-side-panel.js +3 -3
- package/plugin/extensions/omo-task.js +2 -2
- package/plugin/extensions/omo-telemetry-posthog.js +1 -1
- package/plugin/extensions/omo-telemetry-recovery.js +2 -2
- package/plugin/extensions/omo-thread-client.js +2 -2
- package/plugin/extensions/omo.js +3 -3
- package/plugin/package.json +1 -2
- package/plugin/runtime/agent-toolkit-sdk/sdk.js +2 -2
- package/plugin/runtime/ast-grep-mcp/manifest.json +1 -1
- package/plugin/runtime/category-coverage/index.js +5 -5
- package/plugin/runtime/lsp-daemon/dist/.omo-runtime-manifest.json +4 -4
- package/plugin/runtime/lsp-daemon/dist/cli.js +3 -3
- package/plugin/runtime/lsp-daemon/dist/client.js +3 -3
- package/plugin/runtime/lsp-daemon/dist/index.js +3 -3
- package/plugin/runtime/rollback-migrate.js +2 -2
- package/plugin/runtime/task-config/index.js +2 -2
- package/plugin/runtime/thread-sdk/sdk.js +2 -2
- package/plugin/scripts/install.mjs +0 -1
- package/plugin/skills/ast-grep/AGENTS.md +1 -1
- package/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
- package/plugin/skills/frontend/ATTRIBUTION.md +2 -2
- package/plugin/skills/init-deep/SKILL.md +14 -2
- package/plugin/skills/ultimate-browsing/engine/AGENTS.md +1 -1
- package/plugin/skills/ulw-research/SKILL.md +38 -13
- package/plugin/skills/ulw-research/references/deliverable-phase.md +81 -14
- package/plugin/skills/ulw-research/references/fact-ledger-grammar.md +19 -1
- package/plugin/skills/ulw-research/references/fact-ledger.md +95 -0
- package/plugin/skills/ulw-research/references/fidelity-claim-kinds.md +19 -0
- package/plugin/skills/ulw-research/references/report-gates.md +21 -4
- package/plugin/skills/ulw-research/references/report-visualization.md +2 -0
- package/plugin/skills/ulw-research/references/unit-rules.md +157 -0
- package/plugin/skills/ulw-research/scripts/claim-kinds.mjs +116 -0
- package/plugin/skills/ulw-research/scripts/cli-support.mjs +19 -5
- package/plugin/skills/ulw-research/scripts/contracts.mjs +27 -6
- package/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +176 -0
- package/plugin/skills/ulw-research/scripts/fact-commands-polish.mjs +127 -0
- package/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +183 -0
- package/plugin/skills/ulw-research/scripts/fact-commands.mjs +241 -0
- package/plugin/skills/ulw-research/scripts/fact-derive.mjs +66 -0
- package/plugin/skills/ulw-research/scripts/fact-expr.mjs +108 -0
- package/plugin/skills/ulw-research/scripts/fact-fill.mjs +194 -0
- package/plugin/skills/ulw-research/scripts/fact-ledger-kinds.mjs +127 -13
- package/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +33 -16
- package/plugin/skills/ulw-research/scripts/fact-ledger.mjs +29 -9
- package/plugin/skills/ulw-research/scripts/fact-locate.mjs +231 -0
- package/plugin/skills/ulw-research/scripts/fact-pairs.mjs +185 -0
- package/plugin/skills/ulw-research/scripts/fact-recompute.mjs +89 -0
- package/plugin/skills/ulw-research/scripts/fidelity-binding.mjs +130 -0
- package/plugin/skills/ulw-research/scripts/fidelity-brief.mjs +5 -0
- package/plugin/skills/ulw-research/scripts/fidelity-claims.mjs +89 -0
- package/plugin/skills/ulw-research/scripts/fidelity-lexicon.mjs +145 -0
- package/plugin/skills/ulw-research/scripts/fidelity-records.mjs +163 -0
- package/plugin/skills/ulw-research/scripts/fidelity-state.mjs +2 -1
- package/plugin/skills/ulw-research/scripts/fidelity-trace.mjs +85 -0
- package/plugin/skills/ulw-research/scripts/fidelity-values.mjs +229 -0
- package/plugin/skills/ulw-research/scripts/gates-fidelity.mjs +113 -0
- package/plugin/skills/ulw-research/scripts/gates-static.mjs +28 -8
- package/plugin/skills/ulw-research/scripts/html-lite.mjs +2 -2
- package/plugin/skills/ulw-research/scripts/html-markup.mjs +182 -0
- package/plugin/skills/ulw-research/scripts/md-lite.mjs +193 -0
- package/plugin/skills/ulw-research/scripts/meaning-check.mjs +196 -0
- package/plugin/skills/ulw-research/scripts/outcome.mjs +6 -5
- package/plugin/skills/ulw-research/scripts/placeholder.mjs +184 -0
- package/plugin/skills/ulw-research/scripts/polish-apply.mjs +115 -0
- package/plugin/skills/ulw-research/scripts/polish-diff.mjs +31 -0
- package/plugin/skills/ulw-research/scripts/polish-project.mjs +125 -0
- package/plugin/skills/ulw-research/scripts/polish-rules.mjs +170 -0
- package/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +19 -8
- package/plugin/skills/ulw-research/scripts/report-tools.mjs +15 -0
- package/plugin/skills/ulw-research/scripts/source-commands.mjs +140 -0
- package/plugin/skills/ulw-research/scripts/source-snapshot.mjs +176 -0
- package/plugin/skills/ulw-research/scripts/unit-algebra.mjs +101 -0
- package/plugin/skills/ulw-research/scripts/unit-errors.mjs +23 -0
- package/plugin/skills/ulw-research/scripts/unit-metadata.mjs +31 -0
- package/plugin/skills/ulw-research/scripts/unit-pairs.mjs +72 -0
- package/plugin/skills/ulw-research/scripts/unit-precision.mjs +44 -0
- package/plugin/skills/ulw-research/scripts/unit-rules-shapes.mjs +64 -0
- package/plugin/skills/ulw-research/scripts/unit-rules.mjs +173 -0
- package/plugin/skills/ulw-research/scripts/units.mjs +4 -4
- package/bin/lib/dori.js +0 -187
- package/plugin/extensions/gateway-rules-extension.mjs +0 -2
- package/plugin/extensions/omo-dori-migration.js +0 -2
- package/plugin/runtime/dori/layer2.js +0 -2
- package/plugin/runtime/dori/replay.js +0 -2
package/bin/lib/child-process.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process"
|
|
2
|
+
import { StringDecoder } from "node:string_decoder"
|
|
2
3
|
|
|
3
4
|
// POSIX launchers prefer execve and leave no wrapper. This async fallback remains for Windows
|
|
4
5
|
// and missing/failed execve.
|
|
@@ -16,6 +17,9 @@ const HANDLED_SIGNALS = [
|
|
|
16
17
|
// stops waiting on a child that is not going to leave and reports the death it was asked for.
|
|
17
18
|
const DEFAULT_GRACE_MS = 10_000
|
|
18
19
|
|
|
20
|
+
const STDERR_TAIL_CHARS = 64 * 1024
|
|
21
|
+
const STDERR_DRAIN_MS = 500
|
|
22
|
+
|
|
19
23
|
function graceMs(env) {
|
|
20
24
|
const configured = Number(env.OMO_SIGNAL_GRACE_MS)
|
|
21
25
|
return Number.isFinite(configured) && configured > 0 ? configured : DEFAULT_GRACE_MS
|
|
@@ -43,13 +47,25 @@ export function propagateResult(result) {
|
|
|
43
47
|
* would terminate the child abruptly, so nothing is forwarded and the wait is the whole behavior.
|
|
44
48
|
*/
|
|
45
49
|
export function runChild(command, args, options = {}) {
|
|
46
|
-
const
|
|
50
|
+
const { captureStderr = false, ...spawnOptions } = options
|
|
51
|
+
const env = spawnOptions.env ?? process.env
|
|
47
52
|
return new Promise((resolve, reject) => {
|
|
48
53
|
const child = spawn(command, args, {
|
|
49
54
|
stdio: "inherit",
|
|
50
55
|
windowsHide: true,
|
|
51
|
-
...
|
|
56
|
+
...spawnOptions,
|
|
57
|
+
// A captured stderr is still shown live; the caller also gets its tail to classify the failure.
|
|
58
|
+
...(captureStderr ? { stdio: ["inherit", "inherit", "pipe"] } : {}),
|
|
52
59
|
})
|
|
60
|
+
let stderr = ""
|
|
61
|
+
if (captureStderr) {
|
|
62
|
+
// The decoder keeps a multi-byte character split across chunks whole; the echo stays raw bytes.
|
|
63
|
+
const decoder = new StringDecoder("utf8")
|
|
64
|
+
child.stderr.on("data", (chunk) => {
|
|
65
|
+
process.stderr.write(chunk)
|
|
66
|
+
stderr = (stderr + decoder.write(chunk)).slice(-STDERR_TAIL_CHARS)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
53
69
|
|
|
54
70
|
let settled = false
|
|
55
71
|
let graceTimer
|
|
@@ -98,7 +114,25 @@ export function runChild(command, args, options = {}) {
|
|
|
98
114
|
child.on("error", (error) => settle(() => reject(error)))
|
|
99
115
|
// A child that died of the forwarded signal needs no special case: `propagateResult` turns a
|
|
100
116
|
// signaled result into this process dying by the same signal, which is exactly right.
|
|
101
|
-
|
|
117
|
+
const finish = (status, signal) => settle(() => resolve(captureStderr ? { status, signal, stderr } : { status, signal }))
|
|
118
|
+
child.on("exit", (status, signal) => {
|
|
119
|
+
if (!captureStderr || child.stderr.readableEnded) {
|
|
120
|
+
finish(status, signal)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
// The pipe usually ends right after exit. A grandchild that inherited it can hold it open, so the
|
|
124
|
+
// drain is bounded and the result never waits on a process the manager left behind.
|
|
125
|
+
const drained = () => {
|
|
126
|
+
clearTimeout(drainTimer)
|
|
127
|
+
finish(status, signal)
|
|
128
|
+
}
|
|
129
|
+
const drainTimer = setTimeout(() => {
|
|
130
|
+
child.stderr.off("end", drained)
|
|
131
|
+
child.stderr.destroy()
|
|
132
|
+
finish(status, signal)
|
|
133
|
+
}, STDERR_DRAIN_MS)
|
|
134
|
+
child.stderr.once("end", drained)
|
|
135
|
+
})
|
|
102
136
|
})
|
|
103
137
|
}
|
|
104
138
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// omo doctor: a reflection lock held by a run that cannot finish (#10377). The decision is the one the
|
|
2
|
+
// session uses (memory-core reflection/stale-holder.ts), run from its generated bundle, so the two
|
|
3
|
+
// surfaces cannot disagree. A dead holder and a stuck one are both reported with the next step;
|
|
4
|
+
// a live holder or no lock prints nothing.
|
|
5
|
+
|
|
6
|
+
import { existsSync, readdirSync } from "node:fs"
|
|
7
|
+
import { homedir } from "node:os"
|
|
8
|
+
import { basename, join, resolve } from "node:path"
|
|
9
|
+
import { classifyReflectionLockHolder } from "./reflection-lock.generated.js"
|
|
10
|
+
|
|
11
|
+
const MEMORY_ROOT_ENV_VAR = "OMO_MEMORY_HOME"
|
|
12
|
+
|
|
13
|
+
function memoryRoot(env) {
|
|
14
|
+
const override = env[MEMORY_ROOT_ENV_VAR]
|
|
15
|
+
if (override === undefined || override.trim() === "") return join(homedir(), ".omo", "memory")
|
|
16
|
+
return resolve(process.cwd(), override)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function classifyReflectionLock(reflectionDir, probe = {}) {
|
|
20
|
+
return classifyReflectionLockHolder(reflectionDir, probe)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function formatReflectionLockLines(identity, verdict, reflectionDir) {
|
|
24
|
+
if (verdict.state === "none" || verdict.state === "live") return []
|
|
25
|
+
const lock = join(reflectionDir, "active.lock")
|
|
26
|
+
if (verdict.state === "dead") {
|
|
27
|
+
return [`WARN memory reflection is stuck on a stale lock (${identity}): run ${verdict.runId} still holds ${lock}, but its launcher is gone and it already recorded its outcome. Next step: open a session and send /reflect (or any message); the session settles that run and starts any queued request.`]
|
|
28
|
+
}
|
|
29
|
+
return [`WARN memory reflection is stuck on a stale lock (${identity}): run ${verdict.runId} still holds ${lock} and ${verdict.reason}. Next step: run /doctor in a session; if no reflection run is active, move ${lock} aside (keep a backup) and start a new session.`]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function listDurableIdentities(agentsRoot) {
|
|
33
|
+
try {
|
|
34
|
+
return readdirSync(agentsRoot, { withFileTypes: true })
|
|
35
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith("."))
|
|
36
|
+
.map((entry) => join(agentsRoot, entry.name))
|
|
37
|
+
.filter((identityRoot) => existsSync(join(identityRoot, "repo")))
|
|
38
|
+
} catch {
|
|
39
|
+
return []
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function reflectionLockReport(options = {}) {
|
|
44
|
+
const agentsRoot = join(memoryRoot(options.env ?? process.env), "agents")
|
|
45
|
+
const lines = []
|
|
46
|
+
for (const identityRoot of options.listIdentities?.(agentsRoot) ?? listDurableIdentities(agentsRoot)) {
|
|
47
|
+
const reflectionDir = join(identityRoot, "runtime", "reflection")
|
|
48
|
+
const verdict = await classifyReflectionLock(reflectionDir, options.reflectionLockProbe ?? {})
|
|
49
|
+
lines.push(...formatReflectionLockLines(basename(identityRoot), verdict, reflectionDir))
|
|
50
|
+
}
|
|
51
|
+
return lines
|
|
52
|
+
}
|
package/bin/lib/doctor.js
CHANGED
|
@@ -423,12 +423,12 @@ export function runDoctor(inventory, args = [], options = {}) {
|
|
|
423
423
|
lines.push(...staleEngineReport(options))
|
|
424
424
|
lines.push(...retiredPayloadReport(options))
|
|
425
425
|
lines.push(...transientMemoryReport(options))
|
|
426
|
+
lines.push(...(options.reflectionLock ?? []))
|
|
426
427
|
const launchSpec = launchSpecDoctorLines(options.pluginRoot ?? join(packageRoot, "plugin"), options.launchSpecIo)
|
|
427
428
|
if (launchSpec.some((line) => line.startsWith("FAIL "))) failed = true
|
|
428
429
|
lines.push(...launchSpec)
|
|
429
|
-
lines.push(...daemonReport(options), ...(options.computerUse ?? []), ...(options.categoryCoverage ?? [])
|
|
430
|
+
lines.push(...daemonReport(options), ...(options.computerUse ?? []), ...(options.categoryCoverage ?? []))
|
|
430
431
|
if ((options.computerUse ?? []).some((line) => line.startsWith("FAIL "))) failed = true
|
|
431
|
-
if ((options.dori ?? []).some((line) => line.startsWith("FAIL "))) failed = true
|
|
432
432
|
if (needsSetupSuggestion(inventory)) {
|
|
433
433
|
lines.push("INFO no credentials found; run omo setup to review sibling stores")
|
|
434
434
|
}
|
package/bin/lib/launcher.js
CHANGED
|
@@ -11,6 +11,7 @@ import { runDaemonCommand } from "./daemon.js"
|
|
|
11
11
|
import { runThreadCommand } from "./thread.js"
|
|
12
12
|
import { isHostStatusAll, runHostStatusAll, sessionActivityReader } from "./host-status.js"
|
|
13
13
|
import { runDoctor } from "./doctor.js"
|
|
14
|
+
import { reflectionLockReport } from "./doctor-reflection-lock.js"
|
|
14
15
|
import { ensureEnginePrepared, preparePluginLaunchSpec } from "./engine-prepare.js"
|
|
15
16
|
import { migrateLegacyBunGlobalManifest } from "./legacy-bun-global-migration.js"
|
|
16
17
|
import { removeLegacyServiceCredentials } from "./legacy-service-credentials.js"
|
|
@@ -184,29 +185,23 @@ export async function runLauncher(args = process.argv.slice(2)) {
|
|
|
184
185
|
process.exitCode = await runDoctorModels(args.slice(2), { agentDir: canonicalAgentDir() })
|
|
185
186
|
return
|
|
186
187
|
}
|
|
187
|
-
const [categoryCoverage, computerUse, configDiagnostics,
|
|
188
|
+
const [categoryCoverage, computerUse, configDiagnostics, reflectionLock] = args[1] === "--reap"
|
|
188
189
|
? [[], [], [], []]
|
|
189
190
|
: await Promise.all([
|
|
190
191
|
doctorCoverageLines({ agentDir: canonicalAgentDir() }),
|
|
191
192
|
doctorComputerUseLines(),
|
|
192
193
|
doctorConfigLines(),
|
|
193
|
-
|
|
194
|
+
reflectionLockReport(),
|
|
194
195
|
])
|
|
195
196
|
runDoctor(await detectHarnesses(), args.slice(1), {
|
|
196
197
|
daemonEngine: { run: engineHostCall },
|
|
197
198
|
categoryCoverage,
|
|
198
199
|
computerUse,
|
|
199
200
|
configDiagnostics,
|
|
200
|
-
|
|
201
|
+
reflectionLock,
|
|
201
202
|
})
|
|
202
203
|
return
|
|
203
204
|
}
|
|
204
|
-
if (command === "dori" || command === "gateway") {
|
|
205
|
-
if (command === "gateway") process.stderr.write("omo gateway is deprecated; use omo dori instead\n")
|
|
206
|
-
const { runDoriCommand } = await import("./dori.js")
|
|
207
|
-
process.exitCode = await runDoriCommand(args.slice(1))
|
|
208
|
-
return
|
|
209
|
-
}
|
|
210
205
|
if (command === "setup") {
|
|
211
206
|
printSetupReport(await detectHarnesses())
|
|
212
207
|
process.exitCode = 0
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Generated by bun script/build-reflection-lock.ts; do not edit.
|
|
2
|
+
import{hostname as readHostname}from"node:os";import{join}from"node:path";import*as fsSync from"node:fs";import*as fsp from"node:fs/promises";function fsErrorCode(error){if(!(error instanceof Error)||!("code"in error))return;return typeof error.code==="string"?error.code:void 0}async function retryOnEintr(operation){for(let attempt=0;;attempt+=1)try{return await operation()}catch(error){if(fsErrorCode(error)!=="EINTR"||attempt>=128)throw error}}function retryOnEintrSync(operation){for(let attempt=0;;attempt+=1)try{return operation()}catch(error){if(fsErrorCode(error)!=="EINTR"||attempt>=128)throw error}}function isFunction(value){return typeof value==="function"}function withAsyncRetry(operation){return(...args)=>retryOnEintr(async()=>operation(...args))}function withSyncRetry(operation){return(...args)=>retryOnEintrSync(()=>operation(...args))}function resilientNamespace(namespace,kind){let wrapFunction=kind==="async"?withAsyncRetry:withSyncRetry,cache=new Map;return new Proxy(namespace,{get(target,property){if(cache.has(property))return cache.get(property);let value=Reflect.get(target,property);if(!isFunction(value))return value;let wrapped=wrapFunction(value),native=Reflect.get(value,"native");if(isFunction(native))Object.assign(wrapped,{native:wrapFunction(native)});return cache.set(property,wrapped),wrapped}})}var promises=resilientNamespace(fsp,"async");var sync=resilientNamespace(fsSync,"sync"),{access,chmod,copyFile,cp,link,lstat,mkdir,mkdtemp,readFile,readdir,readlink,realpath,rm,rmdir,stat,statfs,unlink}=promises,{accessSync,chmodSync,fsyncSync,linkSync,lstatSync,mkdirSync,readFileSync,readdirSync,realpathSync,statSync:statSync2,unlinkSync,writeFileSync,writeSync}=sync;import{execFile}from"node:child_process";var procPidInfoLookup=null;async function openProcPidInfo(){if(process.platform!=="darwin")return null;try{let{dlopen,FFIType}=await import("bun:ffi"),library=dlopen("/usr/lib/libSystem.B.dylib",{proc_pidinfo:{args:[FFIType.i32,FFIType.i32,FFIType.u64,FFIType.ptr,FFIType.i32],returns:FFIType.i32}});return(pid,flavor,arg,buffer,size)=>Number(library.symbols.proc_pidinfo(pid,flavor,arg,buffer,size))}catch{return null}}function loadProcPidInfo(){return procPidInfoLookup??=openProcPidInfo(),procPidInfoLookup}async function readDarwinProcessStartSeconds(pid){if(process.platform!=="darwin")return null;if(!Number.isSafeInteger(pid)||pid<=0)return null;let procPidInfo=await loadProcPidInfo();if(procPidInfo===null)return null;let buffer=new Uint8Array(136),written=0;try{written=procPidInfo(pid,3,0n,buffer,136)}catch{return null}if(written!==136)return null;let view=new DataView(buffer.buffer,buffer.byteOffset,buffer.byteLength),startSeconds=Number(view.getBigUint64(120,!0));return startSeconds>0?startSeconds:null}var PROCESS_QUERY_LIMITED_INFORMATION=4096,kernel32Lookup=null;async function openKernel32(){if(process.platform!=="win32")return null;try{let{dlopen,FFIType}=await import("bun:ffi");return dlopen("kernel32.dll",{OpenProcess:{args:[FFIType.u32,FFIType.i32,FFIType.u32],returns:FFIType.ptr},GetProcessTimes:{args:[FFIType.ptr,FFIType.ptr,FFIType.ptr,FFIType.ptr,FFIType.ptr],returns:FFIType.i32},CloseHandle:{args:[FFIType.ptr],returns:FFIType.i32}}).symbols}catch{return null}}async function readWin32ProcessCreationFiletime(pid){if(process.platform!=="win32")return null;if(!Number.isSafeInteger(pid)||pid<=0)return null;kernel32Lookup??=openKernel32();let kernel32=await kernel32Lookup;if(kernel32===null)return null;let handle=kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,0,pid);if(handle===null||handle===0||handle===0n)return null;try{let creation=new BigUint64Array(1),ok=kernel32.GetProcessTimes(handle,creation,new BigUint64Array(1),new BigUint64Array(1),new BigUint64Array(1)),filetime=creation[0]??0n;return ok===0||filetime===0n?null:filetime}finally{kernel32.CloseHandle(handle)}}function errorCode(error){if(!(error instanceof Error)||!("code"in error))return;return typeof error.code==="string"?error.code:void 0}async function execFileText(command,args){return await new Promise((resolve)=>{execFile(command,args,{encoding:"utf8",timeout:2000,windowsHide:!0},(error,stdout)=>{if(error!==null){resolve(null);return}let value=stdout.trim();resolve(value.length>0?value:null)})})}async function readLinuxStartIdentity(pid){try{let stat=await readFile(`/proc/${pid}/stat`,"utf8"),commandEnd=stat.lastIndexOf(")");if(commandEnd<0)return null;let startTicks=stat.slice(commandEnd+2).trim().split(/\s+/)[19];return startTicks===void 0?null:`linux-proc-start-ticks:${startTicks}`}catch{return null}}async function readWin32StartIdentity(pid){if(getPidLiveness(pid)==="dead")return null;let creationFiletime=await readWin32ProcessCreationFiletime(pid);if(creationFiletime!==null)return`win32-creation-filetime:${creationFiletime}`;let value=await execFileText("powershell.exe",["-NoProfile","-Command",`(Get-Process -Id ${pid} -ErrorAction SilentlyContinue).StartTime.ToUniversalTime().ToString('o')`]);return value===null?null:`win32-creation-date:${value}`}function createProcessStartIdentityReader(read,ownPid){let ownIdentity;return(pid)=>{if(pid!==ownPid)return read(pid);return ownIdentity??=read(pid).then((identity)=>{if(identity===null)ownIdentity=void 0;return identity},(error)=>{throw ownIdentity=void 0,error}),ownIdentity}}var getProcessStartIdentity=createProcessStartIdentityReader(readProcessStartIdentity,process.pid);async function readProcessStartIdentity(pid){if(process.platform==="linux")return await readLinuxStartIdentity(pid);if(process.platform==="darwin"||process.platform==="freebsd"){if(getPidLiveness(pid)==="dead")return null;let startSeconds=await readDarwinProcessStartSeconds(pid);if(startSeconds!==null)return`proc-start-epoch:${startSeconds}`;let value=await execFileText("/bin/ps",["-o","lstart=","-p",String(pid)]);return value===null?null:`ps-lstart:${value.replace(/\s+/g," ")}`}if(process.platform==="win32")return await readWin32StartIdentity(pid);return null}function identityScheme(identity){let separator=identity.indexOf(":");return separator<=0?null:identity.slice(0,separator)}function startIdentitiesComparable(recorded,actual){return identityScheme(recorded)===identityScheme(actual)}function getPidLiveness(pid){try{return process.kill(pid,0),"alive"}catch(error){let code=errorCode(error);if(code==="ESRCH")return"dead";if(code==="EPERM")return"alive";return"unknown"}}function errorCode2(error){return error instanceof Error&&"code"in error&&typeof error.code==="string"?error.code:"unknown error"}async function readJson(path,readText){let text;try{text=await readText(path)}catch(error){let code=errorCode2(error);return code==="ENOENT"?{kind:"missing"}:{kind:"unreadable",code}}try{return{kind:"ok",value:JSON.parse(text)}}catch{return{kind:"invalid"}}}function fieldsOf(value){return typeof value==="object"&&value!==null?value:{}}function isRunOutcome(value,runId){let fields=fieldsOf(value),childExit=fieldsOf(fields.childExit);return fields.version===1&&fields.runId===runId&&typeof fields.finishedAt==="string"&&(fields.attempt===void 0||typeof fields.attempt==="number"&&Number.isInteger(fields.attempt)&&fields.attempt>0)&&typeof fields.childExit==="object"&&fields.childExit!==null&&(childExit.code===null||typeof childExit.code==="number")&&(childExit.signal===null||typeof childExit.signal==="string")&&typeof fields.timedOut==="boolean"}function stuck(runId,reason){return{state:"stuck",runId,reason}}async function launcherLiveness(pid,recordedStart,probe){let liveness=(probe.getPidLiveness??getPidLiveness)(pid);if(liveness!=="alive"||typeof recordedStart!=="string")return liveness;let actualStart=await(probe.getProcessStartIdentity??getProcessStartIdentity)(pid).catch(()=>null);if(actualStart!==null&&startIdentitiesComparable(recordedStart,actualStart)&&recordedStart!==actualStart)return"dead";return"alive"}async function classifyReflectionLockHolder(reflectionDir,probe={}){let readText=probe.readText??((path)=>readFile(path,"utf8")),active=await readJson(join(reflectionDir,"active.lock"),readText);if(active.kind==="missing")return{state:"none"};if(active.kind==="unreadable")return stuck("unknown",`active.lock could not be read (${active.code})`);if(active.kind==="invalid")return stuck("unknown","active.lock is not valid JSON");let fields=fieldsOf(active.value),runId=typeof fields.runId==="string"?fields.runId:"unknown",launcherPid=typeof fields.launcherPid==="number"?fields.launcherPid:void 0,launcherHostname=typeof fields.launcherHostname==="string"?fields.launcherHostname:void 0;if(launcherPid===void 0||launcherHostname===void 0)return stuck(runId,"its launcher identity is missing");if(launcherHostname!==(probe.hostname??readHostname)())return stuck(runId,`it is owned by host ${launcherHostname}, which cannot be checked from here`);let launcher=await launcherLiveness(launcherPid,fields.launcherProcessStart,probe);if(launcher==="alive")return{state:"live",runId};if(launcher==="unknown")return stuck(runId,`launcher pid ${launcherPid} could not be checked`);let runDir=join(reflectionDir,"runs",runId),outcome=await readJson(join(runDir,"outcome.json"),readText);if(outcome.kind==="missing")return stuck(runId,`launcher pid ${launcherPid} is gone and the run recorded no outcome`);if(outcome.kind==="unreadable")return stuck(runId,`its outcome could not be read (${outcome.code})`);if(outcome.kind==="invalid")return stuck(runId,"its outcome is not valid JSON");if(!isRunOutcome(outcome.value,runId))return stuck(runId,"its outcome is not a recorded run outcome");let claim=await readJson(join(runDir,"terminal-claim.json"),readText);if(claim.kind==="unreadable")return stuck(runId,`its terminal claim could not be read (${claim.code})`);if(claim.kind==="invalid")return stuck(runId,"its terminal claim is not valid JSON");if(claim.kind==="ok"){let claimantPid=fieldsOf(claim.value).claimantPid;if(typeof claimantPid!=="number")return stuck(runId,"its terminal claim names no claimant");let claimant=(probe.getPidLiveness??getPidLiveness)(claimantPid);if(claimant==="alive")return{state:"live",runId};if(claimant==="unknown")return stuck(runId,`publish claimant pid ${claimantPid} could not be checked`)}return{state:"dead",runId}}export{classifyReflectionLockHolder};
|
package/bin/lib/self-update.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { join } from "node:path"
|
|
1
|
+
import { dirname, join } from "node:path"
|
|
2
2
|
import { runChild } from "./child-process.js"
|
|
3
3
|
import { fetchNpmDistTagsSync } from "./npm-dist-tags.js"
|
|
4
|
-
import { channelDistTagVersion, channelPackageSpec, packageManifest, readJson, releaseChannel, resolveSenpi, updateTarget } from "./package-paths.js"
|
|
4
|
+
import { channelDistTagVersion, channelPackageSpec, packageManifest, packageRoot, readJson, releaseChannel, resolveSenpi, updateTarget } from "./package-paths.js"
|
|
5
5
|
import { isPrintOnlyUpdate, updateUsageAnswer } from "./update-args.js"
|
|
6
|
+
import { findHolders, heldTarget, isLockFailure, listWindowsProcesses, LOCK_RETRY_DELAYS_MS } from "./update-lock.js"
|
|
6
7
|
|
|
7
8
|
export { isPrintOnlyUpdate }
|
|
8
9
|
|
|
@@ -34,9 +35,14 @@ export function formatVersionChange(before, after) {
|
|
|
34
35
|
* prove the install moved (#9198). An unreachable registry falls back to the unpinned channel spec.
|
|
35
36
|
* `run` defaults to `runChild` so tests inject a spawn without touching the child-process helper.
|
|
36
37
|
*
|
|
38
|
+
* On Windows a manager failure whose stderr says a file is held (EPERM/EBUSY, #10090) is retried with
|
|
39
|
+
* backoff. If the file stays held, the report names the file, the processes of this install that hold it
|
|
40
|
+
* and one action, and only an install that can no longer be read is reinstalled at the previous version; any readable version is kept.
|
|
41
|
+
*
|
|
37
42
|
* @typedef {{ omo: string, engine: string }} InstalledVersion
|
|
38
|
-
* @typedef {{ status: number | null, signal: string | null }} ChildResult
|
|
39
|
-
* @typedef {{ stdio?: "inherit", windowsHide?: boolean, env?: NodeJS.ProcessEnv }} RunOptions
|
|
43
|
+
* @typedef {{ status: number | null, signal: string | null, stderr?: string }} ChildResult
|
|
44
|
+
* @typedef {{ stdio?: "inherit", windowsHide?: boolean, env?: NodeJS.ProcessEnv, captureStderr?: boolean }} RunOptions
|
|
45
|
+
* @typedef {import("./update-lock.js").ProcessEntry} ProcessEntry
|
|
40
46
|
* @typedef {{ manager: string, command: string, argv: string[], env?: Record<string, string> }} UpdateTarget
|
|
41
47
|
* @typedef {{
|
|
42
48
|
* resolveUpdate?: (targetVersion?: string) => UpdateTarget,
|
|
@@ -46,6 +52,11 @@ export function formatVersionChange(before, after) {
|
|
|
46
52
|
* run?: (command: string, args: string[], options?: RunOptions) => Promise<ChildResult>,
|
|
47
53
|
* readInstalled?: () => InstalledVersion,
|
|
48
54
|
* env?: NodeJS.ProcessEnv,
|
|
55
|
+
* platform?: NodeJS.Platform,
|
|
56
|
+
* sleep?: (ms: number) => Promise<void>,
|
|
57
|
+
* listProcesses?: () => ProcessEntry[],
|
|
58
|
+
* installDir?: string,
|
|
59
|
+
* selfPids?: number[],
|
|
49
60
|
* }} SelfUpdateOptions
|
|
50
61
|
* @param {string[]} args
|
|
51
62
|
* @param {SelfUpdateOptions} [options]
|
|
@@ -60,6 +71,8 @@ export async function runSelfUpdate(args, options = {}) {
|
|
|
60
71
|
const run = options.run ?? runChild
|
|
61
72
|
const readInstalled = options.readInstalled ?? readInstalledVersion
|
|
62
73
|
const env = options.env ?? process.env
|
|
74
|
+
const platform = options.platform ?? process.platform
|
|
75
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)))
|
|
63
76
|
|
|
64
77
|
const usage = updateUsageAnswer(args)
|
|
65
78
|
if (usage !== undefined) {
|
|
@@ -85,20 +98,37 @@ export async function runSelfUpdate(args, options = {}) {
|
|
|
85
98
|
}
|
|
86
99
|
log(formatUpdateCommand(update))
|
|
87
100
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
result = await run(command, argv, {
|
|
101
|
+
const install = async (target) => {
|
|
102
|
+
const [command, ...argv] = target.argv
|
|
103
|
+
return run(command, argv, {
|
|
92
104
|
stdio: "inherit",
|
|
93
105
|
windowsHide: true,
|
|
94
|
-
env: { ...env, ...
|
|
106
|
+
env: { ...env, ...target.env },
|
|
107
|
+
captureStderr: platform === "win32",
|
|
95
108
|
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
}
|
|
110
|
+
const failed = (result) => Boolean(result.signal) || (result.status ?? 1) !== 0
|
|
111
|
+
const heldOnWindows = (result) => platform === "win32" && !result.signal && isLockFailure(result.stderr)
|
|
112
|
+
|
|
113
|
+
let result
|
|
114
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
115
|
+
try {
|
|
116
|
+
result = await install(update)
|
|
117
|
+
} catch {
|
|
118
|
+
error(`omo: update failed; retry with: ${update.command}`)
|
|
119
|
+
return 1
|
|
120
|
+
}
|
|
121
|
+
if (!failed(result) || !heldOnWindows(result) || attempt >= LOCK_RETRY_DELAYS_MS.length) break
|
|
122
|
+
const delay = LOCK_RETRY_DELAYS_MS[attempt]
|
|
123
|
+
log(`omo: ${heldTarget(result.stderr) ?? "a package file"} is held by another process; retrying in ${delay / 1000}s (attempt ${attempt + 2} of ${LOCK_RETRY_DELAYS_MS.length + 1})`)
|
|
124
|
+
await sleep(delay)
|
|
99
125
|
}
|
|
100
126
|
|
|
101
|
-
if (result
|
|
127
|
+
if (failed(result) && heldOnWindows(result)) {
|
|
128
|
+
await reportHeldInstall({ result, before, install, resolveUpdate, readInstalled, error, options, attempts: LOCK_RETRY_DELAYS_MS.length + 1 })
|
|
129
|
+
return 1
|
|
130
|
+
}
|
|
131
|
+
if (failed(result)) {
|
|
102
132
|
error(`omo: update failed; retry with: ${update.command}`)
|
|
103
133
|
return result.status ?? 1
|
|
104
134
|
}
|
|
@@ -112,3 +142,56 @@ export async function runSelfUpdate(args, options = {}) {
|
|
|
112
142
|
log(formatVersionChange(before, after))
|
|
113
143
|
return 0
|
|
114
144
|
}
|
|
145
|
+
|
|
146
|
+
function readInstalledOrUndefined(readInstalled) {
|
|
147
|
+
try {
|
|
148
|
+
return readInstalled()
|
|
149
|
+
} catch {
|
|
150
|
+
return undefined
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function reportHeldInstall({ result, before, install, resolveUpdate, readInstalled, error, options, attempts }) {
|
|
155
|
+
const held = heldTarget(result.stderr)
|
|
156
|
+
const file = held ?? "a package file"
|
|
157
|
+
const listProcesses = options.listProcesses ?? listWindowsProcesses
|
|
158
|
+
const installDir = options.installDir ?? dirname(packageRoot)
|
|
159
|
+
const selfPids = options.selfPids ?? [process.pid, process.ppid]
|
|
160
|
+
const holders = findHolders(installDir, listProcesses(), selfPids, held)
|
|
161
|
+
|
|
162
|
+
error(`omo: update stopped: Windows would not let the package manager replace ${file}; it was still held after ${attempts} attempts.`)
|
|
163
|
+
if (holders.length > 0) {
|
|
164
|
+
error(`omo: held by ${holders.map((holder) => `${holder.name} (pid ${holder.pid})`).join(", ")}`)
|
|
165
|
+
const names = [...new Set(holders.map((holder) => holder.name))].join(", ")
|
|
166
|
+
error(`omo: Quit ${names} and run omo update again.`)
|
|
167
|
+
} else {
|
|
168
|
+
error("omo: No omo command-line process was found holding it. Another app (for example the OmO desktop app or an editor) or antivirus may be holding it: close it, or wait a minute, then run omo update again.")
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const now = readInstalledOrUndefined(readInstalled)
|
|
172
|
+
if (now?.omo === before.omo) {
|
|
173
|
+
error(`omo: omo ${before.omo} is still installed.`)
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
// Any readable omo is a working install, even when the pinned target is unknown (registry down): the
|
|
177
|
+
// manager can fail moving an old dependency after the new omo-ai is in place, and reinstalling over it
|
|
178
|
+
// would undo a working update and hit the same held file. Only an unreadable install is restored.
|
|
179
|
+
if (now !== undefined) {
|
|
180
|
+
error(`omo: omo ${now.omo} is installed, but the package manager did not finish; run omo update again afterwards to complete it.`)
|
|
181
|
+
return
|
|
182
|
+
}
|
|
183
|
+
const previous = resolveUpdate(before.omo)
|
|
184
|
+
let restored
|
|
185
|
+
try {
|
|
186
|
+
restored = await install(previous)
|
|
187
|
+
} catch {
|
|
188
|
+
restored = { status: 1, signal: null }
|
|
189
|
+
}
|
|
190
|
+
const after = readInstalledOrUndefined(readInstalled)
|
|
191
|
+
if ((restored.status ?? 1) === 0 && !restored.signal && after?.omo === before.omo) {
|
|
192
|
+
error(`omo: restored omo ${before.omo}.`)
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
const when = holders.length > 0 ? "after quitting the holder" : "once the file is released"
|
|
196
|
+
error(`omo: the previous omo ${before.omo} could not be restored; ${when}, run: ${previous.command}`)
|
|
197
|
+
}
|