@groundtrack/hooks 0.1.9 → 0.1.10

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 (39) hide show
  1. package/README.md +28 -10
  2. package/dist/agents.d.ts +55 -0
  3. package/dist/agents.js +77 -3
  4. package/dist/groundtrack-hook.js +0 -0
  5. package/dist/groundtrack.js +0 -0
  6. package/dist/session-import/canonical.d.ts +33 -0
  7. package/dist/session-import/canonical.js +10 -0
  8. package/dist/session-import/claude.d.ts +20 -0
  9. package/dist/session-import/claude.js +237 -0
  10. package/dist/session-import/cli.d.ts +3 -2
  11. package/dist/session-import/cli.js +161 -131
  12. package/dist/session-import/client.d.ts +4 -3
  13. package/dist/session-import/client.js +4 -3
  14. package/dist/session-import/codex.d.ts +6 -33
  15. package/dist/session-import/codex.js +62 -9
  16. package/dist/session-import/cursor.d.ts +13 -0
  17. package/dist/session-import/cursor.js +268 -0
  18. package/dist/session-import/discovery.d.ts +16 -7
  19. package/dist/session-import/discovery.js +120 -67
  20. package/dist/session-import/format.d.ts +51 -0
  21. package/dist/session-import/format.js +11 -0
  22. package/dist/session-import/formats.d.ts +4 -0
  23. package/dist/session-import/formats.js +13 -0
  24. package/dist/session-import/normalize.d.ts +21 -0
  25. package/dist/session-import/normalize.js +96 -0
  26. package/dist/session-import/opencode-cli.d.ts +14 -0
  27. package/dist/session-import/opencode-cli.js +178 -0
  28. package/dist/session-import/opencode-normalizer.d.ts +8 -0
  29. package/dist/session-import/opencode-normalizer.js +230 -0
  30. package/dist/session-import/opencode.d.ts +8 -0
  31. package/dist/session-import/opencode.js +230 -0
  32. package/dist/session-import/prune.d.ts +13 -4
  33. package/dist/session-import/prune.js +45 -79
  34. package/dist/session-import/receipts.d.ts +2 -1
  35. package/dist/session-import/receipts.js +3 -3
  36. package/dist/session-import/types.d.ts +21 -7
  37. package/dist/setup/agents.d.ts +32 -0
  38. package/package.json +29 -1
  39. package/src/agents.ts +104 -3
package/src/agents.ts CHANGED
@@ -6,10 +6,57 @@ export const AGENTS = [
6
6
  aliases: ["claude-code"],
7
7
  source: "claude_code",
8
8
  enrichment: "command",
9
+ sessionImport: {
10
+ cli: true,
11
+ web: {
12
+ extension: ".jsonl",
13
+ accept: ".jsonl",
14
+ fileLabel: "Claude Code session JSONL",
15
+ location: "~/.claude/projects/<project>/*.jsonl",
16
+ },
17
+ },
18
+ },
19
+ {
20
+ id: "codex",
21
+ name: "Codex",
22
+ aliases: [],
23
+ source: "codex",
24
+ enrichment: "command",
25
+ sessionImport: {
26
+ cli: true,
27
+ web: {
28
+ extension: ".jsonl",
29
+ accept: ".jsonl",
30
+ fileLabel: "Codex rollout JSONL",
31
+ location: "~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl",
32
+ },
33
+ },
34
+ },
35
+ {
36
+ id: "cursor",
37
+ name: "Cursor",
38
+ aliases: [],
39
+ source: "cursor",
40
+ enrichment: "command",
41
+ sessionImport: { cli: true, web: null },
42
+ },
43
+ {
44
+ id: "opencode",
45
+ name: "OpenCode",
46
+ aliases: [],
47
+ source: "opencode",
48
+ enrichment: "plugin",
49
+ sessionImport: {
50
+ cli: true,
51
+ web: {
52
+ extension: ".json",
53
+ accept: ".json,application/json",
54
+ fileLabel: "OpenCode session export JSON",
55
+ location: "opencode export <session-id> --pure > opencode-session.json",
56
+ note: "Use direct file redirection as shown. Do not add --sanitize; Groundtrack removes sensitive records during import.",
57
+ },
58
+ },
9
59
  },
