@gtc6244/immediacy-daemon 0.1.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.
Files changed (133) hide show
  1. package/dist/src/actions.d.ts +22 -0
  2. package/dist/src/actions.js +44 -0
  3. package/dist/src/actions.js.map +1 -0
  4. package/dist/src/agent/agent.d.ts +89 -0
  5. package/dist/src/agent/agent.js +22 -0
  6. package/dist/src/agent/agent.js.map +1 -0
  7. package/dist/src/agent/claude.d.ts +70 -0
  8. package/dist/src/agent/claude.js +404 -0
  9. package/dist/src/agent/claude.js.map +1 -0
  10. package/dist/src/agent/codex.d.ts +44 -0
  11. package/dist/src/agent/codex.js +303 -0
  12. package/dist/src/agent/codex.js.map +1 -0
  13. package/dist/src/agent/mock.d.ts +31 -0
  14. package/dist/src/agent/mock.js +155 -0
  15. package/dist/src/agent/mock.js.map +1 -0
  16. package/dist/src/agent/model-error.d.ts +8 -0
  17. package/dist/src/agent/model-error.js +25 -0
  18. package/dist/src/agent/model-error.js.map +1 -0
  19. package/dist/src/agent/openrouter.d.ts +38 -0
  20. package/dist/src/agent/openrouter.js +60 -0
  21. package/dist/src/agent/openrouter.js.map +1 -0
  22. package/dist/src/agent/workspace-scope.d.ts +25 -0
  23. package/dist/src/agent/workspace-scope.js +71 -0
  24. package/dist/src/agent/workspace-scope.js.map +1 -0
  25. package/dist/src/allowlist.d.ts +56 -0
  26. package/dist/src/allowlist.js +141 -0
  27. package/dist/src/allowlist.js.map +1 -0
  28. package/dist/src/chatlog.d.ts +50 -0
  29. package/dist/src/chatlog.js +179 -0
  30. package/dist/src/chatlog.js.map +1 -0
  31. package/dist/src/cli/paths.d.ts +40 -0
  32. package/dist/src/cli/paths.js +76 -0
  33. package/dist/src/cli/paths.js.map +1 -0
  34. package/dist/src/cli/service.d.ts +20 -0
  35. package/dist/src/cli/service.js +245 -0
  36. package/dist/src/cli/service.js.map +1 -0
  37. package/dist/src/cli.d.ts +2 -0
  38. package/dist/src/cli.js +227 -0
  39. package/dist/src/cli.js.map +1 -0
  40. package/dist/src/config.d.ts +33 -0
  41. package/dist/src/config.js +122 -0
  42. package/dist/src/config.js.map +1 -0
  43. package/dist/src/credentials.d.ts +38 -0
  44. package/dist/src/credentials.js +120 -0
  45. package/dist/src/credentials.js.map +1 -0
  46. package/dist/src/crypto.d.ts +49 -0
  47. package/dist/src/crypto.js +202 -0
  48. package/dist/src/crypto.js.map +1 -0
  49. package/dist/src/daemon-identity.d.ts +31 -0
  50. package/dist/src/daemon-identity.js +97 -0
  51. package/dist/src/daemon-identity.js.map +1 -0
  52. package/dist/src/envelope.d.ts +14 -0
  53. package/dist/src/envelope.js +28 -0
  54. package/dist/src/envelope.js.map +1 -0
  55. package/dist/src/events.d.ts +40 -0
  56. package/dist/src/events.js +24 -0
  57. package/dist/src/events.js.map +1 -0
  58. package/dist/src/forward.d.ts +51 -0
  59. package/dist/src/forward.js +170 -0
  60. package/dist/src/forward.js.map +1 -0
  61. package/dist/src/fs-scope.d.ts +17 -0
  62. package/dist/src/fs-scope.js +47 -0
  63. package/dist/src/fs-scope.js.map +1 -0
  64. package/dist/src/github.d.ts +70 -0
  65. package/dist/src/github.js +178 -0
  66. package/dist/src/github.js.map +1 -0
  67. package/dist/src/gitops.d.ts +113 -0
  68. package/dist/src/gitops.js +557 -0
  69. package/dist/src/gitops.js.map +1 -0
  70. package/dist/src/hub.d.ts +50 -0
  71. package/dist/src/hub.js +92 -0
  72. package/dist/src/hub.js.map +1 -0
  73. package/dist/src/index.d.ts +22 -0
  74. package/dist/src/index.js +56 -0
  75. package/dist/src/index.js.map +1 -0
  76. package/dist/src/jobs/scheduler.d.ts +94 -0
  77. package/dist/src/jobs/scheduler.js +373 -0
  78. package/dist/src/jobs/scheduler.js.map +1 -0
  79. package/dist/src/jobs/store.d.ts +33 -0
  80. package/dist/src/jobs/store.js +111 -0
  81. package/dist/src/jobs/store.js.map +1 -0
  82. package/dist/src/log.d.ts +61 -0
  83. package/dist/src/log.js +166 -0
  84. package/dist/src/log.js.map +1 -0
  85. package/dist/src/migrate-state-dir.d.ts +1 -0
  86. package/dist/src/migrate-state-dir.js +47 -0
  87. package/dist/src/migrate-state-dir.js.map +1 -0
  88. package/dist/src/models.d.ts +36 -0
  89. package/dist/src/models.js +71 -0
  90. package/dist/src/models.js.map +1 -0
  91. package/dist/src/permission-gate.d.ts +48 -0
  92. package/dist/src/permission-gate.js +93 -0
  93. package/dist/src/permission-gate.js.map +1 -0
  94. package/dist/src/permission-scope.d.ts +77 -0
  95. package/dist/src/permission-scope.js +244 -0
  96. package/dist/src/permission-scope.js.map +1 -0
  97. package/dist/src/ports.d.ts +71 -0
  98. package/dist/src/ports.js +216 -0
  99. package/dist/src/ports.js.map +1 -0
  100. package/dist/src/projects.d.ts +83 -0
  101. package/dist/src/projects.js +205 -0
  102. package/dist/src/projects.js.map +1 -0
  103. package/dist/src/protocol.d.ts +1226 -0
  104. package/dist/src/protocol.js +16 -0
  105. package/dist/src/protocol.js.map +1 -0
  106. package/dist/src/repo-sync.d.ts +49 -0
  107. package/dist/src/repo-sync.js +83 -0
  108. package/dist/src/repo-sync.js.map +1 -0
  109. package/dist/src/server.d.ts +33 -0
  110. package/dist/src/server.js +973 -0
  111. package/dist/src/server.js.map +1 -0
  112. package/dist/src/terminal.d.ts +32 -0
  113. package/dist/src/terminal.js +92 -0
  114. package/dist/src/terminal.js.map +1 -0
  115. package/dist/src/titler.d.ts +15 -0
  116. package/dist/src/titler.js +72 -0
  117. package/dist/src/titler.js.map +1 -0
  118. package/dist/src/types.d.ts +99 -0
  119. package/dist/src/types.js +3 -0
  120. package/dist/src/types.js.map +1 -0
  121. package/dist/src/usage-limit.d.ts +49 -0
  122. package/dist/src/usage-limit.js +83 -0
  123. package/dist/src/usage-limit.js.map +1 -0
  124. package/dist/src/usage.d.ts +23 -0
  125. package/dist/src/usage.js +63 -0
  126. package/dist/src/usage.js.map +1 -0
  127. package/dist/src/workspace.d.ts +303 -0
  128. package/dist/src/workspace.js +1086 -0
  129. package/dist/src/workspace.js.map +1 -0
  130. package/dist/src/worktree.d.ts +133 -0
  131. package/dist/src/worktree.js +561 -0
  132. package/dist/src/worktree.js.map +1 -0
  133. package/package.json +67 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Wire protocol — the contract between the Mac daemon and the Flutter client.
