@opengsd/gsd-pi 1.7.0 → 1.8.1

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 (89) hide show
  1. package/README.md +8 -6
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/extensions/gsd/doctor-history.js +65 -0
  4. package/dist/resources/extensions/gsd/doctor-state-checks.js +509 -0
  5. package/dist/resources/extensions/gsd/doctor-workspace-checks.js +91 -0
  6. package/dist/resources/extensions/gsd/doctor.js +14 -653
  7. package/dist/resources/extensions/gsd/md-importer.js +7 -2
  8. package/dist/resources/extensions/gsd/migrate/planning-writer.js +8 -2
  9. package/dist/resources/extensions/gsd/migration-auto-check.js +4 -0
  10. package/dist/resources/extensions/gsd/state-reconciliation/drift/project-md.js +54 -14
  11. package/dist/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.js +48 -5
  12. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  13. package/dist/web/standalone/.next/BUILD_ID +1 -1
  14. package/dist/web/standalone/.next/app-path-routes-manifest.json +10 -10
  15. package/dist/web/standalone/.next/build-manifest.json +2 -2
  16. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  17. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  18. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  19. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  22. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  25. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  30. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  31. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  32. package/dist/web/standalone/.next/server/app/index.html +1 -1
  33. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  34. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app-paths-manifest.json +10 -10
  40. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  41. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  42. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  43. package/dist/web/standalone/node_modules/@gsd/native/package.json +1 -1
  44. package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
  45. package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
  46. package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
  47. package/integrations/hermes/open_gsd_hermes/gsd_client.py +1 -1
  48. package/integrations/hermes/pyproject.toml +1 -1
  49. package/package.json +6 -6
  50. package/packages/cloud-mcp-gateway/package.json +2 -2
  51. package/packages/contracts/package.json +1 -1
  52. package/packages/daemon/dist/cloud-config.d.ts.map +1 -1
  53. package/packages/daemon/dist/cloud-config.js +25 -7
  54. package/packages/daemon/dist/cloud-config.js.map +1 -1
  55. package/packages/daemon/dist/cloud-config.test.js +19 -1
  56. package/packages/daemon/dist/cloud-config.test.js.map +1 -1
  57. package/packages/daemon/package.json +4 -4
  58. package/packages/gsd-agent-core/package.json +5 -5
  59. package/packages/gsd-agent-modes/package.json +7 -7
  60. package/packages/gsd-cloud/README.md +18 -4
  61. package/packages/gsd-cloud/bin/gsd-cloud.js +6 -5
  62. package/packages/gsd-cloud/package.json +6 -4
  63. package/packages/mcp-server/package.json +4 -4
  64. package/packages/native/package.json +1 -1
  65. package/packages/pi-agent-core/package.json +1 -1
  66. package/packages/pi-ai/package.json +1 -1
  67. package/packages/pi-coding-agent/package.json +7 -7
  68. package/packages/pi-tui/package.json +2 -2
  69. package/packages/rpc-client/package.json +2 -2
  70. package/pkg/package.json +1 -1
  71. package/src/resources/extensions/gsd/doctor-history.ts +81 -0
  72. package/src/resources/extensions/gsd/doctor-state-checks.ts +527 -0
  73. package/src/resources/extensions/gsd/doctor-workspace-checks.ts +97 -0
  74. package/src/resources/extensions/gsd/doctor.ts +14 -673
  75. package/src/resources/extensions/gsd/md-importer.ts +7 -2
  76. package/src/resources/extensions/gsd/migrate/planning-writer.ts +9 -3
  77. package/src/resources/extensions/gsd/migration-auto-check.ts +3 -0
  78. package/src/resources/extensions/gsd/state-reconciliation/drift/project-md.ts +67 -20
  79. package/src/resources/extensions/gsd/state-reconciliation/drift/sketch-flag.ts +47 -5
  80. package/src/resources/extensions/gsd/tests/db-authority-regression.test.ts +76 -1
  81. package/src/resources/extensions/gsd/tests/doctor-history-public-api.test.ts +25 -0
  82. package/src/resources/extensions/gsd/tests/migrate-hierarchy.test.ts +53 -0
  83. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +53 -0
  84. package/src/resources/extensions/gsd/tests/parsers-legacy-importers.test.ts +4 -0
  85. package/src/resources/extensions/gsd/tests/planning-writer.test.ts +18 -1
  86. package/src/resources/extensions/gsd/tests/progressive-planning.test.ts +18 -3
  87. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +177 -25
  88. /package/dist/web/standalone/.next/static/{enWQFRY-aLTUq3wmxG2Qz → UaXRrOYxBpG9QBINKhZkg}/_buildManifest.js +0 -0
  89. /package/dist/web/standalone/.next/static/{enWQFRY-aLTUq3wmxG2Qz → UaXRrOYxBpG9QBINKhZkg}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-config.test.js","sourceRoot":"","sources":["../src/cloud-config.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACtE,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,eAAe,CAAC,UAAU,EAAE;QACzC,WAAW,EAAE,yBAAyB;QACtC,YAAY,EAAE,qBAAqB;QACnC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,QAAQ;QACtB,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;I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B,OAAO,CAAC,IAAI,oBAAoB;YAChE,IAAI,EAAE,UAAU;SACjB,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACnD,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACrG,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { createServer } from \"node:http\";\nimport { mkdtempSync, readFileSync, statSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { test } from \"node:test\";\nimport { loadConfig } from \"./config.js\";\nimport { exchangePairingCode, parseCloudGatewayUrl, redactedCloudStatus, saveCloudConfig } from \"./cloud-config.js\";\n\ntest(\"cloud config stores device token but redacts status output\", () => {\n const dir = mkdtempSync(join(tmpdir(), \"gsd-cloud-config-\"));\n const configPath = join(dir, \"daemon.yaml\");\n\n const config = saveCloudConfig(configPath, {\n gateway_url: \"https://gateway.example\",\n device_token: \"secret-device-token\",\n runtime_id: \"rt1\",\n runtime_name: \"Laptop\",\n enabled: true,\n });\n\n const rawConfig = readFileSync(configPath, \"utf8\");\n assert.doesNotMatch(rawConfig, /secret-device-token/);\n assert.match(rawConfig, /device_token_encrypted:/);\n assert.equal(statSync(configPath).mode & 0o777, 0o600);\n assert.equal(config.cloud?.device_token, \"secret-device-token\");\n assert.deepEqual(redactedCloudStatus(config), {\n configured: true,\n enabled: true,\n gateway_url: \"https://gateway.example/\",\n runtime_id: \"rt1\",\n runtime_name: \"Laptop\",\n [\"device_\" + \"token\"]: \"[redacted]\",\n });\n});\n\ntest(\"cloud config still reads legacy plaintext device tokens\", () => {\n const dir = mkdtempSync(join(tmpdir(), \"gsd-cloud-config-legacy-\"));\n const configPath = join(dir, \"daemon.yaml\");\n const legacyToken = \"legacy-secret-device-token\";\n writeFileSync(configPath, [\n \"cloud:\",\n \" gateway_url: https://gateway.example/\",\n ` device_token: ${legacyToken}`,\n \" runtime_id: rt1\",\n \"\",\n ].join(\"\\n\"));\n assert.equal(loadConfig(configPath).cloud?.device_token, legacyToken);\n\n const config = saveCloudConfig(configPath, {\n gateway_url: \"https://gateway.example\",\n device_token: legacyToken,\n runtime_id: \"rt1\",\n });\n\n const rawConfig = readFileSync(configPath, \"utf8\");\n assert.equal(config.cloud?.device_token, legacyToken);\n assert.doesNotMatch(rawConfig, new RegExp(legacyToken));\n assert.match(rawConfig, /device_token_encrypted:/);\n});\n\ntest(\"cloud gateway URL validation allows HTTPS and localhost HTTP\", () => {\n assert.equal(parseCloudGatewayUrl(\"https://gateway.example/base/\").toString(), \"https://gateway.example/base\");\n assert.equal(parseCloudGatewayUrl(\"http://localhost:8787\").toString(), \"http://localhost:8787/\");\n assert.equal(parseCloudGatewayUrl(\"http://127.0.0.1:8787\").toString(), \"http://127.0.0.1:8787/\");\n});\n\ntest(\"cloud gateway URL validation rejects unsafe destinations\", () => {\n assert.throws(() => parseCloudGatewayUrl(\"file:///tmp/socket\"), /must use http or https/);\n assert.throws(() => parseCloudGatewayUrl(\"http://gateway.example\"), /Plain HTTP/);\n assert.throws(() => parseCloudGatewayUrl(\"https://user:pass@gateway.example\"), /must not include credentials/);\n assert.throws(() => parseCloudGatewayUrl(\"https://gateway.example/#token\"), /must not include a fragment/);\n assert.throws(() => parseCloudGatewayUrl(\"https://127.0.0.1:8787\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://10.0.0.5\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://192.168.1.10\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://[::1]:8787\"), /must not target private/);\n});\n\ntest(\"pairing exchange rejects unsafe gateway URLs before making requests\", async () => {\n const originalFetch = globalThis.fetch;\n let called = false;\n globalThis.fetch = (async () => {\n called = true;\n throw new Error(\"fetch should not be called\");\n }) as typeof fetch;\n try {\n await assert.rejects(\n exchangePairingCode({ gatewayUrl: \"https://127.0.0.1:8787\", code: \"ABCD1234\" }),\n /must not target private/,\n );\n assert.equal(called, false);\n } finally {\n globalThis.fetch = originalFetch;\n }\n});\n\ntest(\"pairing exchange posts to a validated gateway URL\", async (t) => {\n let requestedUrl = \"\";\n let requestBody = \"\";\n const runtimeAuthValue = \"runtime-auth-fixture\";\n const server = createServer((req, res) => {\n requestedUrl = req.url ?? \"\";\n req.setEncoding(\"utf8\");\n req.on(\"data\", (chunk) => {\n requestBody += chunk;\n });\n req.on(\"end\", () => {\n res.writeHead(200, { \"content-type\": \"application/json\" });\n res.end(JSON.stringify({\n runtimeId: \"rt1\",\n [\"device\" + \"Token\"]: runtimeAuthValue,\n }));\n });\n });\n try {\n await new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject);\n server.listen(0, \"127.0.0.1\", resolve);\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EPERM\") {\n t.skip(\"loopback listen is blocked in this sandbox\");\n return;\n }\n throw err;\n }\n try {\n const address = server.address();\n assert.ok(address && typeof address === \"object\");\n const result = await exchangePairingCode({\n gatewayUrl: `http://127.0.0.1:${address.port}/base?ignored=true`,\n code: \"ABCD1234\",\n });\n assert.equal(result.runtimeId, \"rt1\");\n assert.equal(result.deviceToken, runtimeAuthValue);\n assert.equal(requestedUrl, \"/pairing/exchange\");\n assert.deepEqual(JSON.parse(requestBody), { code: \"ABCD1234\" });\n } finally {\n await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));\n }\n});\n"]}
