aicodeman 1.49.0 → 1.50.1
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 +30 -4
- package/dist/cli-install-runner.d.ts +112 -0
- package/dist/cli-install-runner.d.ts.map +1 -0
- package/dist/cli-install-runner.js +289 -0
- package/dist/cli-install-runner.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/config/attachment-guard.d.ts +11 -0
- package/dist/config/attachment-guard.d.ts.map +1 -1
- package/dist/config/attachment-guard.js +21 -1
- package/dist/config/attachment-guard.js.map +1 -1
- package/dist/config/local-model-catalog.d.ts +188 -0
- package/dist/config/local-model-catalog.d.ts.map +1 -0
- package/dist/config/local-model-catalog.js +556 -0
- package/dist/config/local-model-catalog.js.map +1 -0
- package/dist/config-backup.js +1 -1
- package/dist/config-backup.js.map +1 -1
- package/dist/custom-model-hosts-writer.d.ts +50 -0
- package/dist/custom-model-hosts-writer.d.ts.map +1 -0
- package/dist/custom-model-hosts-writer.js +110 -0
- package/dist/custom-model-hosts-writer.js.map +1 -0
- package/dist/git-clone.d.ts.map +1 -1
- package/dist/git-clone.js +21 -1
- package/dist/git-clone.js.map +1 -1
- package/dist/git-fetch.d.ts.map +1 -1
- package/dist/git-fetch.js +6 -0
- package/dist/git-fetch.js.map +1 -1
- package/dist/git-workspace-status.d.ts.map +1 -1
- package/dist/git-workspace-status.js +4 -0
- package/dist/git-workspace-status.js.map +1 -1
- package/dist/git-worktrees.d.ts.map +1 -1
- package/dist/git-worktrees.js +6 -0
- package/dist/git-worktrees.js.map +1 -1
- package/dist/hooks-config.d.ts +15 -3
- package/dist/hooks-config.d.ts.map +1 -1
- package/dist/hooks-config.js +108 -4
- package/dist/hooks-config.js.map +1 -1
- package/dist/live-worktree.d.ts +73 -15
- package/dist/live-worktree.d.ts.map +1 -1
- package/dist/live-worktree.js +200 -32
- package/dist/live-worktree.js.map +1 -1
- package/dist/local-model/connect.d.ts +155 -0
- package/dist/local-model/connect.d.ts.map +1 -0
- package/dist/local-model/connect.js +243 -0
- package/dist/local-model/connect.js.map +1 -0
- package/dist/local-model/developer-tools.d.ts +45 -0
- package/dist/local-model/developer-tools.d.ts.map +1 -0
- package/dist/local-model/developer-tools.js +105 -0
- package/dist/local-model/developer-tools.js.map +1 -0
- package/dist/local-model/format.d.ts +39 -0
- package/dist/local-model/format.d.ts.map +1 -0
- package/dist/local-model/format.js +48 -0
- package/dist/local-model/format.js.map +1 -0
- package/dist/local-model/hardware.d.ts +125 -0
- package/dist/local-model/hardware.d.ts.map +1 -0
- package/dist/local-model/hardware.js +336 -0
- package/dist/local-model/hardware.js.map +1 -0
- package/dist/local-model/harness-facts.d.ts +77 -0
- package/dist/local-model/harness-facts.d.ts.map +1 -0
- package/dist/local-model/harness-facts.js +145 -0
- package/dist/local-model/harness-facts.js.map +1 -0
- package/dist/local-model/install-job.d.ts +431 -0
- package/dist/local-model/install-job.d.ts.map +1 -0
- package/dist/local-model/install-job.js +1822 -0
- package/dist/local-model/install-job.js.map +1 -0
- package/dist/local-model/ollama-client.d.ts +216 -0
- package/dist/local-model/ollama-client.d.ts.map +1 -0
- package/dist/local-model/ollama-client.js +636 -0
- package/dist/local-model/ollama-client.js.map +1 -0
- package/dist/local-model/paths.d.ts +64 -0
- package/dist/local-model/paths.d.ts.map +1 -0
- package/dist/local-model/paths.js +75 -0
- package/dist/local-model/paths.js.map +1 -0
- package/dist/local-model/recommend.d.ts +118 -0
- package/dist/local-model/recommend.d.ts.map +1 -0
- package/dist/local-model/recommend.js +430 -0
- package/dist/local-model/recommend.js.map +1 -0
- package/dist/local-model/runtime.d.ts +339 -0
- package/dist/local-model/runtime.d.ts.map +1 -0
- package/dist/local-model/runtime.js +1240 -0
- package/dist/local-model/runtime.js.map +1 -0
- package/dist/local-model/state-store.d.ts +45 -0
- package/dist/local-model/state-store.d.ts.map +1 -0
- package/dist/local-model/state-store.js +261 -0
- package/dist/local-model/state-store.js.map +1 -0
- package/dist/readmymind-collectors.d.ts.map +1 -1
- package/dist/readmymind-collectors.js +4 -0
- package/dist/readmymind-collectors.js.map +1 -1
- package/dist/reboot-restore.d.ts +3 -1
- package/dist/reboot-restore.d.ts.map +1 -1
- package/dist/reboot-restore.js.map +1 -1
- package/dist/session.d.ts +29 -7
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +63 -10
- package/dist/session.js.map +1 -1
- package/dist/types/common.d.ts +5 -0
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/local-model-install.d.ts +533 -0
- package/dist/types/local-model-install.d.ts.map +1 -0
- package/dist/types/local-model-install.js +169 -0
- package/dist/types/local-model-install.js.map +1 -0
- package/dist/types/local-model.d.ts +551 -0
- package/dist/types/local-model.d.ts.map +1 -0
- package/dist/types/local-model.js +115 -0
- package/dist/types/local-model.js.map +1 -0
- package/dist/types/session.d.ts +17 -6
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js.map +1 -1
- package/dist/utils/cli-executable-resolver.d.ts +18 -0
- package/dist/utils/cli-executable-resolver.d.ts.map +1 -1
- package/dist/utils/cli-executable-resolver.js +34 -2
- package/dist/utils/cli-executable-resolver.js.map +1 -1
- package/dist/utils/git-availability.d.ts +65 -0
- package/dist/utils/git-availability.d.ts.map +1 -0
- package/dist/utils/git-availability.js +134 -0
- package/dist/utils/git-availability.js.map +1 -0
- package/dist/web/agent-skill-default-migration.d.ts +60 -0
- package/dist/web/agent-skill-default-migration.d.ts.map +1 -0
- package/dist/web/agent-skill-default-migration.js +97 -0
- package/dist/web/agent-skill-default-migration.js.map +1 -0
- package/dist/web/approval-inbox.d.ts +10 -0
- package/dist/web/approval-inbox.d.ts.map +1 -1
- package/dist/web/approval-inbox.js +15 -0
- package/dist/web/approval-inbox.js.map +1 -1
- package/dist/web/case-state-sync.d.ts +28 -0
- package/dist/web/case-state-sync.d.ts.map +1 -0
- package/dist/web/case-state-sync.js +41 -0
- package/dist/web/case-state-sync.js.map +1 -0
- package/dist/web/ports/config-port.d.ts +1 -1
- package/dist/web/ports/config-port.d.ts.map +1 -1
- package/dist/web/public/admin-ui.js.gz +0 -0
- package/dist/web/public/api-client.c9b1cddc.js.gz +0 -0
- package/dist/web/public/{app.9ea37070.js → app.07398d90.js} +1 -1
- package/dist/web/public/app.07398d90.js.br +0 -0
- package/dist/web/public/app.07398d90.js.gz +0 -0
- package/dist/web/public/approvals-ui.js.gz +0 -0
- package/dist/web/public/constants.782170e1.js.gz +0 -0
- package/dist/web/public/cron-ui.js.gz +0 -0
- package/dist/web/public/edit-history-ui.js.gz +0 -0
- package/dist/web/public/entrance-animations.js.gz +0 -0
- package/dist/web/public/foreign-sessions.js.gz +0 -0
- package/dist/web/public/git-status-ui.js.gz +0 -0
- package/dist/web/public/header-divider.eb2d2463.js.gz +0 -0
- package/dist/web/public/home-sessions.js +38 -18
- package/dist/web/public/home-sessions.js.br +0 -0
- package/dist/web/public/home-sessions.js.gz +0 -0
- package/dist/web/public/host-wake-ui.js.gz +0 -0
- package/dist/web/public/{i18n.a5e82c95.js → i18n.519d025e.js} +2 -2
- package/dist/web/public/i18n.519d025e.js.br +0 -0
- package/dist/web/public/i18n.519d025e.js.gz +0 -0
- package/dist/web/public/image-input.a5d0f8f3.js.gz +0 -0
- package/dist/web/public/index.html +88 -13
- package/dist/web/public/index.html.br +0 -0
- package/dist/web/public/index.html.gz +0 -0
- package/dist/web/public/input-cjk.8bc46081.js.gz +0 -0
- package/dist/web/public/{keyboard-accessory.b941676c.js → keyboard-accessory.0800fc44.js} +160 -2
- package/dist/web/public/keyboard-accessory.0800fc44.js.br +0 -0
- package/dist/web/public/keyboard-accessory.0800fc44.js.gz +0 -0
- package/dist/web/public/local-model-ui.js +1735 -0
- package/dist/web/public/local-model-ui.js.br +0 -0
- package/dist/web/public/local-model-ui.js.gz +0 -0
- package/dist/web/public/mobile-handlers.f7c3f692.js.gz +0 -0
- package/dist/web/public/mobile-ime-preview.2dbaf262.js.gz +0 -0
- package/dist/web/public/mobile-overview.js +30 -14
- package/dist/web/public/mobile-overview.js.br +0 -0
- package/dist/web/public/mobile-overview.js.gz +0 -0
- package/dist/web/public/mobile.4dfd5c55.css +1 -0
- package/dist/web/public/mobile.4dfd5c55.css.br +0 -0
- package/dist/web/public/mobile.4dfd5c55.css.gz +0 -0
- package/dist/web/public/notification-manager.feb82c04.js.gz +0 -0
- package/dist/web/public/orchestrator-panel.js.gz +0 -0
- package/dist/web/public/{panels-ui.8bcd4473.js → panels-ui.9ba2683e.js} +100 -98
- package/dist/web/public/panels-ui.9ba2683e.js.br +0 -0
- package/dist/web/public/panels-ui.9ba2683e.js.gz +0 -0
- package/dist/web/public/ralph-panel.b350e2ef.js.gz +0 -0
- package/dist/web/public/ralph-wizard.b6c0dd19.js.gz +0 -0
- package/dist/web/public/readmymind-ui.js.gz +0 -0
- package/dist/web/public/reboot-restore-ui.js +2 -0
- package/dist/web/public/reboot-restore-ui.js.br +0 -0
- package/dist/web/public/reboot-restore-ui.js.gz +0 -0
- package/dist/web/public/respawn-ui.304ba0d4.js.gz +0 -0
- package/dist/web/public/sanitize-html.e7147e76.js.gz +0 -0
- package/dist/web/public/session-lineage.js.gz +0 -0
- package/dist/web/public/{session-ui.a7c8c095.js → session-ui.8f300b14.js} +21 -21
- package/dist/web/public/session-ui.8f300b14.js.br +0 -0
- package/dist/web/public/session-ui.8f300b14.js.gz +0 -0
- package/dist/web/public/{settings-ui.18f92052.js → settings-ui.8b37cf07.js} +14 -14
- package/dist/web/public/settings-ui.8b37cf07.js.br +0 -0
- package/dist/web/public/settings-ui.8b37cf07.js.gz +0 -0
- package/dist/web/public/spreadsheet-preview-worker.js.gz +0 -0
- package/dist/web/public/spreadsheet-preview.75c751de.js.gz +0 -0
- package/dist/web/public/spreadsheet-xlsx-core.js.gz +0 -0
- package/dist/web/public/styles.21b93520.css +1 -0
- package/dist/web/public/styles.21b93520.css.br +0 -0
- package/dist/web/public/styles.21b93520.css.gz +0 -0
- package/dist/web/public/subagent-windows.07277a58.js.gz +0 -0
- package/dist/web/public/sw.js +2 -2
- package/dist/web/public/sw.js.br +0 -0
- package/dist/web/public/sw.js.gz +0 -0
- package/dist/web/public/tab-layout-browser.2d6189f7.js.gz +0 -0
- package/dist/web/public/tab-rail-resize.b5cdceaf.js.gz +0 -0
- package/dist/web/public/terminal-keycode229-recovery.98843069.js.gz +0 -0
- package/dist/web/public/terminal-split.js.gz +0 -0
- package/dist/web/public/terminal-tile.js.gz +0 -0
- package/dist/web/public/{terminal-ui.a7883640.js → terminal-ui.f92eae28.js} +2 -2
- package/dist/web/public/terminal-ui.f92eae28.js.br +0 -0
- package/dist/web/public/terminal-ui.f92eae28.js.gz +0 -0
- package/dist/web/public/tile-grid.js.gz +0 -0
- package/dist/web/public/ultracode-panel.js.gz +0 -0
- package/dist/web/public/ultracode-windows.js.gz +0 -0
- package/dist/web/public/vendor/dompurify.min.js.gz +0 -0
- package/dist/web/public/vendor/exceljs.min.js.gz +0 -0
- package/dist/web/public/vendor/fflate.min.js.gz +0 -0
- package/dist/web/public/vendor/marked.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-serialize.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
- package/dist/web/public/vendor/xterm-predictive-echo.276b11d9.js.gz +0 -0
- package/dist/web/public/vendor/xterm-zerolag-input.1be42307.js.gz +0 -0
- package/dist/web/public/vendor/xterm.css.gz +0 -0
- package/dist/web/public/vendor/xterm.min.js.gz +0 -0
- package/dist/web/public/{voice-input.2342c37b.js → voice-input.d0580528.js} +232 -137
- package/dist/web/public/voice-input.d0580528.js.br +0 -0
- package/dist/web/public/voice-input.d0580528.js.gz +0 -0
- package/dist/web/public/voice-pcm-worklet.js.gz +0 -0
- package/dist/web/public/webview-tabs.js.gz +0 -0
- package/dist/web/public/whats-new.json +9 -9
- package/dist/web/repo-status.d.ts.map +1 -1
- package/dist/web/repo-status.js +4 -0
- package/dist/web/repo-status.js.map +1 -1
- package/dist/web/route-helpers.d.ts +29 -0
- package/dist/web/route-helpers.d.ts.map +1 -1
- package/dist/web/route-helpers.js +37 -0
- package/dist/web/route-helpers.js.map +1 -1
- package/dist/web/routes/approval-routes.d.ts.map +1 -1
- package/dist/web/routes/approval-routes.js +3 -2
- package/dist/web/routes/approval-routes.js.map +1 -1
- package/dist/web/routes/case-routes.d.ts.map +1 -1
- package/dist/web/routes/case-routes.js +31 -5
- package/dist/web/routes/case-routes.js.map +1 -1
- package/dist/web/routes/cli-registry-routes.d.ts +1 -27
- package/dist/web/routes/cli-registry-routes.d.ts.map +1 -1
- package/dist/web/routes/cli-registry-routes.js +11 -202
- package/dist/web/routes/cli-registry-routes.js.map +1 -1
- package/dist/web/routes/custom-model-routes.d.ts +15 -0
- package/dist/web/routes/custom-model-routes.d.ts.map +1 -1
- package/dist/web/routes/custom-model-routes.js +114 -33
- package/dist/web/routes/custom-model-routes.js.map +1 -1
- package/dist/web/routes/file-routes.d.ts +4 -2
- package/dist/web/routes/file-routes.d.ts.map +1 -1
- package/dist/web/routes/file-routes.js +160 -24
- package/dist/web/routes/file-routes.js.map +1 -1
- package/dist/web/routes/html-view-routes.d.ts.map +1 -1
- package/dist/web/routes/html-view-routes.js +12 -3
- package/dist/web/routes/html-view-routes.js.map +1 -1
- package/dist/web/routes/index.d.ts +1 -0
- package/dist/web/routes/index.d.ts.map +1 -1
- package/dist/web/routes/index.js +1 -0
- package/dist/web/routes/index.js.map +1 -1
- package/dist/web/routes/local-model-routes.d.ts +103 -0
- package/dist/web/routes/local-model-routes.d.ts.map +1 -0
- package/dist/web/routes/local-model-routes.js +210 -0
- package/dist/web/routes/local-model-routes.js.map +1 -0
- package/dist/web/routes/reboot-restore-routes.d.ts.map +1 -1
- package/dist/web/routes/reboot-restore-routes.js +16 -0
- package/dist/web/routes/reboot-restore-routes.js.map +1 -1
- package/dist/web/routes/session-routes.d.ts.map +1 -1
- package/dist/web/routes/session-routes.js +22 -27
- package/dist/web/routes/session-routes.js.map +1 -1
- package/dist/web/routes/system-routes.d.ts +2 -2
- package/dist/web/routes/system-routes.d.ts.map +1 -1
- package/dist/web/routes/system-routes.js +23 -4
- package/dist/web/routes/system-routes.js.map +1 -1
- package/dist/web/schemas.d.ts +30 -0
- package/dist/web/schemas.d.ts.map +1 -1
- package/dist/web/schemas.js +52 -5
- package/dist/web/schemas.js.map +1 -1
- package/dist/web/self-update.d.ts.map +1 -1
- package/dist/web/self-update.js +4 -0
- package/dist/web/self-update.js.map +1 -1
- package/dist/web/sensitive-path.d.ts.map +1 -1
- package/dist/web/sensitive-path.js +5 -0
- package/dist/web/sensitive-path.js.map +1 -1
- package/dist/web/server.d.ts +20 -0
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +83 -7
- package/dist/web/server.js.map +1 -1
- package/dist/web/voice-stream.d.ts +4 -3
- package/dist/web/voice-stream.d.ts.map +1 -1
- package/dist/web/voice-stream.js +5 -4
- package/dist/web/voice-stream.js.map +1 -1
- package/package.json +2 -1
- package/skills/codeman/SKILL.md +318 -24
- package/skills/codeman/preamble.sh +242 -16
- package/skills/codeman/reference/recipes.md +1 -1
- package/skills/codeman/reference/verbs.md +101 -1
- package/dist/web/public/app.9ea37070.js.br +0 -0
- package/dist/web/public/app.9ea37070.js.gz +0 -0
- package/dist/web/public/i18n.a5e82c95.js.br +0 -0
- package/dist/web/public/i18n.a5e82c95.js.gz +0 -0
- package/dist/web/public/keyboard-accessory.b941676c.js.br +0 -0
- package/dist/web/public/keyboard-accessory.b941676c.js.gz +0 -0
- package/dist/web/public/mobile.67c8eb5b.css +0 -1
- package/dist/web/public/mobile.67c8eb5b.css.br +0 -0
- package/dist/web/public/mobile.67c8eb5b.css.gz +0 -0
- package/dist/web/public/panels-ui.8bcd4473.js.br +0 -0
- package/dist/web/public/panels-ui.8bcd4473.js.gz +0 -0
- package/dist/web/public/session-ui.a7c8c095.js.br +0 -0
- package/dist/web/public/session-ui.a7c8c095.js.gz +0 -0
- package/dist/web/public/settings-ui.18f92052.js.br +0 -0
- package/dist/web/public/settings-ui.18f92052.js.gz +0 -0
- package/dist/web/public/styles.6a718331.css +0 -1
- package/dist/web/public/styles.6a718331.css.br +0 -0
- package/dist/web/public/styles.6a718331.css.gz +0 -0
- package/dist/web/public/terminal-ui.a7883640.js.br +0 -0
- package/dist/web/public/terminal-ui.a7883640.js.gz +0 -0
- package/dist/web/public/voice-input.2342c37b.js.br +0 -0
- package/dist/web/public/voice-input.2342c37b.js.gz +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The formatters of the local model recommendation, and its byte units.
|
|
3
|
+
*
|
|
4
|
+
* `formatGb()` is the ONE place a byte count becomes a size a person reads: decimal GB (the
|
|
5
|
+
* unit the Finder and the model registry use). `hardware.ts` and `recommend.ts` call it to fill
|
|
6
|
+
* the `...Gb` text fields of the payload (`memGb`, `freeDiskGb`, `needGb`, `downloadGb`,
|
|
7
|
+
* `budgetGb`, and the size slots of a `LocalModelMessage`). Nothing else may turn bytes into a
|
|
8
|
+
* size for display, the browser included: it prints the text it was sent.
|
|
9
|
+
*
|
|
10
|
+
* GiB and MiB exist only for the budget math (reserves, the wired limit, the device total the
|
|
11
|
+
* runtime reports) and never reach a person, with one exception: `memClassGb()`, the memory
|
|
12
|
+
* size a Mac is sold as, is how the card names the installed memory ("48 GB memory", what
|
|
13
|
+
* About This Mac shows). It is a name of the machine, not a computed size: `formatGb()` of the
|
|
14
|
+
* same bytes reads 51.5, which no owner recognises. Every computed size (need, budget,
|
|
15
|
+
* download, free disk) is `formatGb()`.
|
|
16
|
+
*
|
|
17
|
+
* Pure: no IO, no state.
|
|
18
|
+
*/
|
|
19
|
+
/** One decimal gigabyte, the unit a person reads. */
|
|
20
|
+
export const GB = 1_000_000_000;
|
|
21
|
+
/** One binary gigabyte. Budget math only. */
|
|
22
|
+
export const GIB = 1024 ** 3;
|
|
23
|
+
/** One binary megabyte. Budget math only. */
|
|
24
|
+
export const MIB = 1024 ** 2;
|
|
25
|
+
/**
|
|
26
|
+
* A byte count as decimal GB text, WITHOUT the unit: one decimal below 100 ('6.6', '17.7',
|
|
27
|
+
* '25.5'), a whole number from 100 ('212'). The caller's sentence supplies ' GB'.
|
|
28
|
+
* Anything that is not a positive finite number reads '0.0'.
|
|
29
|
+
*/
|
|
30
|
+
export function formatGb(bytes) {
|
|
31
|
+
if (!Number.isFinite(bytes) || bytes <= 0)
|
|
32
|
+
return '0.0';
|
|
33
|
+
const tenths = Math.round((bytes / GB) * 10) / 10;
|
|
34
|
+
return tenths >= 100 ? String(Math.round(bytes / GB)) : tenths.toFixed(1);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The memory size a Mac is sold as: whole binary gigabytes (17179869184 bytes is 16). This is
|
|
38
|
+
* `HardwareFacts.memClassGb`: the key of the tier rules ("below 36 GB") and of `TestedOn.memGb`,
|
|
39
|
+
* and what the card and the `noneMemory` sentence call the installed memory. It names a class
|
|
40
|
+
* of Mac; 0 means the size is unknown and is never shown. Any other size for display is
|
|
41
|
+
* `formatGb()`.
|
|
42
|
+
*/
|
|
43
|
+
export function memClassGb(memBytes) {
|
|
44
|
+
if (!Number.isFinite(memBytes) || memBytes <= 0)
|
|
45
|
+
return 0;
|
|
46
|
+
return Math.round(memBytes / GIB);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/local-model/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,qDAAqD;AACrD,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC;AAChC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC;AAC7B,6CAA6C;AAC7C,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC;AAE7B;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACxD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;IAClD,OAAO,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC1D,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The hardware probe of the local model recommendation: what this Mac is.
|
|
3
|
+
*
|
|
4
|
+
* - `parseSysctl()`: a pure parser of `key: value` lines. The command runs WITHOUT `-n`, so a
|
|
5
|
+
* key that is missing on a machine (`sysctl.proc_translated` on Intel) cannot shift the
|
|
6
|
+
* others, and a line it does not know is ignored.
|
|
7
|
+
* - `readHardware()`: ONE bounded async spawn of `SYSCTL_PATH` with `SYSCTL_KEYS`, the free disk
|
|
8
|
+
* of the data dir through `fs.promises.statfs`, fallbacks from `node:os` when the spawn
|
|
9
|
+
* fails, and a 60 s cache.
|
|
10
|
+
*
|
|
11
|
+
* Rules:
|
|
12
|
+
* - Never throws and never rejects: a failed probe is an answer (`source: 'os-fallback'`), and
|
|
13
|
+
* off macOS nothing is spawned and no disk is read (`source: 'not-probed'`).
|
|
14
|
+
* - Never `system_profiler` (tens of milliseconds and a parse of free text), never a second
|
|
15
|
+
* spawn, never a synchronous exec on the server's event loop.
|
|
16
|
+
* - A non-zero exit is tolerated once `hw.memsize` parsed (a missing key makes sysctl exit 1).
|
|
17
|
+
* Without `hw.memsize` nothing else of that output is trusted: the answer is the fallback.
|
|
18
|
+
* - Only a line that ends in a newline counts. A cut-off tail is not a value: half of
|
|
19
|
+
* `hw.memsize` would read as a smaller, valid number.
|
|
20
|
+
* - `iogpu.wired_limit_mb` of 0 means "not set": it is reported as 0 and only a value above 0
|
|
21
|
+
* is ever used as a limit.
|
|
22
|
+
* - The data dir can sit on a network mount that stopped answering, so the disk read is
|
|
23
|
+
* bounded too: the folder is probed with the bounded path probe first, the `statfs` is raced
|
|
24
|
+
* against a timeout, and a `statfs` that never came back is not started a second time.
|
|
25
|
+
* - `memGb`, `memClassGb` and `freeDiskGb` are filled here through src/local-model/format.ts,
|
|
26
|
+
* the one place a size is formatted.
|
|
27
|
+
*/
|
|
28
|
+
import type { HardwareFacts } from '../types.js';
|
|
29
|
+
import { type PathProbeKind } from '../utils/bounded-path-probe.js';
|
|
30
|
+
/** Absolute path, so the server's PATH (minimal under a service manager) cannot change what runs. */
|
|
31
|
+
export declare const SYSCTL_PATH = "/usr/sbin/sysctl";
|
|
32
|
+
/** The keys of the one spawn, in the order they are passed. */
|
|
33
|
+
export declare const SYSCTL_KEYS: readonly ["hw.memsize", "machdep.cpu.brand_string", "hw.optional.arm64", "sysctl.proc_translated", "iogpu.wired_limit_mb", "kern.osproductversion", "hw.model"];
|
|
34
|
+
/** Upper bound of the spawn (it answers in about 2 ms on a real Mac). */
|
|
35
|
+
export declare const SYSCTL_TIMEOUT_MS = 2000;
|
|
36
|
+
/** How long one probe result is reused. */
|
|
37
|
+
export declare const HARDWARE_CACHE_TTL_MS = 60000;
|
|
38
|
+
/** Upper bound of the wait for the free disk figure. */
|
|
39
|
+
export declare const FREE_DISK_TIMEOUT_MS = 2000;
|
|
40
|
+
/** What `parseSysctl()` read. Every field is absent when its key was missing or its value did not parse. */
|
|
41
|
+
export interface SysctlFacts {
|
|
42
|
+
/** `hw.memsize`. */
|
|
43
|
+
memBytes?: number;
|
|
44
|
+
/** `machdep.cpu.brand_string`. */
|
|
45
|
+
chip?: string;
|
|
46
|
+
/** `hw.optional.arm64` is 1. */
|
|
47
|
+
arm64?: boolean;
|
|
48
|
+
/** `sysctl.proc_translated` is 1. */
|
|
49
|
+
translated?: boolean;
|
|
50
|
+
/** `iogpu.wired_limit_mb`, as reported (0 stays 0). */
|
|
51
|
+
wiredLimitMb?: number;
|
|
52
|
+
/** `kern.osproductversion`. */
|
|
53
|
+
macosVersion?: string;
|
|
54
|
+
/** The leading number of `macosVersion`. */
|
|
55
|
+
macosMajor?: number;
|
|
56
|
+
/** `hw.model`. */
|
|
57
|
+
model?: string;
|
|
58
|
+
}
|
|
59
|
+
/** The IO of `readHardware()`, injectable so a test spawns nothing and reads no real disk. Each member defaults to the real thing. */
|
|
60
|
+
export interface HardwareProbeDeps {
|
|
61
|
+
/** Default `process.platform`. */
|
|
62
|
+
platform?: string;
|
|
63
|
+
/** Default `os.arch()`. */
|
|
64
|
+
arch?: string;
|
|
65
|
+
/** Runs the one spawn. Resolves its stdout, also after a non-zero exit, or `undefined` when it could not run or timed out. Never rejects. */
|
|
66
|
+
runSysctl?: () => Promise<string | undefined>;
|
|
67
|
+
/** Free bytes on the data dir's filesystem, or `undefined` when unknown. Never rejects. */
|
|
68
|
+
freeDiskBytes?: () => Promise<number | undefined>;
|
|
69
|
+
/** Default `os.totalmem()`. */
|
|
70
|
+
totalMemBytes?: () => number;
|
|
71
|
+
/** Default `os.cpus()[0]?.model`. */
|
|
72
|
+
cpuModel?: () => string | undefined;
|
|
73
|
+
/** Default `Date.now`. The clock of the cache. */
|
|
74
|
+
now?: () => number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parse the output of `sysctl <keys>` (no `-n`): one `key: value` line per key it knows.
|
|
78
|
+
* Pure. Unknown lines, blank lines and error lines are skipped, and so is a last line that does
|
|
79
|
+
* not end in a newline. The first line of a key wins.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseSysctl(text: string): SysctlFacts;
|
|
82
|
+
/**
|
|
83
|
+
* The one spawn: `command` with `SYSCTL_KEYS` as its arguments and nothing else (no `-n`).
|
|
84
|
+
* Resolves stdout when the program ran, also after a non-zero exit (a key this machine lacks
|
|
85
|
+
* makes sysctl exit 1 while the other keys are printed). Resolves `undefined` when it could not
|
|
86
|
+
* be started, was killed (the timeout) or printed too much. Never rejects.
|
|
87
|
+
*
|
|
88
|
+
* The two parameters exist for the test, which runs a script of its own in place of sysctl.
|
|
89
|
+
*/
|
|
90
|
+
export declare function spawnSysctl(command?: string, timeoutMs?: number): Promise<string | undefined>;
|
|
91
|
+
/**
|
|
92
|
+
* Free bytes on the filesystem that holds `path` (`bavail * bsize`: what an unprivileged
|
|
93
|
+
* process can use), or `undefined` when the filesystem does not say. Not bounded by itself: see
|
|
94
|
+
* `dataDirFreeBytes()`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function freeDiskBytesOf(path: string): Promise<number | undefined>;
|
|
97
|
+
/** The IO of `dataDirFreeBytes()`. Each member defaults to the real thing; a test passes its own. */
|
|
98
|
+
export interface FreeDiskDeps {
|
|
99
|
+
/** Default `getDataDir()`. */
|
|
100
|
+
dataDir?: () => string;
|
|
101
|
+
/** Default the bounded path probe (`probePathKind`). */
|
|
102
|
+
probeKind?: (path: string) => Promise<PathProbeKind>;
|
|
103
|
+
/** Default `freeDiskBytesOf`. */
|
|
104
|
+
freeBytesOf?: (path: string) => Promise<number | undefined>;
|
|
105
|
+
/** Default `FREE_DISK_TIMEOUT_MS`. */
|
|
106
|
+
timeoutMs?: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Free bytes on the data dir's filesystem, bounded. The folder (or, when it does not exist yet,
|
|
110
|
+
* its nearest existing parent) is found with the bounded path probe, which never waits on a
|
|
111
|
+
* dead mount twice; the `statfs` itself is raced against a timeout. `undefined` when the
|
|
112
|
+
* filesystem does not answer in time, or is not known to be a folder.
|
|
113
|
+
*/
|
|
114
|
+
export declare function dataDirFreeBytes(deps?: FreeDiskDeps): Promise<number | undefined>;
|
|
115
|
+
/**
|
|
116
|
+
* What this machine is. Cached for `HARDWARE_CACHE_TTL_MS`; concurrent callers share one probe.
|
|
117
|
+
* Never rejects.
|
|
118
|
+
*
|
|
119
|
+
* The cache is one per process and does not look at `deps`: within the 60 s a second call
|
|
120
|
+
* returns the first call's answer whatever it injects. A test resets it first.
|
|
121
|
+
*/
|
|
122
|
+
export declare function readHardware(deps?: HardwareProbeDeps): Promise<HardwareFacts>;
|
|
123
|
+
/** Drop the cached probe result and the memory of a pending disk read (tests, and nothing else). */
|
|
124
|
+
export declare function resetHardwareCache(): void;
|
|
125
|
+
//# sourceMappingURL=hardware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware.d.ts","sourceRoot":"","sources":["../../src/local-model/hardware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAGnF,qGAAqG;AACrG,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAE9C,+DAA+D;AAC/D,eAAO,MAAM,WAAW,iKAQd,CAAC;AAEX,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,2CAA2C;AAC3C,eAAO,MAAM,q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GAAG,SAAS,CAAC,CA0B7B;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAQ/E;AAKD,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACrD,iCAAiC;IACjC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC5D,sCAAsC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA0C3F;AAyED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAAC,aAAa,CAAC,CA2BvF;AAED,oGAAoG;AACpG,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The hardware probe of the local model recommendation: what this Mac is.
|
|
3
|
+
*
|
|
4
|
+
* - `parseSysctl()`: a pure parser of `key: value` lines. The command runs WITHOUT `-n`, so a
|
|
5
|
+
* key that is missing on a machine (`sysctl.proc_translated` on Intel) cannot shift the
|
|
6
|
+
* others, and a line it does not know is ignored.
|
|
7
|
+
* - `readHardware()`: ONE bounded async spawn of `SYSCTL_PATH` with `SYSCTL_KEYS`, the free disk
|
|
8
|
+
* of the data dir through `fs.promises.statfs`, fallbacks from `node:os` when the spawn
|
|
9
|
+
* fails, and a 60 s cache.
|
|
10
|
+
*
|
|
11
|
+
* Rules:
|
|
12
|
+
* - Never throws and never rejects: a failed probe is an answer (`source: 'os-fallback'`), and
|
|
13
|
+
* off macOS nothing is spawned and no disk is read (`source: 'not-probed'`).
|
|
14
|
+
* - Never `system_profiler` (tens of milliseconds and a parse of free text), never a second
|
|
15
|
+
* spawn, never a synchronous exec on the server's event loop.
|
|
16
|
+
* - A non-zero exit is tolerated once `hw.memsize` parsed (a missing key makes sysctl exit 1).
|
|
17
|
+
* Without `hw.memsize` nothing else of that output is trusted: the answer is the fallback.
|
|
18
|
+
* - Only a line that ends in a newline counts. A cut-off tail is not a value: half of
|
|
19
|
+
* `hw.memsize` would read as a smaller, valid number.
|
|
20
|
+
* - `iogpu.wired_limit_mb` of 0 means "not set": it is reported as 0 and only a value above 0
|
|
21
|
+
* is ever used as a limit.
|
|
22
|
+
* - The data dir can sit on a network mount that stopped answering, so the disk read is
|
|
23
|
+
* bounded too: the folder is probed with the bounded path probe first, the `statfs` is raced
|
|
24
|
+
* against a timeout, and a `statfs` that never came back is not started a second time.
|
|
25
|
+
* - `memGb`, `memClassGb` and `freeDiskGb` are filled here through src/local-model/format.ts,
|
|
26
|
+
* the one place a size is formatted.
|
|
27
|
+
*/
|
|
28
|
+
import { execFile } from 'node:child_process';
|
|
29
|
+
import { statfs } from 'node:fs/promises';
|
|
30
|
+
import os from 'node:os';
|
|
31
|
+
import { dirname } from 'node:path';
|
|
32
|
+
import { getDataDir } from '../config/instance.js';
|
|
33
|
+
import { probePathKind } from '../utils/bounded-path-probe.js';
|
|
34
|
+
import { formatGb, memClassGb } from './format.js';
|
|
35
|
+
/** Absolute path, so the server's PATH (minimal under a service manager) cannot change what runs. */
|
|
36
|
+
export const SYSCTL_PATH = '/usr/sbin/sysctl';
|
|
37
|
+
/** The keys of the one spawn, in the order they are passed. */
|
|
38
|
+
export const SYSCTL_KEYS = [
|
|
39
|
+
'hw.memsize',
|
|
40
|
+
'machdep.cpu.brand_string',
|
|
41
|
+
'hw.optional.arm64',
|
|
42
|
+
'sysctl.proc_translated',
|
|
43
|
+
'iogpu.wired_limit_mb',
|
|
44
|
+
'kern.osproductversion',
|
|
45
|
+
'hw.model',
|
|
46
|
+
];
|
|
47
|
+
/** Upper bound of the spawn (it answers in about 2 ms on a real Mac). */
|
|
48
|
+
export const SYSCTL_TIMEOUT_MS = 2000;
|
|
49
|
+
/** How long one probe result is reused. */
|
|
50
|
+
export const HARDWARE_CACHE_TTL_MS = 60_000;
|
|
51
|
+
/** Upper bound of the wait for the free disk figure. */
|
|
52
|
+
export const FREE_DISK_TIMEOUT_MS = 2000;
|
|
53
|
+
/** Seven short lines are well under this. A larger output is not sysctl's. */
|
|
54
|
+
const SYSCTL_MAX_OUTPUT_BYTES = 64 * 1024;
|
|
55
|
+
/** Longest text value kept (a chip name, a model identifier, a version). */
|
|
56
|
+
const MAX_TEXT_VALUE_LENGTH = 100;
|
|
57
|
+
/** How many parent folders are tried when the data dir does not exist yet. */
|
|
58
|
+
const FREE_DISK_MAX_PARENT_STEPS = 6;
|
|
59
|
+
/** A whole number without sign, as sysctl prints one. */
|
|
60
|
+
function parseCount(value) {
|
|
61
|
+
if (!/^\d+$/.test(value))
|
|
62
|
+
return undefined;
|
|
63
|
+
const parsed = Number(value);
|
|
64
|
+
return Number.isSafeInteger(parsed) ? parsed : undefined;
|
|
65
|
+
}
|
|
66
|
+
/** sysctl prints a flag as 0 or 1. Anything else is not a flag. */
|
|
67
|
+
function parseFlag(value) {
|
|
68
|
+
if (value === '1')
|
|
69
|
+
return true;
|
|
70
|
+
if (value === '0')
|
|
71
|
+
return false;
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
function parseText(value) {
|
|
75
|
+
return value !== '' && value.length <= MAX_TEXT_VALUE_LENGTH ? value : undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse the output of `sysctl <keys>` (no `-n`): one `key: value` line per key it knows.
|
|
79
|
+
* Pure. Unknown lines, blank lines and error lines are skipped, and so is a last line that does
|
|
80
|
+
* not end in a newline. The first line of a key wins.
|
|
81
|
+
*/
|
|
82
|
+
export function parseSysctl(text) {
|
|
83
|
+
const facts = {};
|
|
84
|
+
const lines = text.split('\n');
|
|
85
|
+
// What follows the last newline is either empty or a cut-off line.
|
|
86
|
+
lines.pop();
|
|
87
|
+
for (const rawLine of lines) {
|
|
88
|
+
const line = rawLine.replace(/\r$/, '');
|
|
89
|
+
const colon = line.indexOf(':');
|
|
90
|
+
if (colon <= 0)
|
|
91
|
+
continue;
|
|
92
|
+
const key = line.slice(0, colon).trim();
|
|
93
|
+
const value = line.slice(colon + 1).trim();
|
|
94
|
+
switch (key) {
|
|
95
|
+
case 'hw.memsize': {
|
|
96
|
+
const bytes = parseCount(value);
|
|
97
|
+
if (bytes !== undefined && bytes > 0)
|
|
98
|
+
facts.memBytes ??= bytes;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'machdep.cpu.brand_string':
|
|
102
|
+
facts.chip ??= parseText(value);
|
|
103
|
+
break;
|
|
104
|
+
case 'hw.optional.arm64':
|
|
105
|
+
facts.arm64 ??= parseFlag(value);
|
|
106
|
+
break;
|
|
107
|
+
case 'sysctl.proc_translated':
|
|
108
|
+
facts.translated ??= parseFlag(value);
|
|
109
|
+
break;
|
|
110
|
+
case 'iogpu.wired_limit_mb':
|
|
111
|
+
facts.wiredLimitMb ??= parseCount(value);
|
|
112
|
+
break;
|
|
113
|
+
case 'kern.osproductversion': {
|
|
114
|
+
const version = /^(\d+)(?:\.\d+)*$/.exec(value);
|
|
115
|
+
if (version && value.length <= MAX_TEXT_VALUE_LENGTH && facts.macosVersion === undefined) {
|
|
116
|
+
facts.macosVersion = value;
|
|
117
|
+
facts.macosMajor = Number(version[1]);
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
case 'hw.model':
|
|
122
|
+
facts.model ??= parseText(value);
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return facts;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The one spawn: `command` with `SYSCTL_KEYS` as its arguments and nothing else (no `-n`).
|
|
132
|
+
* Resolves stdout when the program ran, also after a non-zero exit (a key this machine lacks
|
|
133
|
+
* makes sysctl exit 1 while the other keys are printed). Resolves `undefined` when it could not
|
|
134
|
+
* be started, was killed (the timeout) or printed too much. Never rejects.
|
|
135
|
+
*
|
|
136
|
+
* The two parameters exist for the test, which runs a script of its own in place of sysctl.
|
|
137
|
+
*/
|
|
138
|
+
export function spawnSysctl(command = SYSCTL_PATH, timeoutMs = SYSCTL_TIMEOUT_MS) {
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
try {
|
|
141
|
+
execFile(command, [...SYSCTL_KEYS], {
|
|
142
|
+
timeout: timeoutMs,
|
|
143
|
+
maxBuffer: SYSCTL_MAX_OUTPUT_BYTES,
|
|
144
|
+
encoding: 'utf8',
|
|
145
|
+
windowsHide: true,
|
|
146
|
+
// sysctl needs nothing from the server's environment, which can hold a password.
|
|
147
|
+
env: { LC_ALL: 'C' },
|
|
148
|
+
}, (error, stdout) => {
|
|
149
|
+
if (!error)
|
|
150
|
+
return resolve(stdout);
|
|
151
|
+
// A numeric code is an exit status: the program ran. A string code (ENOENT, EACCES,
|
|
152
|
+
// the buffer limit) or a signal means it did not run to its end.
|
|
153
|
+
const ranToEnd = typeof error.code === 'number' && !error.killed && !error.signal;
|
|
154
|
+
resolve(ranToEnd ? stdout : undefined);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
resolve(undefined);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Free bytes on the filesystem that holds `path` (`bavail * bsize`: what an unprivileged
|
|
164
|
+
* process can use), or `undefined` when the filesystem does not say. Not bounded by itself: see
|
|
165
|
+
* `dataDirFreeBytes()`.
|
|
166
|
+
*/
|
|
167
|
+
export async function freeDiskBytesOf(path) {
|
|
168
|
+
try {
|
|
169
|
+
const stat = await statfs(path);
|
|
170
|
+
const free = Number(stat.bavail) * Number(stat.bsize);
|
|
171
|
+
return Number.isFinite(free) && free >= 0 ? free : undefined;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** The one `statfs` that may be pending. While it is, no second one is started. */
|
|
178
|
+
let pendingStatfs;
|
|
179
|
+
/**
|
|
180
|
+
* Free bytes on the data dir's filesystem, bounded. The folder (or, when it does not exist yet,
|
|
181
|
+
* its nearest existing parent) is found with the bounded path probe, which never waits on a
|
|
182
|
+
* dead mount twice; the `statfs` itself is raced against a timeout. `undefined` when the
|
|
183
|
+
* filesystem does not answer in time, or is not known to be a folder.
|
|
184
|
+
*/
|
|
185
|
+
export async function dataDirFreeBytes(deps = {}) {
|
|
186
|
+
// Concurrent probes share one promise in `readHardware()`, so a `statfs` that is still pending
|
|
187
|
+
// here was started by an EARLIER probe and has outlived its timeout: a dead mount. It holds
|
|
188
|
+
// one threadpool worker, and that is the most this module may ever hold.
|
|
189
|
+
if (pendingStatfs)
|
|
190
|
+
return undefined;
|
|
191
|
+
const probeKind = deps.probeKind ?? probePathKind;
|
|
192
|
+
let folder;
|
|
193
|
+
try {
|
|
194
|
+
folder = (deps.dataDir ?? getDataDir)();
|
|
195
|
+
let kind = await probeKind(folder);
|
|
196
|
+
for (let step = 0; kind === 'absent' && step < FREE_DISK_MAX_PARENT_STEPS; step++) {
|
|
197
|
+
const parent = dirname(folder);
|
|
198
|
+
if (parent === folder)
|
|
199
|
+
break;
|
|
200
|
+
folder = parent;
|
|
201
|
+
kind = await probeKind(folder);
|
|
202
|
+
}
|
|
203
|
+
// 'unknown' is a mount that does not answer (or an unreadable path): do not touch it.
|
|
204
|
+
if (kind !== 'directory')
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const started = (deps.freeBytesOf ?? freeDiskBytesOf)(folder).catch(() => undefined);
|
|
211
|
+
pendingStatfs = started;
|
|
212
|
+
const forget = () => {
|
|
213
|
+
if (pendingStatfs === started)
|
|
214
|
+
pendingStatfs = undefined;
|
|
215
|
+
};
|
|
216
|
+
started.then(forget, forget);
|
|
217
|
+
let timer;
|
|
218
|
+
try {
|
|
219
|
+
return await Promise.race([
|
|
220
|
+
started,
|
|
221
|
+
new Promise((resolve) => {
|
|
222
|
+
timer = setTimeout(() => resolve(undefined), deps.timeoutMs ?? FREE_DISK_TIMEOUT_MS);
|
|
223
|
+
timer.unref?.();
|
|
224
|
+
}),
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
if (timer)
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function defaultCpuModel() {
|
|
233
|
+
return os.cpus()[0]?.model;
|
|
234
|
+
}
|
|
235
|
+
/** A dependency that must never break the probe: its value, or `undefined` when it threw or rejected. */
|
|
236
|
+
async function attempt(read) {
|
|
237
|
+
try {
|
|
238
|
+
return await read();
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/** Memory and the three fields derived from it. */
|
|
245
|
+
function memoryFields(memBytes) {
|
|
246
|
+
const bytes = memBytes !== undefined && Number.isFinite(memBytes) && memBytes > 0 ? memBytes : 0;
|
|
247
|
+
return { memBytes: bytes, memGb: formatGb(bytes), memClassGb: memClassGb(bytes) };
|
|
248
|
+
}
|
|
249
|
+
async function probeHardware(deps) {
|
|
250
|
+
const platform = deps.platform ?? process.platform;
|
|
251
|
+
const arch = deps.arch ?? os.arch();
|
|
252
|
+
const totalMemBytes = deps.totalMemBytes ?? os.totalmem;
|
|
253
|
+
const cpuModel = deps.cpuModel ?? defaultCpuModel;
|
|
254
|
+
if (platform !== 'darwin') {
|
|
255
|
+
return { platform, arch, ...memoryFields(await attempt(totalMemBytes)), source: 'not-probed' };
|
|
256
|
+
}
|
|
257
|
+
const [stdout, freeDisk] = await Promise.all([
|
|
258
|
+
attempt(deps.runSysctl ?? (() => spawnSysctl())),
|
|
259
|
+
attempt(deps.freeDiskBytes ?? (() => dataDirFreeBytes())),
|
|
260
|
+
]);
|
|
261
|
+
const disk = freeDisk !== undefined && Number.isFinite(freeDisk) && freeDisk >= 0
|
|
262
|
+
? { freeDiskBytes: freeDisk, freeDiskGb: formatGb(freeDisk) }
|
|
263
|
+
: {};
|
|
264
|
+
const facts = typeof stdout === 'string' ? parseSysctl(stdout) : {};
|
|
265
|
+
if (facts.memBytes === undefined) {
|
|
266
|
+
const chip = await attempt(cpuModel);
|
|
267
|
+
return {
|
|
268
|
+
platform,
|
|
269
|
+
arch,
|
|
270
|
+
...memoryFields(await attempt(totalMemBytes)),
|
|
271
|
+
...(chip ? { chip } : {}),
|
|
272
|
+
...disk,
|
|
273
|
+
source: 'os-fallback',
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const chip = facts.chip ?? (await attempt(cpuModel));
|
|
277
|
+
return {
|
|
278
|
+
platform,
|
|
279
|
+
arch,
|
|
280
|
+
...(facts.arm64 !== undefined ? { arm64: facts.arm64 } : {}),
|
|
281
|
+
...(facts.translated !== undefined ? { translated: facts.translated } : {}),
|
|
282
|
+
...memoryFields(facts.memBytes),
|
|
283
|
+
...(chip ? { chip } : {}),
|
|
284
|
+
...(facts.model !== undefined ? { model: facts.model } : {}),
|
|
285
|
+
...(facts.macosVersion !== undefined ? { macosVersion: facts.macosVersion } : {}),
|
|
286
|
+
...(facts.macosMajor !== undefined ? { macosMajor: facts.macosMajor } : {}),
|
|
287
|
+
...(facts.wiredLimitMb !== undefined ? { wiredLimitMb: facts.wiredLimitMb } : {}),
|
|
288
|
+
...disk,
|
|
289
|
+
source: 'sysctl',
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
let cached;
|
|
293
|
+
let inFlight;
|
|
294
|
+
/**
|
|
295
|
+
* What this machine is. Cached for `HARDWARE_CACHE_TTL_MS`; concurrent callers share one probe.
|
|
296
|
+
* Never rejects.
|
|
297
|
+
*
|
|
298
|
+
* The cache is one per process and does not look at `deps`: within the 60 s a second call
|
|
299
|
+
* returns the first call's answer whatever it injects. A test resets it first.
|
|
300
|
+
*/
|
|
301
|
+
export async function readHardware(deps = {}) {
|
|
302
|
+
const now = deps.now ?? Date.now;
|
|
303
|
+
if (cached) {
|
|
304
|
+
const age = now() - cached.at;
|
|
305
|
+
if (age >= 0 && age < HARDWARE_CACHE_TTL_MS)
|
|
306
|
+
return cached.facts;
|
|
307
|
+
}
|
|
308
|
+
if (inFlight)
|
|
309
|
+
return inFlight;
|
|
310
|
+
const probe = probeHardware(deps)
|
|
311
|
+
.catch(
|
|
312
|
+
// Unreachable by design (every read above is guarded), and still an answer if it is reached.
|
|
313
|
+
() => ({
|
|
314
|
+
platform: deps.platform ?? process.platform,
|
|
315
|
+
arch: deps.arch ?? os.arch(),
|
|
316
|
+
...memoryFields(undefined),
|
|
317
|
+
source: (deps.platform ?? process.platform) === 'darwin' ? 'os-fallback' : 'not-probed',
|
|
318
|
+
}))
|
|
319
|
+
.then((facts) => {
|
|
320
|
+
cached = { at: now(), facts };
|
|
321
|
+
return facts;
|
|
322
|
+
})
|
|
323
|
+
.finally(() => {
|
|
324
|
+
if (inFlight === probe)
|
|
325
|
+
inFlight = undefined;
|
|
326
|
+
});
|
|
327
|
+
inFlight = probe;
|
|
328
|
+
return probe;
|
|
329
|
+
}
|
|
330
|
+
/** Drop the cached probe result and the memory of a pending disk read (tests, and nothing else). */
|
|
331
|
+
export function resetHardwareCache() {
|
|
332
|
+
cached = undefined;
|
|
333
|
+
inFlight = undefined;
|
|
334
|
+
pendingStatfs = undefined;
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=hardware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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kBAAkB;IAChC,MAAM,GAAG,SAAS,CAAC;IACnB,QAAQ,GAAG,SAAS,CAAC;IACrB,aAAa,GAAG,SAAS,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview What the server knows about each catalogue harness on this machine, for the
|
|
3
|
+
* local model recommendation. Server side: this is the one module of src/local-model/ that
|
|
4
|
+
* reads the CLI registry, so `recommend()` can stay pure and name no CLI.
|
|
5
|
+
*
|
|
6
|
+
* `buildHarnessFacts()` walks the catalogue's `harnesses` rows and, for every row:
|
|
7
|
+
* - resolves its `cli` in the CLI registry AT CALL TIME (never in a module-level constant),
|
|
8
|
+
* and leaves the row out when the CLI is unknown, disabled, or has no custom model
|
|
9
|
+
* mechanism (`capabilities.customModelInjection.kind` is `unsupported`);
|
|
10
|
+
* - reports `label` from the registry entry and `installed` from the same probe the page
|
|
11
|
+
* render and `GET /api/clis` use (`utils/cli-installed-probes.ts`), asked once per build;
|
|
12
|
+
* - reports `installable` only for a STOCK CLI that is not installed and whose install
|
|
13
|
+
* command for this platform needs no administrator rights (`installCommandNeedsAdmin()`),
|
|
14
|
+
* and then carries that command as `installCommand`, so the consent screen can print the
|
|
15
|
+
* literal text. The command is the COMPILED stock one (`stockInstallCommand()`), never the
|
|
16
|
+
* one a `clis.json` override supplies: it is exactly what the install job would run, and
|
|
17
|
+
* an override file must not be able to change that;
|
|
18
|
+
* - supplies `acceptsModelId` (`cliAcceptsCustomModelId()`), the test a custom model launch
|
|
19
|
+
* applies to the model id before anything is written.
|
|
20
|
+
*
|
|
21
|
+
* Rules:
|
|
22
|
+
* - No CLI id is compared with a literal here or anywhere: the id comes from the catalogue
|
|
23
|
+
* row and everything else from the registry entry it resolves to.
|
|
24
|
+
* - Read-only: nothing is installed, written or spawned beyond the existing availability
|
|
25
|
+
* probe. An install command is only read as text, never run.
|
|
26
|
+
* - Never throws: a probe that fails reads as "not installed" (with a warning in the log),
|
|
27
|
+
* and the registry's install data still answers `installable`.
|
|
28
|
+
*
|
|
29
|
+
* `cliAcceptsCustomModelId()` composes the two pure pieces the launch path itself calls
|
|
30
|
+
* (`buildCustomModelInjection()` and `matchesPattern()` on the entry's `model` launch param).
|
|
31
|
+
* The launch path keeps that composition inline at two sites in
|
|
32
|
+
* src/web/routes/session-routes.ts (the quick-start `customModel` branch and
|
|
33
|
+
* `POST /api/sessions/:id/custom-model`). A change to the rule there must be made here too,
|
|
34
|
+
* until the three share one helper.
|
|
35
|
+
*/
|
|
36
|
+
import type { CliEntry } from '../config/cli-registry/types.js';
|
|
37
|
+
import { type HarnessFact, type LocalModelCatalog } from '../types.js';
|
|
38
|
+
/** What `buildHarnessFacts()` reads. Each member defaults to the real module; a test overrides what it needs. */
|
|
39
|
+
export interface HarnessFactsDeps {
|
|
40
|
+
/** One CLI of the registry, looked up when the facts are built. */
|
|
41
|
+
getCli: (id: string) => CliEntry | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The availability probe, asked ONCE per build: it answers with a test for single entries.
|
|
44
|
+
* Under vitest the real probe is inert (it finds no CLI), so a test that cares about
|
|
45
|
+
* `installed` passes its own.
|
|
46
|
+
*/
|
|
47
|
+
probeInstalled: () => Promise<(entry: CliEntry) => boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* The install command the install job would run for this CLI on this platform: the compiled
|
|
50
|
+
* stock command, `undefined` for a CLI that is not stock or has none here. Read as text,
|
|
51
|
+
* never run.
|
|
52
|
+
*/
|
|
53
|
+
installCommandFor: (entry: CliEntry) => string | undefined;
|
|
54
|
+
}
|
|
55
|
+
export declare const defaultHarnessFactsDeps: HarnessFactsDeps;
|
|
56
|
+
/**
|
|
57
|
+
* Whether an install command needs administrator rights, read off its text.
|
|
58
|
+
* - `sudo ...` asks for an administrator password.
|
|
59
|
+
* - `brew ...` needs Homebrew, and installing Homebrew needs an administrator (the same rule
|
|
60
|
+
* the installer's no-admin route applies to the CLI menu).
|
|
61
|
+
* `curl ... | bash` installers write into the home directory, and the install runner points an
|
|
62
|
+
* `npm install -g` at a prefix the server user can write, so neither counts.
|
|
63
|
+
*/
|
|
64
|
+
export declare function installCommandNeedsAdmin(command: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a custom model launch of this CLI would accept `modelId`.
|
|
67
|
+
*
|
|
68
|
+
* A CLI whose config alone cannot select the model gets the id forced onto its `model` launch
|
|
69
|
+
* param (the recipe's `launchModel` template). The argv engine DROPS a token that fails the
|
|
70
|
+
* param's pattern, which would start the CLI on its own default provider, so the launch path
|
|
71
|
+
* refuses such an id up front. This is that test: false when the forced value does not match
|
|
72
|
+
* the pattern, and false for a CLI with no custom model mechanism at all.
|
|
73
|
+
*/
|
|
74
|
+
export declare function cliAcceptsCustomModelId(entry: Pick<CliEntry, 'capabilities' | 'launch'>, modelId: string): boolean;
|
|
75
|
+
/** One fact per catalogue harness that resolves in the CLI registry, in catalogue order. */
|
|
76
|
+
export declare function buildHarnessFacts(catalog: LocalModelCatalog, deps?: Partial<HarnessFactsDeps>): Promise<HarnessFact[]>;
|
|
77
|
+
//# sourceMappingURL=harness-facts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness-facts.d.ts","sourceRoot":"","sources":["../../src/local-model/harness-facts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAMhE,OAAO,EAAmB,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExF,iHAAiH;AACjH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,QAAQ,GAAG,SAAS,CAAC;IAC7C;;;;OAIG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC;IAC5D;;;;OAIG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,MAAM,GAAG,SAAS,CAAC;CAC5D;AAED,eAAO,MAAM,uBAAuB,EAAE,gBAOrC,CAAC;AAQF;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjE;AASD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,GAAG,QAAQ,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAelH;AAED,4FAA4F;AAC5F,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,iBAAiB,EAC1B,IAAI,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACnC,OAAO,CAAC,WAAW,EAAE,CAAC,CAiDxB"}
|