editmamei 0.22.1 → 0.22.3

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.
Binary file
Binary file
@@ -11,11 +11,13 @@ import { Session } from './session.js';
11
11
  import { SessionLog, classifyError } from '../utils/session-log.js';
12
12
  import { loadSettings, applyTelemetryEnvOverrides, applyUpdateCheckEnvOverride, } from './settings.js';
13
13
  import { TelemetryClient } from '../telemetry/client.js';
14
+ import { resolveInstallChannel } from '../install-channel.js';
14
15
  import { checkForUpdate, shouldCheckForUpdate } from '../update/check.js';
15
16
  import { join, dirname } from 'node:path';
16
17
  import { pathToFileURL } from 'node:url';
17
18
  import { GoSnippetClient, resolveProBinaryPath, coreBinaryName } from '../api/snippet-client.js';
18
19
  import { isProEntitled } from '../license/entitlement.js';
20
+ import { createPingLicenseRefresher } from '../license/ping-refresh.js';
19
21
  import { loadVerifiedModule, readInstalledModule, installedPath, PRO_SKU, } from '../delivery/store.js';
20
22
  import { provisionModules } from '../delivery/provision.js';
21
23
  import { readLicense } from '../license/store.js';
@@ -25,6 +27,16 @@ import { listTemplates } from '../utils/template-storage.js';
25
27
  import { Kernel } from '../kernel/kernel.js';
26
28
  import { HOST_MIN_ABI } from '../kernel/host-api.js';
27
29
  import { ceModule } from '../modules/ce/index.js';
30
+ import { hostDetectionRuntime } from '../detection/runtime.js';
31
+ export function classifyModuleOutcome(inputs) {
32
+ if (inputs.proModuleLoaded && inputs.skipReason === null)
33
+ return 'loaded';
34
+ if (inputs.skipReason === 'corrupt')
35
+ return 'skipped_corrupt';
36
+ if (inputs.skipReason === 'incompatible')
37
+ return 'skipped_incompatible';
38
+ return inputs.entitled ? 'absent' : 'lapsed';
39
+ }
28
40
  let logScriptOnErrorWarned = false;