10
- { id: "codex", name: "Codex", aliases: [], source: "codex", enrichment: "command" },
11
- { id: "cursor", name: "Cursor", aliases: [], source: "cursor", enrichment: "command" },
12
- { id: "opencode", name: "OpenCode", aliases: [], source: "opencode", enrichment: "plugin" },
13
60
  ] as const;
14
61
 
15
62
  export type AgentDefinition = (typeof AGENTS)[number];
@@ -17,6 +64,29 @@ export type Agent = AgentDefinition["id"];
17
64
  export type CommandHookAgent = Extract<AgentDefinition, { enrichment: "command" }>["id"];
18
65
  export const AGENT_IDS = AGENTS.map((agent) => agent.id);
19
66
 
67
+ export type SessionImportAgentDefinition = Extract<
68
+ AgentDefinition,
69
+ { sessionImport: { cli: true } }
70
+ >;
71
+ export type SessionImportAgent = SessionImportAgentDefinition["id"];
72
+ export type AgentSessionSource = SessionImportAgentDefinition["source"];
73
+ export type WebSessionImportAgentDefinition = Extract<
74
+ SessionImportAgentDefinition,
75
+ { sessionImport: { web: object } }
76
+ >;
77
+ export type WebSessionImportSource = WebSessionImportAgentDefinition["source"];
78
+
79
+ export const SESSION_IMPORT_AGENTS = AGENTS.filter(
80
+ (agent): agent is SessionImportAgentDefinition => agent.sessionImport.cli,
81
+ );
82
+ export const WEB_SESSION_IMPORT_AGENTS = SESSION_IMPORT_AGENTS.filter(
83
+ (agent): agent is WebSessionImportAgentDefinition => agent.sessionImport.web !== null,
84
+ );
85
+ export const WEB_SESSION_IMPORT_SOURCES = WEB_SESSION_IMPORT_AGENTS.map((agent) => agent.source);
86
+
87
+ export const DEFAULT_SESSION_IMPORT_AGENT: SessionImportAgent = "codex";
88
+ export const DEFAULT_WEB_SESSION_IMPORT_SOURCE: WebSessionImportSource = "codex";
89
+
20
90
  export function isAgent(value: unknown): value is Agent {
21
91
  return AGENTS.some((agent) => agent.id === value);
22
92
  }
@@ -27,6 +97,37 @@ export function resolveAgent(value: string): AgentDefinition | undefined {
27
97
  );
28
98
  }
29
99
 
100
+ export function isSessionImportAgent(value: string): value is SessionImportAgent {
101
+ return SESSION_IMPORT_AGENTS.some((agent) => agent.id === value);
102
+ }
103
+
104
+ function isAgentSessionSource(value: string): value is AgentSessionSource {
105
+ return SESSION_IMPORT_AGENTS.some((agent) => agent.source === value);
106
+ }
107
+
108
+ export function normalizeAgentSessionSource(value: string): AgentSessionSource | undefined {
109
+ const source = value === "codex_cli" ? "codex" : value;
110
+ return isAgentSessionSource(source) ? source : undefined;
111
+ }
112
+
113
+ export function isWebSessionImportSource(value: string): value is WebSessionImportSource {
114
+ return WEB_SESSION_IMPORT_AGENTS.some((agent) => agent.source === value);
115
+ }
116
+
117
+ export function resolveSessionImportAgentFromSource(
118
+ source: string | undefined,
119
+ ): SessionImportAgentDefinition | undefined {
120
+ return SESSION_IMPORT_AGENTS.find((agent) => agent.source === source);
121
+ }
122
+
123
+ export function webSessionImportAgentFromSource(
124
+ source: WebSessionImportSource,
125
+ ): WebSessionImportAgentDefinition {
126
+ const agent = WEB_SESSION_IMPORT_AGENTS.find((candidate) => candidate.source === source);
127
+ if (!agent) throw new Error(`Unsupported web session import source: ${source}`);
128
+ return agent;
129
+ }
130
+
30
131
  export function agentFromClientName(value: string | null | undefined): AgentDefinition | undefined {
31
132
  const normalized = value?.trim().toLowerCase() ?? "";
32
133
  return AGENTS.find((agent) => normalized.includes(agent.id));