@phren/cli 0.2.15 → 0.3.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 +2 -2
- package/dist/agent-instructions.d.ts +12 -0
- package/dist/agent-instructions.js +52 -0
- package/dist/bridge/agent-hook-stores.d.ts +32 -0
- package/dist/bridge/agent-hook-stores.js +67 -0
- package/dist/bridge/agent-hooks.d.ts +195 -2
- package/dist/bridge/agent-hooks.js +1049 -38
- package/dist/bridge/canary.d.ts +27 -0
- package/dist/bridge/canary.js +189 -0
- package/dist/bridge/changes.d.ts +57 -0
- package/dist/bridge/changes.js +403 -0
- package/dist/bridge/client.d.ts +3 -0
- package/dist/bridge/client.js +36 -0
- package/dist/bridge/code-note.d.ts +23 -0
- package/dist/bridge/code-note.js +51 -0
- package/dist/bridge/code-routes.d.ts +151 -0
- package/dist/bridge/code-routes.js +442 -0
- package/dist/bridge/codex-threads.d.ts +27 -0
- package/dist/bridge/codex-threads.js +442 -0
- package/dist/bridge/command.d.ts +7 -0
- package/dist/bridge/command.js +50 -5
- package/dist/bridge/computer-names.d.ts +4 -0
- package/dist/bridge/computer-names.js +16 -0
- package/dist/bridge/computers.d.ts +9 -0
- package/dist/bridge/computers.js +111 -0
- package/dist/bridge/context.d.ts +14 -0
- package/dist/bridge/context.js +149 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +93 -0
- package/dist/bridge/dispatch-hosts.d.ts +23 -0
- package/dist/bridge/dispatch-hosts.js +25 -0
- package/dist/bridge/dispatch-returns.d.ts +125 -0
- package/dist/bridge/dispatch-returns.js +283 -0
- package/dist/bridge/dispatch-tree.d.ts +54 -0
- package/dist/bridge/dispatch-tree.js +198 -0
- package/dist/bridge/dispatch.d.ts +210 -0
- package/dist/bridge/dispatch.js +286 -0
- package/dist/bridge/enroll.d.ts +31 -0
- package/dist/bridge/enroll.js +236 -0
- package/dist/bridge/fanout-messages.d.ts +74 -0
- package/dist/bridge/fanout-messages.js +230 -0
- package/dist/bridge/fanouts.d.ts +160 -0
- package/dist/bridge/fanouts.js +702 -0
- package/dist/bridge/file-range.d.ts +16 -0
- package/dist/bridge/file-range.js +90 -0
- package/dist/bridge/files.d.ts +20 -0
- package/dist/bridge/files.js +54 -0
- package/dist/bridge/git-publish.d.ts +23 -0
- package/dist/bridge/git-publish.js +145 -0
- package/dist/bridge/git-worktrees.d.ts +21 -0
- package/dist/bridge/git-worktrees.js +150 -0
- package/dist/bridge/git.d.ts +54 -0
- package/dist/bridge/git.js +552 -0
- package/dist/bridge/grants.d.ts +31 -0
- package/dist/bridge/grants.js +181 -0
- package/dist/bridge/hand-off.d.ts +79 -0
- package/dist/bridge/hand-off.js +151 -0
- package/dist/bridge/health.d.ts +128 -0
- package/dist/bridge/health.js +260 -0
- package/dist/bridge/herdr.d.ts +79 -6
- package/dist/bridge/herdr.js +292 -27
- package/dist/bridge/hook-main.js +2 -0
- package/dist/bridge/install.d.ts +28 -1
- package/dist/bridge/install.js +225 -38
- package/dist/bridge/launch-worktree.d.ts +21 -0
- package/dist/bridge/launch-worktree.js +70 -0
- package/dist/bridge/limits.d.ts +20 -0
- package/dist/bridge/limits.js +65 -0
- package/dist/bridge/locate.d.ts +16 -0
- package/dist/bridge/locate.js +75 -0
- package/dist/bridge/metrics.d.ts +29 -0
- package/dist/bridge/metrics.js +71 -0
- package/dist/bridge/model-switch.d.ts +35 -0
- package/dist/bridge/model-switch.js +250 -0
- package/dist/bridge/models.d.ts +46 -0
- package/dist/bridge/models.js +257 -0
- package/dist/bridge/opencode-approvals.d.ts +6 -0
- package/dist/bridge/opencode-approvals.js +60 -0
- package/dist/bridge/pane-text.d.ts +15 -0
- package/dist/bridge/pane-text.js +23 -0
- package/dist/bridge/peers.d.ts +27 -0
- package/dist/bridge/peers.js +130 -0
- package/dist/bridge/projects.d.ts +12 -1
- package/dist/bridge/projects.js +268 -20
- package/dist/bridge/protocol.d.ts +35 -2
- package/dist/bridge/protocol.js +61 -7
- package/dist/bridge/push.d.ts +83 -0
- package/dist/bridge/push.js +199 -0
- package/dist/bridge/questions.d.ts +38 -0
- package/dist/bridge/questions.js +205 -0
- package/dist/bridge/schedule-format.d.ts +103 -0
- package/dist/bridge/schedule-format.js +266 -0
- package/dist/bridge/schedule-launch.d.ts +11 -0
- package/dist/bridge/schedule-launch.js +169 -0
- package/dist/bridge/schedule-watch.d.ts +54 -0
- package/dist/bridge/schedule-watch.js +255 -0
- package/dist/bridge/schedules.d.ts +48 -0
- package/dist/bridge/schedules.js +205 -0
- package/dist/bridge/server-launch.d.ts +14 -0
- package/dist/bridge/server-launch.js +218 -0
- package/dist/bridge/server-overview.d.ts +45 -0
- package/dist/bridge/server-overview.js +102 -0
- package/dist/bridge/server-pane-routes.d.ts +36 -0
- package/dist/bridge/server-pane-routes.js +479 -0
- package/dist/bridge/server-routes.d.ts +108 -0
- package/dist/bridge/server-routes.js +556 -0
- package/dist/bridge/server-stream.d.ts +46 -0
- package/dist/bridge/server-stream.js +253 -0
- package/dist/bridge/server.d.ts +3 -15
- package/dist/bridge/server.js +162 -264
- package/dist/bridge/session-servers.d.ts +24 -0
- package/dist/bridge/session-servers.js +136 -0
- package/dist/bridge/side-questions.d.ts +74 -0
- package/dist/bridge/side-questions.js +252 -0
- package/dist/bridge/simulators.d.ts +28 -0
- package/dist/bridge/simulators.js +198 -0
- package/dist/bridge/speech-transcribe.d.ts +24 -0
- package/dist/bridge/speech-transcribe.js +124 -0
- package/dist/bridge/speech.d.ts +35 -0
- package/dist/bridge/speech.js +98 -0
- package/dist/bridge/steps.d.ts +13 -0
- package/dist/bridge/steps.js +222 -0
- package/dist/bridge/tab-activity.d.ts +18 -0
- package/dist/bridge/tab-activity.js +99 -0
- package/dist/bridge/terminal-choice.d.ts +64 -0
- package/dist/bridge/terminal-choice.js +281 -0
- package/dist/bridge/transcript-claude.d.ts +22 -0
- package/dist/bridge/transcript-claude.js +353 -0
- package/dist/bridge/transcript-codex.d.ts +30 -0
- package/dist/bridge/transcript-codex.js +282 -0
- package/dist/bridge/transcript-copilot.d.ts +4 -0
- package/dist/bridge/transcript-copilot.js +14 -0
- package/dist/bridge/transcript-opencode.d.ts +5 -0
- package/dist/bridge/transcript-opencode.js +26 -0
- package/dist/bridge/transcript-preview.d.ts +96 -0
- package/dist/bridge/transcript-preview.js +491 -0
- package/dist/bridge/transcripts.d.ts +81 -4
- package/dist/bridge/transcripts.js +332 -67
- package/dist/bridge/transport.d.ts +3 -0
- package/dist/bridge/transport.js +96 -15
- package/dist/bridge/uploads.d.ts +15 -0
- package/dist/bridge/uploads.js +44 -2
- package/dist/bridge/usage.d.ts +124 -0
- package/dist/bridge/usage.js +859 -0
- package/dist/bridge-hook.mjs +46545 -21051
- package/dist/cli/actions.js +14 -1
- package/dist/cli/config-policy.js +25 -0
- package/dist/cli/config-proactivity.d.ts +3 -1
- package/dist/cli/config-proactivity.js +35 -3
- package/dist/cli/config.js +4 -1
- package/dist/cli/extract.d.ts +0 -8
- package/dist/cli/extract.js +4 -7
- package/dist/cli/govern.js +5 -2
- package/dist/cli/hooks-globs.js +1 -1
- package/dist/cli/hooks.d.ts +1 -1
- package/dist/cli/hooks.js +9 -7
- package/dist/cli/namespaces-projects.js +12 -6
- package/dist/cli/namespaces-store.js +37 -6
- package/dist/cli/namespaces-tasks.js +1 -1
- package/dist/cli/schedules.d.ts +1 -0
- package/dist/cli/schedules.js +164 -0
- package/dist/cli/session-background.js +1 -1
- package/dist/cli/session-git.d.ts +8 -5
- package/dist/cli/session-git.js +45 -120
- package/dist/cli/session-start.js +3 -1
- package/dist/cli/session-stop.js +19 -8
- package/dist/cli/team.js +13 -10
- package/dist/cli-handlers.d.ts +1 -1
- package/dist/cli-handlers.js +8 -4
- package/dist/cli-help.d.ts +5 -4
- package/dist/cli-help.js +15 -15
- package/dist/cli-registry.d.ts +4 -1
- package/dist/cli-registry.js +119 -6
- package/dist/content/archive.js +2 -2
- package/dist/content/citation.d.ts +11 -0
- package/dist/content/citation.js +18 -0
- package/dist/content/learning.js +2 -0
- package/dist/content/summarize.d.ts +14 -15
- package/dist/content/summarize.js +60 -5
- package/dist/content/validate.d.ts +17 -4
- package/dist/content/validate.js +200 -122
- package/dist/core/project-registry.d.ts +26 -0
- package/dist/core/project-registry.js +573 -0
- package/dist/core/project.js +2 -3
- package/dist/data/access.d.ts +16 -1
- package/dist/data/access.js +31 -3
- package/dist/data/tasks.d.ts +18 -3
- package/dist/data/tasks.js +8 -7
- package/dist/entrypoint.js +44 -10
- package/dist/fanout/adapters/claude.d.ts +2 -0
- package/dist/fanout/adapters/claude.js +7 -0
- package/dist/fanout/adapters/codex.d.ts +2 -0
- package/dist/fanout/adapters/codex.js +9 -0
- package/dist/fanout/adapters/opencode.d.ts +4 -0
- package/dist/fanout/adapters/opencode.js +9 -0
- package/dist/fanout/adapters/types.d.ts +21 -0
- package/dist/fanout/adapters/types.js +3 -0
- package/dist/fanout/command.d.ts +2 -0
- package/dist/fanout/command.js +78 -0
- package/dist/fanout/launcher.d.ts +27 -0
- package/dist/fanout/launcher.js +156 -0
- package/dist/fanout/opencode-serve.d.ts +24 -0
- package/dist/fanout/opencode-serve.js +191 -0
- package/dist/fanout/picker.d.ts +91 -0
- package/dist/fanout/picker.js +51 -0
- package/dist/fanout/usage.d.ts +5 -0
- package/dist/fanout/usage.js +51 -0
- package/dist/fanout/watchdog.d.ts +10 -0
- package/dist/fanout/watchdog.js +27 -0
- package/dist/filenames.d.ts +9 -0
- package/dist/filenames.js +11 -0
- package/dist/finding/context.js +4 -22
- package/dist/generated/memory-ui-graph.browser.js +525 -419
- package/dist/governance/policy-constants.d.ts +11 -0
- package/dist/governance/policy-constants.js +9 -0
- package/dist/governance/policy.d.ts +5 -8
- package/dist/governance/policy.js +11 -8
- package/dist/graph-core/camera.d.ts +24 -0
- package/dist/graph-core/camera.js +18 -0
- package/dist/graph-core/index.d.ts +2 -0
- package/dist/graph-core/index.js +2 -0
- package/dist/graph-core/labels.d.ts +77 -0
- package/dist/graph-core/labels.js +124 -0
- package/dist/graph-core/model.d.ts +13 -0
- package/dist/graph-core/model.js +33 -0
- package/dist/graph-core/types.d.ts +2 -0
- package/dist/home-paths.d.ts +7 -0
- package/dist/home-paths.js +21 -0
- package/dist/hooks.d.ts +3 -15
- package/dist/hooks.js +14 -1
- package/dist/index.js +24 -2
- package/dist/init/guard-globals.d.ts +1 -1
- package/dist/init/guard-globals.js +4 -4
- package/dist/init/init-configure.js +3 -3
- package/dist/init/init-uninstall.js +15 -5
- package/dist/init/init-walkthrough.js +1 -1
- package/dist/init/init.js +26 -6
- package/dist/init/management-preset.d.ts +1 -1
- package/dist/init/management-preset.js +2 -2
- package/dist/init/preferences.js +1 -1
- package/dist/init/self-wiring.js +1 -1
- package/dist/init/setup.d.ts +3 -26
- package/dist/init/setup.js +68 -593
- package/dist/init/shared.js +2 -0
- package/dist/init/store-gitignore.d.ts +1 -6
- package/dist/init/store-gitignore.js +2 -8
- package/dist/init/teardown.d.ts +1 -1
- package/dist/init/teardown.js +2 -2
- package/dist/link/context-imports.d.ts +15 -0
- package/dist/link/context-imports.js +101 -0
- package/dist/link/context.js +1 -1
- package/dist/link/doctor.d.ts +22 -1
- package/dist/link/doctor.js +128 -58
- package/dist/link/link.js +29 -61
- package/dist/link/refresh.js +2 -2
- package/dist/link/skills.js +26 -5
- package/dist/machine-identity.d.ts +3 -0
- package/dist/machine-identity.js +6 -0
- package/dist/mcp/profile.d.ts +2 -19
- package/dist/mcp/profile.js +64 -22
- package/dist/memory-ui-graph.runtime.js +525 -419
- package/dist/modules/code-package.d.ts +16 -0
- package/dist/modules/code-package.js +160 -0
- package/dist/modules/command.d.ts +2 -0
- package/dist/modules/command.js +67 -0
- package/dist/modules/config.d.ts +4 -0
- package/dist/modules/config.js +70 -0
- package/dist/modules/manifest.d.ts +41 -0
- package/dist/modules/manifest.js +1 -0
- package/dist/modules/provision.d.ts +3 -0
- package/dist/modules/provision.js +84 -0
- package/dist/modules/registry.d.ts +16 -0
- package/dist/modules/registry.js +250 -0
- package/dist/modules/runtime.d.ts +15 -0
- package/dist/modules/runtime.js +59 -0
- package/dist/package-metadata.js +10 -2
- package/dist/phren-dotenv.js +4 -2
- package/dist/phren-paths.d.ts +3 -2
- package/dist/phren-paths.js +4 -5
- package/dist/profile-store.js +43 -8
- package/dist/project-config.d.ts +19 -1
- package/dist/project-config.js +29 -3
- package/dist/project-topics.d.ts +1 -0
- package/dist/project-topics.js +13 -10
- package/dist/provider-adapters.js +1 -4
- package/dist/query-correlation.js +6 -6
- package/dist/session/artifacts.js +5 -5
- package/dist/session/checkpoints.js +5 -0
- package/dist/session/utils.d.ts +2 -2
- package/dist/session/utils.js +6 -6
- package/dist/shared/content.d.ts +1 -1
- package/dist/shared/content.js +1 -1
- package/dist/shared/data-utils.js +1 -1
- package/dist/shared/fragment-graph.d.ts +1 -1
- package/dist/shared/fragment-graph.js +5 -5
- package/dist/shared/index.js +48 -7
- package/dist/shared/retrieval.d.ts +18 -3
- package/dist/shared/retrieval.js +101 -12
- package/dist/shared/search-fallback.js +4 -6
- package/dist/shared/sqljs.d.ts +2 -0
- package/dist/shared/sqljs.js +4 -2
- package/dist/shared.d.ts +0 -1
- package/dist/shared.js +0 -1
- package/dist/shell/input.d.ts +1 -5
- package/dist/shell/input.js +16 -10
- package/dist/shell/palette.d.ts +2 -2
- package/dist/shell/palette.js +3 -7
- package/dist/shell/render.d.ts +3 -1
- package/dist/shell/render.js +4 -4
- package/dist/shell/shell.js +4 -1
- package/dist/shell/types.d.ts +1 -0
- package/dist/shell/types.js +4 -0
- package/dist/shell/view.d.ts +0 -4
- package/dist/shell/view.js +19 -27
- package/dist/skill/registry.js +25 -17
- package/dist/skill/state.d.ts +3 -0
- package/dist/skill/state.js +13 -7
- package/dist/status.js +38 -17
- package/dist/store-registry.d.ts +44 -18
- package/dist/store-registry.js +169 -60
- package/dist/store-weight.d.ts +1 -6
- package/dist/store-weight.js +4 -2
- package/dist/sync/auth-doctor.d.ts +8 -0
- package/dist/sync/auth-doctor.js +27 -0
- package/dist/sync/auth.d.ts +27 -0
- package/dist/sync/auth.js +114 -0
- package/dist/sync/conflict-resolve.d.ts +9 -0
- package/dist/sync/conflict-resolve.js +146 -0
- package/dist/sync/git-state.d.ts +4 -0
- package/dist/sync/git-state.js +49 -0
- package/dist/sync/outcome.d.ts +34 -0
- package/dist/sync/outcome.js +57 -0
- package/dist/sync/pull.d.ts +15 -7
- package/dist/sync/pull.js +84 -35
- package/dist/sync/store-merge.d.ts +29 -0
- package/dist/sync/store-merge.js +137 -0
- package/dist/sync/task-merge.d.ts +22 -0
- package/dist/sync/task-merge.js +158 -0
- package/dist/task/github.js +1 -1
- package/dist/task/lifecycle.d.ts +5 -0
- package/dist/task/lifecycle.js +67 -23
- package/dist/terminal-text.d.ts +5 -0
- package/dist/terminal-text.js +11 -0
- package/dist/test-global-setup.js +7 -0
- package/dist/tool-registry.d.ts +1 -1
- package/dist/tool-registry.js +3 -1
- package/dist/tools/code.d.ts +3 -0
- package/dist/tools/code.js +186 -0
- package/dist/tools/config.js +8 -0
- package/dist/tools/data.js +14 -7
- package/dist/tools/dispatch.d.ts +2 -0
- package/dist/tools/dispatch.js +66 -0
- package/dist/tools/finding.d.ts +11 -0
- package/dist/tools/finding.js +180 -123
- package/dist/tools/ops.js +5 -2
- package/dist/tools/search.js +21 -8
- package/dist/tools/session.js +21 -22
- package/dist/tools/tasks.js +8 -2
- package/dist/tools/types.d.ts +2 -2
- package/dist/tools/types.js +2 -2
- package/dist/ui/assets.js +1 -1
- package/dist/ui/data.js +14 -15
- package/dist/ui/deep-void.d.ts +1 -1
- package/dist/ui/deep-void.js +0 -1
- package/dist/ui/graph-chrome.d.ts +1 -1
- package/dist/ui/graph-chrome.js +51 -0
- package/dist/ui/page.js +5 -5
- package/dist/ui/scripts.js +67 -30
- package/dist/ui/server.js +52 -7
- package/dist/update.js +22 -11
- package/dist/utils-fts.js +1 -0
- package/dist/utils-helpers.d.ts +7 -0
- package/dist/utils-helpers.js +17 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +49 -7
- package/plugins/opencode/phren-transcript.js +340 -0
- package/starter/README.md +4 -4
- package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
- package/starter/global/skills/conductor/SKILL.md +106 -0
- package/starter/global/skills/fanout/SKILL.md +20 -0
- package/starter/global/skills/phren-discover/SKILL.md +6 -6
- package/starter/global/skills/phren-init/SKILL.md +4 -4
- package/starter/global/skills/phren-sync/SKILL.md +3 -3
- package/starter/templates/frontend/reference/README.md +1 -1
- package/starter/templates/library/reference/README.md +1 -1
- package/starter/templates/monorepo/reference/README.md +1 -1
- package/starter/templates/python-project/reference/README.md +1 -1
- /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
- /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
package/dist/bridge/uploads.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, readdir, lstat, unlink, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readdir, lstat, realpath, readFile, stat, unlink, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { bridgeRoot, BridgeError, MAX_FRAME } from "./protocol.js";
|
|
@@ -8,9 +8,14 @@ export function imageBytes(bytes) {
|
|
|
8
8
|
|| /^GIF8[79]a/.test(bytes.subarray(0, 6).toString())
|
|
9
9
|
|| (bytes.subarray(0, 4).toString() === "RIFF" && bytes.subarray(8, 12).toString() === "WEBP");
|
|
10
10
|
}
|
|
11
|
+
export const IMAGE_NAME = /\.(png|jpe?g|gif|webp)$/i;
|
|
11
12
|
let uploadQueue = Promise.resolve();
|
|
13
|
+
/** Stores a file the phone sent under uploads/<session>/. A name with an
|
|
14
|
+
* image extension must hold image bytes; anything else is kept as-is. */
|
|
12
15
|
export async function saveUpload(session, name, bytes) {
|
|
13
|
-
if (!bytes.length || bytes.length > MAX_FRAME
|
|
16
|
+
if (!bytes.length || bytes.length > MAX_FRAME)
|
|
17
|
+
throw new BridgeError(400, "The file is empty or too large.");
|
|
18
|
+
if (IMAGE_NAME.test(name) && !imageBytes(bytes))
|
|
14
19
|
throw new BridgeError(400, "Choose a PNG, JPEG, GIF, or WebP image.");
|
|
15
20
|
let saved = "";
|
|
16
21
|
const task = uploadQueue.catch(() => { }).then(async () => {
|
|
@@ -43,3 +48,40 @@ export async function saveUpload(session, name, bytes) {
|
|
|
43
48
|
await task;
|
|
44
49
|
return saved;
|
|
45
50
|
}
|
|
51
|
+
/** What the phone has put in one folder, newest first. */
|
|
52
|
+
export async function listUploads(session) {
|
|
53
|
+
const folder = path.join(bridgeRoot(), "uploads", session);
|
|
54
|
+
const entries = await readdir(folder, { withFileTypes: true }).catch(() => []);
|
|
55
|
+
const files = [];
|
|
56
|
+
for (const entry of entries) {
|
|
57
|
+
if (!entry.isFile())
|
|
58
|
+
continue;
|
|
59
|
+
const file = path.join(folder, entry.name), metadata = await stat(file);
|
|
60
|
+
files.push({ name: entry.name.replace(/^[0-9a-f-]{36}-/, ""), path: file, size: metadata.size, modified: metadata.mtime.toISOString() });
|
|
61
|
+
}
|
|
62
|
+
return files.sort((a, b) => b.modified.localeCompare(a.modified)).slice(0, 200);
|
|
63
|
+
}
|
|
64
|
+
/** The bytes of one image the phone put under uploads/, by the absolute
|
|
65
|
+
* path the transcript names. Served only when the path resolves (through
|
|
66
|
+
* any link) to a regular file inside the uploads folder whose bytes are
|
|
67
|
+
* an image; anything else — outside, traversal, a note — is 404. */
|
|
68
|
+
export async function uploadImage(requested) {
|
|
69
|
+
const missing = new BridgeError(404, "This image is not one of the phone's uploads.");
|
|
70
|
+
if (!requested || requested.length > 4096 || !path.isAbsolute(requested))
|
|
71
|
+
throw missing;
|
|
72
|
+
const root = await realpath(path.join(bridgeRoot(), "uploads")).catch(() => undefined);
|
|
73
|
+
const file = await realpath(requested).catch(() => undefined);
|
|
74
|
+
if (!root || !file || !file.startsWith(root + path.sep))
|
|
75
|
+
throw missing;
|
|
76
|
+
const metadata = await stat(file);
|
|
77
|
+
if (!metadata.isFile())
|
|
78
|
+
throw missing;
|
|
79
|
+
if (metadata.size > 8_388_608)
|
|
80
|
+
throw new BridgeError(413, "This image is too large.");
|
|
81
|
+
const bytes = await readFile(file);
|
|
82
|
+
if (bytes.length > 8_388_608)
|
|
83
|
+
throw new BridgeError(413, "This image is too large.");
|
|
84
|
+
if (!imageBytes(bytes))
|
|
85
|
+
throw missing;
|
|
86
|
+
return bytes;
|
|
87
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
export interface UsageWindow {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
/** A percentage is omitted rather than invented when a service has no limit. */
|
|
6
|
+
usedPercent?: number;
|
|
7
|
+
/** Local Go-ledger values; quota readers deliberately do not use these. */
|
|
8
|
+
usedUSD?: number;
|
|
9
|
+
limitUSD?: number;
|
|
10
|
+
usedTokens?: number;
|
|
11
|
+
resetsAt?: string;
|
|
12
|
+
asOf?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UsageSpend {
|
|
15
|
+
amountUSD: number;
|
|
16
|
+
period: "rolling_7_days" | "rolling_30_days" | "calendar_week";
|
|
17
|
+
}
|
|
18
|
+
export interface AccountUsage {
|
|
19
|
+
source: "codex" | "claude" | "opencode" | "opencode-go" | "openrouter";
|
|
20
|
+
windows: UsageWindow[];
|
|
21
|
+
updatedAt?: string;
|
|
22
|
+
message?: string;
|
|
23
|
+
spend?: UsageSpend;
|
|
24
|
+
/** Opaque key identity used only to avoid counting one OpenRouter key twice. */
|
|
25
|
+
accountId?: string;
|
|
26
|
+
/** Which Claude report fed this account: the status-line rate_limits payload
|
|
27
|
+
* or the OAuth usage endpoint. Per-model windows the status line never
|
|
28
|
+
* carries document their own age through each window's asOf instead. */
|
|
29
|
+
origin?: "status-line" | "oauth";
|
|
30
|
+
}
|
|
31
|
+
export declare function codexUsage(value: unknown, now?: Date): AccountUsage;
|
|
32
|
+
/** Parse OpenCode's own cost ledger. `stats --days 7` is a rolling local view. */
|
|
33
|
+
export declare function openCodeUsage(output: string, now?: Date): AccountUsage;
|
|
34
|
+
/** Read the authoritative cost that OpenCode records for its local sessions. */
|
|
35
|
+
export declare function readOpenCodeUsage(executable?: string, now?: Date): Promise<AccountUsage>;
|
|
36
|
+
/** Not installed, not signed in and a failing command each say so, with the command's own first line. */
|
|
37
|
+
export declare function openCodeFailure(error: unknown): string;
|
|
38
|
+
/** OpenCode's OpenRouter key stays local and is used only with OpenRouter. */
|
|
39
|
+
export declare function readOpenRouterKey(): Promise<string | undefined>;
|
|
40
|
+
/** OpenCode Go's key stays local and is sent only to the Go gateway. */
|
|
41
|
+
export declare function readOpenCodeGoKey(): Promise<string | undefined>;
|
|
42
|
+
type GoPeriod = "5h" | "7d" | "30d";
|
|
43
|
+
type GoLimit = {
|
|
44
|
+
limitUSD: number;
|
|
45
|
+
resetsAt?: string;
|
|
46
|
+
};
|
|
47
|
+
type GoLimits = Map<string, Partial<Record<GoPeriod, GoLimit>>>;
|
|
48
|
+
type GoTotals = Map<string, Record<GoPeriod, {
|
|
49
|
+
usedUSD: number;
|
|
50
|
+
usedTokens: number;
|
|
51
|
+
}>>;
|
|
52
|
+
/** Best-effort gateway discovery. All four requests are independent because
|
|
53
|
+
* undocumented routes vary by OpenCode release and account. */
|
|
54
|
+
export declare function fetchOpenCodeGoLimits(key: string, fetchImpl?: typeof fetch): Promise<GoLimits>;
|
|
55
|
+
/** Sum only completed OpenCode Go fan-outs. Their ledger stays on the
|
|
56
|
+
* computer and malformed jobs are ignored rather than becoming usage. */
|
|
57
|
+
export declare function readOpenCodeGoLedger(root?: string, now?: Date): Promise<GoTotals>;
|
|
58
|
+
export declare function readOpenCodeGoUsage(now?: Date, options?: {
|
|
59
|
+
root?: string;
|
|
60
|
+
readKey?: () => Promise<string | undefined>;
|
|
61
|
+
fetchImpl?: typeof fetch;
|
|
62
|
+
}): Promise<AccountUsage>;
|
|
63
|
+
/** OpenRouter reports the current UTC calendar week's charged usage per key. */
|
|
64
|
+
export declare function fetchOpenRouterUsage(key: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
65
|
+
/** Claude Code's documented status-line payload: rate_limits carries the
|
|
66
|
+
* five_hour and seven_day windows (the 5h/7d unified limits) and, when the
|
|
67
|
+
* build emits them, per-model keys such as seven_day_fable. Every window
|
|
68
|
+
* keeps its own reset time; a per-model window is its own weekly allowance
|
|
69
|
+
* with its own denominator, not a subset of seven_day, so it can show a
|
|
70
|
+
* higher percentage without contradicting the all-models window. */
|
|
71
|
+
export declare function claudeUsage(value: unknown, now?: Date): AccountUsage;
|
|
72
|
+
/**
|
|
73
|
+
* Claude's per-model weekly windows (Fable today) never reach the status
|
|
74
|
+
* line, so they come from the snapshot Claude Code itself keeps of its usage
|
|
75
|
+
* endpoint in ~/.claude.json — refreshed whenever Claude opens /usage or
|
|
76
|
+
* checks a limit. Each window carries the snapshot's own time so the phone
|
|
77
|
+
* can say how old it is. No sign-in token is read or sent.
|
|
78
|
+
*/
|
|
79
|
+
export declare function claudeScopedWindows(config: unknown, now?: Date): UsageWindow[];
|
|
80
|
+
/**
|
|
81
|
+
* The OAuth usage endpoint Claude Code itself reads, mapped to the same
|
|
82
|
+
* windows the status-line snapshot produces. `limits` is the structured
|
|
83
|
+
* list (session, weekly_all, weekly_scoped with the model name); the older
|
|
84
|
+
* per-key fields are ignored because `limits` already carries them.
|
|
85
|
+
*/
|
|
86
|
+
export declare function claudeOAuthUsage(value: unknown, now?: Date): AccountUsage;
|
|
87
|
+
/**
|
|
88
|
+
* Claude Code's own sign-in token, read locally and used only against
|
|
89
|
+
* Anthropic's usage endpoint — never persisted, logged, or sent elsewhere.
|
|
90
|
+
* The file is authoritative off macOS; macOS keeps it in the login keychain,
|
|
91
|
+
* with the file left stale after a refresh.
|
|
92
|
+
*/
|
|
93
|
+
export declare function readClaudeToken(execSecurity?: typeof execFile.__promisify__, platform?: NodeJS.Platform): Promise<string | undefined>;
|
|
94
|
+
/** Fetch live limits; any failure falls back to the local snapshot. */
|
|
95
|
+
export declare function fetchClaudeUsage(token: string, fetchImpl?: typeof fetch, now?: Date): Promise<AccountUsage>;
|
|
96
|
+
/** Only initialize and read limits. Never create a thread, prompt, or login. */
|
|
97
|
+
export declare function readCodexLimits(executable?: string): Promise<AccountUsage>;
|
|
98
|
+
export declare class AccountUsageReader {
|
|
99
|
+
private readCodex;
|
|
100
|
+
private now;
|
|
101
|
+
private readClaudeLive;
|
|
102
|
+
private readOpenCode;
|
|
103
|
+
private readOpenRouter;
|
|
104
|
+
private readOpenCodeGo;
|
|
105
|
+
private cached?;
|
|
106
|
+
private pending?;
|
|
107
|
+
private claudeCached?;
|
|
108
|
+
private claudePending?;
|
|
109
|
+
private spendingCached?;
|
|
110
|
+
private spendingPending?;
|
|
111
|
+
constructor(readCodex?: typeof readCodexLimits, now?: () => number, readClaudeLive?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCode?: (now: Date) => Promise<AccountUsage>, readOpenRouter?: (now: Date) => Promise<AccountUsage | undefined>, readOpenCodeGo?: (now: Date) => Promise<AccountUsage>);
|
|
112
|
+
read(): Promise<{
|
|
113
|
+
accounts: AccountUsage[];
|
|
114
|
+
}>;
|
|
115
|
+
private spending;
|
|
116
|
+
/** Live first, so the phone's minute-by-minute poll keeps Claude current
|
|
117
|
+
* even when Claude Code is not running; the local snapshot is the backup. */
|
|
118
|
+
private claude;
|
|
119
|
+
private snapshotClaude;
|
|
120
|
+
}
|
|
121
|
+
/** Wrap an existing status line, preserving its input, output and options. */
|
|
122
|
+
export declare function usageStatusLine(current: unknown, program: string, remove: boolean): unknown;
|
|
123
|
+
export declare function captureClaudeUsage(original: string): Promise<void>;
|
|
124
|
+
export {};
|