@primitive.ai/prim 0.1.0-alpha.56 → 0.1.0-alpha.58

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.
@@ -1,82 +0,0 @@
1
- // src/lib/activation.ts
2
- import { execFileSync as execFileSync2 } from "child_process";
3
- import { existsSync, readFileSync } from "fs";
4
- import { homedir } from "os";
5
- import { join } from "path";
6
-
7
- // src/lib/git.ts
8
- import { execFileSync } from "child_process";
9
- function gitToplevel(cwd) {
10
- try {
11
- return execFileSync("git", ["rev-parse", "--show-toplevel"], {
12
- cwd,
13
- encoding: "utf-8",
14
- stdio: ["ignore", "pipe", "ignore"]
15
- }).trim();
16
- } catch {
17
- return null;
18
- }
19
- }
20
-
21
- // src/lib/activation.ts
22
- var PRIM_ACTIVE_KEY = "prim.active";
23
- var PROJECT_INSTALL_FILES = [".claude/settings.json", ".codex/hooks.json"];
24
- var PRIM_HOOK_BINS = ["prim-hook", "prim-pre-tool-use", "prim-post-tool-use"];
25
- function repoActiveFlag(cwd) {
26
- try {
27
- const value = execFileSync2("git", ["config", "--get", PRIM_ACTIVE_KEY], {
28
- cwd,
29
- encoding: "utf-8",
30
- stdio: ["ignore", "pipe", "ignore"]
31
- }).trim();
32
- if (value === "true") return "true";
33
- if (value === "false") return "false";
34
- return void 0;
35
- } catch {
36
- return void 0;
37
- }
38
- }
39
- function setRepoActive(cwd, active) {
40
- execFileSync2("git", ["config", "--local", PRIM_ACTIVE_KEY, active ? "true" : "false"], {
41
- cwd,
42
- stdio: ["ignore", "ignore", "pipe"]
43
- });
44
- }
45
- function activateRepoBestEffort(cwd) {
46
- try {
47
- setRepoActive(cwd, true);
48
- } catch {
49
- }
50
- }
51
- function hasProjectPrimInstall(cwd) {
52
- const root = gitToplevel(cwd);
53
- if (root === null || root === homedir()) return false;
54
- for (const rel of PROJECT_INSTALL_FILES) {
55
- const path = join(root, rel);
56
- if (existsSync(path)) {
57
- try {
58
- const content = readFileSync(path, "utf-8");
59
- if (PRIM_HOOK_BINS.some((bin) => content.includes(bin))) return true;
60
- } catch {
61
- }
62
- }
63
- }
64
- return false;
65
- }
66
- function isRepoActiveForCapture(cwd) {
67
- const flag = repoActiveFlag(cwd);
68
- if (flag === "true") return true;
69
- if (flag === "false") return false;
70
- return hasProjectPrimInstall(cwd);
71
- }
72
- function decisionIngestionStatus(cwd) {
73
- return isRepoActiveForCapture(cwd) ? "enabled" : "disabled";
74
- }
75
-
76
- export {
77
- gitToplevel,
78
- setRepoActive,
79
- activateRepoBestEffort,
80
- isRepoActiveForCapture,
81
- decisionIngestionStatus
82
- };