offwatch 0.5.8 → 0.5.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 (94) hide show
  1. package/bin/offwatch.js +7 -6
  2. package/package.json +4 -3
  3. package/src/__tests__/agent-jwt-env.test.ts +79 -0
  4. package/src/__tests__/allowed-hostname.test.ts +80 -0
  5. package/src/__tests__/auth-command-registration.test.ts +16 -0
  6. package/src/__tests__/board-auth.test.ts +53 -0
  7. package/src/__tests__/common.test.ts +98 -0
  8. package/src/__tests__/company-delete.test.ts +95 -0
  9. package/src/__tests__/company-import-export-e2e.test.ts +502 -0
  10. package/src/__tests__/company-import-url.test.ts +74 -0
  11. package/src/__tests__/company-import-zip.test.ts +44 -0
  12. package/src/__tests__/company.test.ts +599 -0
  13. package/src/__tests__/context.test.ts +70 -0
  14. package/src/__tests__/data-dir.test.ts +79 -0
  15. package/src/__tests__/doctor.test.ts +102 -0
  16. package/src/__tests__/feedback.test.ts +177 -0
  17. package/src/__tests__/helpers/embedded-postgres.ts +6 -0
  18. package/src/__tests__/helpers/zip.ts +87 -0
  19. package/src/__tests__/home-paths.test.ts +44 -0
  20. package/src/__tests__/http.test.ts +106 -0
  21. package/src/__tests__/network-bind.test.ts +62 -0
  22. package/src/__tests__/onboard.test.ts +166 -0
  23. package/src/__tests__/routines.test.ts +249 -0
  24. package/src/__tests__/telemetry.test.ts +117 -0
  25. package/src/__tests__/worktree-merge-history.test.ts +492 -0
  26. package/src/__tests__/worktree.test.ts +982 -0
  27. package/src/adapters/http/format-event.ts +4 -0
  28. package/src/adapters/http/index.ts +7 -0
  29. package/src/adapters/index.ts +2 -0
  30. package/src/adapters/process/format-event.ts +4 -0
  31. package/src/adapters/process/index.ts +7 -0
  32. package/src/adapters/registry.ts +63 -0
  33. package/src/checks/agent-jwt-secret-check.ts +40 -0
  34. package/src/checks/config-check.ts +33 -0
  35. package/src/checks/database-check.ts +59 -0
  36. package/src/checks/deployment-auth-check.ts +88 -0
  37. package/src/checks/index.ts +18 -0
  38. package/src/checks/llm-check.ts +82 -0
  39. package/src/checks/log-check.ts +30 -0
  40. package/src/checks/path-resolver.ts +1 -0
  41. package/src/checks/port-check.ts +24 -0
  42. package/src/checks/secrets-check.ts +146 -0
  43. package/src/checks/storage-check.ts +51 -0
  44. package/src/client/board-auth.ts +282 -0
  45. package/src/client/command-label.ts +4 -0
  46. package/src/client/context.ts +175 -0
  47. package/src/client/http.ts +255 -0
  48. package/src/commands/allowed-hostname.ts +40 -0
  49. package/src/commands/auth-bootstrap-ceo.ts +138 -0
  50. package/src/commands/client/activity.ts +71 -0
  51. package/src/commands/client/agent.ts +315 -0
  52. package/src/commands/client/approval.ts +259 -0
  53. package/src/commands/client/auth.ts +113 -0
  54. package/src/commands/client/common.ts +221 -0
  55. package/src/commands/client/company.ts +1578 -0
  56. package/src/commands/client/context.ts +125 -0
  57. package/src/commands/client/dashboard.ts +34 -0
  58. package/src/commands/client/feedback.ts +645 -0
  59. package/src/commands/client/issue.ts +411 -0
  60. package/src/commands/client/plugin.ts +374 -0
  61. package/src/commands/client/zip.ts +129 -0
  62. package/src/commands/configure.ts +201 -0
  63. package/src/commands/db-backup.ts +102 -0
  64. package/src/commands/doctor.ts +203 -0
  65. package/src/commands/env.ts +411 -0
  66. package/src/commands/heartbeat-run.ts +344 -0
  67. package/src/commands/onboard.ts +692 -0
  68. package/src/commands/routines.ts +352 -0
  69. package/src/commands/run.ts +216 -0
  70. package/src/commands/worktree-lib.ts +279 -0
  71. package/src/commands/worktree-merge-history-lib.ts +764 -0
  72. package/src/commands/worktree.ts +2876 -0
  73. package/src/config/data-dir.ts +48 -0
  74. package/src/config/env.ts +125 -0
  75. package/src/config/home.ts +80 -0
  76. package/src/config/hostnames.ts +26 -0
  77. package/src/config/schema.ts +30 -0
  78. package/src/config/secrets-key.ts +48 -0
  79. package/src/config/server-bind.ts +183 -0
  80. package/src/config/store.ts +120 -0
  81. package/src/index.ts +182 -0
  82. package/src/prompts/database.ts +157 -0
  83. package/src/prompts/llm.ts +43 -0
  84. package/src/prompts/logging.ts +37 -0
  85. package/src/prompts/secrets.ts +99 -0
  86. package/src/prompts/server.ts +221 -0
  87. package/src/prompts/storage.ts +146 -0
  88. package/src/telemetry.ts +49 -0
  89. package/src/utils/banner.ts +24 -0
  90. package/src/utils/net.ts +18 -0
  91. package/src/utils/path-resolver.ts +25 -0
  92. package/src/version.ts +10 -0
  93. package/lib/downloader.js +0 -112
  94. package/postinstall.js +0 -23
