sparkecoder 0.1.131 → 0.1.133

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 (155) hide show
  1. package/dist/agent/index.d.ts +3 -3
  2. package/dist/cli.js +348 -92
  3. package/dist/cli.js.map +1 -1
  4. package/dist/db/index.d.ts +2 -2
  5. package/dist/{index-BM99kjgq.d.ts → index-Bc0p0VPE.d.ts} +96 -96
  6. package/dist/index.d.ts +5 -5
  7. package/dist/index.js +292 -36
  8. package/dist/index.js.map +1 -1
  9. package/dist/{schema-Dz-wABVY.d.ts → schema-BSz4MzhJ.d.ts} +3 -3
  10. package/dist/{search-CVVfuBPZ.d.ts → search-DOzC4ojH.d.ts} +4 -4
  11. package/dist/server/index.js +292 -36
  12. package/dist/server/index.js.map +1 -1
  13. package/dist/tools/index.d.ts +3 -3
  14. package/package.json +1 -1
  15. package/web/.next/BUILD_ID +1 -1
  16. package/web/.next/standalone/web/.next/BUILD_ID +1 -1
  17. package/web/.next/standalone/web/.next/app-path-routes-manifest.json +1 -0
  18. package/web/.next/standalone/web/.next/build-manifest.json +2 -2
  19. package/web/.next/standalone/web/.next/prerender-manifest.json +3 -3
  20. package/web/.next/standalone/web/.next/routes-manifest.json +8 -0
  21. package/web/.next/standalone/web/.next/server/app/(main)/agents/page_client-reference-manifest.js +1 -1
  22. package/web/.next/standalone/web/.next/server/app/(main)/page_client-reference-manifest.js +1 -1
  23. package/web/.next/standalone/web/.next/server/app/(main)/session/[id]/page_client-reference-manifest.js +1 -1
  24. package/web/.next/standalone/web/.next/server/app/(main)/settings/page_client-reference-manifest.js +1 -1
  25. package/web/.next/standalone/web/.next/server/app/_global-error.html +2 -2
  26. package/web/.next/standalone/web/.next/server/app/_global-error.rsc +1 -1
  27. package/web/.next/standalone/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  28. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  29. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  30. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  31. package/web/.next/standalone/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  32. package/web/.next/standalone/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  33. package/web/.next/standalone/web/.next/server/app/_not-found.html +1 -1
  34. package/web/.next/standalone/web/.next/server/app/_not-found.rsc +2 -2
  35. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  36. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  37. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  38. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  39. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  40. package/web/.next/standalone/web/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  41. package/web/.next/standalone/web/.next/server/app/agents.html +1 -1
  42. package/web/.next/standalone/web/.next/server/app/agents.rsc +4 -4
  43. package/web/.next/standalone/web/.next/server/app/agents.segments/!KG1haW4p/agents/__PAGE__.segment.rsc +2 -2
  44. package/web/.next/standalone/web/.next/server/app/agents.segments/!KG1haW4p/agents.segment.rsc +1 -1
  45. package/web/.next/standalone/web/.next/server/app/agents.segments/!KG1haW4p.segment.rsc +2 -2
  46. package/web/.next/standalone/web/.next/server/app/agents.segments/_full.segment.rsc +4 -4
  47. package/web/.next/standalone/web/.next/server/app/agents.segments/_head.segment.rsc +1 -1
  48. package/web/.next/standalone/web/.next/server/app/agents.segments/_index.segment.rsc +2 -2
  49. package/web/.next/standalone/web/.next/server/app/agents.segments/_tree.segment.rsc +1 -1
  50. package/web/.next/standalone/web/.next/server/app/api/config/route.js +2 -1
  51. package/web/.next/standalone/web/.next/server/app/api/config/route.js.nft.json +1 -1
  52. package/web/.next/standalone/web/.next/server/app/api/health/route.js +2 -1
  53. package/web/.next/standalone/web/.next/server/app/api/health/route.js.nft.json +1 -1
  54. package/web/.next/standalone/web/.next/server/app/apple-icon.png/route.js +2 -1
  55. package/web/.next/standalone/web/.next/server/app/apple-icon.png/route.js.nft.json +1 -1
  56. package/web/.next/standalone/web/.next/server/app/docs/installation/page_client-reference-manifest.js +1 -1
  57. package/web/.next/standalone/web/.next/server/app/docs/installation.html +2 -2
  58. package/web/.next/standalone/web/.next/server/app/docs/installation.rsc +3 -3
  59. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_full.segment.rsc +3 -3
  60. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_head.segment.rsc +1 -1
  61. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_index.segment.rsc +2 -2
  62. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/_tree.segment.rsc +1 -1
  63. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation/__PAGE__.segment.rsc +2 -2
  64. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs/installation.segment.rsc +1 -1
  65. package/web/.next/standalone/web/.next/server/app/docs/installation.segments/docs.segment.rsc +2 -2
  66. package/web/.next/standalone/web/.next/server/app/docs/page_client-reference-manifest.js +1 -1
  67. package/web/.next/standalone/web/.next/server/app/docs/skills/page_client-reference-manifest.js +1 -1
  68. package/web/.next/standalone/web/.next/server/app/docs/skills.html +2 -2
  69. package/web/.next/standalone/web/.next/server/app/docs/skills.rsc +3 -3
  70. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_full.segment.rsc +3 -3
  71. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_head.segment.rsc +1 -1
  72. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_index.segment.rsc +2 -2
  73. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/_tree.segment.rsc +1 -1
  74. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills/__PAGE__.segment.rsc +1 -1
  75. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs/skills.segment.rsc +1 -1
  76. package/web/.next/standalone/web/.next/server/app/docs/skills.segments/docs.segment.rsc +2 -2
  77. package/web/.next/standalone/web/.next/server/app/docs/tools/page_client-reference-manifest.js +1 -1
  78. package/web/.next/standalone/web/.next/server/app/docs/tools.html +2 -2
  79. package/web/.next/standalone/web/.next/server/app/docs/tools.rsc +3 -3
  80. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_full.segment.rsc +3 -3
  81. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_head.segment.rsc +1 -1
  82. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_index.segment.rsc +2 -2
  83. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/_tree.segment.rsc +1 -1
  84. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools/__PAGE__.segment.rsc +2 -2
  85. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs/tools.segment.rsc +1 -1
  86. package/web/.next/standalone/web/.next/server/app/docs/tools.segments/docs.segment.rsc +2 -2
  87. package/web/.next/standalone/web/.next/server/app/docs.html +2 -2
  88. package/web/.next/standalone/web/.next/server/app/docs.rsc +3 -3
  89. package/web/.next/standalone/web/.next/server/app/docs.segments/_full.segment.rsc +3 -3
  90. package/web/.next/standalone/web/.next/server/app/docs.segments/_head.segment.rsc +1 -1
  91. package/web/.next/standalone/web/.next/server/app/docs.segments/_index.segment.rsc +2 -2
  92. package/web/.next/standalone/web/.next/server/app/docs.segments/_tree.segment.rsc +1 -1
  93. package/web/.next/standalone/web/.next/server/app/docs.segments/docs/__PAGE__.segment.rsc +2 -2
  94. package/web/.next/standalone/web/.next/server/app/docs.segments/docs.segment.rsc +2 -2
  95. package/web/.next/standalone/web/.next/server/app/favicon.ico/route.js +2 -1
  96. package/web/.next/standalone/web/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  97. package/web/.next/standalone/web/.next/server/app/icon.png/route.js +2 -1
  98. package/web/.next/standalone/web/.next/server/app/icon.png/route.js.nft.json +1 -1
  99. package/web/.next/standalone/web/.next/server/app/index.html +1 -1
  100. package/web/.next/standalone/web/.next/server/app/index.rsc +4 -4
  101. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p/__PAGE__.segment.rsc +2 -2
  102. package/web/.next/standalone/web/.next/server/app/index.segments/!KG1haW4p.segment.rsc +2 -2
  103. package/web/.next/standalone/web/.next/server/app/index.segments/_full.segment.rsc +4 -4
  104. package/web/.next/standalone/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  105. package/web/.next/standalone/web/.next/server/app/index.segments/_index.segment.rsc +2 -2
  106. package/web/.next/standalone/web/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  107. package/web/.next/standalone/web/.next/server/app/opengraph-image.png/route.js +2 -1
  108. package/web/.next/standalone/web/.next/server/app/opengraph-image.png/route.js.nft.json +1 -1
  109. package/web/.next/standalone/web/.next/server/app/settings.html +1 -1
  110. package/web/.next/standalone/web/.next/server/app/settings.rsc +4 -4
  111. package/web/.next/standalone/web/.next/server/app/settings.segments/!KG1haW4p/settings/__PAGE__.segment.rsc +2 -2
  112. package/web/.next/standalone/web/.next/server/app/settings.segments/!KG1haW4p/settings.segment.rsc +1 -1
  113. package/web/.next/standalone/web/.next/server/app/settings.segments/!KG1haW4p.segment.rsc +2 -2
  114. package/web/.next/standalone/web/.next/server/app/settings.segments/_full.segment.rsc +4 -4
  115. package/web/.next/standalone/web/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  116. package/web/.next/standalone/web/.next/server/app/settings.segments/_index.segment.rsc +2 -2
  117. package/web/.next/standalone/web/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
  118. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route/app-paths-manifest.json +3 -0
  119. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route/build-manifest.json +11 -0
  120. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route/server-reference-manifest.json +4 -0
  121. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route.js +6 -0
  122. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route.js.map +5 -0
  123. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route.js.nft.json +1 -0
  124. package/web/.next/standalone/web/.next/server/app/sfapi/[...path]/route_client-reference-manifest.js +2 -0
  125. package/web/.next/standalone/web/.next/server/app/twitter-image.png/route.js +2 -1
  126. package/web/.next/standalone/web/.next/server/app/twitter-image.png/route.js.nft.json +1 -1
  127. package/web/.next/standalone/web/.next/server/app-paths-manifest.json +1 -0
  128. package/web/.next/standalone/web/.next/server/chunks/2374f_next_bb86da32._.js +17 -0
  129. package/web/.next/standalone/web/.next/server/chunks/[root-of-the-server]__24426eb4._.js +7 -0
  130. package/web/.next/standalone/web/.next/server/chunks/[root-of-the-server]__912d97d3._.js +3 -0
  131. package/web/.next/standalone/web/.next/server/chunks/web__next-internal_server_app_sfapi_[___path]_route_actions_36c4ef97.js +3 -0
  132. package/web/.next/standalone/web/.next/server/pages/404.html +1 -1
  133. package/web/.next/standalone/web/.next/server/pages/500.html +2 -2
  134. package/web/.next/standalone/web/.next/server/server-reference-manifest.js +1 -1
  135. package/web/.next/standalone/web/.next/server/server-reference-manifest.json +1 -1
  136. package/web/.next/standalone/web/.next/static/chunks/7a7abb7146d0a913.js +1 -0
  137. package/web/.next/standalone/web/.next/static/static/chunks/7a7abb7146d0a913.js +1 -0
  138. package/web/.next/standalone/web/package-lock.json +12 -12
  139. package/web/.next/standalone/web/runtime-config.json +2 -1
  140. package/web/.next/standalone/web/src/app/sfapi/[...path]/route.ts +100 -0
  141. package/web/.next/standalone/web/src/lib/config.ts +23 -7
  142. package/web/.next/static/chunks/7a7abb7146d0a913.js +1 -0
  143. package/web/.next/standalone/web/.next/server/chunks/[root-of-the-server]__6aefd356._.js +0 -21
  144. package/web/.next/standalone/web/.next/static/chunks/5aece72c38f86fbd.js +0 -1
  145. package/web/.next/standalone/web/.next/static/static/chunks/5aece72c38f86fbd.js +0 -1
  146. package/web/.next/static/chunks/5aece72c38f86fbd.js +0 -1
  147. /package/web/.next/standalone/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_buildManifest.js +0 -0
  148. /package/web/.next/standalone/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_clientMiddlewareManifest.json +0 -0
  149. /package/web/.next/standalone/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_ssgManifest.js +0 -0
  150. /package/web/.next/standalone/web/.next/static/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_buildManifest.js +0 -0
  151. /package/web/.next/standalone/web/.next/static/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_clientMiddlewareManifest.json +0 -0
  152. /package/web/.next/standalone/web/.next/static/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_ssgManifest.js +0 -0
  153. /package/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_buildManifest.js +0 -0
  154. /package/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_clientMiddlewareManifest.json +0 -0
  155. /package/web/.next/static/{KQbunVSU5tNoYBl7TnhLn → Mvd2J29fa2_xre21byVay}/_ssgManifest.js +0 -0
