hacklab 0.6.0 → 0.6.2

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 (74) hide show
  1. package/dist/commands/brag.js +4 -4
  2. package/dist/commands/brag.js.map +1 -1
  3. package/dist/commands/chat.d.ts.map +1 -1
  4. package/dist/commands/chat.js +16 -12
  5. package/dist/commands/chat.js.map +1 -1
  6. package/dist/commands/drop.d.ts +9 -0
  7. package/dist/commands/drop.d.ts.map +1 -1
  8. package/dist/commands/drop.js +33 -4
  9. package/dist/commands/drop.js.map +1 -1
  10. package/dist/commands/join.d.ts +3 -1
  11. package/dist/commands/join.d.ts.map +1 -1
  12. package/dist/commands/join.js +31 -3
  13. package/dist/commands/join.js.map +1 -1
  14. package/dist/commands/login.d.ts +18 -1
  15. package/dist/commands/login.d.ts.map +1 -1
  16. package/dist/commands/login.js +156 -19
  17. package/dist/commands/login.js.map +1 -1
  18. package/dist/commands/logout.d.ts +2 -0
  19. package/dist/commands/logout.d.ts.map +1 -0
  20. package/dist/commands/logout.js +15 -0
  21. package/dist/commands/logout.js.map +1 -0
  22. package/dist/commands/org.js +5 -5
  23. package/dist/commands/org.js.map +1 -1
  24. package/dist/commands/sync.d.ts.map +1 -1
  25. package/dist/commands/sync.js +9 -1
  26. package/dist/commands/sync.js.map +1 -1
  27. package/dist/commands/whoami.d.ts.map +1 -1
  28. package/dist/commands/whoami.js +10 -2
  29. package/dist/commands/whoami.js.map +1 -1
  30. package/dist/index.js +27 -88
  31. package/dist/index.js.map +1 -1
  32. package/dist/registry.d.ts +15 -0
  33. package/dist/registry.d.ts.map +1 -0
  34. package/dist/registry.js +77 -0
  35. package/dist/registry.js.map +1 -0
  36. package/dist/resolve-command.d.ts +0 -1
  37. package/dist/resolve-command.d.ts.map +1 -1
  38. package/dist/resolve-command.js +2 -17
  39. package/dist/resolve-command.js.map +1 -1
  40. package/dist/session.d.ts +26 -5
  41. package/dist/session.d.ts.map +1 -1
  42. package/dist/session.js +55 -8
  43. package/dist/session.js.map +1 -1
  44. package/dist/share.d.ts +2 -2
  45. package/dist/share.js +2 -2
  46. package/dist/sync.d.ts +18 -34
  47. package/dist/sync.d.ts.map +1 -1
  48. package/dist/sync.js +47 -686
  49. package/dist/sync.js.map +1 -1
  50. package/dist/ui.d.ts +2 -0
  51. package/dist/ui.d.ts.map +1 -1
  52. package/dist/ui.js +4 -0
  53. package/dist/ui.js.map +1 -1
  54. package/dist/utils/openBrowser.d.ts +12 -0
  55. package/dist/utils/openBrowser.d.ts.map +1 -1
  56. package/dist/utils/openBrowser.js +30 -12
  57. package/dist/utils/openBrowser.js.map +1 -1
  58. package/package.json +3 -2
  59. package/dist/commands/company.d.ts +0 -2
  60. package/dist/commands/company.d.ts.map +0 -1
  61. package/dist/commands/company.js +0 -214
  62. package/dist/commands/company.js.map +0 -1
  63. package/dist/commands/exam.d.ts +0 -5
  64. package/dist/commands/exam.d.ts.map +0 -1
  65. package/dist/commands/exam.js +0 -224
  66. package/dist/commands/exam.js.map +0 -1
  67. package/dist/commands/scan-profile.d.ts +0 -33
  68. package/dist/commands/scan-profile.d.ts.map +0 -1
  69. package/dist/commands/scan-profile.js +0 -279
  70. package/dist/commands/scan-profile.js.map +0 -1
  71. package/dist/dd.d.ts +0 -3
  72. package/dist/dd.d.ts.map +0 -1
  73. package/dist/dd.js +0 -28
  74. package/dist/dd.js.map +0 -1