3
+ *
4
+ * This file is the SOURCE OF TRUTH. The Dart mirror lives at
5
+ * app/lib/protocol.dart and must be kept in sync by hand (the shapes are small
6
+ * and stable enough that codegen is not worth the toolchain weight yet).
7
+ *
8
+ * Transport-agnostic by design: nothing here may assume Cloudflare, WSS, or any
9
+ * particular framing. A single multiplexed connection carries every message.
10
+ *
11
+ * The envelope fields (v, id, ts, ws, type) stay in clear for routing. Only
12
+ * `payload` is encrypted in the E2E layer (slice 5); until then it travels as
13
+ * plain JSON.
14
+ */
15
+ export const PROTOCOL_VERSION = 1;
16
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Keep a base repo's remote-tracking refs fresh, shared across all of its
3
+ * worktrees.
4
+ *
5
+ * The status/diff numbers (ahead/behind, added/removed) are computed against
6
+ * `origin/<base>` and `origin/<branch>` — refs that only move on `git fetch`.
7
+ * Nothing on the read path used to fetch, so as soon as someone pushed to the
8
+ * base the numbers went stale and stayed stale until an unrelated action (branch
9
+ * picker, Resolve) happened to fetch.
10
+ *
11
+ * This module fetches on the status-poll path, but with two properties that keep
12
+ * it cheap:
13
+ * - Throttled per repo: at most one fetch per `intervalMs` (default 60s) for a
14
+ * given base repo, regardless of how many worktrees poll.
15
+ * - Coalesced: concurrent callers for the same repo (e.g. a project's 7
16
+ * worktrees all polling at once) await a single in-flight fetch, so 7
17
+ * worktrees still cost one fetch, not seven.
18
+ *
19
+ * A deliberate user action — opening a worktree, or the explicit Refresh — passes
20
+ * `force`, which bypasses only the throttle (a click means "show me origin *now*",
21
+ * not "within the last minute is fine"). Coalescing still holds under force, so a
22
+ * burst of clicks across a project's worktrees rides one in-flight fetch rather
23
+ * than firing several. Background polls stay throttled, so this stays cheap.
24
+ *
25
+ * Worktrees of a repo share one object/ref store, so fetching from any of their
26
+ * paths — or the base repo — updates the remote-tracking refs every worktree
27
+ * reads. We key throttling on the base repo path so that sharing holds.
28
+ *
29
+ * Best-effort throughout: an offline/no-remote fetch fails silently and the
30
+ * throttle still advances, so an unreachable remote isn't retried every poll.
31
+ */
32
+ /** Default minimum spacing between fetches for a single base repo. */
33
+ export declare const DEFAULT_SYNC_INTERVAL_MS = 60000;
34
+ /**
35
+ * Fetch `repo`'s remote-tracking refs if it hasn't fetched within `intervalMs`.
36
+ * Returns when the refs are current enough to read: awaits an in-flight fetch,
37
+ * kicks off (and awaits) a new one when due, or returns immediately when a
38
+ * recent fetch already refreshed them. Never throws.
39
+ *
40
+ * Pass `force` for a deliberate open/refresh: it ignores the throttle interval
41
+ * (but still coalesces onto an in-flight fetch) so the caller sees origin as of
42
+ * right now rather than up to `intervalMs` ago.
43
+ */
44
+ export declare function maybeSyncRepo(repo: string, opts?: {
45
+ intervalMs?: number;
46
+ force?: boolean;
47
+ }): Promise<void>;
48
+ /** Testing/reset hook: forget all per-repo throttle state. */
49
+ export declare function resetRepoSyncState(): void;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Keep a base repo's remote-tracking refs fresh, shared across all of its
3
+ * worktrees.
4
+ *
5
+ * The status/diff numbers (ahead/behind, added/removed) are computed against
6
+ * `origin/<base>` and `origin/<branch>` — refs that only move on `git fetch`.
7
+ * Nothing on the read path used to fetch, so as soon as someone pushed to the
8
+ * base the numbers went stale and stayed stale until an unrelated action (branch
9
+ * picker, Resolve) happened to fetch.
10
+ *
11
+ * This module fetches on the status-poll path, but with two properties that keep
12
+ * it cheap:
13
+ * - Throttled per repo: at most one fetch per `intervalMs` (default 60s) for a
14
+ * given base repo, regardless of how many worktrees poll.
15
+ * - Coalesced: concurrent callers for the same repo (e.g. a project's 7
16
+ * worktrees all polling at once) await a single in-flight fetch, so 7
17
+ * worktrees still cost one fetch, not seven.
18
+ *
19
+ * A deliberate user action — opening a worktree, or the explicit Refresh — passes
20
+ * `force`, which bypasses only the throttle (a click means "show me origin *now*",
21
+ * not "within the last minute is fine"). Coalescing still holds under force, so a
22
+ * burst of clicks across a project's worktrees rides one in-flight fetch rather
23
+ * than firing several. Background polls stay throttled, so this stays cheap.
24
+ *
25
+ * Worktrees of a repo share one object/ref store, so fetching from any of their
26
+ * paths — or the base repo — updates the remote-tracking refs every worktree
27
+ * reads. We key throttling on the base repo path so that sharing holds.
28
+ *
29
+ * Best-effort throughout: an offline/no-remote fetch fails silently and the
30
+ * throttle still advances, so an unreachable remote isn't retried every poll.
31
+ */
32
+ import { resolve } from "node:path";
33
+ import { simpleGit } from "simple-git";
34
+ /** Default minimum spacing between fetches for a single base repo. */
35
+ export const DEFAULT_SYNC_INTERVAL_MS = 60_000;
36
+ const state = new Map();
37
+ /**
38
+ * Fetch `repo`'s remote-tracking refs if it hasn't fetched within `intervalMs`.
39
+ * Returns when the refs are current enough to read: awaits an in-flight fetch,
40
+ * kicks off (and awaits) a new one when due, or returns immediately when a
41
+ * recent fetch already refreshed them. Never throws.
42
+ *
43
+ * Pass `force` for a deliberate open/refresh: it ignores the throttle interval
44
+ * (but still coalesces onto an in-flight fetch) so the caller sees origin as of
45
+ * right now rather than up to `intervalMs` ago.
46
+ */
47
+ export async function maybeSyncRepo(repo, opts = {}) {
48
+ const { intervalMs = DEFAULT_SYNC_INTERVAL_MS, force = false } = opts;
49
+ const key = resolve(repo);
50
+ let s = state.get(key);
51
+ if (!s) {
52
+ s = { lastAt: 0, inflight: null };
53
+ state.set(key, s);
54
+ }
55
+ // A fetch is already running for this repo — ride along with it rather than
56
+ // starting a second one (this is the 7-worktrees-poll-at-once case). Holds
57
+ // even under force, so a burst of clicks costs one fetch, not one per click.
58
+ if (s.inflight)
59
+ return s.inflight;
60
+ // Fetched recently enough — the refs are fresh, don't hit the network. A
61
+ // forced (deliberate) refresh skips this and always fetches.
62
+ if (!force && Date.now() - s.lastAt < intervalMs)
63
+ return;
64
+ const st = s;
65
+ st.inflight = (async () => {
66
+ try {
67
+ await simpleGit(key).fetch(["--all", "--prune"]);
68
+ }
69
+ catch {
70
+ /* offline / no remote — keep the last-known refs, retry after interval */
71
+ }
72
+ finally {
73
+ st.lastAt = Date.now();
74
+ st.inflight = null;
75
+ }
76
+ })();
77
+ return st.inflight;
78
+ }
79
+ /** Testing/reset hook: forget all per-repo throttle state. */
80
+ export function resetRepoSyncState() {
81
+ state.clear();
82
+ }
83
+ //# sourceMappingURL=repo-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-sync.js","sourceRoot":"","sources":["../../src/repo-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,sEAAsE;AACtE,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAS/C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,OAAiD,EAAE;IAEnD,MAAM,EAAE,UAAU,GAAG,wBAAwB,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC;IACtE,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAClC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,4EAA4E;IAC5E,2EAA2E;IAC3E,6EAA6E;IAC7E,IAAI,CAAC,CAAC,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,CAAC;IAClC,yEAAyE;IACzE,6DAA6D;IAC7D,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,UAAU;QAAE,OAAO;IAEzD,MAAM,EAAE,GAAG,CAAC,CAAC;IACb,EAAE,CAAC,QAAQ,GAAG,CAAC,KAAK,IAAI,EAAE;QACxB,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YACP,0EAA0E;QAC5E,CAAC;gBAAS,CAAC;YACT,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,EAAE,CAAC,QAAQ,CAAC;AACrB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,kBAAkB;IAChC,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * WSS server + message dispatch.
3
+ *
4
+ * Speaks the envelope contract only; knows nothing about Cloudflare
5
+ * (cloudflared dials this local port). A pluggable Codec decides whether
6
+ * payloads are cleartext (slices 1–4 / dev) or sealed NaCl boxes (slice 5).
7
+ */
8
+ import { type Server } from "node:http";
9
+ import { WebSocketServer } from "ws";
10
+ import { type Keypair } from "./crypto.js";
11
+ import { Hub } from "./hub.js";
12
+ import { WorkspaceManager } from "./workspace.js";
13
+ import { JobScheduler } from "./jobs/scheduler.js";
14
+ export interface DaemonOptions {
15
+ port: number;
16
+ host: string;
17
+ /**
18
+ * Present when E2E is on. The daemon seals each socket's frames to that
19
+ * device's key after its `hello` handshake; without this, every socket stays
20
+ * cleartext (local dev / slices 1–4).
21
+ */
22
+ crypto?: {
23
+ self: Keypair;
24
+ };
25
+ }
26
+ export interface Daemon {
27
+ http: Server;
28
+ wss: WebSocketServer;
29
+ hub: Hub;
30
+ workspaces: WorkspaceManager;
31
+ jobs: JobScheduler;
32
+ }
33
+ export declare function startServer(opts: DaemonOptions): Promise<Daemon>;