1
+ {"version":3,"file":"cloud-config.test.js","sourceRoot":"","sources":["../src/cloud-config.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzI,kFAAkF;AAClF,SAAS,gBAAgB,CAAC,GAAW,EAAE,OAAgB;IACrD,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,MAAoF,CACnF,WAAW,EACX,OAAO,EACP,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAG,IAAI,CAAC,CAAC,CAAkB,IAAI,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAC7F,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,CAAC,8HAA8H,EAAE,KAAK,IAAI,EAAE;IAC9I,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,gB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AChE,IAAI,EAAE,UAAU;SACjB,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;QACnD,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IAClE,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACrG,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { createServer } from \"node:http\";\nimport { mkdtempSync, readFileSync, statSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { test } from \"node:test\";\nimport { loadConfig } from \"./config.js\";\nimport { createGatewayLookup, exchangePairingCode, parseCloudGatewayUrl, redactedCloudStatus, saveCloudConfig } from \"./cloud-config.js\";\n\n// Invoke a gateway lookup and capture (err, result) from its Node-style callback.\nfunction runGatewayLookup(url: string, options: unknown): Promise<{ err: Error | null; result: unknown }> {\n const lookup = createGatewayLookup(new URL(url));\n return new Promise((resolve) => {\n (lookup as unknown as (h: string, o: unknown, cb: (...a: unknown[]) => void) => void)(\n \"localhost\",\n options,\n (...args: unknown[]) => resolve({ err: (args[0] as Error | null) ?? null, result: args[1] }),\n );\n });\n}\n\ntest(\"createGatewayLookup honors all:true with an array callback (regression: scalar form threw 'Invalid IP address' on Node >=20)\", async () => {\n const { err, result } = await runGatewayLookup(\"http://localhost\", { all: true, family: 0 });\n assert.equal(err, null, \"loopback allowed for http URL\");\n assert.ok(Array.isArray(result), \"all:true must call back with an array\");\n assert.ok((result as unknown[]).length > 0, \"expected at least one address\");\n});\n\ntest(\"createGatewayLookup all:true still enforces the SSRF guard on every address\", async () => {\n const { err } = await runGatewayLookup(\"https://localhost\", { all: true, family: 0 });\n assert.ok(err instanceof Error, \"https loopback must be rejected\");\n assert.match(err!.message, /private or loopback/);\n});\n\ntest(\"cloud config stores device token but redacts status output\", () => {\n const dir = mkdtempSync(join(tmpdir(), \"gsd-cloud-config-\"));\n const configPath = join(dir, \"daemon.yaml\");\n\n const config = saveCloudConfig(configPath, {\n gateway_url: \"https://gateway.example\",\n device_token: \"secret-device-token\",\n runtime_id: \"rt1\",\n runtime_name: \"Laptop\",\n enabled: true,\n });\n\n const rawConfig = readFileSync(configPath, \"utf8\");\n assert.doesNotMatch(rawConfig, /secret-device-token/);\n assert.match(rawConfig, /device_token_encrypted:/);\n assert.equal(statSync(configPath).mode & 0o777, 0o600);\n assert.equal(config.cloud?.device_token, \"secret-device-token\");\n assert.deepEqual(redactedCloudStatus(config), {\n configured: true,\n enabled: true,\n gateway_url: \"https://gateway.example/\",\n runtime_id: \"rt1\",\n runtime_name: \"Laptop\",\n [\"device_\" + \"token\"]: \"[redacted]\",\n });\n});\n\ntest(\"cloud config still reads legacy plaintext device tokens\", () => {\n const dir = mkdtempSync(join(tmpdir(), \"gsd-cloud-config-legacy-\"));\n const configPath = join(dir, \"daemon.yaml\");\n const legacyToken = \"legacy-secret-device-token\";\n writeFileSync(configPath, [\n \"cloud:\",\n \" gateway_url: https://gateway.example/\",\n ` device_token: ${legacyToken}`,\n \" runtime_id: rt1\",\n \"\",\n ].join(\"\\n\"));\n assert.equal(loadConfig(configPath).cloud?.device_token, legacyToken);\n\n const config = saveCloudConfig(configPath, {\n gateway_url: \"https://gateway.example\",\n device_token: legacyToken,\n runtime_id: \"rt1\",\n });\n\n const rawConfig = readFileSync(configPath, \"utf8\");\n assert.equal(config.cloud?.device_token, legacyToken);\n assert.doesNotMatch(rawConfig, new RegExp(legacyToken));\n assert.match(rawConfig, /device_token_encrypted:/);\n});\n\ntest(\"cloud gateway URL validation allows HTTPS and localhost HTTP\", () => {\n assert.equal(parseCloudGatewayUrl(\"https://gateway.example/base/\").toString(), \"https://gateway.example/base\");\n assert.equal(parseCloudGatewayUrl(\"http://localhost:8787\").toString(), \"http://localhost:8787/\");\n assert.equal(parseCloudGatewayUrl(\"http://127.0.0.1:8787\").toString(), \"http://127.0.0.1:8787/\");\n});\n\ntest(\"cloud gateway URL validation rejects unsafe destinations\", () => {\n assert.throws(() => parseCloudGatewayUrl(\"file:///tmp/socket\"), /must use http or https/);\n assert.throws(() => parseCloudGatewayUrl(\"http://gateway.example\"), /Plain HTTP/);\n assert.throws(() => parseCloudGatewayUrl(\"https://user:pass@gateway.example\"), /must not include credentials/);\n assert.throws(() => parseCloudGatewayUrl(\"https://gateway.example/#token\"), /must not include a fragment/);\n assert.throws(() => parseCloudGatewayUrl(\"https://127.0.0.1:8787\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://10.0.0.5\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://192.168.1.10\"), /must not target private/);\n assert.throws(() => parseCloudGatewayUrl(\"https://[::1]:8787\"), /must not target private/);\n});\n\ntest(\"pairing exchange rejects unsafe gateway URLs before making requests\", async () => {\n const originalFetch = globalThis.fetch;\n let called = false;\n globalThis.fetch = (async () => {\n called = true;\n throw new Error(\"fetch should not be called\");\n }) as typeof fetch;\n try {\n await assert.rejects(\n exchangePairingCode({ gatewayUrl: \"https://127.0.0.1:8787\", code: \"ABCD1234\" }),\n /must not target private/,\n );\n assert.equal(called, false);\n } finally {\n globalThis.fetch = originalFetch;\n }\n});\n\ntest(\"pairing exchange posts to a validated gateway URL\", async (t) => {\n let requestedUrl = \"\";\n let requestBody = \"\";\n const runtimeAuthValue = \"runtime-auth-fixture\";\n const server = createServer((req, res) => {\n requestedUrl = req.url ?? \"\";\n req.setEncoding(\"utf8\");\n req.on(\"data\", (chunk) => {\n requestBody += chunk;\n });\n req.on(\"end\", () => {\n res.writeHead(200, { \"content-type\": \"application/json\" });\n res.end(JSON.stringify({\n runtimeId: \"rt1\",\n [\"device\" + \"Token\"]: runtimeAuthValue,\n }));\n });\n });\n try {\n await new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject);\n server.listen(0, \"127.0.0.1\", resolve);\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EPERM\") {\n t.skip(\"loopback listen is blocked in this sandbox\");\n return;\n }\n throw err;\n }\n try {\n const address = server.address();\n assert.ok(address && typeof address === \"object\");\n const result = await exchangePairingCode({\n gatewayUrl: `http://127.0.0.1:${address.port}/base?ignored=true`,\n code: \"ABCD1234\",\n });\n assert.equal(result.runtimeId, \"rt1\");\n assert.equal(result.deviceToken, runtimeAuthValue);\n assert.equal(requestedUrl, \"/pairing/exchange\");\n assert.deepEqual(JSON.parse(requestBody), { code: \"ABCD1234\" });\n } finally {\n await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));\n }\n});\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengsd/daemon",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "GSD daemon — background process for project monitoring and Discord integration",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@anthropic-ai/sdk": "^0.52.0",
34
- "@opengsd/contracts": "^1.7.0",
35
- "@opengsd/mcp-server": "^1.7.0",
36
- "@opengsd/rpc-client": "^1.7.0",
34
+ "@opengsd/contracts": "^1.8.1",
35
+ "@opengsd/mcp-server": "^1.8.1",
36
+ "@opengsd/rpc-client": "^1.8.1",
37
37
  "discord.js": "^14.25.1",
38
38
  "ws": "^8.20.0",
39
39
  "yaml": "^2.8.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/agent-core",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "GSD session orchestration layer on top of @gsd/pi-coding-agent",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -25,9 +25,9 @@
25
25
  "test": "node --import ../../src/resources/extensions/gsd/tests/resolve-ts.mjs --experimental-strip-types --test src/*.test.ts src/**/*.test.ts"
26
26
  },
27
27
  "dependencies": {
28
- "@gsd/native": "^1.7.0",
29
- "@gsd/pi-agent-core": "^1.7.0",
30
- "@gsd/pi-ai": "^1.7.0",
31
- "@gsd/pi-coding-agent": "^1.7.0"
28
+ "@gsd/native": "^1.8.1",
29
+ "@gsd/pi-agent-core": "^1.8.1",
30
+ "@gsd/pi-ai": "^1.8.1",
31
+ "@gsd/pi-coding-agent": "^1.8.1"
32
32
  }
33
33
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/agent-modes",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "GSD run modes and CLI layer",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -25,12 +25,12 @@
25
25
  "test": "node --import ../../src/resources/extensions/gsd/tests/resolve-ts.mjs --experimental-strip-types --test src/**/*.test.ts"
26
26
  },