@@ -85,7 +85,7 @@ declare const sessions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
85
85
  tableName: "sessions";
86
86
  dataType: "string";
87
87
  columnType: "SQLiteText";
88
- data: "completed" | "error" | "active" | "waiting";
88
+ data: "error" | "completed" | "active" | "waiting";
89
89
  driverParam: string;
90
90
  notNull: true;
91
91
  hasDefault: true;
@@ -391,7 +391,7 @@ declare const toolExecutions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
391
391
  tableName: "tool_executions";
392
392
  dataType: "string";
393
393
  columnType: "SQLiteText";
394
- data: "completed" | "error" | "pending" | "approved" | "rejected";
394
+ data: "error" | "completed" | "pending" | "approved" | "rejected";
395
395
  driverParam: string;
396
396
  notNull: true;
397
397
  hasDefault: true;
@@ -814,7 +814,7 @@ declare const terminals: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
814
814
  tableName: "terminals";
815
815
  dataType: "string";
816
816
  columnType: "SQLiteText";
817
- data: "running" | "error" | "stopped";
817
+ data: "error" | "running" | "stopped";
818
818
  driverParam: string;
819
819
  notNull: true;
820
820
  hasDefault: true;
@@ -16,11 +16,11 @@ interface BashToolOptions {
16
16
  declare function createBashTool(options: BashToolOptions): ai.Tool<{
17
17
  background: boolean;
18
18
  id?: string | undefined;
19
- input?: string | undefined;
20
19
  command?: string | undefined;
20
+ input?: string | undefined;
21
21
  kill?: boolean | undefined;
22
22
  tail?: number | undefined;
23
- key?: "Enter" | "Escape" | "Up" | "Down" | "Left" | "Right" | "Tab" | "C-c" | "C-d" | "y" | "n" | undefined;
23
+ key?: "y" | "Enter" | "Escape" | "Up" | "Down" | "Left" | "Right" | "Tab" | "C-c" | "C-d" | "n" | undefined;
24
24
  }, {
25
25
  success: boolean;
26
26
  id: string;
@@ -66,7 +66,7 @@ declare function createBashTool(options: BashToolOptions): ai.Tool<{
66
66
  id: string;
67
67
  output: string;
68
68
  exitCode: number;
69
- status: "running" | "completed" | "error" | "stopped";
69
+ status: "error" | "completed" | "running" | "stopped";
70
70
  message?: undefined;
71
71
  error?: undefined;
72
72
  } | {
@@ -218,8 +218,8 @@ interface SearchToolOptions {
218
218
  * Progress is streamed back to the UI so users can see exploration happening.
219
219
  */
220
220
  declare function createSearchTool(options: SearchToolOptions): ai.Tool<{
221
- query: string;
222
221
  context: string;
222
+ query: string;
223
223
  }, {
224
224
  success: boolean;
225
225
  error: string;
@@ -1162,12 +1162,12 @@ function loadConfig(configPath, workingDirectory) {
1162
1162
  ]
1163
1163
  };
1164
1164
  const DEFAULT_REMOTE_URL = "https://agent-remote-server.sparkecode.com";
1165
- const remoteUrl = process.env.SPARKECODER_REMOTE_URL || config.remoteServer?.url || DEFAULT_REMOTE_URL;
1165
+ const remoteUrl2 = process.env.SPARKECODER_REMOTE_URL || config.remoteServer?.url || DEFAULT_REMOTE_URL;
1166
1166
  const remoteAuthKey = process.env.SPARKECODER_AUTH_KEY || config.remoteServer?.authKey || loadStoredAuthKey();
1167
1167
  const resolvedRemoteServer = {
1168
- url: remoteUrl,
1168
+ url: remoteUrl2,
1169
1169
  authKey: remoteAuthKey,
1170
- isConfigured: !!remoteUrl && !!remoteAuthKey
1170
+ isConfigured: !!remoteUrl2 && !!remoteAuthKey
1171
1171
  };
1172
1172
  const resolved = {
1173
1173
  ...config,
@@ -4893,11 +4893,11 @@ async function getRepoNamespace(workingDirectory, configuredNamespace) {
4893
4893
  if (configuredNamespace) {
4894
4894
  return configuredNamespace;
4895
4895
  }
4896
- const remoteUrl = getGitRemoteUrl(workingDirectory);
4897
- if (!remoteUrl) {
4896
+ const remoteUrl2 = getGitRemoteUrl(workingDirectory);
4897
+ if (!remoteUrl2) {
4898
4898
  return null;
4899
4899
  }
4900
- const parsed = parseGitRemoteUrl(remoteUrl);
4900
+ const parsed = parseGitRemoteUrl(remoteUrl2);
4901
4901
  if (!parsed) {
4902
4902
  return null;
4903
4903
  }
@@ -8345,6 +8345,29 @@ var init_persistence = __esm({
8345
8345
  });
8346
8346
 
8347
8347
  // src/integrations/slack/client.ts
8348
+ var client_exports = {};
8349
+ __export(client_exports, {
8350
+ LOADING_REACTION: () => LOADING_REACTION,
8351
+ RESULT_REACTIONS: () => RESULT_REACTIONS,
8352
+ addLoadingReaction: () => addLoadingReaction,
8353
+ addResultReaction: () => addResultReaction,
8354
+ botParticipatedInThread: () => botParticipatedInThread,
8355
+ ensureSlackSelfIdentity: () => ensureSlackSelfIdentity,
8356
+ getCachedSlackSelfIdentity: () => getCachedSlackSelfIdentity,
8357
+ getDefaultOrchestratorName: () => getDefaultOrchestratorName,
8358
+ getSlackAdapter: () => getSlackAdapter,
8359
+ getSlackAllowlistPolicy: () => getSlackAllowlistPolicy,
8360
+ getSlackBotToken: () => getSlackBotToken,
8361
+ getSlackDeniedReplyPolicy: () => getSlackDeniedReplyPolicy,
8362
+ getSlackSigningSecret: () => getSlackSigningSecret,
8363
+ isSlackConfigured: () => isSlackConfigured,
8364
+ normalizeSlackMentions: () => normalizeSlackMentions,
8365
+ noteBotPostedInThread: () => noteBotPostedInThread,
8366
+ postThreadMessage: () => postThreadMessage,
8367
+ removeLoadingReaction: () => removeLoadingReaction,
8368
+ resolveSlackUserInfo: () => resolveSlackUserInfo,
8369
+ resolveSlackUserName: () => resolveSlackUserName
8370
+ });
8348
8371
  function slackBackoffMs(attempt) {
8349
8372
  const expo = SLACK_BACKOFF_BASE_MS * 2 ** attempt;
8350
8373
  const jitter = Math.floor(Math.random() * SLACK_BACKOFF_BASE_MS);
@@ -11661,11 +11684,11 @@ ${p.text}` : p.text;
11661
11684
  const { isRemoteConfigured: isRemoteConfigured2, storageQueries: storageQueries2 } = await Promise.resolve().then(() => (init_remote(), remote_exports));
11662
11685
  if (!isRemoteConfigured2()) return [];
11663
11686
  const { readFile: readFile13 } = await import("fs/promises");
11664
- const { join: join19, basename: basename7 } = await import("path");
11687
+ const { join: join20, basename: basename7 } = await import("path");
11665
11688
  const urls = [];
11666
11689
  for (const filePath of filePaths) {
11667
11690
  try {
11668
- const fullPath = filePath.startsWith("/") ? filePath : join19(this.session.workingDirectory, filePath);
11691
+ const fullPath = filePath.startsWith("/") ? filePath : join20(this.session.workingDirectory, filePath);
11669
11692
  const fileName = basename7(fullPath);
11670
11693
  const ext = fileName.split(".").pop()?.toLowerCase() || "";
11671
11694
  const mimeMap = {
@@ -12036,6 +12059,233 @@ var init_ensure_orchestrator = __esm({
12036
12059
  }
12037
12060
  });
12038
12061
 
12062
+ // src/orchestrator/self-update.ts
12063
+ var self_update_exports = {};
12064
+ __export(self_update_exports, {
12065
+ __test: () => __test,
12066
+ startSelfUpdater: () => startSelfUpdater,
12067
+ stopSelfUpdater: () => stopSelfUpdater
12068
+ });
12069
+ import { spawn as spawn2, execFile } from "child_process";
12070
+ import { readFileSync as readFileSync11, writeFileSync as writeFileSync7, mkdirSync as mkdirSync10 } from "fs";
12071
+ import { dirname as dirname10, join as join18 } from "path";
12072
+ import { fileURLToPath as fileURLToPath4 } from "url";
12073
+ function currentVersion2() {
12074
+ const here = dirname10(fileURLToPath4(import.meta.url));
12075
+ const candidates = [
12076
+ join18(here, "..", "..", "package.json"),
12077
+ join18(here, "..", "package.json"),
12078
+ join18(process.cwd(), "package.json")
12079
+ ];
12080
+ for (const p of candidates) {
12081
+ try {
12082
+ const pkg = JSON.parse(readFileSync11(p, "utf8"));
12083
+ if (pkg.name === "sparkecoder" && pkg.version) return pkg.version;
12084
+ } catch {
12085
+ }
12086
+ }
12087
+ return "0.0.0";
12088
+ }
12089
+ function isLikelyGlobalInstall() {
12090
+ const here = dirname10(fileURLToPath4(import.meta.url));
12091
+ return here.includes("/node_modules/sparkecoder/") || here.includes("\\node_modules\\sparkecoder\\");
12092
+ }
12093
+ function isEnabled() {
12094
+ if (process.env.SPARKECODER_AUTO_UPDATE === "false" || process.env.SPARKECODER_AUTO_UPDATE === "0") return false;
12095
+ try {
12096
+ const cfg = getConfig();
12097
+ if (cfg?.autoUpdate?.enabled === false) return false;
12098
+ } catch {
12099
+ }
12100
+ return true;
12101
+ }
12102
+ function remoteUrl() {
12103
+ try {
12104
+ const cfg = getConfig();
12105
+ const url = cfg?.remoteServer?.url;
12106
+ return typeof url === "string" && url.length > 0 ? url.replace(/\/+$/, "") : null;
12107
+ } catch {
12108
+ return null;
12109
+ }
12110
+ }
12111
+ function intervalMs() {
12112
+ try {
12113
+ const h = getConfig()?.autoUpdate?.intervalHours;
12114
+ if (typeof h === "number" && h > 0) return h * 60 * 6e4;
12115
+ } catch {
12116
+ }
12117
+ return DEFAULT_INTERVAL_HOURS * 60 * 6e4;
12118
+ }
12119
+ function semverGt(a, b) {
12120
+ const parse = (v) => v.split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
12121
+ const pa = parse(a);
12122
+ const pb = parse(b);
12123
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
12124
+ const x = pa[i] ?? 0;
12125
+ const y = pb[i] ?? 0;
12126
+ if (x > y) return true;
12127
+ if (x < y) return false;
12128
+ }
12129
+ return false;
12130
+ }
12131
+ function statePath() {
12132
+ try {
12133
+ return join18(getAppDataDirectory(), "self-update-state.json");
12134
+ } catch {
12135
+ return null;
12136
+ }
12137
+ }
12138
+ function readState() {
12139
+ const p = statePath();
12140
+ if (!p) return {};
12141
+ try {
12142
+ return JSON.parse(readFileSync11(p, "utf8"));
12143
+ } catch {
12144
+ return {};
12145
+ }
12146
+ }
12147
+ function writeState(s) {
12148
+ const p = statePath();
12149
+ if (!p) return;
12150
+ try {
12151
+ mkdirSync10(dirname10(p), { recursive: true });
12152
+ writeFileSync7(p, JSON.stringify(s));
12153
+ } catch {
12154
+ }
12155
+ }
12156
+ function attemptedRecently(target, now) {
12157
+ const s = readState();
12158
+ return s.lastTarget === target && typeof s.lastAttemptAt === "number" && now - s.lastAttemptAt < RETRY_COOLDOWN_MS;
12159
+ }
12160
+ function latestPublishedVersion() {
12161
+ return new Promise((resolve13) => {
12162
+ execFile("npm", ["view", "sparkecoder", "version"], { timeout: 3e4 }, (err, stdout) => {
12163
+ if (err) {
12164
+ resolve13(null);
12165
+ return;
12166
+ }
12167
+ const v = String(stdout).trim();
12168
+ resolve13(/^\d+\.\d+\.\d+/.test(v) ? v : null);
12169
+ });
12170
+ });
12171
+ }
12172
+ function runInstaller(url) {
12173
+ const secret = process.env.SPARKECODER_SETUP_SECRET || process.env.SPARKECODER_TUNNEL_SECRET || "";
12174
+ const query = secret ? `?secret=${encodeURIComponent(secret)}` : "";
12175
+ const oneLiner = `bash -c "$(curl -fsSL '${url}/install.sh${query}')" >/tmp/sparkecoder-selfupdate.log 2>&1`;
12176
+ const child = spawn2("bash", ["-lc", oneLiner], {
12177
+ detached: true,
12178
+ stdio: "ignore"
12179
+ });
12180
+ child.unref();
12181
+ }
12182
+ async function checkAndUpdate() {
12183
+ if (upgrading || !isEnabled()) return;
12184
+ const url = remoteUrl();
12185
+ if (!url) return;
12186
+ const latest = await latestPublishedVersion();
12187
+ if (!latest) return;
12188
+ const current = currentVersion2();
12189
+ if (!semverGt(latest, current)) return;
12190
+ const now = Date.now();
12191
+ if (attemptedRecently(latest, now)) {
12192
+ console.log(`[self-update] v${latest} already attempted recently; skipping until cooldown elapses`);
12193
+ return;
12194
+ }
12195
+ upgrading = true;
12196
+ const announced = await announceUpdate(latest);
12197
+ const delay = announced ? ANNOUNCE_GRACE_MS : 0;
12198
+ if (announced) {
12199
+ console.log(`[self-update] announced v${latest} in Slack; updating in ${Math.round(delay / 6e4)}m`);
12200
+ }
12201
+ const t = setTimeout(() => doInstall(latest, url, current), delay);
12202
+ if (typeof t.unref === "function") t.unref();
12203
+ }
12204
+ function doInstall(latest, url, current) {
12205
+ const prev = readState();
12206
+ writeState({
12207
+ lastTarget: latest,
12208
+ lastAttemptAt: Date.now(),
12209
+ attempts: prev.lastTarget === latest ? (prev.attempts ?? 0) + 1 : 1
12210
+ });
12211
+ console.log(`[self-update] newer version available: v${current} \u2192 v${latest}; re-running installer`);
12212
+ try {
12213
+ runInstaller(url);
12214
+ } catch (err) {
12215
+ upgrading = false;
12216
+ console.warn("[self-update] failed to launch installer:", err?.message || err);
12217
+ }
12218
+ }
12219
+ async function findOrchestratorId() {
12220
+ try {
12221
+ const { sessionQueries: sessionQueries2 } = await Promise.resolve().then(() => (init_db(), db_exports));
12222
+ const all = await sessionQueries2.list(500, 0);
12223
+ const orch = all.find((s) => s?.config?.role === "orchestrator");
12224
+ return orch?.id ?? null;
12225
+ } catch {
12226
+ return null;
12227
+ }
12228
+ }
12229
+ async function announceUpdate(target) {
12230
+ try {
12231
+ const { isSlackConfigured: isSlackConfigured2 } = await Promise.resolve().then(() => (init_client3(), client_exports));
12232
+ if (!isSlackConfigured2()) return false;
12233
+ const orchId = await findOrchestratorId();
12234
+ if (!orchId) return false;
12235
+ const { pushToInbox: pushToInbox2 } = await Promise.resolve().then(() => (init_inbox(), inbox_exports));
12236
+ pushToInbox2(orchId, {
12237
+ ref: { channel: "system", kind: "worker.completed", workerId: "self-update", workerName: "self-update" },
12238
+ content: `[SYSTEM self-update] A software update to v${target} will begin in about 5 minutes and the service will restart briefly (expect ~1\u20132 minutes of downtime). Send a short Slack heads-up to whoever you normally talk to / the bot owner that you'll be offline for a quick update, then carry on. Use the messenger tool to deliver it. If you genuinely don't know who to tell, post in the most relevant channel you've recently been active in; if Slack isn't reachable, skip silently \u2014 the update will proceed regardless.`,
12239
+ wake: "now",
12240
+ enqueuedAt: /* @__PURE__ */ new Date()
12241
+ });
12242
+ return true;
12243
+ } catch {
12244
+ return false;
12245
+ }
12246
+ }
12247
+ function startSelfUpdater() {
12248
+ if (started) return;
12249
+ started = true;
12250
+ if (!isEnabled()) {
12251
+ console.log("[self-update] disabled");
12252
+ return;
12253
+ }
12254
+ if (!isLikelyGlobalInstall()) {
12255
+ console.log("[self-update] skipped (not a global install)");
12256
+ return;
12257
+ }
12258
+ const kickoff = setTimeout(() => {
12259
+ void checkAndUpdate();
12260
+ timer = setInterval(() => {
12261
+ void checkAndUpdate();
12262
+ }, intervalMs());
12263
+ if (typeof timer.unref === "function") timer.unref();
12264
+ }, INITIAL_DELAY_MS);
12265
+ if (typeof kickoff.unref === "function") kickoff.unref();
12266
+ }
12267
+ function stopSelfUpdater() {
12268
+ if (timer) {
12269
+ clearInterval(timer);
12270
+ timer = null;
12271
+ }
12272
+ }
12273
+ var INITIAL_DELAY_MS, DEFAULT_INTERVAL_HOURS, ANNOUNCE_GRACE_MS, RETRY_COOLDOWN_MS, timer, started, upgrading, __test;
12274
+ var init_self_update = __esm({
12275
+ "src/orchestrator/self-update.ts"() {
12276
+ "use strict";
12277
+ init_config();
12278
+ INITIAL_DELAY_MS = 5 * 6e4;
12279
+ DEFAULT_INTERVAL_HOURS = 6;
12280
+ ANNOUNCE_GRACE_MS = 5 * 6e4;
12281
+ RETRY_COOLDOWN_MS = 24 * 60 * 6e4;
12282
+ timer = null;
12283
+ started = false;
12284
+ upgrading = false;
12285
+ __test = { currentVersion: currentVersion2, semverGt, isLikelyGlobalInstall };
12286
+ }
12287
+ });
12288
+
12039
12289
  // src/tasks/scheduler.ts
12040
12290
  var scheduler_exports = {};
12041
12291
  __export(scheduler_exports, {
@@ -12119,11 +12369,11 @@ import { Hono as Hono10 } from "hono";
12119
12369
  import { serve } from "@hono/node-server";
12120
12370
  import { cors } from "hono/cors";
12121
12371
  import { logger } from "hono/logger";
12122
- import { existsSync as existsSync22, mkdirSync as mkdirSync10, writeFileSync as writeFileSync7 } from "fs";
12123
- import { resolve as resolve12, dirname as dirname10, join as join18 } from "path";
12124
- import { spawn as spawn2 } from "child_process";
12372
+ import { existsSync as existsSync22, mkdirSync as mkdirSync11, writeFileSync as writeFileSync8 } from "fs";
12373
+ import { resolve as resolve12, dirname as dirname11, join as join19 } from "path";
12374
+ import { spawn as spawn3 } from "child_process";
12125
12375
  import { createServer as createNetServer } from "net";
12126
- import { fileURLToPath as fileURLToPath4 } from "url";
12376
+ import { fileURLToPath as fileURLToPath5 } from "url";
12127
12377
 
12128
12378
  // src/server/routes/sessions.ts
12129
12379
  init_db();
@@ -16506,13 +16756,13 @@ var DEFAULT_WEB_PORT = 6969;
16506
16756
  var WEB_PORT_SEQUENCE = [6969, 6970, 6971, 6972, 6973, 6974, 6975, 6976, 6977, 6978];
16507
16757
  function getWebDirectory() {
16508
16758
  try {
16509
- const currentDir = dirname10(fileURLToPath4(import.meta.url));
16759
+ const currentDir = dirname11(fileURLToPath5(import.meta.url));
16510
16760
  const webDir = resolve12(currentDir, "..", "web");
16511
- if (existsSync22(webDir) && existsSync22(join18(webDir, "package.json"))) {
16761
+ if (existsSync22(webDir) && existsSync22(join19(webDir, "package.json"))) {
16512
16762
  return webDir;
16513
16763
  }
16514
16764
  const altWebDir = resolve12(currentDir, "..", "..", "web");
16515
- if (existsSync22(altWebDir) && existsSync22(join18(altWebDir, "package.json"))) {
16765
+ if (existsSync22(altWebDir) && existsSync22(join19(altWebDir, "package.json"))) {
16516
16766
  return altWebDir;
16517
16767
  }
16518
16768
  return null;
@@ -16570,20 +16820,20 @@ async function findWebPort(preferredPort) {
16570
16820
  return { port: preferredPort, alreadyRunning: false };
16571
16821
  }
16572
16822
  function hasProductionBuild(webDir) {
16573
- const buildIdPath = join18(webDir, ".next", "BUILD_ID");
16823
+ const buildIdPath = join19(webDir, ".next", "BUILD_ID");
16574
16824
  return existsSync22(buildIdPath);
16575
16825
  }
16576
16826
  function hasSourceFiles(webDir) {
16577
- const appDir = join18(webDir, "src", "app");
16578
- const pagesDir = join18(webDir, "src", "pages");
16579
- const rootAppDir = join18(webDir, "app");
16580
- const rootPagesDir = join18(webDir, "pages");
16827
+ const appDir = join19(webDir, "src", "app");
16828
+ const pagesDir = join19(webDir, "src", "pages");
16829
+ const rootAppDir = join19(webDir, "app");
16830
+ const rootPagesDir = join19(webDir, "pages");
16581
16831
  return existsSync22(appDir) || existsSync22(pagesDir) || existsSync22(rootAppDir) || existsSync22(rootPagesDir);
16582
16832
  }
16583
16833
  function getStandaloneServerPath(webDir) {
16584
16834
  const possiblePaths2 = [
16585
- join18(webDir, ".next", "standalone", "server.js"),
16586
- join18(webDir, ".next", "standalone", "web", "server.js")
16835
+ join19(webDir, ".next", "standalone", "server.js"),
16836
+ join19(webDir, ".next", "standalone", "web", "server.js")
16587
16837
  ];
16588
16838
  for (const serverPath of possiblePaths2) {
16589
16839
  if (existsSync22(serverPath)) {
@@ -16594,7 +16844,7 @@ function getStandaloneServerPath(webDir) {
16594
16844
  }
16595
16845
  function runCommand(command, args, cwd, env) {
16596
16846
  return new Promise((resolve13) => {
16597
- const child = spawn2(command, args, {
16847
+ const child = spawn3(command, args, {
16598
16848
  cwd,
16599
16849
  stdio: ["ignore", "pipe", "pipe"],
16600
16850
  env,
@@ -16626,15 +16876,15 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16626
16876
  if (!quiet) console.log(` \u2713 Web UI already running at http://localhost:${actualPort}`);
16627
16877
  return { process: null, port: actualPort };
16628
16878
  }
16629
- const usePnpm = existsSync22(join18(webDir, "pnpm-lock.yaml"));
16630
- const useNpm = !usePnpm && existsSync22(join18(webDir, "package-lock.json"));
16879
+ const usePnpm = existsSync22(join19(webDir, "pnpm-lock.yaml"));
16880
+ const useNpm = !usePnpm && existsSync22(join19(webDir, "package-lock.json"));
16631
16881
  const pkgManager = usePnpm ? "pnpm" : useNpm ? "npm" : "npx";
16632
16882
  const { NODE_OPTIONS, TSX_TSCONFIG_PATH, ...cleanEnv } = process.env;
16633
16883
  const apiUrl = publicUrl || `http://127.0.0.1:${apiPort}`;
16634
- const runtimeConfig = { apiBaseUrl: apiUrl };
16635
- const runtimeConfigPath = join18(webDir, "runtime-config.json");
16884
+ const runtimeConfig = { apiBaseUrl: apiUrl, localApiBaseUrl: `http://127.0.0.1:${apiPort}` };
16885
+ const runtimeConfigPath = join19(webDir, "runtime-config.json");
16636
16886
  try {
16637
- writeFileSync7(runtimeConfigPath, JSON.stringify(runtimeConfig, null, 2));
16887
+ writeFileSync8(runtimeConfigPath, JSON.stringify(runtimeConfig, null, 2));
16638
16888
  if (!quiet) console.log(` \u{1F4DD} Runtime config written to ${runtimeConfigPath}`);
16639
16889
  } catch (err) {
16640
16890
  if (!quiet) console.warn(` \u26A0 Could not write runtime config: ${err}`);
@@ -16654,7 +16904,7 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16654
16904
  if (standaloneServerPath) {
16655
16905
  command = "node";
16656
16906
  args = ["server.js"];
16657
- cwd = dirname10(standaloneServerPath);
16907
+ cwd = dirname11(standaloneServerPath);
16658
16908
  webEnv.PORT = String(actualPort);
16659
16909
  webEnv.HOSTNAME = "0.0.0.0";
16660
16910
  if (!quiet) console.log(" \u{1F4E6} Starting Web UI from standalone build...");
@@ -16684,7 +16934,7 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16684
16934
  }
16685
16935
  return { process: null, port: actualPort };
16686
16936
  }
16687
- const child = spawn2(command, args, {
16937
+ const child = spawn3(command, args, {
16688
16938
  cwd,
16689
16939
  stdio: ["ignore", "pipe", "pipe"],
16690
16940
  env: webEnv,
@@ -16692,12 +16942,12 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16692
16942
  shell: true
16693
16943
  });
16694
16944
  const startupTimeout = 3e4;
16695
- let started = false;
16945
+ let started2 = false;
16696
16946
  let exited = false;
16697
16947
  let exitCode = null;
16698
16948
  const startedPromise = new Promise((resolve13) => {
16699
16949
  const timeout = setTimeout(() => {
16700
- if (!started && !exited) {
16950
+ if (!started2 && !exited) {
16701
16951
  resolve13(false);
16702
16952
  }
16703
16953
  }, startupTimeout);
@@ -16709,8 +16959,8 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16709
16959
  console.log(` Web UI: ${line}`);
16710
16960
  }
16711
16961
  }
16712
- if (!started && (output.includes("Ready") || output.includes("started") || output.includes("localhost"))) {
16713
- started = true;
16962
+ if (!started2 && (output.includes("Ready") || output.includes("started") || output.includes("localhost"))) {
16963
+ started2 = true;
16714
16964
  clearTimeout(timeout);
16715
16965
  resolve13(true);
16716
16966
  }
@@ -16729,7 +16979,7 @@ async function startWebUI(apiPort, webPort = DEFAULT_WEB_PORT, quiet = false, pu
16729
16979
  child.on("exit", (code) => {
16730
16980
  exited = true;
16731
16981
  exitCode = code;
16732
- if (!started) {
16982
+ if (!started2) {
16733
16983
  clearTimeout(timeout);
16734
16984
  resolve13(false);
16735
16985
  }
@@ -16849,7 +17099,7 @@ async function startServer(options = {}) {
16849
17099
  config.resolvedWorkingDirectory = options.workingDirectory;
16850
17100
  }
16851
17101
  if (!existsSync22(config.resolvedWorkingDirectory)) {
16852
- mkdirSync10(config.resolvedWorkingDirectory, { recursive: true });
17102
+ mkdirSync11(config.resolvedWorkingDirectory, { recursive: true });
16853
17103
  if (!options.quiet) console.log(`\u{1F4C1} Created agent workspace: ${config.resolvedWorkingDirectory}`);
16854
17104
  }
16855
17105
  if (!config.resolvedRemoteServer.url) {
@@ -16885,6 +17135,12 @@ async function startServer(options = {}) {
16885
17135
  } catch (err) {
16886
17136
  if (!options.quiet) console.warn(`[daemon] start skipped: ${err.message}`);
16887
17137
  }
17138
+ try {
17139
+ const { startSelfUpdater: startSelfUpdater2 } = await Promise.resolve().then(() => (init_self_update(), self_update_exports));
17140
+ startSelfUpdater2();
17141
+ } catch (err) {
17142
+ if (!options.quiet) console.warn(`[self-update] start skipped: ${err.message}`);
17143
+ }
16888
17144
  try {
16889
17145
  const { startScheduler: startScheduler2 } = await Promise.resolve().then(() => (init_scheduler(), scheduler_exports));
16890
17146
  startScheduler2({ quiet: options.quiet });