@@ -0,0 +1,15 @@
1
+ export type CommandSpec = {
2
+ /** The full command name, e.g. `chat`. */
3
+ name: string;
4
+ /** Args shown after the name in help, e.g. `<key> <val>`. Omit if it takes none. */
5
+ args?: string;
6
+ /** One-line description shown in `hacklab --help`. */
7
+ summary: string;
8
+ /** Run the command with the per-command args (the global `--env` is already stripped). */
9
+ run: (args: string[]) => Promise<void> | void;
10
+ };
11
+ export declare const COMMANDS: CommandSpec[];
12
+ /** Every command name, in registry order — the source of truth for resolution. */
13
+ export declare const COMMAND_NAMES: string[];
14
+ export declare function findCommand(name: string): CommandSpec | undefined;
15
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,WAAW,GAAG;IACxB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,oFAAoF;IACpF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAA;IACf,0FAA0F;IAC1F,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CAC9C,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,WAAW,EA6DjC,CAAA;AAED,kFAAkF;AAClF,eAAO,MAAM,aAAa,UAA8B,CAAA;AAExD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEjE"}
@@ -0,0 +1,77 @@
1
+ import { brag, parseBragArgs } from './commands/brag.js';
2
+ import { chat } from './commands/chat.js';
3
+ import { configCommand } from './commands/config.js';
4
+ import { drop, parseDropArgs } from './commands/drop.js';
5
+ import { join } from './commands/join.js';
6
+ import { login } from './commands/login.js';
7
+ import { logout } from './commands/logout.js';
8
+ import { org } from './commands/org.js';
9
+ import { sync } from './commands/sync.js';
10
+ import { whoami } from './commands/whoami.js';
11
+ export const COMMANDS = [
12
+ {
13
+ name: 'join',
14
+ args: '[--browser]',
15
+ summary: 'join hacklab from your terminal',
16
+ run: (args) => join({ browser: args.includes('--browser') }),
17
+ },
18
+ {
19
+ name: 'sync',
20
+ summary: 'sync AI token usage to your profile',
21
+ run: () => sync(),
22
+ },
23
+ {
24
+ name: 'whoami',
25
+ summary: "check who you're logged in as",
26
+ run: () => whoami(),
27
+ },
28
+ {
29
+ name: 'drop',
30
+ args: '"message"',
31
+ summary: 'post a drop to your feed',
32
+ run: (args) => {
33
+ const { text, url } = parseDropArgs(args);
34
+ return drop(text, url);
35
+ },
36
+ },
37
+ {
38
+ name: 'login',
39
+ args: '[--browser]',
40
+ summary: 're-authenticate with github (--browser for the local browser flow)',
41
+ run: (args) => login({ browser: args.includes('--browser') }),
42
+ },
43
+ {
44
+ name: 'logout',
45
+ summary: 'clear your saved session on this machine',
46
+ run: () => logout(),
47
+ },
48
+ {
49
+ name: 'config',
50
+ args: '<key> <val>',
51
+ summary: 'set config (cursor-api-key, cursor-email)',
52
+ run: (args) => configCommand(args),
53
+ },
54
+ {
55
+ name: 'brag',
56
+ args: '[path]',
57
+ summary: 'sync .hacklab/project.yaml',
58
+ run: (args) => brag(parseBragArgs(args).manifestPath),
59
+ },
60
+ {
61
+ name: 'org',
62
+ summary: 'edit your organization',
63
+ run: () => org(),
64
+ },
65
+ {
66
+ name: 'chat',
67
+ args: '[sub]',
68
+ summary: 'open the live channel (or tail/post/dm/…; --json for agents)',
69
+ run: (args) => chat(args),
70
+ },
71
+ ];
72
+ /** Every command name, in registry order — the source of truth for resolution. */
73
+ export const COMMAND_NAMES = COMMANDS.map((c) => c.name);
74
+ export function findCommand(name) {
75
+ return COMMANDS.find((c) => c.name === name);
76
+ }
77
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,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ACd,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,2CAA2C;QACpD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC;KACnC;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE,4BAA4B;QACrC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;KACtD;IACD;QACE,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,wBAAwB;QACjC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE;KACjB;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,8DAA8D;QACvE,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;KAC1B;CACF,CAAA;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAExD,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;AAC9C,CAAC"}
@@ -1,4 +1,3 @@
1
- export declare const COMMANDS: readonly ["join", "login", "whoami", "sync", "drop", "exam", "scan", "config", "brag", "org", "chat"];
2
1
  export type ResolvedCommand = {
3
2
  kind: 'match';
4
3
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-command.d.ts","sourceRoot":"","sources":["../src/resolve-command.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,uGAYX,CAAA;AAEV,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAEvB;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,SAAS,MAAM,EAAa,GACrC,eAAe,CAOjB"}
1
+ {"version":3,"file":"resolve-command.d.ts","sourceRoot":"","sources":["../src/resolve-command.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAEvB;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,SAAS,MAAM,EAAkB,GAC1C,eAAe,CAOjB"}
@@ -1,19 +1,4 @@
1
- // All top-level hacklab subcommands. Used both to dispatch and to resolve a
2
- // typed prefix to its full name (e.g. `sy` -> sync). Keep in sync with the
3
- // dispatch chain in index.ts.
4
- export const COMMANDS = [
5
- 'join',
6
- 'login',
7
- 'whoami',
8
- 'sync',
9
- 'drop',
10
- 'exam',
11
- 'scan',
12
- 'config',
13
- 'brag',
14
- 'org',
15
- 'chat',
16
- ];
1
+ import { COMMAND_NAMES } from './registry.js';
17
2
  /**
18
3
  * Resolve a (possibly abbreviated) command token to a full command name by
19
4
  * shortest unambiguous prefix:
@@ -23,7 +8,7 @@ export const COMMANDS = [
23
8
  * - a prefix matching several is ambiguous (`s` -> sync | scan);
24
9
  * - a token matching none is unknown (a typo like `ogr` does not resolve).
25
10
  */
26
- export function resolveCommand(token, commands = COMMANDS) {
11
+ export function resolveCommand(token, commands = COMMAND_NAMES) {
27
12
  if (commands.includes(token))
28
13
  return { kind: 'match', name: token };
29
14
  const matches = commands.filter((c) => c.startsWith(token));
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-command.js","sourceRoot":"","sources":["../src/resolve-command.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,2EAA2E;AAC3E,8BAA8B;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,MAAM;IACN,KAAK;IACL,MAAM;CACE,CAAA;AAOV;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,WAA8B,QAAQ;IAEtC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IAEnE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,CAAA;IACrE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAA;IAC7D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;AAC5B,CAAC"}
1
+ {"version":3,"file":"resolve-command.js","sourceRoot":"","sources":["../src/resolve-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAO7C;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAa,EACb,WAA8B,aAAa;IAE3C,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IAEnE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,CAAA;IACrE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAA;IAC7D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;AAC5B,CAAC"}
package/dist/session.d.ts CHANGED
@@ -19,6 +19,12 @@ export declare function getSessionExpiresAt(session: Pick<Session, 'expiresAt' |
19
19
  export declare function isSessionExpired(session: Pick<Session, 'expiresAt' | 'savedAt'>, now?: Date): boolean;
20
20
  export declare function loadSessionState(): Promise<LoadSessionState>;
21
21
  export declare function loadSession(): Promise<Session | null>;
22
+ /**
23
+ * Delete the local session file. Returns true if a file was removed, false if
24
+ * there was nothing to clear (no session). Local-only — it doesn't revoke the
25
+ * token server-side, so the token stays valid until it expires.
26
+ */
27
+ export declare function clearSession(): Promise<boolean>;
22
28
  /** Named backends the CLI can target via `--env`. */
23
29
  export declare const HACKLAB_ENVIRONMENTS: {
24
30
  readonly production: "https://hacklab.so";
@@ -28,11 +34,26 @@ export declare const HACKLAB_ENVIRONMENTS: {
28
34
  export type HacklabEnv = keyof typeof HACKLAB_ENVIRONMENTS;
29
35
  export declare function isHacklabEnv(value: string): value is HacklabEnv;
30
36
  /**
31
- * Which backend to talk to. Precedence: an explicit `HACKLAB_APP_URL`
32
- * (also how `--env` is applied — see index.ts) wins; otherwise default to
33
- * production, so a freshly-installed `hacklab` hits hacklab.so rather than a
34
- * localhost server that isn't running. Use `--env development` (or
35
- * `HACKLAB_APP_URL`) for local work.
37
+ * Resolve an `--env` value to a canonical backend name. Accepts the full name,
38
+ * any unambiguous prefix (`dev`/`prod`/`stag`, mirroring how command names
39
+ * resolve so abbreviations work everywhere), and a couple of natural aliases
40
+ * (`local`/`localhost`). Returns null if it matches none — the three env names
41
+ * start with distinct letters, so a prefix is never ambiguous.
42
+ */
43
+ export declare function resolveHacklabEnv(value: string): HacklabEnv | null;
44
+ /**
45
+ * Which backend to talk to, by precedence:
46
+ * 1. an explicit `HACKLAB_APP_URL` (also how `--env` is applied — see
47
+ * index.ts) so `--env staging` always switches backends;
48
+ * 2. the backend you logged into (`session.appUrl`), when a session is given;
49
+ * 3. the production default, so a freshly-installed `hacklab` hits hacklab.so
50
+ * rather than a localhost server that isn't running.
51
+ *
52
+ * The single source of this precedence: `getAppUrl()` is the no-session form,
53
+ * and the chat command's `baseUrl()` is the session-aware form. Note the token
54
+ * is per-backend, so pointing `--env` at an env you haven't logged into will
55
+ * 401 until you `hacklab login --env <that>`.
36
56
  */
57
+ export declare function resolveAppUrl(session?: Pick<Session, 'appUrl'> | null): string;
37
58
  export declare function getAppUrl(): string;
38
59
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAKD,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,SAAS,GAAG,SA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AAG,SAAS,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,CAAA;AAEhE,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjE;AASD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC,GAC9C,IAAI,GAAG,IAAI,CAQb;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC,EAC/C,GAAG,OAAa,GACf,OAAO,CAGT;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAyBlE;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAE3D;AAED;;;;GAIG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAOrD;AAED,qDAAqD;AACrD,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAA;AAEV,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,oBAAoB,CAAA;AAE1D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/D;AAQD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAMlE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAAI,GACvC,MAAM,CAOR;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
package/dist/session.js CHANGED
@@ -1,4 +1,4 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
1
+ import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
2
  import { homedir } from 'node:os';
3
3
  import { dirname, join } from 'node:path';
4
4
  const SESSION_PATH = join(homedir(), '.hacklab', 'session.json');
@@ -57,6 +57,20 @@ export async function loadSessionState() {
57
57
  export async function loadSession() {
58
58
  return (await loadSessionState()).session;
59
59
  }
60
+ /**
61
+ * Delete the local session file. Returns true if a file was removed, false if
62
+ * there was nothing to clear (no session). Local-only — it doesn't revoke the
63
+ * token server-side, so the token stays valid until it expires.
64
+ */
65
+ export async function clearSession() {
66
+ try {
67
+ await rm(getSessionPath());
68
+ return true;
69
+ }
70
+ catch {
71
+ return false;
72
+ }
73
+ }
60
74
  /** Named backends the CLI can target via `--env`. */
61
75
  export const HACKLAB_ENVIRONMENTS = {
62
76
  production: 'https://hacklab.so',
@@ -66,15 +80,48 @@ export const HACKLAB_ENVIRONMENTS = {
66
80
  export function isHacklabEnv(value) {
67
81
  return Object.hasOwn(HACKLAB_ENVIRONMENTS, value);
68
82
  }
83
+ // Natural words that aren't a prefix of a canonical name but mean the same env.
84
+ const ENV_ALIASES = {
85
+ local: 'development',
86
+ localhost: 'development',
87
+ };
88
+ /**
89
+ * Resolve an `--env` value to a canonical backend name. Accepts the full name,
90
+ * any unambiguous prefix (`dev`/`prod`/`stag`, mirroring how command names
91
+ * resolve so abbreviations work everywhere), and a couple of natural aliases
92
+ * (`local`/`localhost`). Returns null if it matches none — the three env names
93
+ * start with distinct letters, so a prefix is never ambiguous.
94
+ */
95
+ export function resolveHacklabEnv(value) {
96
+ if (isHacklabEnv(value))
97
+ return value;
98
+ if (Object.hasOwn(ENV_ALIASES, value))
99
+ return ENV_ALIASES[value];
100
+ const names = Object.keys(HACKLAB_ENVIRONMENTS);
101
+ const matches = names.filter((n) => n.startsWith(value));
102
+ return matches.length === 1 ? matches[0] : null;
103
+ }
69
104
  /**
70
- * Which backend to talk to. Precedence: an explicit `HACKLAB_APP_URL`
71
- * (also how `--env` is applied — see index.ts) wins; otherwise default to
72
- * production, so a freshly-installed `hacklab` hits hacklab.so rather than a
73
- * localhost server that isn't running. Use `--env development` (or
74
- * `HACKLAB_APP_URL`) for local work.
105
+ * Which backend to talk to, by precedence:
106
+ * 1. an explicit `HACKLAB_APP_URL` (also how `--env` is applied — see
107
+ * index.ts) so `--env staging` always switches backends;
108
+ * 2. the backend you logged into (`session.appUrl`), when a session is given;
109
+ * 3. the production default, so a freshly-installed `hacklab` hits hacklab.so
110
+ * rather than a localhost server that isn't running.
111
+ *
112
+ * The single source of this precedence: `getAppUrl()` is the no-session form,
113
+ * and the chat command's `baseUrl()` is the session-aware form. Note the token
114
+ * is per-backend, so pointing `--env` at an env you haven't logged into will
115
+ * 401 until you `hacklab login --env <that>`.
75
116
  */
117
+ export function resolveAppUrl(session) {
118
+ const url = process.env.HACKLAB_APP_URL ??
119
+ session?.appUrl ??
120
+ HACKLAB_ENVIRONMENTS.production;
121
+ // Normalize here so callers never re-strip the trailing slash themselves.
122
+ return url.replace(/\/$/, '');
123
+ }
76
124
  export function getAppUrl() {
77
- return (process.env.HACKLAB_APP_URL?.replace(/\/$/, '') ??
78
- HACKLAB_ENVIRONMENTS.production);
125
+ return resolveAppUrl();
79
126
  }
80
127
  //# sourceMappingURL=session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAWzC,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,cAAc,CAAC,CAAA;AAChE,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAMrD,MAAM,UAAU,cAAc;IAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI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B,CAAC,KAAa;IAC7C,IAAI,YAAY,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC,KAAK,CAAE,CAAA;IACjE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAiB,CAAA;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;IACxD,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAClD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAwC;IAExC,MAAM,GAAG,GACP,OAAO,CAAC,GAAG,CAAC,eAAe;QAC3B,OAAO,EAAE,MAAM;QACf,oBAAoB,CAAC,UAAU,CAAA;IACjC,0EAA0E;IAC1E,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,aAAa,EAAE,CAAA;AACxB,CAAC"}
package/dist/share.d.ts CHANGED
@@ -2,8 +2,8 @@ import type { ShareCardData } from './share-card.js';
2
2
  export type { ShareCardData } from './share-card.js';
3
3
  /**
4
4
  * Generate the stats thumbnail, show it inline, copy it to the clipboard, and
5
- * offer to save it. Lifted from the old exam.ts/claim.ts flow into one reusable
6
- * place so `join` (and a future `sync`/`exam`) share it.
5
+ * offer to save it. A reusable place so `join` (and a future `sync --card`)
6
+ * can share the same card rendering.
7
7
  *
8
8
  * Best-effort: card rendering is optional (satori/resvg may fail on some
9
9
  * platforms) and the save prompt is skippable. Never throws — a failed card
package/dist/share.js CHANGED
@@ -7,8 +7,8 @@ import { dim, info, success } from './ui.js';
7
7
  import { openBrowser } from './utils/openBrowser.js';
8
8
  /**
9
9
  * Generate the stats thumbnail, show it inline, copy it to the clipboard, and
10
- * offer to save it. Lifted from the old exam.ts/claim.ts flow into one reusable
11
- * place so `join` (and a future `sync`/`exam`) share it.
10
+ * offer to save it. A reusable place so `join` (and a future `sync --card`)
11
+ * can share the same card rendering.
12
12
  *
13
13
  * Best-effort: card rendering is optional (satori/resvg may fail on some
14
14
  * platforms) and the save prompt is skippable. Never throws — a failed card
package/dist/sync.d.ts CHANGED
@@ -1,34 +1,7 @@
1
- import type { Session } from './session.js';
2
- export type DailyToolEntry = {
3
- date: string;
4
- tool: string;
5
- tokens: number;
6
- messages?: number;
7
- model?: string;
8
- };
9
- export type CursorStats = {
10
- totalCommits: number;
11
- aiLinesAdded: number;
12
- humanLinesAdded: number;
13
- avgAiPercent: number;
14
- models: Array<{
15
- model: string;
16
- uses: number;
17
- }>;
18
- };
19
- export type CursorScanStatus = {
20
- source: 'none';
21
- } | {
22
- source: 'api';
23
- events: number;
24
- } | {
25
- source: 'api-partial';
26
- events: number;
27
- reason: string;
28
- } | {
29
- source: 'api-failed';
30
- reason: string;
31
- };
1
+ import { type CursorScanStatus, type CursorStats, type DailyToolEntry, formatBytes, formatTokens } from './scanners/index.js';
2
+ import { type Session } from './session.js';
3
+ export type { CursorScanStatus, CursorStats, DailyToolEntry };
4
+ export { formatBytes, formatTokens };
32
5
  export type SyncResult = {
33
6
  claudeTotal: number;
34
7
  codexTotal: number;
@@ -57,8 +30,19 @@ type SessionCheck = {
57
30
  };
58
31
  export declare function fetchApi(session: Session, path: string, init?: RequestInit): Promise<Response>;
59
32
  export declare function checkSession(session: Session): Promise<SessionCheck>;
60
- export declare function formatTokens(n: number): string;
61
- export declare function formatBytes(n: number): string;
33
+ /**
34
+ * Ask the server to mirror the user's pinned GitHub repos into their projects
35
+ * (and drop ones that are no longer pinned/public). Best-effort and non-fatal —
36
+ * returns null on any failure so a GitHub hiccup never fails `sync`/`join`.
37
+ */
38
+ export declare function syncGithubRepos(session: Session): Promise<{
39
+ synced: number;
40
+ removed: number;
41
+ } | null>;
42
+ /**
43
+ * Scan local AI usage (via the shared scanners) and upload it to the claim
44
+ * endpoint. Uses the exact same scan path as `join`, so the two commands report
45
+ * identical numbers for the same machine.
46
+ */
62
47
  export declare function runSync(session: Session): Promise<SyncResult>;
63
- export {};
64
48
  //# sourceMappingURL=sync.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAaD,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC/C,CAAA;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5C,MAAM,MAAM,U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