@druumen/sessions-db 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.
- package/CHANGELOG.md +249 -0
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +250 -0
- package/cli/_write-helpers.mjs +99 -0
- package/cli/alias.mjs +115 -0
- package/cli/argparse.mjs +296 -0
- package/cli/close.mjs +116 -0
- package/cli/find.mjs +185 -0
- package/cli/format.mjs +277 -0
- package/cli/link-parent.mjs +133 -0
- package/cli/link.mjs +132 -0
- package/cli/rebuild.mjs +98 -0
- package/cli/sessions-db-session-start-main.mjs +454 -0
- package/cli/sessions-db-session-start.mjs +56 -0
- package/cli/sessions-db.mjs +119 -0
- package/cli/sweep.mjs +171 -0
- package/cli/tree.mjs +127 -0
- package/lib/git-context.mjs +479 -0
- package/lib/identity.mjs +616 -0
- package/lib/index.mjs +145 -0
- package/lib/init.mjs +185 -0
- package/lib/lock.mjs +86 -0
- package/lib/operations.mjs +490 -0
- package/lib/paths.mjs +199 -0
- package/lib/projection.mjs +496 -0
- package/lib/sanitize.mjs +131 -0
- package/lib/storage.mjs +759 -0
- package/lib/sweep.mjs +209 -0
- package/lib/transcript.mjs +230 -0
- package/lib/types.mjs +276 -0
- package/lib/uuid.mjs +116 -0
- package/lib/watch.mjs +217 -0
- package/package.json +53 -0
- package/types/git-context.d.mts +98 -0
- package/types/identity.d.mts +658 -0
- package/types/index.d.mts +10 -0
- package/types/index.d.ts +127 -0
- package/types/init.d.mts +53 -0
- package/types/lock.d.mts +18 -0
- package/types/operations.d.mts +204 -0
- package/types/paths.d.mts +54 -0
- package/types/projection.d.mts +79 -0
- package/types/sanitize.d.mts +39 -0
- package/types/storage.d.mts +276 -0
- package/types/sweep.d.mts +58 -0
- package/types/transcript.d.mts +59 -0
- package/types/types.d.mts +255 -0
- package/types/uuid.d.mts +17 -0
- package/types/watch.d.mts +33 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} GitContext
|
|
3
|
+
* @property {string} cwd The cwd we ran probes against (always set).
|
|
4
|
+
* @property {string|null} worktreePath Output of `git rev-parse --show-toplevel` (worktree root).
|
|
5
|
+
* @property {string|null} worktreeRealpath realpath() of worktreePath, with symlinks resolved.
|
|
6
|
+
* @property {string|null} gitCommonDir Output of `git rev-parse --git-common-dir` (resolved to absolute).
|
|
7
|
+
* @property {boolean} isInWorktree True when worktree's `.git` is a file (linked worktree),
|
|
8
|
+
* i.e. gitCommonDir's parent != worktreePath.
|
|
9
|
+
* @property {boolean} isInsideRepo True when cwd is inside any git repo (linked worktree counts).
|
|
10
|
+
* @property {string|null} branch `git branch --show-current` (empty string => detached HEAD => null).
|
|
11
|
+
* @property {string|null} head `git rev-parse HEAD` (full SHA).
|
|
12
|
+
* @property {string|null} registryName Key in the dev-offload registry whose `worktree_path` matches us.
|
|
13
|
+
* @property {'ok'|'partial'|'not_a_repo'|'error'} status
|
|
14
|
+
* @property {string[]} errors One-liner error summaries, suitable for jsonl logging.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Probe git context for `cwd`. Never throws; returns a `GitContext` whose
|
|
18
|
+
* `status` field tells the caller what to trust.
|
|
19
|
+
*
|
|
20
|
+
* Budget model: `totalBudgetMs` is the wall-clock budget for ALL probes
|
|
21
|
+
* combined. Each individual probe gets `min(remaining, MIN_PROBE_BUDGET_MS)`
|
|
22
|
+
* — once the budget is exhausted, we stop probing and return whatever we
|
|
23
|
+
* have so far with `status: 'partial'`.
|
|
24
|
+
*
|
|
25
|
+
* @param {{ cwd?: string, totalBudgetMs?: number, registryPath?: string }} [opts]
|
|
26
|
+
* @returns {Promise<GitContext>}
|
|
27
|
+
*/
|
|
28
|
+
export function gitContext(opts?: {
|
|
29
|
+
cwd?: string;
|
|
30
|
+
totalBudgetMs?: number;
|
|
31
|
+
registryPath?: string;
|
|
32
|
+
}): Promise<GitContext>;
|
|
33
|
+
/**
|
|
34
|
+
* Run a single `git <args>` command with a per-call budget derived from the
|
|
35
|
+
* shared deadline. Uses non-blocking spawn + Promise.race so the hook's outer
|
|
36
|
+
* setTimeout can actually fire (was: spawnSync blocked the event loop).
|
|
37
|
+
*
|
|
38
|
+
* @returns {Promise<{ ok: boolean, stdout: string, stderr: string,
|
|
39
|
+
* code: number|null, signal: NodeJS.Signals|null,
|
|
40
|
+
* spawnFailed: boolean, timedOut: boolean }>}
|
|
41
|
+
*/
|
|
42
|
+
export function runGit(args: any, { cwd, deadlineAt, encoding }: {
|
|
43
|
+
cwd: any;
|
|
44
|
+
deadlineAt: any;
|
|
45
|
+
encoding?: string;
|
|
46
|
+
}, ctx: any): Promise<{
|
|
47
|
+
ok: boolean;
|
|
48
|
+
stdout: string;
|
|
49
|
+
stderr: string;
|
|
50
|
+
code: number | null;
|
|
51
|
+
signal: NodeJS.Signals | null;
|
|
52
|
+
spawnFailed: boolean;
|
|
53
|
+
timedOut: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
export type GitContext = {
|
|
56
|
+
/**
|
|
57
|
+
* The cwd we ran probes against (always set).
|
|
58
|
+
*/
|
|
59
|
+
cwd: string;
|
|
60
|
+
/**
|
|
61
|
+
* Output of `git rev-parse --show-toplevel` (worktree root).
|
|
62
|
+
*/
|
|
63
|
+
worktreePath: string | null;
|
|
64
|
+
/**
|
|
65
|
+
* realpath() of worktreePath, with symlinks resolved.
|
|
66
|
+
*/
|
|
67
|
+
worktreeRealpath: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Output of `git rev-parse --git-common-dir` (resolved to absolute).
|
|
70
|
+
*/
|
|
71
|
+
gitCommonDir: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* True when worktree's `.git` is a file (linked worktree),
|
|
74
|
+
* i.e. gitCommonDir's parent != worktreePath.
|
|
75
|
+
*/
|
|
76
|
+
isInWorktree: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* True when cwd is inside any git repo (linked worktree counts).
|
|
79
|
+
*/
|
|
80
|
+
isInsideRepo: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* `git branch --show-current` (empty string => detached HEAD => null).
|
|
83
|
+
*/
|
|
84
|
+
branch: string | null;
|
|
85
|
+
/**
|
|
86
|
+
* `git rev-parse HEAD` (full SHA).
|
|
87
|
+
*/
|
|
88
|
+
head: string | null;
|
|
89
|
+
/**
|
|
90
|
+
* Key in the dev-offload registry whose `worktree_path` matches us.
|
|
91
|
+
*/
|
|
92
|
+
registryName: string | null;
|
|
93
|
+
status: "ok" | "partial" | "not_a_repo" | "error";
|
|
94
|
+
/**
|
|
95
|
+
* One-liner error summaries, suitable for jsonl logging.
|
|
96
|
+
*/
|
|
97
|
+
errors: string[];
|
|
98
|
+
};
|