@portel/photon 1.18.0 → 1.19.0

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 (172) hide show
  1. package/dist/auto-ui/beam.d.ts.map +1 -1
  2. package/dist/auto-ui/beam.js +14 -4
  3. package/dist/auto-ui/beam.js.map +1 -1
  4. package/dist/beam-form.bundle.js +5 -3
  5. package/dist/beam-form.bundle.js.map +2 -2
  6. package/dist/beam.bundle.js +686 -30
  7. package/dist/beam.bundle.js.map +3 -3
  8. package/dist/claude-code-plugin.js +1 -1
  9. package/dist/cli/commands/beam.d.ts.map +1 -1
  10. package/dist/cli/commands/beam.js +8 -2
  11. package/dist/cli/commands/beam.js.map +1 -1
  12. package/dist/cli/commands/changelog.d.ts +9 -0
  13. package/dist/cli/commands/changelog.d.ts.map +1 -0
  14. package/dist/cli/commands/changelog.js +133 -0
  15. package/dist/cli/commands/changelog.js.map +1 -0
  16. package/dist/cli/commands/maker.d.ts.map +1 -1
  17. package/dist/cli/commands/maker.js +23 -2
  18. package/dist/cli/commands/maker.js.map +1 -1
  19. package/dist/cli/commands/mcp.d.ts.map +1 -1
  20. package/dist/cli/commands/mcp.js +53 -0
  21. package/dist/cli/commands/mcp.js.map +1 -1
  22. package/dist/cli/commands/package.d.ts.map +1 -1
  23. package/dist/cli/commands/package.js +18 -2
  24. package/dist/cli/commands/package.js.map +1 -1
  25. package/dist/cli/commands/run.d.ts.map +1 -1
  26. package/dist/cli/commands/run.js +1 -0
  27. package/dist/cli/commands/run.js.map +1 -1
  28. package/dist/cli/commands/update.d.ts +3 -2
  29. package/dist/cli/commands/update.d.ts.map +1 -1
  30. package/dist/cli/commands/update.js +50 -43
  31. package/dist/cli/commands/update.js.map +1 -1
  32. package/dist/cli/index.d.ts.map +1 -1
  33. package/dist/cli/index.js +16 -2
  34. package/dist/cli/index.js.map +1 -1
  35. package/dist/cli-alias.js +1 -1
  36. package/dist/cli-alias.js.map +1 -1
  37. package/dist/context-store.d.ts +23 -33
  38. package/dist/context-store.d.ts.map +1 -1
  39. package/dist/context-store.js +147 -97
  40. package/dist/context-store.js.map +1 -1
  41. package/dist/context.d.ts +15 -10
  42. package/dist/context.d.ts.map +1 -1
  43. package/dist/context.js +37 -13
  44. package/dist/context.js.map +1 -1
  45. package/dist/daemon/server.js +4 -2
  46. package/dist/daemon/server.js.map +1 -1
  47. package/dist/data-migration.d.ts +27 -0
  48. package/dist/data-migration.d.ts.map +1 -0
  49. package/dist/data-migration.js +307 -0
  50. package/dist/data-migration.js.map +1 -0
  51. package/dist/editor-support/docblock-tag-catalog.d.ts.map +1 -1
  52. package/dist/editor-support/docblock-tag-catalog.js +6 -0
  53. package/dist/editor-support/docblock-tag-catalog.js.map +1 -1
  54. package/dist/loader.d.ts +10 -0
  55. package/dist/loader.d.ts.map +1 -1
  56. package/dist/loader.js +97 -12
  57. package/dist/loader.js.map +1 -1
  58. package/dist/marketplace-manager.d.ts.map +1 -1
  59. package/dist/marketplace-manager.js +25 -5
  60. package/dist/marketplace-manager.js.map +1 -1
  61. package/dist/photon-cli-runner.d.ts.map +1 -1
  62. package/dist/photon-cli-runner.js +47 -21
  63. package/dist/photon-cli-runner.js.map +1 -1
  64. package/dist/photon-doc-extractor.d.ts +1 -0
  65. package/dist/photon-doc-extractor.d.ts.map +1 -1
  66. package/dist/photon-doc-extractor.js +6 -0
  67. package/dist/photon-doc-extractor.js.map +1 -1
  68. package/dist/readme-syncer.d.ts.map +1 -1
  69. package/dist/readme-syncer.js +6 -1
  70. package/dist/readme-syncer.js.map +1 -1
  71. package/dist/server.d.ts +40 -0
  72. package/dist/server.d.ts.map +1 -1
  73. package/dist/server.js +143 -28
  74. package/dist/server.js.map +1 -1
  75. package/dist/shared/audit.js +4 -4
  76. package/dist/shared/audit.js.map +1 -1
  77. package/dist/tasks/store.d.ts.map +1 -1
  78. package/dist/tasks/store.js +6 -2
  79. package/dist/tasks/store.js.map +1 -1
  80. package/dist/version-notify.d.ts +27 -0
  81. package/dist/version-notify.d.ts.map +1 -0
  82. package/dist/version-notify.js +142 -0
  83. package/dist/version-notify.js.map +1 -0
  84. package/package.json +2 -2
  85. package/dist/auto-ui/bridge/openai-shim.d.ts +0 -20
  86. package/dist/auto-ui/bridge/openai-shim.d.ts.map +0 -1
  87. package/dist/auto-ui/bridge/openai-shim.js +0 -231
  88. package/dist/auto-ui/bridge/openai-shim.js.map +0 -1
  89. package/dist/auto-ui/bridge/photon-app.d.ts +0 -162
  90. package/dist/auto-ui/bridge/photon-app.d.ts.map +0 -1
  91. package/dist/auto-ui/bridge/photon-app.js +0 -460
  92. package/dist/auto-ui/bridge/photon-app.js.map +0 -1
  93. package/dist/auto-ui/daemon-tools.d.ts +0 -45
  94. package/dist/auto-ui/daemon-tools.d.ts.map +0 -1
  95. package/dist/auto-ui/daemon-tools.js +0 -581
  96. package/dist/auto-ui/daemon-tools.js.map +0 -1
  97. package/dist/auto-ui/design-system/index.d.ts +0 -21
  98. package/dist/auto-ui/design-system/index.d.ts.map +0 -1
  99. package/dist/auto-ui/design-system/index.js +0 -27
  100. package/dist/auto-ui/design-system/index.js.map +0 -1
  101. package/dist/auto-ui/design-system/transaction-ui.d.ts +0 -70
  102. package/dist/auto-ui/design-system/transaction-ui.d.ts.map +0 -1
  103. package/dist/auto-ui/design-system/transaction-ui.js +0 -982
  104. package/dist/auto-ui/design-system/transaction-ui.js.map +0 -1
  105. package/dist/auto-ui/playground-server.d.ts +0 -7
  106. package/dist/auto-ui/playground-server.d.ts.map +0 -1
  107. package/dist/auto-ui/playground-server.js +0 -840
  108. package/dist/auto-ui/playground-server.js.map +0 -1
  109. package/dist/auto-ui/rendering/components.d.ts +0 -29
  110. package/dist/auto-ui/rendering/components.d.ts.map +0 -1
  111. package/dist/auto-ui/rendering/components.js +0 -1341
  112. package/dist/auto-ui/rendering/components.js.map +0 -1
  113. package/dist/auto-ui/rendering/field-analyzer.d.ts +0 -104
  114. package/dist/auto-ui/rendering/field-analyzer.d.ts.map +0 -1
  115. package/dist/auto-ui/rendering/field-analyzer.js +0 -447
  116. package/dist/auto-ui/rendering/field-analyzer.js.map +0 -1
  117. package/dist/auto-ui/rendering/field-renderers.d.ts +0 -64
  118. package/dist/auto-ui/rendering/field-renderers.d.ts.map +0 -1
  119. package/dist/auto-ui/rendering/field-renderers.js +0 -317
  120. package/dist/auto-ui/rendering/field-renderers.js.map +0 -1
  121. package/dist/auto-ui/rendering/index.d.ts +0 -28
  122. package/dist/auto-ui/rendering/index.d.ts.map +0 -1
  123. package/dist/auto-ui/rendering/index.js +0 -60
  124. package/dist/auto-ui/rendering/index.js.map +0 -1
  125. package/dist/auto-ui/rendering/layout-selector.d.ts +0 -60
  126. package/dist/auto-ui/rendering/layout-selector.d.ts.map +0 -1
  127. package/dist/auto-ui/rendering/layout-selector.js +0 -476
  128. package/dist/auto-ui/rendering/layout-selector.js.map +0 -1
  129. package/dist/markdown-utils.d.ts +0 -8
  130. package/dist/markdown-utils.d.ts.map +0 -1
  131. package/dist/markdown-utils.js +0 -64
  132. package/dist/markdown-utils.js.map +0 -1
  133. package/dist/mcp-client.d.ts +0 -9
  134. package/dist/mcp-client.d.ts.map +0 -1
  135. package/dist/mcp-client.js +0 -11
  136. package/dist/mcp-client.js.map +0 -1
  137. package/dist/mcp-elicitation.d.ts +0 -32
  138. package/dist/mcp-elicitation.d.ts.map +0 -1
  139. package/dist/mcp-elicitation.js +0 -26
  140. package/dist/mcp-elicitation.js.map +0 -1
  141. package/dist/photons/builder-compass.photon.d.ts +0 -167
  142. package/dist/photons/builder-compass.photon.d.ts.map +0 -1
  143. package/dist/photons/builder-compass.photon.js +0 -816
  144. package/dist/photons/builder-compass.photon.js.map +0 -1
  145. package/dist/photons/builder-compass.photon.ts +0 -1129
  146. package/dist/photons/docs/ui/docs.html +0 -441
  147. package/dist/photons/docs.photon.d.ts +0 -237
  148. package/dist/photons/docs.photon.d.ts.map +0 -1
  149. package/dist/photons/docs.photon.js +0 -483
  150. package/dist/photons/docs.photon.js.map +0 -1
  151. package/dist/photons/docs.photon.ts +0 -536
  152. package/dist/photons/slides.photon.d.ts +0 -212
  153. package/dist/photons/slides.photon.d.ts.map +0 -1
  154. package/dist/photons/slides.photon.js +0 -355
  155. package/dist/photons/slides.photon.js.map +0 -1
  156. package/dist/photons/slides.photon.ts +0 -370
  157. package/dist/photons/spreadsheet/ui/spreadsheet.html +0 -779
  158. package/dist/photons/spreadsheet.photon.d.ts +0 -554
  159. package/dist/photons/spreadsheet.photon.d.ts.map +0 -1
  160. package/dist/photons/spreadsheet.photon.js +0 -1050
  161. package/dist/photons/spreadsheet.photon.js.map +0 -1
  162. package/dist/photons/spreadsheet.photon.ts +0 -1239
  163. package/dist/photons/ui/builder-compass.html +0 -1199
  164. package/dist/photons/ui/builder-compass.photon.html +0 -380
  165. package/dist/security-scanner.d.ts +0 -52
  166. package/dist/security-scanner.d.ts.map +0 -1
  167. package/dist/security-scanner.js +0 -181
  168. package/dist/security-scanner.js.map +0 -1
  169. package/dist/shared/performance.d.ts +0 -65
  170. package/dist/shared/performance.d.ts.map +0 -1
  171. package/dist/shared/performance.js +0 -136
  172. package/dist/shared/performance.js.map +0 -1
