editmamei 1.7.0 → 1.7.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.
- package/README.md +4 -3
- package/dist/bin/editmamei-core-darwin-arm64 +0 -0
- package/dist/bin/editmamei-core-darwin-x64 +0 -0
- package/dist/bin/editmamei-core-win-x64.exe +0 -0
- package/dist/cli/help.js +2 -2
- package/dist/cli/install.js +2 -2
- package/dist/install-channel.js +2 -0
- package/dist/skills/editmamei-skill.zip +0 -0
- package/dist/telemetry/client.js +23 -16
- package/dist/telemetry/outbox.js +248 -28
- package/dist/update/check.js +2 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ These are the choices that shape the surface, and the reason an AI assistant can
|
|
|
81
81
|
|
|
82
82
|
## Tool surface
|
|
83
83
|
|
|
84
|
-
**
|
|
84
|
+
**107 tools total.** The Photoshop surface is **83 tools across 16 capability groups** (62 Community, 21 Pro), covering the work in groups rather than one tool per Photoshop feature. Every one is namespaced `ps_*` and discoverable at runtime via `tools/list`. Community tools ship in both editions; Pro tools unlock with a license. Alongside it, a second, independent editor surface drives headless GIMP: **24 `gimp_*` tools, Community, currently in beta**, see [GIMP (beta)](#gimp-beta) below. Pro's additions are Photoshop-only; GIMP has no Pro tier.
|
|
85
85
|
|
|
86
86
|
| Group | Edition | Tools |
|
|
87
87
|
| --- | --- | --- |
|
|
@@ -116,7 +116,7 @@ These are the choices that shape the surface, and the reason an AI assistant can
|
|
|
116
116
|
## Editions
|
|
117
117
|
|
|
118
118
|
- **Community** is free and covers the everyday editing surface: documents, layers, selections (including AI Select Subject and Select Sky), non-destructive adjustments, filters, masks, type, retouching, on-device perception, and the inspect/verify primitives.
|
|
119
|
-
- **Pro** adds Camera Raw
|
|
119
|
+
- **Pro** adds Camera Raw as a re-editable filter, raw files developed before they open, folder batch, the reproducible-template system, the grounded precision tools (warp, named-object masks, precision placement), subject-instance and face-mesh targeting, and Photoshop Actions plus the scripting escape hatch.
|
|
120
120
|
|
|
121
121
|
Pro is a Photoshop-only upgrade: it adds nothing to the GIMP surface below.
|
|
122
122
|
|
|
@@ -128,7 +128,7 @@ This repository holds the Community source. Pro is a separately licensed module
|
|
|
128
128
|
|
|
129
129
|
Editmamei can also drive GIMP, headless, as a second editor alongside (or instead of) Photoshop. When GIMP 3.2+ is detected on your machine, a `gimp_*` tool set registers next to the `ps_*` one; use it when you ask for GIMP, or when Photoshop isn't available. There's no visible window: edits happen in a background `gimp-console` process, and you follow along through rendered previews in the conversation instead of watching a window change.
|
|
130
130
|
|
|
131
|
-
The beta covers documents (open, create, save `.xcf`, export), layers and groups, placing one photo into another, 13 non-destructive adjustment types and six effects (vignette, black and white, motion and lens blur, noise, drop shadow), geometric masks, crop/resize/rotate/flip, canvas extension,
|
|
131
|
+
The beta covers documents (open, create, save `.xcf`, export), layers and groups, placing one photo into another, 13 non-destructive adjustment types and six effects (vignette, black and white, motion and lens blur, noise, drop shadow), geometric masks, crop/resize/rotate/flip, canvas extension, color/grayscale conversion, checkpoints you can restore, and the same preview/histogram/compare verification primitives the Photoshop side has. It doesn't yet cover heal/clone, AI subject or sky selection, or text. Full details, requirements, and troubleshooting: [docs/gimp.md](docs/gimp.md).
|
|
132
132
|
|
|
133
133
|
## Build from source
|
|
134
134
|
|
|
@@ -170,6 +170,7 @@ The source in this repository is the same code published to npm, so none of the
|
|
|
170
170
|
- **Install:** [docs/installation.md](docs/installation.md)
|
|
171
171
|
- **Getting started:** [docs/getting-started.md](docs/getting-started.md)
|
|
172
172
|
- **FAQ:** [docs/faq.md](docs/faq.md)
|
|
173
|
+
- **AI clients:** [docs/clients.md](docs/clients.md)
|
|
173
174
|
- **Troubleshooting:** [docs/troubleshooting.md](docs/troubleshooting.md)
|
|
174
175
|
- **GIMP (beta):** [docs/gimp.md](docs/gimp.md)
|
|
175
176
|
- **Pro features:** [docs/pro-features.md](docs/pro-features.md)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/cli/help.js
CHANGED
|
@@ -27,8 +27,8 @@ Install options:
|
|
|
27
27
|
|
|
28
28
|
--skip-skill Skip copying the editmamei skill bundle to your Downloads folder.
|
|
29
29
|
By default, install drops editmamei-skill.zip in Downloads with
|
|
30
|
-
instructions for uploading it to claude.ai (Settings >
|
|
31
|
-
|
|
30
|
+
instructions for uploading it to claude.ai (Settings > Skills).
|
|
31
|
+
Pass this flag for headless / CI installs where the skill
|
|
32
32
|
upload step doesn't apply.
|
|
33
33
|
|
|
34
34
|
Config examples:
|
package/dist/cli/install.js
CHANGED
|
@@ -61,8 +61,8 @@ export async function runInstall(opts = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
if (skillResult?.status === 'copied') {
|
|
63
63
|
out(` 2. Upload the editmamei skill to your Claude account:\n`);
|
|
64
|
-
out(` - Open https://claude.ai/settings (
|
|
65
|
-
out(` - Click "Upload skill"\n`);
|
|
64
|
+
out(` - Open https://claude.ai/settings (Settings > Skills)\n`);
|
|
65
|
+
out(` - Click Add, then "Upload skill"\n`);
|
|
66
66
|
out(` - Choose the file at ${skillResult.destPath}\n`);
|
|
67
67
|
out(` The skill auto-loads in any photo-editing conversation. It's a one-time upload.\n`);
|
|
68
68
|
out(` 3. Then ask the AI: "Is Photoshop connected?" — it will call ps_ping and return your Photoshop version.\n`);
|
package/dist/install-channel.js
CHANGED
|
@@ -30,6 +30,8 @@ export function resolveInstallChannel(env = process.env, edition = EDITION, argv
|
|
|
30
30
|
return 'dev';
|
|
31
31
|
if (env.EDITMAMEI_INSTALL_CHANNEL === 'mcpb')
|
|
32
32
|
return 'mcpb';
|
|
33
|
+
if (env.EDITMAMEI_INSTALL_CHANNEL === 'plugin')
|
|
34
|
+
return 'plugin';
|
|
33
35
|
const trimmedArgv1 = argv1?.trim();
|
|
34
36
|
if (!trimmedArgv1)
|
|
35
37
|
return 'unknown';
|
|
Binary file
|
package/dist/telemetry/client.js
CHANGED
|
@@ -7,7 +7,7 @@ import { READ_ONLY_TOOLS, KEPT_WORK_TOOLS, nodeMajor, archToken, osMajor, boundM
|
|
|
7
7
|
import { buildClientConnected, buildDiagnosticEvent, buildModuleStatus, buildSessionStart, buildSessionSummary, buildUsageEvent, dayBucket, normalizeDayBucket, isContentSafe, PS_VERSION_UNKNOWN, } from './events.js';
|
|
8
8
|
import { sanitizeMessage, sanitizeSnippet, sanitizeStderrTail } from './sanitize.js';
|
|
9
9
|
import { httpTransport, resolveEndpoint } from './transport.js';
|
|
10
|
-
import { appendOutboxSync,
|
|
10
|
+
import { appendOutboxSync, claimOrphanedSessionStates, claimOutboxForDrain, clearSessionState, writeSessionStateSync, } from './outbox.js';
|
|
11
11
|
const MAX_BATCH_SIZE = 100;
|
|
12
12
|
const MAX_QUEUE_SIZE = 500;
|
|
13
13
|
const DEFAULT_FLUSH_INTERVAL_MS = 5 * 60_000;
|
|
@@ -50,6 +50,8 @@ export class TelemetryClient {
|
|
|
50
50
|
moduleUpdate = 'none';
|
|
51
51
|
installAssets = {};
|
|
52
52
|
lastSessionPersistMs = 0;
|
|
53
|
+
sessionStatePersisted = false;
|
|
54
|
+
startupFlushStarted = false;
|
|
53
55
|
startDayBucket = null;
|
|
54
56
|
constructor(opts) {
|
|
55
57
|
this.settings = opts.settings;
|
|
@@ -59,7 +61,11 @@ export class TelemetryClient {
|
|
|
59
61
|
this.flushIntervalMs = opts.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
60
62
|
this.maxBatchSize = opts.maxBatchSize ?? MAX_BATCH_SIZE;
|
|
61
63
|
this.active = opts.active ?? (EDITION !== 'dev' && !isTestEnv());
|
|
62
|
-
this.outboxOpts =
|
|
64
|
+
this.outboxOpts = {
|
|
65
|
+
...(opts.outboxDir ? { dir: opts.outboxDir } : {}),
|
|
66
|
+
...(opts.outboxPid !== undefined ? { pid: opts.outboxPid } : {}),
|
|
67
|
+
...(opts.isPidAlive ? { isPidAlive: opts.isPidAlive } : {}),
|
|
68
|
+
};
|
|
63
69
|
this.getModuleStatus = opts.getModuleStatus ?? (() => null);
|
|
64
70
|
this.dims = {
|
|
65
71
|
install_id: this.settings.telemetry.install_id,
|
|
@@ -200,6 +206,7 @@ export class TelemetryClient {
|
|
|
200
206
|
...this.summaryFields(),
|
|
201
207
|
};
|
|
202
208
|
writeSessionStateSync(state, this.outboxOpts);
|
|
209
|
+
this.sessionStatePersisted = true;
|
|
203
210
|
}
|
|
204
211
|
onPsVersionResolved() {
|
|
205
212
|
if (!this.active || !this.settings.telemetry.usage || this.toolCallCount === 0)
|
|
@@ -297,22 +304,27 @@ export class TelemetryClient {
|
|
|
297
304
|
clearSessionState(this.outboxOpts);
|
|
298
305
|
}
|
|
299
306
|
async flushOutboxOnStartup() {
|
|
300
|
-
if (!this.active)
|
|
307
|
+
if (!this.active || this.startupFlushStarted)
|
|
301
308
|
return;
|
|
309
|
+
this.startupFlushStarted = true;
|
|
302
310
|
try {
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
311
|
+
const orphans = claimOrphanedSessionStates(this.outboxOpts, {
|
|
312
|
+
includeOwn: !this.sessionStatePersisted,
|
|
313
|
+
});
|
|
314
|
+
if (this.settings.telemetry.usage) {
|
|
315
|
+
const summaries = orphans.states.filter((s) => s.tool_call_count > 0).map(summaryFromState);
|
|
316
|
+
this.droppedOutbox += appendOutboxSync(summaries, this.outboxOpts);
|
|
306
317
|
}
|
|
307
|
-
|
|
308
|
-
const
|
|
318
|
+
orphans.release();
|
|
319
|
+
const claimed = claimOutboxForDrain(this.outboxOpts);
|
|
320
|
+
const { events: pending, discarded } = claimed;
|
|
309
321
|
this.droppedOutbox += discarded;
|
|
310
322
|
if (pending.length === 0) {
|
|
311
|
-
|
|
323
|
+
claimed.release([]);
|
|
312
324
|
return;
|
|
313
325
|
}
|
|
314
326
|
if (!this.settings.telemetry.usage) {
|
|
315
|
-
|
|
327
|
+
claimed.release([]);
|
|
316
328
|
return;
|
|
317
329
|
}
|
|
318
330
|
const sendable = pending.filter(isContentSafe);
|
|
@@ -330,12 +342,7 @@ export class TelemetryClient {
|
|
|
330
342
|
}
|
|
331
343
|
settled = i + batch.length;
|
|
332
344
|
}
|
|
333
|
-
|
|
334
|
-
clearOutbox(this.outboxOpts);
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
rewriteOutbox(sendable.slice(settled), this.outboxOpts);
|
|
338
|
-
}
|
|
345
|
+
this.droppedOutbox += claimed.release(sendable.slice(settled));
|
|
339
346
|
}
|
|
340
347
|
catch (err) {
|
|
341
348
|
this.logger.debug(`startup outbox flush error: ${errMsg(err)}`);
|
package/dist/telemetry/outbox.js
CHANGED
|
@@ -1,21 +1,86 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import { join, dirname } from 'node:path';
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, appendFileSync, statSync, rmSync, } from 'node:fs';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync, renameSync, appendFileSync, statSync, rmSync, } from 'node:fs';
|
|
4
4
|
import { Logger } from '../utils/logger.js';
|
|
5
5
|
const logger = new Logger('TelemetryOutbox');
|
|
6
6
|
const DIRNAME = '.editmamei';
|
|
7
7
|
const OUTBOX_FILENAME = 'telemetry-outbox.ndjson';
|
|
8
|
-
const
|
|
8
|
+
const LEGACY_SESSION_STATE_FILENAME = 'telemetry-session.json';
|
|
9
|
+
const SESSION_STATE_RE = /^telemetry-session\.(\d+)\.json$/;
|
|
10
|
+
const RECOVER_RE = /^\.session-recover\.(\d+)\.(telemetry-session(?:\.\d+)?\.json)$/;
|
|
11
|
+
const CLAIM_RE = /^telemetry-outbox\.(?:draining|compacting)\.(\d+)\.(\d+)\.ndjson$/;
|
|
9
12
|
export const MAX_OUTBOX_EVENTS = 5_000;
|
|
10
13
|
export const MAX_OUTBOX_BYTES = 2_000_000;
|
|
14
|
+
export function isPidAlive(pid) {
|
|
15
|
+
try {
|
|
16
|
+
process.kill(pid, 0);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return err.code === 'EPERM';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
function baseDir(opts) {
|
|
12
24
|
return opts.dir ?? join(homedir(), DIRNAME);
|
|
13
25
|
}
|
|
14
26
|
export function outboxPath(opts = {}) {
|
|
15
27
|
return join(baseDir(opts), OUTBOX_FILENAME);
|
|
16
28
|
}
|
|
29
|
+
function ownPid(opts) {
|
|
30
|
+
return opts.pid ?? process.pid;
|
|
31
|
+
}
|
|
17
32
|
export function sessionStatePath(opts = {}) {
|
|
18
|
-
return join(baseDir(opts),
|
|
33
|
+
return join(baseDir(opts), `telemetry-session.${ownPid(opts)}.json`);
|
|
34
|
+
}
|
|
35
|
+
function listDir(dir) {
|
|
36
|
+
try {
|
|
37
|
+
return readdirSync(dir);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function claim(from, to) {
|
|
44
|
+
try {
|
|
45
|
+
renameSync(from, to);
|
|
46
|
+
return to;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function freeClaimName(dir, kind, pid) {
|
|
53
|
+
for (let seq = 0;; seq++) {
|
|
54
|
+
const path = join(dir, `telemetry-outbox.${kind}.${pid}.${seq}.ndjson`);
|
|
55
|
+
if (!existsSync(path))
|
|
56
|
+
return path;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function readClaim(path) {
|
|
60
|
+
const buf = readFileSync(path);
|
|
61
|
+
const bytes = buf.lastIndexOf(0x0a) + 1;
|
|
62
|
+
return { ...parseOutbox(buf.subarray(0, bytes).toString('utf8')), bytes };
|
|
63
|
+
}
|
|
64
|
+
function readClaimTail(path, bytes) {
|
|
65
|
+
const buf = readFileSync(path);
|
|
66
|
+
if (buf.length <= bytes)
|
|
67
|
+
return { events: [], discarded: 0 };
|
|
68
|
+
return parseOutbox(buf.subarray(bytes).toString('utf8'));
|
|
69
|
+
}
|
|
70
|
+
function removeClaim(path, what) {
|
|
71
|
+
try {
|
|
72
|
+
rmSync(path, { force: true });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
logger.debug(`${what} delete failed: ${errMsg(err)}`);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
writeFileSync(path, '');
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
logger.debug(`${what} truncate failed: ${errMsg(err)}`);
|
|
83
|
+
}
|
|
19
84
|
}
|
|
20
85
|
function ensureDir(path) {
|
|
21
86
|
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
@@ -44,31 +109,100 @@ export function readOutboxWithDiscards(opts = {}) {
|
|
|
44
109
|
if (!existsSync(path))
|
|
45
110
|
return { events: [], discarded: 0 };
|
|
46
111
|
try {
|
|
47
|
-
|
|
48
|
-
const events = [];
|
|
49
|
-
let discarded = 0;
|
|
50
|
-
for (const line of raw.split('\n')) {
|
|
51
|
-
const trimmed = line.trim();
|
|
52
|
-
if (trimmed.length === 0)
|
|
53
|
-
continue;
|
|
54
|
-
try {
|
|
55
|
-
events.push(JSON.parse(trimmed));
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
discarded += 1;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (events.length > MAX_OUTBOX_EVENTS) {
|
|
62
|
-
const over = events.length - MAX_OUTBOX_EVENTS;
|
|
63
|
-
return { events: events.slice(over), discarded: discarded + over };
|
|
64
|
-
}
|
|
65
|
-
return { events, discarded };
|
|
112
|
+
return boundOutbox(parseOutbox(readFileSync(path, 'utf8')));
|
|
66
113
|
}
|
|
67
114
|
catch (err) {
|
|
68
115
|
logger.debug(`outbox read failed: ${errMsg(err)}`);
|
|
69
116
|
return { events: [], discarded: 0 };
|
|
70
117
|
}
|
|
71
118
|
}
|
|
119
|
+
function parseOutbox(raw) {
|
|
120
|
+
const events = [];
|
|
121
|
+
let discarded = 0;
|
|
122
|
+
for (const line of raw.split('\n')) {
|
|
123
|
+
const trimmed = line.trim();
|
|
124
|
+
if (trimmed.length === 0)
|
|
125
|
+
continue;
|
|
126
|
+
try {
|
|
127
|
+
events.push(JSON.parse(trimmed));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
discarded += 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { events, discarded };
|
|
134
|
+
}
|
|
135
|
+
function boundOutbox({ events, discarded }) {
|
|
136
|
+
if (events.length <= MAX_OUTBOX_EVENTS)
|
|
137
|
+
return { events, discarded };
|
|
138
|
+
const over = events.length - MAX_OUTBOX_EVENTS;
|
|
139
|
+
return { events: events.slice(over), discarded: discarded + over };
|
|
140
|
+
}
|
|
141
|
+
export function claimOutboxForDrain(opts = {}) {
|
|
142
|
+
const dir = baseDir(opts);
|
|
143
|
+
const me = ownPid(opts);
|
|
144
|
+
const alive = opts.isPidAlive ?? isPidAlive;
|
|
145
|
+
const claimed = [];
|
|
146
|
+
const nextName = () => freeClaimName(dir, 'draining', me);
|
|
147
|
+
const abandoned = listDir(dir)
|
|
148
|
+
.flatMap((name) => {
|
|
149
|
+
const m = CLAIM_RE.exec(name);
|
|
150
|
+
return m ? [{ name, pid: Number(m[1]), seq: Number(m[2]) }] : [];
|
|
151
|
+
})
|
|
152
|
+
.filter((c) => c.pid === me || !alive(c.pid))
|
|
153
|
+
.sort((a, b) => a.pid - b.pid || a.seq - b.seq || a.name.localeCompare(b.name));
|
|
154
|
+
for (const c of abandoned) {
|
|
155
|
+
const from = join(dir, c.name);
|
|
156
|
+
const got = c.pid === me ? from : claim(from, nextName());
|
|
157
|
+
if (got)
|
|
158
|
+
claimed.push(got);
|
|
159
|
+
}
|
|
160
|
+
const live = claim(outboxPath(opts), nextName());
|
|
161
|
+
if (live)
|
|
162
|
+
claimed.push(live);
|
|
163
|
+
const consumed = [];
|
|
164
|
+
let read = { events: [], discarded: 0 };
|
|
165
|
+
for (const path of claimed) {
|
|
166
|
+
try {
|
|
167
|
+
const part = readClaim(path);
|
|
168
|
+
read = {
|
|
169
|
+
events: read.events.concat(part.events),
|
|
170
|
+
discarded: read.discarded + part.discarded,
|
|
171
|
+
};
|
|
172
|
+
consumed.push({ path, bytes: part.bytes });
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
logger.debug(`claimed outbox read failed: ${errMsg(err)}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const { events, discarded } = boundOutbox(read);
|
|
179
|
+
let released = false;
|
|
180
|
+
return {
|
|
181
|
+
events,
|
|
182
|
+
discarded,
|
|
183
|
+
release(undelivered) {
|
|
184
|
+
if (released)
|
|
185
|
+
return 0;
|
|
186
|
+
released = true;
|
|
187
|
+
const late = [];
|
|
188
|
+
let lost = 0;
|
|
189
|
+
for (const { path, bytes } of consumed) {
|
|
190
|
+
try {
|
|
191
|
+
const tail = readClaimTail(path, bytes);
|
|
192
|
+
late.push(...tail.events);
|
|
193
|
+
lost += tail.discarded;
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
logger.debug(`claimed outbox re-read failed: ${errMsg(err)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
lost += appendOutboxSync(undelivered.concat(late), opts);
|
|
200
|
+
for (const { path } of consumed)
|
|
201
|
+
removeClaim(path, 'claimed outbox');
|
|
202
|
+
return lost;
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
72
206
|
export function readOutbox(opts = {}) {
|
|
73
207
|
return readOutboxWithDiscards(opts).events;
|
|
74
208
|
}
|
|
@@ -88,7 +222,7 @@ export function rewriteOutbox(events, opts = {}) {
|
|
|
88
222
|
const path = outboxPath(opts);
|
|
89
223
|
try {
|
|
90
224
|
ensureDir(path);
|
|
91
|
-
const tmp = join(dirname(path), `.outbox.${
|
|
225
|
+
const tmp = join(dirname(path), `.outbox.${ownPid(opts)}.tmp`);
|
|
92
226
|
writeFileSync(tmp, events.map((e) => JSON.stringify(e)).join('\n') + '\n', {
|
|
93
227
|
encoding: 'utf8',
|
|
94
228
|
mode: 0o600,
|
|
@@ -100,7 +234,18 @@ export function rewriteOutbox(events, opts = {}) {
|
|
|
100
234
|
}
|
|
101
235
|
}
|
|
102
236
|
function compactOutbox(opts = {}) {
|
|
103
|
-
const
|
|
237
|
+
const path = claim(outboxPath(opts), freeClaimName(baseDir(opts), 'compacting', ownPid(opts)));
|
|
238
|
+
if (!path)
|
|
239
|
+
return 0;
|
|
240
|
+
let read;
|
|
241
|
+
try {
|
|
242
|
+
read = readClaim(path);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
logger.debug(`compaction read failed, leaving the claim for recovery: ${errMsg(err)}`);
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
const { events, discarded } = boundOutbox(read);
|
|
104
249
|
const target = MAX_OUTBOX_BYTES / 2;
|
|
105
250
|
let bytes = 0;
|
|
106
251
|
let firstKept = Math.max(events.length - 1, 0);
|
|
@@ -111,14 +256,34 @@ function compactOutbox(opts = {}) {
|
|
|
111
256
|
firstKept = i;
|
|
112
257
|
}
|
|
113
258
|
const kept = events.slice(firstKept);
|
|
114
|
-
|
|
115
|
-
|
|
259
|
+
let late = { events: [], discarded: 0 };
|
|
260
|
+
try {
|
|
261
|
+
late = readClaimTail(path, read.bytes);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
logger.debug(`compaction re-read failed: ${errMsg(err)}`);
|
|
265
|
+
}
|
|
266
|
+
const back = kept.concat(late.events);
|
|
267
|
+
if (back.length > 0) {
|
|
268
|
+
try {
|
|
269
|
+
appendFileSync(outboxPath(opts), back.map((e) => JSON.stringify(e)).join('\n') + '\n', {
|
|
270
|
+
encoding: 'utf8',
|
|
271
|
+
mode: 0o600,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
logger.debug(`compaction write-back failed, leaving the claim for recovery: ${errMsg(err)}`);
|
|
276
|
+
return 0;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
removeClaim(path, 'compaction claim');
|
|
280
|
+
return discarded + (events.length - kept.length) + late.discarded;
|
|
116
281
|
}
|
|
117
282
|
export function writeSessionStateSync(state, opts = {}) {
|
|
118
283
|
const path = sessionStatePath(opts);
|
|
119
284
|
try {
|
|
120
285
|
ensureDir(path);
|
|
121
|
-
const tmp = join(dirname(path), `.session.${
|
|
286
|
+
const tmp = join(dirname(path), `.session.${ownPid(opts)}.tmp`);
|
|
122
287
|
writeFileSync(tmp, JSON.stringify(state), { encoding: 'utf8', mode: 0o600 });
|
|
123
288
|
renameSync(tmp, path);
|
|
124
289
|
}
|
|
@@ -127,7 +292,62 @@ export function writeSessionStateSync(state, opts = {}) {
|
|
|
127
292
|
}
|
|
128
293
|
}
|
|
129
294
|
export function readSessionState(opts = {}) {
|
|
130
|
-
|
|
295
|
+
return readSessionStateAt(sessionStatePath(opts));
|
|
296
|
+
}
|
|
297
|
+
export function claimOrphanedSessionStates(opts = {}, { includeOwn }) {
|
|
298
|
+
const dir = baseDir(opts);
|
|
299
|
+
const me = ownPid(opts);
|
|
300
|
+
const alive = opts.isPidAlive ?? isPidAlive;
|
|
301
|
+
const takeable = (pid) => (pid === me ? includeOwn : !alive(pid));
|
|
302
|
+
const claimed = [];
|
|
303
|
+
for (const name of listDir(dir)) {
|
|
304
|
+
let original;
|
|
305
|
+
const r = RECOVER_RE.exec(name);
|
|
306
|
+
if (r) {
|
|
307
|
+
const pid = Number(r[1]);
|
|
308
|
+
if (!takeable(pid))
|
|
309
|
+
continue;
|
|
310
|
+
if (pid === me) {
|
|
311
|
+
claimed.push(join(dir, name));
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
original = r[2];
|
|
315
|
+
}
|
|
316
|
+
else if (name === LEGACY_SESSION_STATE_FILENAME) {
|
|
317
|
+
original = name;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const m = SESSION_STATE_RE.exec(name);
|
|
321
|
+
if (!m || !takeable(Number(m[1])))
|
|
322
|
+
continue;
|
|
323
|
+
original = name;
|
|
324
|
+
}
|
|
325
|
+
const target = join(dir, `.session-recover.${me}.${original}`);
|
|
326
|
+
if (existsSync(target))
|
|
327
|
+
continue;
|
|
328
|
+
const got = claim(join(dir, name), target);
|
|
329
|
+
if (got)
|
|
330
|
+
claimed.push(got);
|
|
331
|
+
}
|
|
332
|
+
const states = [];
|
|
333
|
+
for (const path of claimed) {
|
|
334
|
+
const state = readSessionStateAt(path);
|
|
335
|
+
if (state)
|
|
336
|
+
states.push(state);
|
|
337
|
+
}
|
|
338
|
+
let released = false;
|
|
339
|
+
return {
|
|
340
|
+
states,
|
|
341
|
+
release() {
|
|
342
|
+
if (released)
|
|
343
|
+
return;
|
|
344
|
+
released = true;
|
|
345
|
+
for (const path of claimed)
|
|
346
|
+
removeClaim(path, 'session-state recover');
|
|
347
|
+
},
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function readSessionStateAt(path) {
|
|
131
351
|
if (!existsSync(path))
|
|
132
352
|
return null;
|
|
133
353
|
try {
|
package/dist/update/check.js
CHANGED
|
@@ -99,6 +99,8 @@ export function updateMessage(channel, latest) {
|
|
|
99
99
|
switch (channel) {
|
|
100
100
|
case 'mcpb':
|
|
101
101
|
return `Download editmamei.mcpb (v${latest}) from ${RELEASES_URL} and reinstall the Claude Desktop extension.`;
|
|
102
|
+
case 'plugin':
|
|
103
|
+
return `Editmamei v${latest} is available. Update the Editmamei plugin in Claude, then restart.`;
|
|
102
104
|
case 'dev':
|
|
103
105
|
return `You're on a local dev build — pull the latest source and rebuild.`;
|
|
104
106
|
case 'npx':
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.7.
|
|
1
|
+
export const VERSION = '1.7.1';
|
package/package.json
CHANGED