omo-ai 5.1.44 → 5.1.46
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/bun-bin-shim.js +53 -72
- 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 -8
- package/bin/lib/provider-map.json +1 -1
- package/bin/lib/reflection-lock.generated.js +2 -0
- package/bin/lib/self-update.js +96 -13
- package/bin/lib/service-auth.generated.js +4 -4
- package/bin/lib/update-lock.js +113 -0
- package/bin/omo.js +3 -4
- package/bin/senpi-patch.mjs +3 -4
- package/package.json +2 -2
- package/plugin/CHANGELOG.md +186 -9
- package/plugin/extensions/dream-persona.md +2 -2
- 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 +2 -2
- package/plugin/extensions/omo-computer-use.js +2 -2
- package/plugin/extensions/omo-device-account.js +2 -0
- package/plugin/extensions/omo-feedback.js +2 -2
- package/plugin/extensions/omo-init-deep-advisor.js +2 -2
- package/plugin/extensions/omo-member.js +2 -2
- package/plugin/extensions/omo-memory-commands.js +11 -0
- 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 +2 -2
- 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 +2 -2
- package/plugin/extensions/omo-side-panel.js +3 -3
- package/plugin/extensions/omo-task.js +2 -2
- package/plugin/extensions/omo-telemetry-posthog.js +2 -2
- package/plugin/extensions/omo-telemetry-recovery.js +2 -0
- package/plugin/extensions/omo-thread-client.js +2 -2
- package/plugin/extensions/omo.js +3 -3
- package/plugin/extensions/reflection-persona.md +1 -1
- package/plugin/package.json +8 -2
- package/plugin/runtime/agent-toolkit-sdk/sdk.js +2 -2
- package/plugin/runtime/ast-grep-mcp/cli.js +6 -6
- package/plugin/runtime/ast-grep-mcp/manifest.json +2 -2
- package/plugin/runtime/category-coverage/index.js +40 -76
- package/plugin/runtime/lsp-daemon/dist/.omo-runtime-manifest.json +4 -4
- package/plugin/runtime/lsp-daemon/dist/cli.js +7 -7
- package/plugin/runtime/lsp-daemon/dist/client.js +7 -7
- package/plugin/runtime/lsp-daemon/dist/index.js +7 -7
- 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 +4 -2
- package/plugin/skills/ast-grep/AGENTS.md +1 -1
- package/plugin/skills/browser/SKILL.md +21 -22
- package/plugin/skills/browser/references/commands.md +2 -9
- package/plugin/skills/browser/references/install.md +1 -2
- package/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
- package/plugin/skills/browser/scripts/browser-doctor.mjs +2 -2
- package/plugin/skills/browser/scripts/browser-engine-guard.mjs +63 -487
- package/plugin/skills/browser/scripts/browser-install.mjs +1 -1
- package/plugin/skills/browser/scripts/omowright.mjs +1 -10
- package/plugin/skills/frontend/ATTRIBUTION.md +2 -2
- package/plugin/skills/frontend/SKILL.md +79 -118
- package/plugin/skills/frontend/references/design/README.md +75 -221
- package/plugin/skills/frontend/references/design/stylegallery.md +32 -27
- package/plugin/skills/frontend/references/perfection/README.md +2 -2
- package/plugin/skills/frontend/scripts/perfection/check-accent-stripes.ts +8 -24
- package/plugin/skills/frontend/scripts/perfection/check-draft-guard.ts +40 -0
- package/plugin/skills/frontend/scripts/perfection/collect-files.ts +53 -0
- package/plugin/skills/frontend/scripts/perfection/draft-guard/findings.ts +16 -0
- package/plugin/skills/frontend/scripts/perfection/draft-guard/lint.ts +38 -0
- package/plugin/skills/frontend/scripts/perfection/draft-guard/rules.ts +69 -0
- package/plugin/skills/frontend/scripts/perfection/draft-guard/text-nodes.ts +121 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/attr-lookalikes.tsx +10 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/bound-values.tsx +12 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/const-generics.tsx +3 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/generics.tsx +7 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/measured-stats.html +6 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/plain-copy.html +9 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/negative/state-copy.html +11 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/attribute-edges.html +7 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/components.tsx +16 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/decorative-badge.vue +7 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/emoji-icons.tsx +9 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/jsx-edges.tsx +1 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/promo-copy.html +6 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/promo-copy.tsx +8 -0
- package/plugin/skills/frontend/scripts/perfection/fixtures/draft-guard/positive/vanity-stats.html +5 -0
- package/plugin/skills/init-deep/SKILL.md +14 -2
- package/plugin/skills/programming/SKILL.md +10 -7
- package/plugin/skills/programming/references/typescript/README.md +10 -7
- package/plugin/skills/programming/references/typescript/bootstrap.md +9 -23
- package/plugin/skills/programming/references/typescript/oxc-lint.md +130 -0
- package/plugin/skills/programming/references/typescript/tsconfig-strict.md +6 -62
- package/plugin/skills/programming/scripts/typescript/check-no-excuse-rules.ts +12 -12
- package/plugin/skills/programming/scripts/typescript/new-project.ts +20 -81
- package/plugin/skills/programming/scripts/typescript/oxc/.oxfmtrc.json +9 -0
- package/plugin/skills/programming/scripts/typescript/oxc/.oxlintrc.json +46 -0
- package/plugin/skills/programming/scripts/typescript/oxc/lint/oxlint-plugin/LICENSE +21 -0
- package/plugin/skills/programming/scripts/typescript/oxc/lint/oxlint-plugin/index.js +10 -0
- package/plugin/skills/programming/scripts/typescript/oxc/lint/oxlint-plugin/no-em-dash-copy.js +28 -0
- package/plugin/skills/programming/scripts/typescript/oxc/lint/oxlint-plugin/require-suppression-reason.js +62 -0
- package/plugin/skills/programming/scripts/typescript/oxc/tsconfig.json +29 -0
- package/plugin/skills/refactor/SKILL.md +13 -13
- package/plugin/skills/ultimate-browsing/engine/AGENTS.md +1 -1
- package/plugin/skills/ulw-execute/SKILL.md +1 -1
- package/plugin/skills/ulw-research/SKILL.md +38 -13
- package/plugin/skills/ulw-research/references/deliverable-phase.md +77 -16
- package/plugin/skills/ulw-research/references/fact-ledger-grammar.md +134 -0
- 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 +68 -3
- 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/claims-index.mjs +125 -0
- package/plugin/skills/ulw-research/scripts/cli-support.mjs +19 -5
- package/plugin/skills/ulw-research/scripts/contracts.mjs +89 -3
- package/plugin/skills/ulw-research/scripts/fact-commands-meaning.mjs +191 -0
- package/plugin/skills/ulw-research/scripts/fact-commands-verify.mjs +164 -0
- package/plugin/skills/ulw-research/scripts/fact-commands.mjs +239 -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 +250 -0
- package/plugin/skills/ulw-research/scripts/fact-ledger-schema.mjs +221 -0
- package/plugin/skills/ulw-research/scripts/fact-ledger.mjs +123 -0
- package/plugin/skills/ulw-research/scripts/fact-locate.mjs +231 -0
- package/plugin/skills/ulw-research/scripts/fact-pairs.mjs +187 -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 +150 -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 +64 -0
- 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 +29 -9
- package/plugin/skills/ulw-research/scripts/gates-structure.mjs +1 -1
- package/plugin/skills/ulw-research/scripts/gates-text.mjs +1 -27
- 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/lexicon.mjs +47 -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/numerals.mjs +226 -0
- package/plugin/skills/ulw-research/scripts/outcome.mjs +8 -8
- package/plugin/skills/ulw-research/scripts/particles-ko.mjs +108 -0
- 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/rational.mjs +139 -0
- package/plugin/skills/ulw-research/scripts/report-tools-commands.mjs +21 -10
- package/plugin/skills/ulw-research/scripts/report-tools.mjs +15 -0
- package/plugin/skills/ulw-research/scripts/sentence-split.mjs +77 -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/text-normalize.mjs +82 -0
- package/plugin/skills/ulw-research/scripts/text-similarity.mjs +28 -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 +105 -0
- package/plugin/skills/visual-qa/SKILL.md +70 -63
- package/plugin/skills/visualize/SKILL.md +1 -1
- package/plugin/telemetry-schema.json +3857 -0
- package/plugin/telemetry-schema.omo-cloud.json +3850 -0
- package/bin/lib/gateway.js +0 -166
- package/plugin/extensions/gateway-rules-extension.mjs +0 -2
package/bin/lib/bun-bin-shim.js
CHANGED
|
@@ -1,53 +1,38 @@
|
|
|
1
|
-
import { chmodSync, lstatSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs"
|
|
1
|
+
import { chmodSync, lstatSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs"
|
|
2
2
|
import { homedir as osHomedir } from "node:os"
|
|
3
|
-
import { join } from "node:path"
|
|
3
|
+
import { dirname, join, relative } from "node:path"
|
|
4
4
|
import { bunRoot, findBunBinary, isUnderBunGlobalTree } from "./bun-runtime.js"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
const
|
|
6
|
+
const NODE_SHEBANG = "#!/usr/bin/env node\n"
|
|
7
|
+
// sh executes the second line; JS sees a string expression followed by a comment. No install
|
|
8
|
+
// paths are interpolated into code, so spaces, quotes and newlines in BUN_INSTALL stay data.
|
|
9
|
+
const BUN_PRELUDE = [
|
|
10
|
+
"#!/bin/sh",
|
|
11
|
+
`':' //; if [ "$OMO_RUNTIME" != node ]; then for b in "\${BUN_INSTALL:-$HOME/.bun}/bin/bun" "$HOME/.bun/bin/bun"; do if [ -x "$b" ]; then exec "$b" "$0" "$@"; fi; done; if command -v bun >/dev/null 2>&1; then exec bun "$0" "$@"; fi; fi; exec node "$0" "$@"`,
|
|
12
|
+
"",
|
|
13
|
+
].join("\n")
|
|
10
14
|
|
|
11
|
-
// The two bins a POSIX bun-global install exposes for the same launcher. `bun add -g` links the
|
|
12
|
-
// package bin into BOTH, and a bun layout that puts the global node_modules/.bin on PATH first
|
|
13
|
-
// makes the second one the entry a typed `omo` actually reaches - so repairing only the first
|
|
14
|
-
// leaves those machines paying for a node boot on every launch. Each entry is judged on its own.
|
|
15
15
|
const BIN_ENTRIES = [
|
|
16
16
|
{ label: "bin", segments: ["bin", "omo"] },
|
|
17
17
|
{ label: "node-modules-bin", segments: ["install", "global", "node_modules", ".bin", "omo"] },
|
|
18
18
|
]
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return [
|
|
34
|
-
"#!/bin/sh",
|
|
35
|
-
`# ${SHIM_MARKER} v${SHIM_VERSION} - generated by omo-ai; safe to delete, the next launch recreates it`,
|
|
36
|
-
`# entry: ${entryPath}`,
|
|
37
|
-
`if [ "$OMO_RUNTIME" != "node" ] && [ -x ${quoteForShell(bunPath)} ]; then exec ${quoteForShell(bunPath)} ${quoteForShell(entryPath)} "$@"; fi`,
|
|
38
|
-
`exec ${quoteForShell(entryPath)} "$@"`,
|
|
39
|
-
"",
|
|
40
|
-
].join("\n")
|
|
20
|
+
/** Prepare only the package-owned file. Bun's bin symlinks must never become regular files. */
|
|
21
|
+
function prepareEntrypoint(io) {
|
|
22
|
+
const source = io.readFile(io.scriptPath, "utf8")
|
|
23
|
+
if (source.startsWith(BUN_PRELUDE)) return
|
|
24
|
+
if (!source.startsWith(NODE_SHEBANG)) throw new Error("unrecognized omo entrypoint")
|
|
25
|
+
const temporary = `${io.scriptPath}.${io.pid}.tmp`
|
|
26
|
+
try {
|
|
27
|
+
io.write(temporary, BUN_PRELUDE + source.slice(NODE_SHEBANG.length), { mode: 0o755 })
|
|
28
|
+
io.chmod(temporary, 0o755)
|
|
29
|
+
io.rename(temporary, io.scriptPath)
|
|
30
|
+
} finally {
|
|
31
|
+
io.remove(temporary, { force: true })
|
|
32
|
+
}
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
* Brings ONE bin entry to the shim, or explains why it was left as it was. Only bun's own link to
|
|
45
|
-
* THIS install, or a file already carrying the marker, is ever replaced; anything else - a link
|
|
46
|
-
* into another install, a hand-written file, a directory, a socket - is not ours to touch.
|
|
47
|
-
* Returns the labelled action; the caller owns the try/catch, so a broken entry cannot take the
|
|
48
|
-
* other one down with it.
|
|
49
|
-
*/
|
|
50
|
-
function applyShim(binPath, script, io) {
|
|
35
|
+
function restoreLegacyBin(binPath, io) {
|
|
51
36
|
let stats
|
|
52
37
|
try {
|
|
53
38
|
stats = io.lstat(binPath)
|
|
@@ -55,47 +40,36 @@ function applyShim(binPath, script, io) {
|
|
|
55
40
|
return "absent-bin"
|
|
56
41
|
}
|
|
57
42
|
if (stats.isSymbolicLink()) {
|
|
58
|
-
|
|
59
|
-
} else if (stats.isFile()) {
|
|
60
|
-
const current = io.readFile(binPath, "utf8")
|
|
61
|
-
if (current === script) return "current"
|
|
62
|
-
if (!current.includes(SHIM_MARKER)) return "foreign-file"
|
|
63
|
-
} else {
|
|
64
|
-
return "foreign-entry"
|
|
43
|
+
return io.realpath(binPath) === io.scriptPath ? "current" : "foreign-link"
|
|
65
44
|
}
|
|
66
|
-
|
|
45
|
+
if (!stats.isFile()) return "foreign-entry"
|
|
46
|
+
const source = io.readFile(binPath, "utf8")
|
|
47
|
+
const legacy = /^#!\/bin\/sh\n# omo-ai bun launcher shim v\d+[^\n]*\n/.exec(source)
|
|
48
|
+
if (!legacy || !source.slice(legacy[0].length).startsWith(`# entry: ${io.scriptPath}\n`)) return "foreign-file"
|
|
67
49
|
const temporary = `${binPath}.${io.pid}.tmp`
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
try {
|
|
51
|
+
io.symlink(relative(io.realpath(dirname(binPath)), io.scriptPath), temporary)
|
|
52
|
+
io.rename(temporary, binPath)
|
|
53
|
+
} finally {
|
|
54
|
+
io.remove(temporary, { force: true })
|
|
55
|
+
}
|
|
72
56
|
return "repaired"
|
|
73
57
|
}
|
|
74
58
|
|
|
75
|
-
function repairBinEntry(entry, root,
|
|
59
|
+
function repairBinEntry(entry, root, io) {
|
|
76
60
|
const path = join(root, ...entry.segments)
|
|
77
61
|
try {
|
|
78
|
-
return { label: entry.label, path, action:
|
|
62
|
+
return { label: entry.label, path, action: restoreLegacyBin(path, io), error: undefined }
|
|
79
63
|
} catch (error) {
|
|
80
|
-
if (io.env.OMO_DEBUG) io.warn(`omo: bun launcher
|
|
64
|
+
if (io.env.OMO_DEBUG) io.warn(`omo: bun launcher migration left untouched at ${path}: ${error.message}`)
|
|
81
65
|
return { label: entry.label, path, action: "failed", error: error.message }
|
|
82
66
|
}
|
|
83
67
|
}
|
|
84
68
|
|
|
85
69
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* launch: every failure path - foreign file, missing bin, unwritable bin dir - returns quietly,
|
|
90
|
-
* one entry's failure never stops the other from being repaired, and only OMO_DEBUG narrates.
|
|
91
|
-
* It runs under bun as well as node: `bun add -g` links the bin back to the node-shebang entrypoint
|
|
92
|
-
* and then runs omo-ai's postinstall (`bin/senpi-patch.mjs`) under bun whenever node is not on
|
|
93
|
-
* PATH, and that postinstall is the only code that runs before the next `omo`. A node-only repair
|
|
94
|
-
* left a bun-only machine (a launchd job, cron, node only through nvm) with an `omo` that cannot
|
|
95
|
-
* start until something boots it under node (#9293).
|
|
96
|
-
*
|
|
97
|
-
* The answer is per entry (`entries`), with the primary `<bunRoot>/bin/omo` entry's action and
|
|
98
|
-
* error mirrored at the top level for callers that only ever cared about that one.
|
|
70
|
+
* Trusted postinstall prepares Bun-only startup (#9293); launches also repair older installs.
|
|
71
|
+
* Prepare the entrypoint before replacing old marked wrappers, so a failed preparation leaves
|
|
72
|
+
* their working Bun launch path intact. Windows/npm retain their shipped Node entrypoint.
|
|
99
73
|
*/
|
|
100
74
|
export function ensureBunBinShim(input) {
|
|
101
75
|
const env = input.env ?? process.env
|
|
@@ -110,6 +84,8 @@ export function ensureBunBinShim(input) {
|
|
|
110
84
|
write: input.write ?? writeFileSync,
|
|
111
85
|
rename: input.rename ?? renameSync,
|
|
112
86
|
chmod: input.chmod ?? chmodSync,
|
|
87
|
+
symlink: input.symlink ?? symlinkSync,
|
|
88
|
+
remove: input.remove ?? rmSync,
|
|
113
89
|
pid: input.pid ?? process.pid,
|
|
114
90
|
warn: input.warn ?? ((message) => console.error(message)),
|
|
115
91
|
}
|
|
@@ -118,12 +94,17 @@ export function ensureBunBinShim(input) {
|
|
|
118
94
|
if (!isUnderBunGlobalTree(input.scriptPath, { env, homedir, platform, realpath: io.realpath })) {
|
|
119
95
|
return { action: "skipped-install", error: undefined, entries: [] }
|
|
120
96
|
}
|
|
121
|
-
|
|
122
|
-
|
|
97
|
+
if (!findBunBinary({ env, homedir, platform, exists: input.exists, realpath: io.realpath })) {
|
|
98
|
+
return { action: "skipped-no-bun", error: undefined, entries: [] }
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
prepareEntrypoint(io)
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (env.OMO_DEBUG) io.warn(`omo: bun entrypoint left untouched at ${io.scriptPath}: ${error.message}`)
|
|
104
|
+
return { action: "failed", error: error.message, entries: [] }
|
|
105
|
+
}
|
|
123
106
|
|
|
124
|
-
const
|
|
125
|
-
const script = bunBinShimScript(input.scriptPath, bunPath)
|
|
126
|
-
const entries = BIN_ENTRIES.map((entry) => repairBinEntry(entry, root, script, io))
|
|
107
|
+
const entries = BIN_ENTRIES.map((entry) => repairBinEntry(entry, bunRoot(env, homedir, platform), io))
|
|
127
108
|
const primary = entries[0]
|
|
128
109
|
return { action: primary.action, error: primary.error, entries }
|
|
129
110
|
}
|
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.gateway ?? []).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,28 +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 === "gateway") {
|
|
205
|
-
const { runGatewayCommand } = await import("./gateway.js")
|
|
206
|
-
process.exitCode = await runGatewayCommand(args.slice(1))
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
205
|
if (command === "setup") {
|
|
210
206
|
printSetupReport(await detectHarnesses())
|
|
211
207
|
process.exitCode = 0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_comment": "Derived from @code-yeongyu/senpi 2026.10.
|
|
2
|
+
"_comment": "Derived from @code-yeongyu/senpi 2026.10.23-1 builtinProviders(). builtinProviderIds and oauthProviderIds are the engine registry verbatim; providers maps a source harness id onto the omo provider that serves the same endpoint; oauthLogins maps a source OAuth id onto the omo provider to run /login for. Re-derive all four whenever the senpi pin changes.",
|
|
3
3
|
"builtinProviderIds": [
|
|
4
4
|
"alibaba-token-plan",
|
|
5
5
|
"amazon-bedrock",
|
|
@@ -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
|
+
}
|