27
27
  "dependencies": {
28
- "@gsd/agent-core": "^1.7.0",
29
- "@gsd/pi-agent-core": "^1.7.0",
30
- "@gsd/pi-ai": "^1.7.0",
31
- "@gsd/pi-coding-agent": "^1.7.0",
32
- "@gsd/pi-tui": "^1.7.0",
33
- "@opengsd/contracts": "^1.7.0",
28
+ "@gsd/agent-core": "^1.8.1",
29
+ "@gsd/pi-agent-core": "^1.8.1",
30
+ "@gsd/pi-ai": "^1.8.1",
31
+ "@gsd/pi-coding-agent": "^1.8.1",
32
+ "@gsd/pi-tui": "^1.8.1",
33
+ "@opengsd/contracts": "^1.8.1",
34
34
  "chalk": "^5.5.0"
35
35
  }
36
36
  }
@@ -3,10 +3,15 @@
3
3
  Connect a local GSD runtime to [GSD Cloud](https://cloud.opengsd.net) so you can
4
4
  monitor and control your GSD projects from any browser.
5
5
 
6
- This is a thin wrapper over `@opengsd/daemon`'s cloud runtime commands. Its only
7
- added behavior is defaulting the gateway to `https://cloud.opengsd.net` for the
8
- `login` and `pair` commands, so you never have to type `--gateway`. All
9
- device-flow, pairing, and connection logic is provided by the daemon.
6
+ This is a **self-contained** agent. It depends only on `ws` and `yaml` no
7
+ `@opengsd/daemon`, no `@opengsd/mcp-server`, no `@opengsd/gsd-pi`. It runs the
8
+ RFC 8628 device-flow login, opens a persistent WebSocket to the cloud gateway,
9
+ and forwards each requested GSD workflow tool to your locally-installed `gsd`
10
+ CLI (via `gsd --mode mcp`). The gateway default of `https://cloud.opengsd.net`
11
+ is injected for `login`/`pair` so you never have to type `--gateway`.
12
+
13
+ Requires the `gsd` CLI (from `@opengsd/gsd-pi`) to be installed and on your
14
+ `PATH` (or set `GSD_CLI_PATH`).
10
15
 
11
16
  ## Usage
12
17
 
@@ -29,6 +34,15 @@ npx @opengsd/gsd-cloud disconnect
29
34
  different gateway, pass `--gateway <url>` explicitly — the explicit flag always
30
35
  wins. The `status`, `connect`, and `disconnect` commands do not use a gateway.
31
36
 
37
+ ## Environment
38
+
39
+ - `GSD_CLOUD_PROJECTS` — path-delimiter separated list of project directories to
40
+ advertise to the cloud (default: the current working directory).
41
+ - `GSD_CLI_PATH` — path to the `gsd` binary (default: `gsd` on `PATH`).
42
+ - `GSD_CLOUD_EXECUTOR` — backend adapter: `gsd-pi` (default). `codex` and
43
+ `claude` adapters are stubbed for future use.
44
+
32
45
  ## Requirements
33
46
 
34
47
  - Node.js >= 22
48
+ - The `gsd` CLI (`@opengsd/gsd-pi`) installed locally
@@ -1,25 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  // Project/App: Open GSD
3
- // File Purpose: gsd-cloud CLI entry — inject the default gateway then delegate to the daemon.
3
+ // File Purpose: gsd-cloud CLI entry — inject the default gateway, then run the
4
+ // standalone cloud command handler. No @opengsd/daemon dependency.
4
5
  import { existsSync } from 'node:fs';
5
6
  import { dirname, join } from 'node:path';
6
7
  import { fileURLToPath } from 'node:url';
7
8
 
8
9
  const binDir = dirname(fileURLToPath(import.meta.url));
9
- const target = join(binDir, '..', 'dist', 'inject-gateway.js');
10
+ const distDir = join(binDir, '..', 'dist');
10
11
 
11
- if (!existsSync(target)) {
12
+ if (!existsSync(join(distDir, 'cli.js'))) {
12
13
  process.stderr.write('gsd-cloud: build output missing. Run `pnpm --filter @opengsd/gsd-cloud run build`.\n');
13
14
  process.exit(1);
14
15
  }
15
16
 
16
17
  const { injectDefaultGateway } = await import('../dist/inject-gateway.js');
17
- const { handleCloudRuntimeCommand } = await import('@opengsd/daemon');
18
+ const { handleCloudCommand } = await import('../dist/cli.js');
18
19
 
19
20
  const argv = injectDefaultGateway(process.argv.slice(2));
20
21
 
21
22
  try {
22
- await handleCloudRuntimeCommand(argv, { binaryName: 'gsd-cloud' });
23
+ await handleCloudCommand(argv, { binaryName: 'gsd-cloud' });
23
24
  } catch (err) {
24
25
  const msg = err instanceof Error ? err.message : String(err);
25
26
  process.stderr.write(`gsd-cloud: fatal: ${msg}\n`);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@opengsd/gsd-cloud",
3
- "version": "1.7.0",
4
- "description": "Thin CLI wrapper that connects a local GSD runtime to GSD Cloud (cloud.opengsd.net)",
3
+ "version": "1.8.1",
4
+ "description": "Standalone CLI agent that connects a local GSD runtime to GSD Cloud (cloud.opengsd.net)",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -17,13 +17,15 @@
17
17
  },
18
18
  "scripts": {
19
19
  "build": "node ../../scripts/clean-package-dist.cjs && tsc",
20
- "test": "pnpm run build && node --test dist/inject-gateway.test.js"
20
+ "test": "pnpm run build && node --test dist/inject-gateway.test.js dist/cloud-gateway-lookup.test.js dist/cloud-runtime.test.js dist/executors/mcp-stdio-client.test.js dist/executors/gsd-pi-executor.test.js"
21
21
  },
22
22
  "dependencies": {
23
- "@opengsd/daemon": "^1.7.0"
23
+ "ws": "^8.21.0",
24
+ "yaml": "^2.8.2"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^24.12.0",
28
+ "@types/ws": "^8.5.13",
27
29
  "typescript": "^5.4.0"
28
30
  },
29
31
  "engines": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengsd/mcp-server",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "MCP server exposing GSD orchestration tools for compatible clients",
5
5
  "license": "MIT",
6
6
  "gsd": {
@@ -50,9 +50,9 @@
50
50
  "test": "pnpm run build:test && node --test dist/mcp-server.test.js dist/remote-questions.test.js dist/moonshot-tool-schema.test.js dist/pid-registry.test.js dist/probe-mode.test.js dist/stdio-watchdog.test.js dist/cli-runner.test.js dist/readers/graph.test.js dist/readers/paths.test.js dist/readers/readers.test.js"
51
51
  },
52
52
  "dependencies": {
53
- "@gsd/pi-ai": "^1.7.0",
54
- "@opengsd/contracts": "^1.7.0",
55
- "@opengsd/rpc-client": "^1.7.0",
53
+ "@gsd/pi-ai": "^1.8.1",
54
+ "@opengsd/contracts": "^1.8.1",
55
+ "@opengsd/rpc-client": "^1.8.1",
56
56
  "@modelcontextprotocol/sdk": "^1.27.1",
57
57
  "zod": "^4.0.0"
58
58
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/native",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Native Rust bindings for GSD — high-performance native modules via N-API",
5
5
  "type": "commonjs",
6
6
  "gsd": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-agent-core",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "General-purpose agent with transport abstraction, state management, and attachment support",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-ai",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-coding-agent",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Coding agent CLI (vendored from earendil-works/pi)",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -33,7 +33,7 @@
33
33
  "copy-assets": "node scripts/copy-assets.cjs"
34
34
  },
35
35
  "dependencies": {
36
- "@opengsd/contracts": "^1.7.0",
36
+ "@opengsd/contracts": "^1.8.1",
37
37
  "@mariozechner/jiti": "^2.6.2",
38
38
  "@silvia-odwyer/photon-node": "0.3.4",
39
39
  "chalk": "5.6.2",
@@ -53,11 +53,11 @@
53
53
  "typebox": "1.1.38",
54
54
  "undici": "7.28.0",
55
55
  "yaml": "2.9.0",
56
- "@gsd/agent-core": "^1.7.0",
57
- "@gsd/native": "^1.7.0",
58
- "@gsd/pi-agent-core": "^1.7.0",
59
- "@gsd/pi-ai": "^1.7.0",
60
- "@gsd/pi-tui": "^1.7.0",
56
+ "@gsd/agent-core": "^1.8.1",
57
+ "@gsd/native": "^1.8.1",
58
+ "@gsd/pi-agent-core": "^1.8.1",
59
+ "@gsd/pi-ai": "^1.8.1",
60
+ "@gsd/pi-tui": "^1.8.1",
61
61
  "@sinclair/typebox": "^0.34.41"
62
62
  },
63
63
  "devDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-tui",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Terminal UI library (vendored from earendil-works/pi)",
5
5
  "type": "module",
6
6
  "gsd": {
@@ -21,7 +21,7 @@
21
21
  "build": "node ../../scripts/clean-package-dist.cjs && tsc -p tsconfig.json --incremental false"
22
22
  },
23
23
  "dependencies": {
24
- "@gsd/native": "^1.7.0",
24
+ "@gsd/native": "^1.8.1",
25
25
  "get-east-asian-width": "1.6.0",
26
26
  "marked": "15.0.12",
27
27
  "@sinclair/typebox": "^0.34.41"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengsd/rpc-client",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Standalone RPC client SDK for GSD — zero internal dependencies",
5
5
  "license": "MIT",
6
6
  "gsd": {
@@ -34,7 +34,7 @@
34
34
  "test": "node --test dist/rpc-client.test.js"
35
35
  },
36
36
  "dependencies": {
37
- "@opengsd/contracts": "^1.7.0"
37
+ "@opengsd/contracts": "^1.8.1"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=22.0.0"
package/pkg/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittercowboy/gsd",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "piConfig": {
5
5
  "name": "gsd",
6
6
  "configDir": ".gsd"
@@ -0,0 +1,81 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { saveFile } from "./files.js";
5
+ import { gsdRoot } from "./paths.js";
6
+
7
+ import type { DoctorReport } from "./doctor-types.js";
8
+
9
+ export interface DoctorHistoryEntry {
10
+ ts: string;
11
+ ok: boolean;
12
+ errors: number;
13
+ warnings: number;
14
+ fixes: number;
15
+ codes: string[];
16
+ /** Issue messages with severity and scope (added in Phase 2). */
17
+ issues?: Array<{ severity: string; code: string; message: string; unitId: string }>;
18
+ /** Fix descriptions applied during this run (added in Phase 2). */
19
+ fixDescriptions?: string[];
20
+ /** Milestone/slice scope this doctor run was scoped to (e.g. "M001/S02"). */
21
+ scope?: string;
22
+ /** Human-readable one-line summary of this doctor run. */
23
+ summary?: string;
24
+ }
25
+
26
+ function buildDoctorHistorySummary(report: DoctorReport, errorCount: number, warningCount: number, issueDetails: DoctorHistoryEntry["issues"]): string {
27
+ const summaryParts: string[] = [];
28
+ if (report.ok) {
29
+ summaryParts.push("Clean");
30
+ } else {
31
+ const counts: string[] = [];
32
+ if (errorCount > 0) counts.push(`${errorCount} error${errorCount > 1 ? "s" : ""}`);
33
+ if (warningCount > 0) counts.push(`${warningCount} warning${warningCount > 1 ? "s" : ""}`);
34
+ summaryParts.push(counts.join(", "));
35
+ }
36
+ if (report.fixesApplied.length > 0) {
37
+ summaryParts.push(`${report.fixesApplied.length} fixed`);
38
+ }
39
+ if (issueDetails && issueDetails.length > 0) {
40
+ const topIssue = issueDetails.find(i => i.severity === "error") ?? issueDetails[0]!;
41
+ summaryParts.push(topIssue.message);
42
+ }
43
+ return summaryParts.join(" · ");
44
+ }
45
+
46
+ export async function appendDoctorHistory(basePath: string, report: DoctorReport): Promise<void> {
47
+ try {
48
+ const historyPath = join(gsdRoot(basePath), "doctor-history.jsonl");
49
+ const errorCount = report.issues.filter(i => i.severity === "error").length;
50
+ const warningCount = report.issues.filter(i => i.severity === "warning").length;
51
+ const issueDetails = report.issues
52
+ .filter(i => i.severity === "error" || i.severity === "warning")
53
+ .slice(0, 10) // cap to keep JSONL lines bounded
54
+ .map(i => ({ severity: i.severity, code: i.code, message: i.message, unitId: i.unitId }));
55
+
56
+ const entry = JSON.stringify({
57
+ ts: new Date().toISOString(),
58
+ ok: report.ok,
59
+ errors: errorCount,
60
+ warnings: warningCount,
61
+ fixes: report.fixesApplied.length,
62
+ codes: [...new Set(report.issues.map(i => i.code))],
63
+ issues: issueDetails.length > 0 ? issueDetails : undefined,
64
+ fixDescriptions: report.fixesApplied.length > 0 ? report.fixesApplied : undefined,
65
+ scope: (report as { scope?: string }).scope,
66
+ summary: buildDoctorHistorySummary(report, errorCount, warningCount, issueDetails),
67
+ } satisfies DoctorHistoryEntry);
68
+ const existing = existsSync(historyPath) ? readFileSync(historyPath, "utf-8") : "";
69
+ await saveFile(historyPath, existing + entry + "\n");
70
+ } catch { /* non-fatal */ }
71
+ }
72
+
73
+ /** Read the last N doctor history entries. Returns most-recent-first. */
74
+ export async function readDoctorHistory(basePath: string, lastN = 50): Promise<DoctorHistoryEntry[]> {
75
+ try {
76
+ const historyPath = join(gsdRoot(basePath), "doctor-history.jsonl");
77
+ if (!existsSync(historyPath)) return [];
78
+ const lines = readFileSync(historyPath, "utf-8").split("\n").filter(l => l.trim());
79
+ return lines.slice(-lastN).reverse().map(l => JSON.parse(l) as DoctorHistoryEntry);
80
+ } catch { return []; }
81
+ }