package/dist/loader.js CHANGED
@@ -36,7 +36,7 @@ executionContext,
36
36
  // Lock helper
37
37
  withLock as withLockHelper,
38
38
  // Middleware system
39
- builtinRegistry, MiddlewareRegistry, buildMiddlewareChain, } from '@portel/photon-core';
39
+ builtinRegistry, MiddlewareRegistry, buildMiddlewareChain, detectNamespace, getCacheDir, } from '@portel/photon-core';
40
40
  import { getDefaultContext } from './context.js';
41
41
  import * as os from 'os';
42
42
  import { MarketplaceManager } from './marketplace-manager.js';
@@ -332,7 +332,7 @@ export class PhotonLoader {
332
332
  * Directory where MCP-specific dependencies are cached
333
333
  */
334
334
  getDependencyCacheDir(cacheKey) {
335
- return path.join(os.homedir(), '.cache', 'photon-mcp', 'dependencies', cacheKey);
335
+ return path.join(getCacheDir(), 'dependencies', cacheKey);
336
336
  }
337
337
  getBuildCacheDir(cacheKey) {
338
338
  return path.join(this.getDependencyCacheDir(cacheKey), '.build');
@@ -402,7 +402,11 @@ export class PhotonLoader {
402
402
  ? this.dependenciesEqual(metadata.dependencies, dependencies)
403
403
  : false;
404
404
  const resolvedCoreVersion = getResolvedPhotonCoreVersion();
405
- const coreVersionChanged = metadata?.photonCoreVersion !== resolvedCoreVersion;
405
+ // Compare versions tolerantly: "2.17.6" matches "^2.17.6" and vice versa
406
+ // This prevents unnecessary cache clears when createRequire fallback returns a range
407
+ const storedVersion = metadata?.photonCoreVersion || '';
408
+ const coreVersionChanged = storedVersion !== resolvedCoreVersion &&
409
+ storedVersion.replace(/^[\^~]/, '') !== resolvedCoreVersion.replace(/^[\^~]/, '');
406
410
  // Only clear dependency cache when deps or core version actually changed.
407
411
  // Source-only changes just need a build cache clear (recompile is fast).
408
412
  const needsDepClear = Boolean(metadata && (!depsMatch || coreVersionChanged));
@@ -457,24 +461,39 @@ export class PhotonLoader {
457
461
  const message = error instanceof Error ? error.message : String(error);
458
462
  return (message.includes('Cannot find package') ||
459
463
  message.includes('ERR_MODULE_NOT_FOUND') ||
460
- message.includes('Cannot find module'));
464
+ message.includes('Cannot find module') ||
465
+ message.includes('require is not defined'));
461
466
  }
462
467
  static parseDependenciesFromSource(source) {
463
468
  const deps = [];
469
+ // Only match @dependencies inside JSDoc blocks (/** ... */)
470
+ const jsdocBlocks = source.match(/\/\*\*[\s\S]*?\*\//g) || [];
471
+ const jsdocText = jsdocBlocks.join('\n');
464
472
  const regex = /@dependencies\s+([^\r\n]+)/g;
465
473
  let match;
466
- while ((match = regex.exec(source)) !== null) {
474
+ while ((match = regex.exec(jsdocText)) !== null) {
467
475
  const entries = match[1]
476
+ .replace(/\*\/$/, '') // strip trailing */ if on same line
468
477
  .split(',')
469
478
  .map((entry) => entry.trim())
470
479
  .filter(Boolean);
471
480
  for (const entry of entries) {
472
481
  const atIndex = entry.lastIndexOf('@');
482
+ let name;
483
+ let version;
473
484
  if (atIndex <= 0) {
485
+ // No version specified (e.g., "sharp") — default to latest
486
+ name = entry.trim();
487
+ version = '*';
488
+ }
489
+ else {
490
+ name = entry.slice(0, atIndex).trim();
491
+ version = entry.slice(atIndex + 1).trim();
492
+ }
493
+ // Validate: npm package names are lowercase, may have @scope/, no spaces
494
+ if (name.includes(' ') || !/^(@[a-z0-9-]+\/)?[a-z0-9._-]+$/.test(name)) {
474
495
  continue;
475
496
  }
476
- const name = entry.slice(0, atIndex).trim();
477
- let version = entry.slice(atIndex + 1).trim();
478
497
  // Trailing ? marks the dependency as optional (e.g. sharp@^0.33.0?)
479
498
  const optional = version.endsWith('?');
480
499
  if (optional) {
@@ -609,8 +628,9 @@ export class PhotonLoader {
609
628
  this.logger.warn(`⚠️ ${name} loaded with configuration warnings:`);
610
629
  this.logger.warn(String(configError));
611
630
  }
612
- // Set photon name for event source identification
631
+ // Set photon name and namespace for event source identification and data paths
613
632
  instance._photonName = name;
633
+ instance._photonNamespace = this.resolveNamespace(absolutePath);
614
634
  // Inject instance name for named instances (runtime concept, not code)
615
635
  instance.instanceName = options?.instanceName ?? '';
616
636
  // Inject file path for storage()/assets() resolution
@@ -702,11 +722,12 @@ export class PhotonLoader {
702
722
  };
703
723
  }
704
724
  if (caps.has('memory')) {
705
- // Inject lazy memory provider
725
+ // Inject lazy memory provider — capture baseDir from loader context
726
+ const memoryBaseDir = this.baseDir;
706
727
  Object.defineProperty(instance, 'memory', {
707
728
  get() {
708
729
  if (!this._memory) {
709
- this._memory = new MemoryProvider(name, this._sessionId);
730
+ this._memory = new MemoryProvider(name, this._sessionId, this._photonNamespace, memoryBaseDir);
710
731
  }
711
732
  return this._memory;
712
733
  },
@@ -904,6 +925,42 @@ export class PhotonLoader {
904
925
  }
905
926
  this.log(`🔌 Injected channel event infrastructure into ${name}`);
906
927
  }
928
+ // Inject this.channel() for channel notifications — works for both Photon
929
+ // subclasses and plain classes. Emits on '{photonName}:channel-push' daemon
930
+ // channel which the MCP server intercepts and translates to the client's
931
+ // notification method (e.g. notifications/claude/channel).
932
+ //
933
+ // this.channel(content, meta) — send a message to the client
934
+ // this.channel.respond(id, behavior) — respond to permission requests
935
+ // this.channel.onPermission(handler) — register permission request handler
936
+ if (typeof instance.emit === 'function') {
937
+ const emitFn = instance.emit.bind(instance);
938
+ // Permission handler stored locally — wired by server after load
939
+ let permissionHandler;
940
+ const channelFn = Object.assign((content, meta) => {
941
+ emitFn({
942
+ channel: `${name}:channel-push`,
943
+ event: 'channel',
944
+ data: { content, meta },
945
+ });
946
+ }, {
947
+ respond: (requestId, behavior) => {
948
+ emitFn({
949
+ channel: `${name}:channel-permission-response`,
950
+ event: 'permission-response',
951
+ data: { request_id: requestId, behavior },
952
+ });
953
+ },
954
+ onPermission: (handler) => {
955
+ permissionHandler = handler;
956
+ },
957
+ // Internal: called by the server when a permission request arrives
958
+ _dispatchPermission: (request) => {
959
+ permissionHandler?.(request);
960
+ },
961
+ });
962
+ instance.channel = channelFn;
963
+ }
907
964
  // Check @cli dependencies (required system CLI tools)
908
965
  if (tsContent) {
909
966
  await this.checkCLIDependencies(tsContent, name);
@@ -1037,6 +1094,7 @@ export class PhotonLoader {
1037
1094
  instance._photonConfigError = configError;
1038
1095
  }
1039
1096
  instance._photonName = name;
1097
+ instance._photonNamespace = this.resolveNamespace(absolutePath);
1040
1098
  instance.instanceName = options?.instanceName ?? '';
1041
1099
  // Inject file path for storage()/assets() resolution.
1042
1100
  // For preloaded modules (compiled binaries), remap to ~/.photon/ so storage()
@@ -1116,10 +1174,11 @@ export class PhotonLoader {
1116
1174
  };
1117
1175
  }
1118
1176
  if (caps.has('memory')) {
1177
+ const memoryBaseDir = this.baseDir;
1119
1178
  Object.defineProperty(instance, 'memory', {
1120
1179
  get() {
1121
1180
  if (!this._memory) {
1122
- this._memory = new MemoryProvider(name, this._sessionId);
1181
+ this._memory = new MemoryProvider(name, this._sessionId, this._photonNamespace, memoryBaseDir);
1123
1182
  }
1124
1183
  return this._memory;
1125
1184
  },
@@ -1945,7 +2004,7 @@ export class PhotonLoader {
1945
2004
  }
1946
2005
  // If configured but failed, provide more specific error
1947
2006
  throw new Error(`MCP "${dep.name}" is configured but failed to connect: ${errorMsg}\n` +
1948
- `Check your ~/.photon/config.json configuration and ensure:\n` +
2007
+ `Check your config.json configuration and ensure:\n` +
1949
2008
  ` • The command/URL is correct\n` +
1950
2009
  ` • Required environment variables are set\n` +
1951
2010
  ` • The MCP server is accessible`);
@@ -2990,12 +3049,19 @@ Run: photon mcp ${mcpName} --config
2990
3049
  return; // No emit function, can't wrap methods
2991
3050
  }
2992
3051
  // Get all public method names from the instance
3052
+ // Skip runtime-injected methods (emit, render, push, ask) — these are
3053
+ // capability methods injected by the loader, not user-defined tools
3054
+ const RUNTIME_METHODS = new Set(['emit', 'render', 'channel', 'ask', 'call']);
2993
3055
  const proto = Object.getPrototypeOf(instance);
2994
3056
  const methodNames = Object.getOwnPropertyNames(proto).filter((name) => {
2995
3057
  // Skip constructor and private/protected methods
2996
3058
  if (name === 'constructor' || name.startsWith('_')) {
2997
3059
  return false;
2998
3060
  }
3061
+ // Skip runtime-injected capability methods
3062
+ if (RUNTIME_METHODS.has(name)) {
3063
+ return false;
3064
+ }
2999
3065
  const descriptor = Object.getOwnPropertyDescriptor(proto, name);
3000
3066
  return descriptor && typeof descriptor.value === 'function';
3001
3067
  });
@@ -3211,6 +3277,25 @@ Run: photon mcp ${mcpName} --config
3211
3277
  check.on('error', () => resolve(false));
3212
3278
  });
3213
3279
  }
3280
+ /**
3281
+ * Resolve the namespace for a photon based on its file path.
3282
+ * Extracts the directory name between baseDir and the photon file.
3283
+ *
3284
+ * Examples:
3285
+ * ~/.photon/portel-dev/todo.photon.ts → 'portel-dev'
3286
+ * ~/.photon/local/todo.photon.ts → 'local'
3287
+ * ~/.photon/todo.photon.ts → detected from git or 'local'
3288
+ */
3289
+ resolveNamespace(absolutePath) {
3290
+ const rel = path.relative(this.baseDir, absolutePath);
3291
+ const parts = rel.split(path.sep);
3292
+ // If file is in a subdirectory (namespace/photon.ts), use that as namespace
3293
+ if (parts.length >= 2) {
3294
+ return parts[0];
3295
+ }
3296
+ // Flat file at root — detect from git remote or default to 'local'
3297
+ return detectNamespace(this.baseDir);
3298
+ }
3214
3299
  /**
3215
3300
  * Discover and extract assets from a Photon file
3216
3301
  * Uses shared discoverAssets from photon-core for core logic,