29
41
  function warnLogScriptOnErrorOnce(logger) {
30
42
  if (logScriptOnErrorWarned)
@@ -40,8 +52,8 @@ export function __resetLogScriptOnErrorWarnForTests() {
40
52
  logScriptOnErrorWarned = false;
41
53
  }
42
54
  const FIRST_RUN_DISCLOSURE = 'First run: Editmamei collects anonymous, content-free usage telemetry (tool name, ' +
43
- 'success, duration, version/edition/OS/PS-version) to find what breaks. It never sends ' +
44
- 'image content, file paths, or personal data. Opt out anytime: ' +
55
+ 'success, duration, version/edition/OS/PS-version, install channel) to find what breaks. ' +
56
+ 'It never sends image content, file paths, or personal data. Opt out anytime: ' +
45
57
  '`editmamei config set telemetry.usage false` (or edit ~/.editmamei/settings.json). ' +
46
58
  'Opt in to sanitized diagnostics: `editmamei config set telemetry.diagnostics true`.';
47
59
  export class EditmameiServer {
@@ -57,6 +69,7 @@ export class EditmameiServer {
57
69
  psVersion = null;
58
70
  updateInfo = null;
59
71
  snippetClient = new GoSnippetClient();
72
+ refreshLicenseOnPing = createPingLicenseRefresher();
60
73
  constructor() {
61
74
  this.logger = new Logger('EditmameiServer');
62
75
  this.session = new Session();
@@ -67,6 +80,9 @@ export class EditmameiServer {
67
80
  this.telemetry = new TelemetryClient({
68
81
  settings: effectiveSettings,
69
82
  getPsVersion: () => this.psVersion,
83
+ edition: isProEntitled() ? 'pro' : 'community',
84
+ channel: resolveInstallChannel(),
85
+ getModuleStatus: () => this.computeModuleStatus(),
70
86
  });
71
87
  if (created)
72
88
  this.logger.info(FIRST_RUN_DISCLOSURE);
@@ -193,6 +209,7 @@ export class EditmameiServer {
193
209
  registry: this.toolRegistry,
194
210
  connection: this.session.getConnection(),
195
211
  snippet: this.snippetClient,
212
+ detection: hostDetectionRuntime(),
196
213
  resolveModuleSnippet: (manifest) => manifest.goCoreSnippets && manifest.goCoreSnippets.length > 0 && this.proModule
197
214
  ? new GoSnippetClient({ binaryPath: join(this.proModule.binDir, coreBinaryName()) })
198
215
  : null,
@@ -250,6 +267,21 @@ export class EditmameiServer {
250
267
  this.moduleSkipReason = 'incompatible';
251
268
  }
252
269
  }
270
+ computeModuleStatus() {
271
+ if (!readLicense())
272
+ return null;
273
+ const installed = readInstalledModule(PRO_SKU);
274
+ return {
275
+ module: PRO_SKU,
276
+ outcome: classifyModuleOutcome({
277
+ proModuleLoaded: this.proModule !== null,
278
+ skipReason: this.moduleSkipReason,
279
+ entitled: isProEntitled(),
280
+ }),
281
+ module_version: installed?.version ?? null,
282
+ abi: installed?.abi ?? null,
283
+ };
284
+ }
253
285
  async reprovisionIfModuleSkipped(delivery = {}) {
254
286
  const reason = this.moduleSkipReason;
255
287
  if (reason === null)
@@ -369,6 +401,7 @@ export class EditmameiServer {
369
401
  }
370
402
  }
371
403
  async pingPhotoshop() {
404
+ this.refreshLicenseOnPing();
372
405
  const connection = this.session.getConnection();
373
406
  const isConnected = await connection.ping();
374
407
  if (!isConnected) {
@@ -2,35 +2,60 @@ import { createRequire } from 'node:module';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { decode } from 'jpeg-js';
5
- import { readFileSync } from 'node:fs';
6
- import * as ort from 'onnxruntime-web';
5
+ import { existsSync, readFileSync } from 'node:fs';
6
+ import * as staticOrt from 'onnxruntime-web';
7
+ export let ort = staticOrt;
8
+ let injectedLoadModel = null;
9
+ let injectedModelDirs = null;
10
+ export function useHostRuntime(host, proModelsDir) {
11
+ injectedLoadModel = host.loadModel;
12
+ ort = host.ort;
13
+ injectedModelDirs = [proModelsDir, host.ceModelsDir];
14
+ }
15
+ export function hostDetectionRuntime() {
16
+ return { loadModel: hostLoadModel, ort: staticOrt, ceModelsDir: hostModelsDir() };
17
+ }
7
18
  let configured = false;
8
19
  function configureOrt() {
9
20
  if (configured)
10
21
  return;
11
22
  const require = createRequire(import.meta.url);
12
23
  const ortDist = dirname(require.resolve('onnxruntime-web'));
13
- ort.env.wasm.wasmPaths = pathToFileURL(join(ortDist, '/')).href;
14
- ort.env.wasm.numThreads = 1;
15
- ort.env.logLevel = 'error';
24
+ staticOrt.env.wasm.wasmPaths = pathToFileURL(join(ortDist, '/')).href;
25
+ staticOrt.env.wasm.numThreads = 1;
26
+ staticOrt.env.logLevel = 'error';
16
27
  configured = true;
17
28
  }
18
29
  const sessions = new Map();
19
- export function loadModel(absPath) {
30
+ function hostLoadModel(absPath) {
20
31
  configureOrt();
21
32
  let p = sessions.get(absPath);
22
33
  if (!p) {
23
- p = ort.InferenceSession.create(absPath, { logSeverityLevel: 3 });
34
+ p = staticOrt.InferenceSession.create(absPath, { logSeverityLevel: 3 });
24
35
  sessions.set(absPath, p);
25
36
  }
26
37
  return p;
27
38
  }
28
- export function resolveModelPath(filename) {
39
+ export function loadModel(absPath) {
40
+ return injectedLoadModel ? injectedLoadModel(absPath) : hostLoadModel(absPath);
41
+ }
42
+ function hostModelsDir() {
29
43
  const override = process.env.EDITMAMEI_MODELS_DIR;
30
44
  if (override)
31
- return join(override, filename);
45
+ return override;
32
46
  const here = dirname(fileURLToPath(import.meta.url));
33
- return join(here, '..', 'models', filename);
47
+ return join(here, '..', 'models');
48
+ }
49
+ export function resolveModelPath(filename) {
50
+ if (injectedModelDirs) {
51
+ for (const dir of injectedModelDirs) {
52
+ const candidate = join(dir, filename);
53
+ if (existsSync(candidate))
54
+ return candidate;
55
+ }
56
+ return join(injectedModelDirs[injectedModelDirs.length - 1], filename);
57
+ }
58
+ return join(hostModelsDir(), filename);
34
59
  }
35
60
  export function decodeJpeg(path) {
36
61
  let img;
@@ -43,4 +68,3 @@ export function decodeJpeg(path) {
43
68
  }
44
69
  return { width: img.width, height: img.height, data: img.data };
45
70
  }
46
- export { ort };
@@ -1,2 +1,2 @@
1
- export const KERNEL_ABI = 1;
1
+ export const KERNEL_ABI = 2;
2
2
  export const HOST_MIN_ABI = 1;
@@ -1,12 +1,13 @@
1
1
  import { CompositeSnippetClient } from '../api/snippet-client.js';
2
2
  import { Logger } from '../utils/logger.js';
3
3
  import { runScript } from '../utils/run-script.js';
4
- import { KERNEL_ABI } from './host-api.js';
4
+ import { KERNEL_ABI, } from './host-api.js';
5
5
  export class Kernel {
6
6
  registry;
7
7
  connection;
8
8
  snippet;
9
9
  resolveModuleSnippet;
10
+ detection;
10
11
  sessionId;
11
12
  logger;
12
13
  invokeDepth = 0;
@@ -16,6 +17,7 @@ export class Kernel {
16
17
  this.connection = deps.connection;
17
18
  this.snippet = deps.snippet;
18
19
  this.resolveModuleSnippet = deps.resolveModuleSnippet;
20
+ this.detection = deps.detection;
19
21
  this.sessionId = deps.sessionId;
20
22
  this.logger = deps.logger;
21
23
  }
@@ -35,6 +37,7 @@ export class Kernel {
35
37
  connection: this.connection,
36
38
  executeScript: (innerBody, timeoutMs) => runScript(this.connection, innerBody, timeoutMs),
37
39
  snippet: this.snippetFor(manifest),
40
+ detection: this.detection,
38
41
  session: { id: this.sessionId },
39
42
  logger: new Logger(`module:${manifest.id}`),
40
43
  };
@@ -7,6 +7,7 @@ const logger = new Logger('License');
7
7
  export const GRACE_MS = 30 * 24 * 60 * 60 * 1000;
8
8
  export const REFRESH_AFTER_MS = 7 * 24 * 60 * 60 * 1000;
9
9
  export const EXPIRED_REFRESH_TIMEOUT_MS = 5_000;
10
+ export const CLOCK_SKEW_TOLERANCE_MS = 24 * 60 * 60 * 1000;
10
11
  export function evaluateEntitlement(rec, now) {
11
12
  if (!rec)
12
13
  return { entitled: false, reason: 'no-license' };
@@ -77,9 +78,10 @@ export async function refreshIfStale(ops = {}) {
77
78
  return;
78
79
  const last = Date.parse(rec.last_validated_at);
79
80
  const age = Number.isFinite(last) ? now - last : Infinity;
80
- if (age <= REFRESH_AFTER_MS)
81
+ const clockSkewed = age < -CLOCK_SKEW_TOLERANCE_MS;
82
+ if (!clockSkewed && age <= REFRESH_AFTER_MS)
81
83
  return;
82
- if (age <= GRACE_MS) {
84
+ if (clockSkewed || age <= GRACE_MS) {
83
85
  refresh(ops).catch((err) => {
84
86
  logger.warn(`Background license refresh failed (grace covers offline use): ` +
85
87
  `${err instanceof Error ? err.message : String(err)}`);
@@ -0,0 +1,14 @@
1
+ import { refreshIfStale } from './entitlement.js';
2
+ export function createPingLicenseRefresher(refresh = refreshIfStale) {
3
+ let fired = false;
4
+ return () => {
5
+ if (fired)
6
+ return;
7
+ fired = true;
8
+ try {
9
+ void refresh().catch(() => { });
10
+ }
11
+ catch {
12
+ }
13
+ };
14
+ }
@@ -103,7 +103,6 @@ export class MacOSExecutor {
103
103
  throw new Error('jsxPath contains a character that would break AppleScript interpolation');
104
104
  }
105
105
  return `tell application "${this.appName}"
106
- \tactivate
107
106
  \tdo javascript "$.evalFile(decodeURI('${encodeURI(posixPath)}'))"
108
107
  end tell`;
109
108
  }
Binary file
@@ -1,7 +1,8 @@
1
1
  import { Logger } from '../utils/logger.js';
2
2
  import { EDITION } from '../edition.js';
3
3
  import { VERSION } from '../version.js';
4
- import { buildDiagnosticEvent, buildSessionStart, buildSessionSummary, buildUsageEvent, dayBucket, isContentSafe, PS_VERSION_UNKNOWN, } from './events.js';
4
+ import { resolveInstallChannel } from '../install-channel.js';
5
+ import { buildDiagnosticEvent, buildModuleStatus, buildSessionStart, buildSessionSummary, buildUsageEvent, dayBucket, isContentSafe, PS_VERSION_UNKNOWN, } from './events.js';
5
6
  import { sanitizeMessage, sanitizeSnippet, sanitizeStderrTail } from './sanitize.js';
6
7
  import { httpTransport, resolveEndpoint } from './transport.js';
7
8
  import { appendOutboxSync, clearOutbox, clearSessionState, readOutbox, readSessionState, writeSessionStateSync, } from './outbox.js';
@@ -23,6 +24,7 @@ export class TelemetryClient {
23
24
  maxBatchSize;
24
25
  active;
25
26
  outboxOpts;
27
+ getModuleStatus;
26
28
  queue = [];
27
29
  timer = null;
28
30
  shutdownPromise = null;
@@ -39,11 +41,13 @@ export class TelemetryClient {
39
41
  this.maxBatchSize = opts.maxBatchSize ?? MAX_BATCH_SIZE;
40
42
  this.active = opts.active ?? (EDITION !== 'dev' && !isTestEnv());
41
43
  this.outboxOpts = opts.outboxDir ? { dir: opts.outboxDir } : {};
44
+ this.getModuleStatus = opts.getModuleStatus ?? (() => null);
42
45
  this.dims = {
43
46
  install_id: this.settings.telemetry.install_id,
44
47
  editmamei_version: VERSION,
45
- edition: EDITION,
48
+ edition: opts.edition ?? EDITION,
46
49
  platform: process.platform,
50
+ channel: opts.channel ?? resolveInstallChannel(),
47
51
  getPsVersion: opts.getPsVersion,
48
52
  };
49
53
  }
@@ -57,6 +61,9 @@ export class TelemetryClient {
57
61
  this.timer.unref?.();
58
62
  if (this.settings.telemetry.usage) {
59
63
  this.enqueue(buildSessionStart(this.dims, this.now()));
64
+ const moduleStatus = this.getModuleStatus();
65
+ if (moduleStatus)
66
+ this.enqueue(buildModuleStatus(this.dims, moduleStatus, this.now()));
60
67
  void this.flush();
61
68
  }
62
69
  }
@@ -55,6 +55,22 @@ export function buildSessionStart(dims, now) {
55
55
  edition: dims.edition,
56
56
  platform: dims.platform,
57
57
  ps_version: psVersionOf(dims),
58
+ channel: dims.channel,
59
+ };
60
+ }
61
+ export function buildModuleStatus(dims, status, now) {
62
+ return {
63
+ v: TELEMETRY_SCHEMA_VERSION,
64
+ type: 'module_status',
65
+ install_id: dims.install_id,
66
+ ts_bucket: dayBucket(now),
67
+ editmamei_version: dims.editmamei_version,
68
+ edition: dims.edition,
69
+ platform: dims.platform,
70
+ module: status.module,
71
+ outcome: status.outcome,
72
+ module_version: status.module_version,
73
+ abi: status.abi,
58
74
  };
59
75
  }
60
76
  export function buildDiagnosticEvent(dims, diag, now) {
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.22.1';
1
+ export const VERSION = '0.22.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editmamei",
3
- "version": "0.22.1",
3
+ "version": "0.22.3",
4
4
  "description": "Editmamei — Unlock Photoshop with natural-language photo editing (Community Edition)",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@modelcontextprotocol/sdk": "^1.0.4",
44
- "adm-zip": "^0.5.17",
44
+ "adm-zip": "^0.6.0",
45
45
  "jpeg-js": "^0.4.4",
46
46
  "onnxruntime-web": "1.27.0"
47
47
  }