oh-my-agent-web 0.3.0 → 0.5.0
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/README.md +108 -450
- package/dist/server/approval/read-only.js +107 -0
- package/dist/server/approval/rules.js +85 -0
- package/dist/server/approval/scope.js +150 -0
- package/dist/server/brand.js +2 -0
- package/dist/server/cli-config.js +52 -0
- package/dist/server/cli-info.js +101 -0
- package/dist/server/cli.js +304 -0
- package/dist/server/engine/builtin.js +84 -0
- package/dist/server/engine/catalog.js +8 -0
- package/dist/server/engine/codex-approvals.js +45 -0
- package/dist/server/engine/codex-map.js +298 -0
- package/dist/server/engine/codex-sessions.js +159 -0
- package/dist/server/engine/codex-transport.js +49 -0
- package/dist/server/engine/codex.js +314 -0
- package/dist/server/engine/dsh-history.js +195 -0
- package/dist/server/engine/dsh-log.js +245 -0
- package/dist/server/engine/dsh-map.js +221 -0
- package/dist/server/engine/dsh-sessions.js +207 -0
- package/dist/server/engine/dsh-transport.js +37 -0
- package/dist/server/engine/dsh.js +284 -0
- package/dist/server/engine/fake.js +231 -0
- package/dist/server/engine/jsonrpc-stdio.js +241 -0
- package/dist/server/engine/model-registry-reload.js +115 -0
- package/dist/server/engine/narrate-guidance.js +22 -0
- package/dist/server/engine/opencode-map.js +499 -0
- package/dist/server/engine/opencode-projects.js +61 -0
- package/dist/server/engine/opencode-sessions.js +195 -0
- package/dist/server/engine/opencode-transport.js +48 -0
- package/dist/server/engine/opencode.js +394 -0
- package/dist/server/engine/pi-events.js +148 -0
- package/dist/server/engine/pi-plugins.js +310 -0
- package/dist/server/engine/pi-rename.js +14 -0
- package/dist/server/engine/pi-sdk.js +503 -0
- package/dist/server/engine/pi-session-model.js +23 -0
- package/dist/server/engine/pi-subagent-tool.js +166 -0
- package/dist/server/engine/pi-subagents.js +372 -0
- package/dist/server/engine/pi-thinking.js +34 -0
- package/dist/server/engine/pi-transcript.js +225 -0
- package/dist/server/engine/pi-version.js +11 -0
- package/dist/server/engine/port.js +1 -0
- package/dist/server/engine/registry.js +47 -0
- package/dist/server/engine/scratch.js +13 -0
- package/dist/server/engine/subagent-guidance.js +22 -0
- package/dist/server/engine/suggestion-guidance.js +9 -0
- package/dist/server/engine/switchable.js +22 -0
- package/dist/server/engine/wiring.js +166 -0
- package/dist/server/files/dir-routes.js +40 -0
- package/dist/server/files/file-search.js +63 -0
- package/dist/server/files/file-service.js +232 -0
- package/dist/server/files/files-routes.js +210 -0
- package/dist/server/files/git-info.js +361 -0
- package/dist/server/http/auth-routes.js +99 -0
- package/dist/server/http/auth.js +191 -0
- package/dist/server/http/aux-routes.js +40 -0
- package/dist/server/http/compress.js +77 -0
- package/dist/server/http/health-and-static.js +33 -0
- package/dist/server/http/live-routes.js +113 -0
- package/dist/server/http/login-page.js +200 -0
- package/dist/server/index.js +363 -520
- package/dist/server/markers/actions.js +262 -0
- package/dist/server/mcp/mcp-auth.js +184 -0
- package/dist/server/mcp/mcp-command.js +94 -0
- package/dist/server/mcp/mcp-import.js +290 -0
- package/dist/server/mcp/mcp-market-sources.js +192 -0
- package/dist/server/mcp/mcp-market-types.js +5 -0
- package/dist/server/mcp/mcp-market.js +175 -0
- package/dist/server/mcp/mcp-probe.js +134 -0
- package/dist/server/mcp/mcp-routes.js +70 -0
- package/dist/server/mcp/mcp-store.js +286 -0
- package/dist/server/mcp/pi-mcp-config.js +280 -0
- package/dist/server/plugins/plugin-routes.js +21 -0
- package/dist/server/protocol-parse.js +262 -0
- package/dist/server/protocol-settings.js +1 -0
- package/dist/server/protocol.js +6 -0
- package/dist/server/providers/catalog-store.js +85 -0
- package/dist/server/providers/catalog-writes.js +197 -0
- package/dist/server/providers/catalog.js +77 -0
- package/dist/server/providers/codex-models.js +96 -0
- package/dist/server/providers/codex-test.js +124 -0
- package/dist/server/providers/enabled-models.js +118 -0
- package/dist/server/providers/import-models.js +69 -0
- package/dist/server/providers/import-routes.js +203 -0
- package/dist/server/providers/model-test.js +52 -0
- package/dist/server/providers/probe.js +64 -0
- package/dist/server/providers/provider-handlers.js +223 -0
- package/dist/server/providers/provider-store.js +359 -0
- package/dist/server/providers/request-headers.js +7 -0
- package/dist/server/providers/subscription-routes.js +181 -0
- package/dist/server/providers/validate.js +241 -0
- package/dist/server/push/push-routes.js +114 -0
- package/dist/server/push/push.js +120 -0
- package/dist/server/session/approval-bridge.js +103 -0
- package/dist/server/session/attachment-resolve.js +21 -0
- package/dist/server/session/client-view.js +82 -0
- package/dist/server/session/conversation-create.js +65 -0
- package/dist/server/session/delete-session.js +84 -0
- package/dist/server/session/engine-switch.js +108 -0
- package/dist/server/session/lock.js +82 -0
- package/dist/server/session/model-controller.js +119 -0
- package/dist/server/session/notices.js +31 -0
- package/dist/server/session/pi-opener.js +123 -0
- package/dist/server/session/pi-refresh.js +51 -0
- package/dist/server/session/pi-sessions-provider.js +46 -0
- package/dist/server/session/pi-sessions.js +272 -0
- package/dist/server/session/refresh-actions.js +42 -0
- package/dist/server/session/rename-session.js +23 -0
- package/dist/server/session/runtime-services.js +28 -0
- package/dist/server/session/runtime-types.js +1 -0
- package/dist/server/session/runtime.js +380 -0
- package/dist/server/session/session-stats.js +91 -0
- package/dist/server/session/settings.js +367 -0
- package/dist/server/session/snapshot-for.js +7 -0
- package/dist/server/session/stats-refresher.js +50 -0
- package/dist/server/session/subagents.js +116 -0
- package/dist/server/session/switch-conversation.js +86 -0
- package/dist/server/session/throttle.js +14 -0
- package/dist/server/session/turn-events.js +126 -0
- package/dist/server/session/turn-finish.js +79 -0
- package/dist/server/session/turn-markers.js +26 -0
- package/dist/server/session/turn-queue.js +111 -0
- package/dist/server/session/turn-send.js +108 -0
- package/dist/server/session/turn-watchdog.js +77 -0
- package/dist/server/sessions/session-routes.js +17 -0
- package/dist/server/skills/skill-install.js +186 -0
- package/dist/server/skills/skill-routes.js +134 -0
- package/dist/server/skills/skill-store.js +163 -0
- package/dist/server/skills/skillhub.js +214 -0
- package/dist/server/skills/zip.js +121 -0
- package/dist/server/snapshot/fan-out.js +10 -0
- package/dist/server/snapshot/messages.js +75 -0
- package/dist/server/snapshot/sender.js +62 -0
- package/dist/server/snapshot/state.js +202 -0
- package/dist/server/subagents/profile-store.js +287 -0
- package/dist/server/terminal/terminal-routes.js +176 -0
- package/dist/server/terminal/terminal-session.js +140 -0
- package/dist/server/uploads/upload-routes.js +64 -0
- package/dist/server/uploads/upload-store.js +115 -0
- package/dist/server/util/data-dir.js +36 -0
- package/dist/server/util/env.js +146 -0
- package/dist/server/util/ids.js +28 -0
- package/dist/server/util/log-file.js +67 -0
- package/dist/server/util/log.js +52 -0
- package/dist/server/util/origin.js +75 -0
- package/dist/server/util/paths.js +60 -0
- package/dist/server/util/pricing-index.js +121 -0
- package/dist/server/util/pricing.js +214 -0
- package/dist/server/util/startup.js +34 -0
- package/dist/server/util/upstream-version.js +140 -0
- package/dist/server/util/usage.js +19 -0
- package/dist/server/util/version.js +50 -0
- package/dist/server/ws/handle-message.js +107 -0
- package/package.json +50 -63
- package/web/dist/apple-touch-icon-precomposed.png +0 -0
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/abnfDiagram-WEYOIA3C-VUKLHHSn.js +1 -0
- package/web/dist/assets/arc-BeUkaHhk.js +1 -0
- package/web/dist/assets/architecture-WOLXFQ4H-B9I4s0NV.js +1 -0
- package/web/dist/assets/architectureDiagram-ZHVYKT53-CaEkLhfq.js +36 -0
- package/web/dist/assets/array-BifhSqXX.js +1 -0
- package/web/dist/assets/blockDiagram-RJAE7QA3-IR49UNE_.js +140 -0
- package/web/dist/assets/c4Diagram-XDPPPE54-B-81CloB.js +38 -0
- package/web/dist/assets/channel-B_mTTjGt.js +1 -0
- package/web/dist/assets/chunk-2E7WHVMD-CaWVF7qv.js +88 -0
- package/web/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/web/dist/assets/chunk-4EMNKR2T-BvXf2tq-.js +1 -0
- package/web/dist/assets/chunk-55XCU76K-Bz_d2e2D.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/web/dist/assets/chunk-7S6XSTFO-B_SPMiU8.js +2 -0
- package/web/dist/assets/chunk-AQDTSKZB-Cen-_xej.js +72 -0
- package/web/dist/assets/chunk-DSNLSHJZ-DEw1kFwj.js +129 -0
- package/web/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/web/dist/assets/chunk-HAGFOTED-BwpOOcw8.js +62 -0
- package/web/dist/assets/chunk-HNE4Q36P-BjCwi2uW.js +1 -0
- package/web/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/web/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/web/dist/assets/chunk-NGNAAXSQ-C2Wy9Xmz.js +136 -0
- package/web/dist/assets/chunk-NQOKRVIF-WcqhWFS5.js +213 -0
- package/web/dist/assets/chunk-UHW7PFBP-quDvQby8.js +1 -0
- package/web/dist/assets/chunk-VQ5W62QI-DZBwmhzq.js +1 -0
- package/web/dist/assets/chunk-WQQL4CDK-wYyHYuui.js +10 -0
- package/web/dist/assets/chunk-XXDRQBXY-DfJzC7nt.js +1 -0
- package/web/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/web/dist/assets/chunk-YZO67HFG-CWLraGk_.js +1 -0
- package/web/dist/assets/chunk-ZAUX2LTX-ChBUt_FJ.js +1 -0
- package/web/dist/assets/chunk-ZCHMQSOR-C57UFT60.js +2 -0
- package/web/dist/assets/classDiagram-v2-4MYWR3UA-Bo4i7SNY.js +217 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-CK360NdH.js +1 -0
- package/web/dist/assets/cynefin-EF2NZ3EQ-DlXFjIFm.js +1 -0
- package/web/dist/assets/cynefinDiagram-WF24UDRP-zvZIqA1c.js +62 -0
- package/web/dist/assets/cytoscape.esm-BegBNzOV.js +321 -0
- package/web/dist/assets/dagre-NK4GIZVX-CnKhCu-v.js +4 -0
- package/web/dist/assets/defaultLocale-BFoDCU3G.js +1 -0
- package/web/dist/assets/diagram-CBK3MWTC-3QTR8Fjx.js +24 -0
- package/web/dist/assets/diagram-I5XIIV2D-D9lSd7z6.js +24 -0
- package/web/dist/assets/diagram-ODIL2UCW-DWJD6lPM.js +30 -0
- package/web/dist/assets/diagram-PFBEJUXE-CWJmoUg4.js +3 -0
- package/web/dist/assets/diagram-RJA3I4VV-D1SZHQcQ.js +41 -0
- package/web/dist/assets/diagram-TYUNFSNR-DCCjGi1x.js +200 -0
- package/web/dist/assets/dist-VOk_Iv17.js +1 -0
- package/web/dist/assets/ebnfDiagram-V4P3TTPT-CQLdqEiW.js +1 -0
- package/web/dist/assets/elk-QONTBCTQ-Dp2pEp6b.js +27 -0
- package/web/dist/assets/erDiagram-KYQIGQAA-BFGNoFQ-.js +99 -0
- package/web/dist/assets/eventmodeling-K75KTNOO-CFfAemGw.js +1 -0
- package/web/dist/assets/flowDiagram-IUGLLWBU-DmSp3cbW.js +1 -0
- package/web/dist/assets/ganttDiagram-R7GPNTJY-vK3jPGDq.js +292 -0
- package/web/dist/assets/gitGraph-VSP46ZUC-rXBgHTdq.js +1 -0
- package/web/dist/assets/gitGraphDiagram-PDYL7XHY-CBbGhago.js +106 -0
- package/web/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/web/dist/assets/index-DBOF_OJe.js +104 -0
- package/web/dist/assets/index-nlY_-OaR.css +1 -0
- package/web/dist/assets/info-OHQRW6UA-Cd9vp-6C.js +1 -0
- package/web/dist/assets/infoDiagram-MVDRKAX5-Ce-Sg_qu.js +2 -0
- package/web/dist/assets/init-C-OQMol4.js +1 -0
- package/web/dist/assets/ishikawaDiagram-HPEHV2GE-DWlmR6BY.js +70 -0
- package/web/dist/assets/journeyDiagram-BOSHW7O7-DmDG97ae.js +139 -0
- package/web/dist/assets/kanban-definition-FNSA4HC5-1Z4sDrgV.js +89 -0
- package/web/dist/assets/katex-B_JcIwqj.js +257 -0
- package/web/dist/assets/line-DGM1-9KW.js +1 -0
- package/web/dist/assets/linear-B6hyeGHu.js +1 -0
- package/web/dist/assets/mermaid-parser.core-D1HmdkA4.js +7 -0
- package/web/dist/assets/mermaid.core-DeUJrhO1.js +44 -0
- package/web/dist/assets/mindmap-definition-6OY57UG3-C3-FByy8.js +98 -0
- package/web/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/web/dist/assets/packet-JDAUHWVQ-BoOr7DaW.js +1 -0
- package/web/dist/assets/path-fybaL0A-.js +1 -0
- package/web/dist/assets/pegDiagram-ECIUJNBX-Bn7m75TZ.js +1 -0
- package/web/dist/assets/pie-XZMESJXO-CGuMTDBp.js +1 -0
- package/web/dist/assets/pieDiagram-GNMPY74T-DHhaPwZe.js +39 -0
- package/web/dist/assets/quadrantDiagram-D57K4MC3-DxTgFHLK.js +7 -0
- package/web/dist/assets/radar-ABXABTNO-BiKxmALL.js +1 -0
- package/web/dist/assets/railroad-I3PHUGI6-BKYufgg4.js +1 -0
- package/web/dist/assets/railroad-abnf-LNEFI6M7-DmOrjlyL.js +1 -0
- package/web/dist/assets/railroad-ebnf-DWYD2UWJ-BgMyVDd1.js +1 -0
- package/web/dist/assets/railroad-peg-JR7BVNR7-BN6NL8S-.js +1 -0
- package/web/dist/assets/railroadDiagram-Y72NRBL7-BsbA-9gP.js +1 -0
- package/web/dist/assets/requirementDiagram-EQYSW5RA-HUw4YqWd.js +84 -0
- package/web/dist/assets/rough.esm-Dy-Kn_BL.js +1 -0
- package/web/dist/assets/sankeyDiagram-SY24JHO5-Dx1MOFRu.js +40 -0
- package/web/dist/assets/sequenceDiagram-BLEHNHQU-C0-Rzg3g.js +169 -0
- package/web/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/web/dist/assets/src-CuHygcpj.js +1 -0
- package/web/dist/assets/stateDiagram-v2-A6IESKWZ-BnEICGtg.js +291 -0
- package/web/dist/assets/swimlanes-B3ENRKFQ-CwDRCHZD.js +1 -0
- package/web/dist/assets/swimlanesDiagram-AYQRV4AK-DZ_aAXmG.js +8 -0
- package/web/dist/assets/timeline-definition-JXYKGLGB-C4BVpgzc.js +120 -0
- package/web/dist/assets/treeView-D4JQ5SDB-BBsvEMP3.js +1 -0
- package/web/dist/assets/treemap-SAJKECNS-BYw6cxC8.js +1 -0
- package/web/dist/assets/usecaseDiagram-WPOLBNNX-BkOXLgwP.js +328 -0
- package/web/dist/assets/vennDiagram-Q3Y3IDCW-Kgjk_n6B.js +34 -0
- package/web/dist/assets/wardley-7MLQ67FV-BGVObhvJ.js +1 -0
- package/web/dist/assets/wardleyDiagram-IVAIDKWA-i97uD6tL.js +78 -0
- package/web/dist/assets/xychartDiagram-4URNHDU4-awJi5TfJ.js +7 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +20 -8
- package/web/dist/icons/apple-touch-icon-180.png +0 -0
- package/web/dist/icons/icon-192.png +0 -0
- package/web/dist/icons/icon-512.png +0 -0
- package/web/dist/icons/icon-maskable-512.png +0 -0
- package/web/dist/index.html +31 -24
- package/web/dist/manifest.webmanifest +17 -0
- package/web/dist/maskable.svg +25 -0
- package/web/dist/sw.js +40 -0
- package/bin/oh-my-agent-web-ps.mjs +0 -203
- package/bin/oh-my-agent-web-ws.mjs +0 -782
- package/bin/oh-my-agent-web.mjs +0 -321
- package/bin/update-check.mjs +0 -142
- package/dist/server/codex-client.js +0 -310
- package/dist/server/codex-supervisor.js +0 -446
- package/dist/server/fs-service.js +0 -144
- package/dist/server/request-inspector.js +0 -458
- package/dist/shared/protocol.js +0 -112
- package/scripts/manage-server.mjs +0 -155
- package/scripts/omaw.mjs +0 -74
- package/shared/protocol.ts +0 -228
- package/web/dist/assets/index-5LJ5fRcO.js +0 -42
- package/web/dist/assets/index-QiDfPKFo.css +0 -1
- package/web/dist/assets/markdown-CYXe6JZx.js +0 -55
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* oh-my-agent-web ps — 列出正在运行的 oh-my-agent-web / codex app-server 进程及其监听端口。
|
|
4
|
-
*
|
|
5
|
-
* oh-my-agent-web ps # 表格
|
|
6
|
-
* oh-my-agent-web ps --json # 机器可读
|
|
7
|
-
*
|
|
8
|
-
* 仅用 Node 内置能力(必要时调用 lsof / ps),无第三方依赖。
|
|
9
|
-
*/
|
|
10
|
-
import { execFileSync } from "node:child_process";
|
|
11
|
-
|
|
12
|
-
const DEFAULT_UI_PORT = 25257;
|
|
13
|
-
const DEFAULT_CODEX_PORT = 25258;
|
|
14
|
-
|
|
15
|
-
const HELP = `oh-my-agent-web ps — show running oh-my-agent-web / app-server processes and their ports
|
|
16
|
-
|
|
17
|
-
Usage:
|
|
18
|
-
oh-my-agent-web ps [--json] [--help]
|
|
19
|
-
|
|
20
|
-
Options:
|
|
21
|
-
--json Print machine-readable JSON
|
|
22
|
-
-h, --help Show this help
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
function sh(cmd, args) {
|
|
26
|
-
try {
|
|
27
|
-
return execFileSync(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
28
|
-
} catch {
|
|
29
|
-
return "";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** All processes as { pid, ppid, command }. */
|
|
34
|
-
function listProcesses() {
|
|
35
|
-
const out = sh("ps", ["-eo", "pid=,ppid=,command="]);
|
|
36
|
-
const rows = [];
|
|
37
|
-
for (const line of out.split("\n")) {
|
|
38
|
-
const m = line.match(/^\s*(\d+)\s+(\d+)\s+(.*)$/);
|
|
39
|
-
if (!m) continue;
|
|
40
|
-
rows.push({ pid: Number(m[1]), ppid: Number(m[2]), command: m[3].trim() });
|
|
41
|
-
}
|
|
42
|
-
return rows;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The CLI answers to a long name and a short alias, and which one shows up in
|
|
47
|
-
* `ps` depends on how it was invoked: the npm bin symlink puts the alias in the
|
|
48
|
-
* process command line (`.../bin/omaw`), while a direct `node bin/…mjs` puts the
|
|
49
|
-
* file name there instead. Both must classify the same, or `omaw ps` would fail
|
|
50
|
-
* to see its own server and mislabel its managed app-server as "external".
|
|
51
|
-
*/
|
|
52
|
-
const CLI_NAMES = ["oh-my-agent-web", "omaw"];
|
|
53
|
-
const CLI = CLI_NAMES.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
54
|
-
|
|
55
|
-
/** Classify a command line: "oh-my-agent-web" | "app-server" | "ws-client" | null. */
|
|
56
|
-
function classify(command) {
|
|
57
|
-
// skip our own `... ps` invocation lines
|
|
58
|
-
if (new RegExp(`\\b(?:${CLI})(?:\\.mjs)?\\s+(?:ps|status|ports)\\b`).test(command)) return null;
|
|
59
|
-
// the ws client is a short-lived client, not a server
|
|
60
|
-
if (new RegExp(`\\b(?:${CLI})(?:\\.mjs)?\\s+ws\\b`).test(command)) return "ws-client";
|
|
61
|
-
if (new RegExp(`\\b(?:${CLI})(?:\\.mjs)?\\b`).test(command)) return "oh-my-agent-web";
|
|
62
|
-
if (/\bapp-server\b/.test(command) && /\bcodex\b/.test(command)) return "app-server";
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** TCP ports this pid is LISTENing on (via lsof), best-effort. */
|
|
67
|
-
function listenPorts(pid) {
|
|
68
|
-
const out = sh("lsof", ["-nP", "-a", "-p", String(pid), "-iTCP", "-sTCP:LISTEN"]);
|
|
69
|
-
const ports = new Set();
|
|
70
|
-
for (const line of out.split("\n").slice(1)) {
|
|
71
|
-
const m = line.match(/:(\d+)\s+\(LISTEN\)/);
|
|
72
|
-
if (m) ports.add(Number(m[1]));
|
|
73
|
-
}
|
|
74
|
-
return ports;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Ports guessed from the command line (fallback when lsof is unavailable).
|
|
78
|
-
* Only app-servers declare a listen port; the ws client's `--port` is a remote
|
|
79
|
-
* target, so it must NOT be reported as a local listening port. */
|
|
80
|
-
function portsFromCmd(command, kind) {
|
|
81
|
-
const ports = new Set();
|
|
82
|
-
if (kind !== "app-server") return ports;
|
|
83
|
-
const listen = command.match(/--listen[= ]+ws:\/\/[^:\s]+:(\d+)/);
|
|
84
|
-
if (listen) ports.add(Number(listen[1]));
|
|
85
|
-
return ports;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function pidsListeningOn(port) {
|
|
89
|
-
const out = sh("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"]);
|
|
90
|
-
return [...new Set(out.split(/\s+/).filter(Boolean).map(Number))];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function truncate(s, n) {
|
|
94
|
-
return s.length > n ? s.slice(0, n - 1) + "…" : s;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function collect() {
|
|
98
|
-
const self = process.pid;
|
|
99
|
-
const all = listProcesses();
|
|
100
|
-
const ppidOf = new Map(all.map((p) => [p.pid, p.ppid]));
|
|
101
|
-
const matched = [];
|
|
102
|
-
for (const p of all) {
|
|
103
|
-
if (p.pid === self) continue;
|
|
104
|
-
const kind = classify(p.command);
|
|
105
|
-
if (kind) matched.push({ ...p, kind });
|
|
106
|
-
}
|
|
107
|
-
const omawPids = new Set(matched.filter((p) => p.kind === "oh-my-agent-web").map((p) => p.pid));
|
|
108
|
-
// Walk up the ancestor chain (the app-server re-execs, so the listener's
|
|
109
|
-
// parent is the shim, not oh-my-agent-web directly).
|
|
110
|
-
const isManaged = (pid) => {
|
|
111
|
-
let cur = pid;
|
|
112
|
-
for (let hops = 0; hops < 12; hops += 1) {
|
|
113
|
-
const parent = ppidOf.get(cur);
|
|
114
|
-
if (parent === undefined || parent <= 1) return false;
|
|
115
|
-
if (omawPids.has(parent)) return true;
|
|
116
|
-
cur = parent;
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const procs = matched.map((p) => {
|
|
122
|
-
const ports = listenPorts(p.pid);
|
|
123
|
-
for (const extra of portsFromCmd(p.command, p.kind)) ports.add(extra);
|
|
124
|
-
const scope = p.kind === "app-server" ? (isManaged(p.pid) ? "managed" : "external") : "";
|
|
125
|
-
return {
|
|
126
|
-
kind: p.kind,
|
|
127
|
-
pid: p.pid,
|
|
128
|
-
ppid: p.ppid,
|
|
129
|
-
scope,
|
|
130
|
-
ports: [...ports].sort((a, b) => a - b),
|
|
131
|
-
command: p.command,
|
|
132
|
-
};
|
|
133
|
-
});
|
|
134
|
-
procs.sort((a, b) => (a.kind === b.kind ? a.pid - b.pid : a.kind.localeCompare(b.kind)));
|
|
135
|
-
|
|
136
|
-
const uiPort = Number(process.env.OMAW_PORT) || DEFAULT_UI_PORT;
|
|
137
|
-
const codexPort = Number(process.env.OMAW_CODEX_PORT) || DEFAULT_CODEX_PORT;
|
|
138
|
-
const portOwners = {};
|
|
139
|
-
for (const port of new Set([uiPort, codexPort])) {
|
|
140
|
-
portOwners[port] = pidsListeningOn(port);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return { processes: procs, uiPort, codexPort, portOwners };
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function render(data) {
|
|
147
|
-
const { processes, uiPort, codexPort, portOwners } = data;
|
|
148
|
-
if (processes.length === 0) {
|
|
149
|
-
console.log("no oh-my-agent-web / app-server process found.");
|
|
150
|
-
} else {
|
|
151
|
-
const rows = [
|
|
152
|
-
["TYPE", "PID", "PPID", "SCOPE", "PORTS", "COMMAND"],
|
|
153
|
-
...processes.map((p) => [
|
|
154
|
-
p.kind,
|
|
155
|
-
String(p.pid),
|
|
156
|
-
String(p.ppid),
|
|
157
|
-
p.scope || "-",
|
|
158
|
-
p.ports.length ? p.ports.join(",") : "-",
|
|
159
|
-
truncate(p.command, 60),
|
|
160
|
-
]),
|
|
161
|
-
];
|
|
162
|
-
const widths = rows[0].map((_, i) => Math.max(...rows.map((r) => r[i].length)));
|
|
163
|
-
for (const r of rows) {
|
|
164
|
-
console.log(r.map((c, i) => c.padEnd(widths[i])).join(" ").trimEnd());
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
console.log("");
|
|
169
|
-
console.log(`ports: ui=${uiPort}${process.env.OMAW_PORT ? " (OMAW_PORT)" : ""} app-server=${codexPort}${process.env.OMAW_CODEX_PORT ? " (OMAW_CODEX_PORT)" : ""}`);
|
|
170
|
-
for (const [port, pids] of Object.entries(portOwners)) {
|
|
171
|
-
const who = pids.length ? pids.join(",") : "—";
|
|
172
|
-
console.log(` ${String(port).padEnd(6)} listening: ${pids.length ? "yes" : "no "} pid: ${who}`);
|
|
173
|
-
}
|
|
174
|
-
if (processes.some((p) => p.kind === "app-server")) {
|
|
175
|
-
const ws =
|
|
176
|
-
processes.find((p) => p.kind === "app-server" && p.scope === "managed" && p.ports.length) ??
|
|
177
|
-
processes.find((p) => p.kind === "app-server" && p.ports.length);
|
|
178
|
-
if (ws) console.log(`\ntip: oh-my-agent-web ws --port ${ws.ports[0]}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export async function runPs(argv) {
|
|
183
|
-
if (argv.includes("-h") || argv.includes("--help")) {
|
|
184
|
-
process.stdout.write(HELP);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const data = collect();
|
|
188
|
-
if (argv.includes("--json")) {
|
|
189
|
-
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
render(data);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Allow running this file directly: `node bin/oh-my-agent-web-ps.mjs`
|
|
196
|
-
import { pathToFileURL } from "node:url";
|
|
197
|
-
const invoked = process.argv[1] ? pathToFileURL(process.argv[1]).href : "";
|
|
198
|
-
if (invoked === import.meta.url) {
|
|
199
|
-
runPs(process.argv.slice(2)).catch((err) => {
|
|
200
|
-
console.error(`[oh-my-agent-web ps] ${err instanceof Error ? err.message : String(err)}`);
|
|
201
|
-
process.exit(1);
|
|
202
|
-
});
|
|
203
|
-
}
|