package/bin/offwatch.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { loadCLIBinPath } from "../lib/downloader.js";
3
2
  import { spawn } from "child_process";
4
- import { dirname } from "path";
3
+ import { dirname, resolve } from "path";
5
4
  import { fileURLToPath } from "url";
6
5
 
7
6
  const __dirname = dirname(fileURLToPath(import.meta.url));
7
+ const srcDir = resolve(__dirname, "..", "src");
8
8
 
9
- const binPath = await loadCLIBinPath(__dirname);
10
-
11
- // Run the downloaded CLI with node
12
- spawn("node", [binPath], { stdio: "inherit" });
9
+ // Run the CLI source with tsx (TypeScript executor)
10
+ spawn("npx", ["tsx", resolve(srcDir, "index.ts")], {
11
+ stdio: "inherit",
12
+ shell: true,
13
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "offwatch",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Offwatch — orchestrate AI agent teams to automate dev work",
5
5
  "type": "module",
6
6
  "bin": {
@@ -24,9 +24,9 @@
24
24
  "url": "https://github.com/triss-smith/offwatch/issues"
25
25
  },
26
26
  "files": [
27
+ "src",
27
28
  "bin",
28
- "lib",
29
- "postinstall.js"
29
+ "lib"
30
30
  ],
31
31
  "publishConfig": {
32
32
  "access": "public"
@@ -35,6 +35,7 @@
35
35
  "postinstall": "node postinstall.js"
36
36
  },
37
37
  "dependencies": {
38
+ "tsx": "^4.19.2",
38
39
  "fs-extra": "^10.1.0",
39
40
  "got": "^14.0.0",
40
41
  "tar": "^6.2.0"
@@ -0,0 +1,79 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import {
6
+ ensureAgentJwtSecret,
7
+ mergePaperclipEnvEntries,
8
+ readAgentJwtSecretFromEnv,
9
+ readPaperclipEnvEntries,
10
+ resolveAgentJwtEnvFile,
11
+ } from "../config/env.js";
12
+ import { agentJwtSecretCheck } from "../checks/agent-jwt-secret-check.js";
13
+
14
+ const ORIGINAL_ENV = { ...process.env };
15
+
16
+ function tempConfigPath(): string {
17
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-jwt-env-"));
18
+ const configDir = path.join(dir, "custom");
19
+ fs.mkdirSync(configDir, { recursive: true });
20
+ return path.join(configDir, "config.json");
21
+ }
22
+
23
+ describe("agent jwt env helpers", () => {
24
+ beforeEach(() => {
25
+ process.env = { ...ORIGINAL_ENV };
26
+ delete process.env.PAPERCLIP_AGENT_JWT_SECRET;
27
+ });
28
+
29
+ afterEach(() => {
30
+ process.env = { ...ORIGINAL_ENV };
31
+ });
32
+
33
+ it("writes .env next to explicit config path", () => {
34
+ const configPath = tempConfigPath();
35
+ const result = ensureAgentJwtSecret(configPath);
36
+
37
+ expect(result.created).toBe(true);
38
+
39
+ const envPath = resolveAgentJwtEnvFile(configPath);
40
+ expect(fs.existsSync(envPath)).toBe(true);
41
+ const contents = fs.readFileSync(envPath, "utf-8");
42
+ expect(contents).toContain("PAPERCLIP_AGENT_JWT_SECRET=");
43
+ });
44
+
45
+ it("loads secret from .env next to explicit config path", () => {
46
+ const configPath = tempConfigPath();
47
+ const envPath = resolveAgentJwtEnvFile(configPath);
48
+ fs.writeFileSync(envPath, "PAPERCLIP_AGENT_JWT_SECRET=test-secret\n", { mode: 0o600 });
49
+
50
+ const loaded = readAgentJwtSecretFromEnv(configPath);
51
+ expect(loaded).toBe("test-secret");
52
+ expect(process.env.PAPERCLIP_AGENT_JWT_SECRET).toBe("test-secret");
53
+ });
54
+
55
+ it("doctor check passes when secret exists in adjacent .env", () => {
56
+ const configPath = tempConfigPath();
57
+ const envPath = resolveAgentJwtEnvFile(configPath);
58
+ fs.writeFileSync(envPath, "PAPERCLIP_AGENT_JWT_SECRET=check-secret\n", { mode: 0o600 });
59
+
60
+ const result = agentJwtSecretCheck(configPath);
61
+ expect(result.status).toBe("pass");
62
+ });
63
+
64
+ it("quotes hash-prefixed env values so dotenv round-trips them", () => {
65
+ const configPath = tempConfigPath();
66
+ const envPath = resolveAgentJwtEnvFile(configPath);
67
+
68
+ mergePaperclipEnvEntries(
69
+ {
70
+ PAPERCLIP_WORKTREE_COLOR: "#439edb",
71
+ },
72
+ envPath,
73
+ );
74
+
75
+ const contents = fs.readFileSync(envPath, "utf-8");
76
+ expect(contents).toContain('PAPERCLIP_WORKTREE_COLOR="#439edb"');
77
+ expect(readPaperclipEnvEntries(envPath).PAPERCLIP_WORKTREE_COLOR).toBe("#439edb");
78
+ });
79
+ });
@@ -0,0 +1,80 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, expect, it } from "vitest";
5
+ import type { PaperclipConfig } from "../config/schema.js";
6
+ import { addAllowedHostname } from "../commands/allowed-hostname.js";
7
+
8
+ function createTempConfigPath() {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-allowed-hostname-"));
10
+ return path.join(dir, "config.json");
11
+ }
12
+
13
+ function writeBaseConfig(configPath: string) {
14
+ const base: PaperclipConfig = {
15
+ $meta: {
16
+ version: 1,
17
+ updatedAt: new Date("2026-01-01T00:00:00.000Z").toISOString(),
18
+ source: "configure",
19
+ },
20
+ database: {
21
+ mode: "embedded-postgres",
22
+ embeddedPostgresDataDir: "/tmp/paperclip-db",
23
+ embeddedPostgresPort: 54329,
24
+ backup: {
25
+ enabled: true,
26
+ intervalMinutes: 60,
27
+ retentionDays: 30,
28
+ dir: "/tmp/paperclip-backups",
29
+ },
30
+ },
31
+ logging: {
32
+ mode: "file",
33
+ logDir: "/tmp/paperclip-logs",
34
+ },
35
+ server: {
36
+ deploymentMode: "authenticated",
37
+ exposure: "private",
38
+ host: "0.0.0.0",
39
+ port: 3100,
40
+ allowedHostnames: [],
41
+ serveUi: true,
42
+ },
43
+ auth: {
44
+ baseUrlMode: "auto",
45
+ disableSignUp: false,
46
+ },
47
+ telemetry: {
48
+ enabled: true,
49
+ },
50
+ storage: {
51
+ provider: "local_disk",
52
+ localDisk: { baseDir: "/tmp/paperclip-storage" },
53
+ s3: {
54
+ bucket: "paperclip",
55
+ region: "us-east-1",
56
+ prefix: "",
57
+ forcePathStyle: false,
58
+ },
59
+ },
60
+ secrets: {
61
+ provider: "local_encrypted",
62
+ strictMode: false,
63
+ localEncrypted: { keyFilePath: "/tmp/paperclip-secrets/master.key" },
64
+ },
65
+ };
66
+ fs.writeFileSync(configPath, JSON.stringify(base, null, 2));
67
+ }
68
+
69
+ describe("allowed-hostname command", () => {
70
+ it("adds and normalizes hostnames", async () => {
71
+ const configPath = createTempConfigPath();
72
+ writeBaseConfig(configPath);
73
+
74
+ await addAllowedHostname("https://Dotta-MacBook-Pro:3100", { config: configPath });
75
+ await addAllowedHostname("dotta-macbook-pro", { config: configPath });
76
+
77
+ const raw = JSON.parse(fs.readFileSync(configPath, "utf-8")) as PaperclipConfig;
78
+ expect(raw.server.allowedHostnames).toEqual(["dotta-macbook-pro"]);
79
+ });
80
+ });
@@ -0,0 +1,16 @@
1
+ import { Command } from "commander";
2
+ import { describe, expect, it } from "vitest";
3
+ import { registerClientAuthCommands } from "../commands/client/auth.js";
4
+
5
+ describe("registerClientAuthCommands", () => {
6
+ it("registers auth commands without duplicate company-id flags", () => {
7
+ const program = new Command();
8
+ const auth = program.command("auth");
9
+
10
+ expect(() => registerClientAuthCommands(auth)).not.toThrow();
11
+
12
+ const login = auth.commands.find((command) => command.name() === "login");
13
+ expect(login).toBeDefined();
14
+ expect(login?.options.filter((option) => option.long === "--company-id")).toHaveLength(1);
15
+ });
16
+ });
@@ -0,0 +1,53 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, expect, it } from "vitest";
5
+ import {
6
+ getStoredBoardCredential,
7
+ readBoardAuthStore,
8
+ removeStoredBoardCredential,
9
+ setStoredBoardCredential,
10
+ } from "../client/board-auth.js";
11
+
12
+ function createTempAuthPath(): string {
13
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-cli-auth-"));
14
+ return path.join(dir, "auth.json");
15
+ }
16
+
17
+ describe("board auth store", () => {
18
+ it("returns an empty store when the file does not exist", () => {
19
+ const authPath = createTempAuthPath();
20
+ expect(readBoardAuthStore(authPath)).toEqual({
21
+ version: 1,
22
+ credentials: {},
23
+ });
24
+ });
25
+
26
+ it("stores and retrieves credentials by normalized api base", () => {
27
+ const authPath = createTempAuthPath();
28
+ setStoredBoardCredential({
29
+ apiBase: "http://localhost:3100/",
30
+ token: "token-123",
31
+ userId: "user-1",
32
+ storePath: authPath,
33
+ });
34
+
35
+ expect(getStoredBoardCredential("http://localhost:3100", authPath)).toMatchObject({
36
+ apiBase: "http://localhost:3100",
37
+ token: "token-123",
38
+ userId: "user-1",
39
+ });
40
+ });
41
+
42
+ it("removes stored credentials", () => {
43
+ const authPath = createTempAuthPath();
44
+ setStoredBoardCredential({
45
+ apiBase: "http://localhost:3100",
46
+ token: "token-123",
47
+ storePath: authPath,
48
+ });
49
+
50
+ expect(removeStoredBoardCredential("http://localhost:3100", authPath)).toBe(true);
51
+ expect(getStoredBoardCredential("http://localhost:3100", authPath)).toBeNull();
52
+ });
53
+ });
@@ -0,0 +1,98 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import { writeContext } from "../client/context.js";
6
+ import { resolveCommandContext } from "../commands/client/common.js";
7
+
8
+ const ORIGINAL_ENV = { ...process.env };
9
+
10
+ function createTempPath(name: string): string {
11
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "paperclip-cli-common-"));
12
+ return path.join(dir, name);
13
+ }
14
+
15
+ describe("resolveCommandContext", () => {
16
+ beforeEach(() => {
17
+ process.env = { ...ORIGINAL_ENV };
18
+ delete process.env.PAPERCLIP_API_URL;
19
+ delete process.env.PAPERCLIP_API_KEY;
20
+ delete process.env.PAPERCLIP_COMPANY_ID;
21
+ });
22
+
23
+ afterEach(() => {
24
+ process.env = { ...ORIGINAL_ENV };
25
+ });
26
+
27
+ it("uses profile defaults when options/env are not provided", () => {
28
+ const contextPath = createTempPath("context.json");
29
+
30
+ writeContext(
31
+ {
32
+ version: 1,
33
+ currentProfile: "ops",
34
+ profiles: {
35
+ ops: {
36
+ apiBase: "http://127.0.0.1:9999",
37
+ companyId: "company-profile",
38
+ apiKeyEnvVarName: "AGENT_KEY",
39
+ },
40
+ },
41
+ },
42
+ contextPath,
43
+ );
44
+ process.env.AGENT_KEY = "key-from-env";
45
+
46
+ const resolved = resolveCommandContext({ context: contextPath }, { requireCompany: true });
47
+ expect(resolved.api.apiBase).toBe("http://127.0.0.1:9999");
48
+ expect(resolved.companyId).toBe("company-profile");
49
+ expect(resolved.api.apiKey).toBe("key-from-env");
50
+ });
51
+
52
+ it("prefers explicit options over profile values", () => {
53
+ const contextPath = createTempPath("context.json");
54
+ writeContext(
55
+ {
56
+ version: 1,
57
+ currentProfile: "default",
58
+ profiles: {
59
+ default: {
60
+ apiBase: "http://profile:3100",
61
+ companyId: "company-profile",
62
+ },
63
+ },
64
+ },
65
+ contextPath,
66
+ );
67
+
68
+ const resolved = resolveCommandContext(
69
+ {
70
+ context: contextPath,
71
+ apiBase: "http://override:3200",
72
+ apiKey: "direct-token",
73
+ companyId: "company-override",
74
+ },
75
+ { requireCompany: true },
76
+ );
77
+
78
+ expect(resolved.api.apiBase).toBe("http://override:3200");
79
+ expect(resolved.companyId).toBe("company-override");
80
+ expect(resolved.api.apiKey).toBe("direct-token");
81
+ });
82
+
83
+ it("throws when company is required but unresolved", () => {
84
+ const contextPath = createTempPath("context.json");
85
+ writeContext(
86
+ {
87
+ version: 1,
88
+ currentProfile: "default",
89
+ profiles: { default: {} },
90
+ },
91
+ contextPath,
92
+ );
93
+
94
+ expect(() =>
95
+ resolveCommandContext({ context: contextPath, apiBase: "http://localhost:3100" }, { requireCompany: true }),
96
+ ).toThrow(/Company ID is required/);
97
+ });
98
+ });
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { Company } from "@paperclipai/shared";
3
+ import { assertDeleteConfirmation, resolveCompanyForDeletion } from "../commands/client/company.js";
4
+
5
+ function makeCompany(overrides: Partial<Company>): Company {
6
+ return {
7
+ id: "11111111-1111-1111-1111-111111111111",
8
+ name: "Alpha",
9
+ description: null,
10
+ status: "active",
11
+ pauseReason: null,
12
+ pausedAt: null,
13
+ issuePrefix: "ALP",
14
+ issueCounter: 1,
15
+ budgetMonthlyCents: 0,
16
+ spentMonthlyCents: 0,
17
+ requireBoardApprovalForNewAgents: false,
18
+ feedbackDataSharingEnabled: false,
19
+ feedbackDataSharingConsentAt: null,
20
+ feedbackDataSharingConsentByUserId: null,
21
+ feedbackDataSharingTermsVersion: null,
22
+ brandColor: null,
23
+ logoAssetId: null,
24
+ logoUrl: null,
25
+ createdAt: new Date(),
26
+ updatedAt: new Date(),
27
+ ...overrides,
28
+ };
29
+ }
30
+
31
+ describe("resolveCompanyForDeletion", () => {
32
+ const companies: Company[] = [
33
+ makeCompany({
34
+ id: "11111111-1111-1111-1111-111111111111",
35
+ name: "Alpha",
36
+ issuePrefix: "ALP",
37
+ }),
38
+ makeCompany({
39
+ id: "22222222-2222-2222-2222-222222222222",
40
+ name: "Paperclip",
41
+ issuePrefix: "PAP",
42
+ }),
43
+ ];
44
+
45
+ it("resolves by ID in auto mode", () => {
46
+ const result = resolveCompanyForDeletion(companies, "22222222-2222-2222-2222-222222222222", "auto");
47
+ expect(result.issuePrefix).toBe("PAP");
48
+ });
49
+
50
+ it("resolves by prefix in auto mode", () => {
51
+ const result = resolveCompanyForDeletion(companies, "pap", "auto");
52
+ expect(result.id).toBe("22222222-2222-2222-2222-222222222222");
53
+ });
54
+
55
+ it("throws when selector is not found", () => {
56
+ expect(() => resolveCompanyForDeletion(companies, "MISSING", "auto")).toThrow(/No company found/);
57
+ });
58
+
59
+ it("respects explicit id mode", () => {
60
+ expect(() => resolveCompanyForDeletion(companies, "PAP", "id")).toThrow(/No company found by ID/);
61
+ });
62
+
63
+ it("respects explicit prefix mode", () => {
64
+ expect(() => resolveCompanyForDeletion(companies, "22222222-2222-2222-2222-222222222222", "prefix"))
65
+ .toThrow(/No company found by shortname/);
66
+ });
67
+ });
68
+
69
+ describe("assertDeleteConfirmation", () => {
70
+ const company = makeCompany({
71
+ id: "22222222-2222-2222-2222-222222222222",
72
+ issuePrefix: "PAP",
73
+ });
74
+
75
+ it("requires --yes", () => {
76
+ expect(() => assertDeleteConfirmation(company, { confirm: "PAP" })).toThrow(/requires --yes/);
77
+ });
78
+
79
+ it("accepts matching prefix confirmation", () => {
80
+ expect(() => assertDeleteConfirmation(company, { yes: true, confirm: "pap" })).not.toThrow();
81
+ });
82
+
83
+ it("accepts matching id confirmation", () => {
84
+ expect(() =>
85
+ assertDeleteConfirmation(company, {
86
+ yes: true,
87
+ confirm: "22222222-2222-2222-2222-222222222222",
88
+ })).not.toThrow();
89
+ });
90
+
91
+ it("rejects mismatched confirmation", () => {
92
+ expect(() => assertDeleteConfirmation(company, { yes: true, confirm: "nope" }))
93
+ .toThrow(/does not match target company/);
94
+ });
95
+ });