@lalalic/markcut 3.2.45 → 3.2.46
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/docs/developer-reference.md +2 -2
- package/package.json +1 -1
- package/skills/markcut/SKILL.md +2 -2
- package/skills/markcut/references/mobile-event-preview-cli.md +2 -2
- package/specs/001-preview-review-delivery/spec.md +14 -10
- package/src/mcp/bridge.mjs +9 -2
- package/src/mcp/compile-operation.mjs +2 -2
- package/src/mcp/compile-worker.mjs +21 -2
- package/src/mcp/mobile-review-cli.mjs +16 -89
- package/src/mcp/phone-notification.mjs +52 -0
- package/src/mcp/preview.mjs +2 -1
- package/src/render/cli.mjs +1 -1
- package/tests/mobile-preview-cli.test.ts +43 -58
|
@@ -50,10 +50,10 @@ See [docs/markdown-strict-descriptive.md](docs/markdown-strict-descriptive.md) f
|
|
|
50
50
|
```bash
|
|
51
51
|
markcut render <file.json|.md> [--output path]
|
|
52
52
|
markcut preview <file.json|.md> [--edit] [--label] [--port 3001]
|
|
53
|
-
markcut preview <file.md> --delivery event --event-template /absolute/event.json
|
|
53
|
+
markcut preview <file.md> --delivery event --event-template /absolute/event.json
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
For Codex/terminal event delivery, `preview --delivery event` uses the hosted MCP compiler and an **asynchronous**
|
|
56
|
+
For Codex/terminal event delivery, `preview --delivery event` uses the hosted MCP compiler and stores the review on Neo Master. Neo Master sends an APNs notification; Neo Mobile fetches the request when opened and publishes an **asynchronous** Event after human review. Every hosted MCP Preview also sends a phone notification, independently of the result-delivery mode. Text-only previews without a Relay Event Template are read-only on phone. The `--event-template` file must follow Relay's canonical `task.interactive_decision` Contract. See `skills/markcut/references/mobile-event-preview-cli.md`. Only `text` (native preview) and `event` (phone-review route) are supported.
|
|
57
57
|
|
|
58
58
|
## Project structure
|
|
59
59
|
|
package/package.json
CHANGED
package/skills/markcut/SKILL.md
CHANGED
|
@@ -16,7 +16,7 @@ Markcut turns a Markdown video definition into a compiled stream tree and a play
|
|
|
16
16
|
| Quickly assess story structure | `markcut preview <file> --storyboard` (placeholder media, not a final-video quality check). |
|
|
17
17
|
| Watch a native work-in-progress video | `markcut preview <file>`; test real visuals, sound, and seeking. |
|
|
18
18
|
| Ask a person to review in ChatGPT | Call the available `markcut.preview({path})` tool; handle revision-specific feedback and approval. |
|
|
19
|
-
| Ask for human review from Codex/terminal via iPhone | Use `markcut preview <video.md> --delivery event --event-template <relay-event.json>` on Neo Master.
|
|
19
|
+
| Ask for human review from Codex/terminal via iPhone | Use `markcut preview <video.md> --delivery event --event-template <relay-event.json>` on Neo Master. Neo Master stores the Preview and APNs notifies iPhone; the phone publishes the Event when the person submits. |
|
|
20
20
|
| Deliver a finished MP4 | `markcut render <file> --output <path>`; inspect the resulting video and sound. |
|
|
21
21
|
| Visualize a route or trip | Use a Markdown `map` stream; load [route/map reference](docs/map-dynamic-camera.md). |
|
|
22
22
|
|
|
@@ -57,7 +57,7 @@ Asset paths are relative to the Markdown document. A `prompt` without `src` asks
|
|
|
57
57
|
1. **Structure gate:** `npx @lalalic/markcut verify video.md`, then `npx @lalalic/markcut preview video.md --storyboard` when rapid scene review is useful. Storyboard placeholders do not verify generated media or final audio.
|
|
58
58
|
2. **Playback gate:** `npx @lalalic/markcut preview video.md`. Play and seek representative scenes; check black tails, media loading, narration, BGM, subtitles, route movement, and timing. For browser failures, load [Preview Troubleshooting](references/preview-troubleshooting.md) on demand.
|
|
59
59
|
3. **Human review gate:** Use Neo's `markcut.preview({path: "/absolute/path/video.md"})` when the user wants the hosted ChatGPT video player. This is **not** the CLI preview. The tool compiles/publishes a revision for playback; it does not rewrite the source. Comments with `decision: changes_requested` require editing that Markdown and calling `markcut.preview` again. `decision: approved` applies **only** to the identified revision/content hash; never apply an old approval to changed content. Follow [Review Contract](review.md) for actual video assessment.
|
|
60
|
-
4. **Codex / terminal human-review gate:** `npx @lalalic/markcut preview /absolute/video.md --delivery event --event-template /absolute/relay-event.json` on Neo Master. The Event Template must match Relay's canonical `task.interactive_decision` Contract (`type`, `source`, `data.interactive.{jobId,taskId,executionId,invocationId}` only, without review-result fields). The CLI reuses the MCP compiler, publishes immutable preview assets,
|
|
60
|
+
4. **Codex / terminal human-review gate:** `npx @lalalic/markcut preview /absolute/video.md --delivery event --event-template /absolute/relay-event.json` on Neo Master. The Event Template must match Relay's canonical `task.interactive_decision` Contract (`type`, `source`, `data.interactive.{jobId,taskId,executionId,invocationId}` only, without review-result fields). The CLI reuses the MCP compiler, publishes immutable preview assets, persists the review request on Neo Master and dispatches an APNs notification through the existing Neo Mobile provider. Exit receipt `review_requested` confirms only that **the iPhone inbox accepted the request**; human decisions arrive asynchronously on Events Bus. The phone need not be online. APNs delivery is best-effort; Neo Mobile synchronizes persisted requests on foreground. There is no automatic text fallback. Do not claim approval or Relay worker continuation from the receipt. For retries with an uncertain phone acknowledgment, pass a stable `--request-id UUID`. See [Codex/mobile review CLI](references/mobile-event-preview-cli.md).
|
|
61
61
|
5. **Delivery gate:** `npx @lalalic/markcut render video.md --output out/video.mp4`. Confirm the MP4 exists and examine playback, including the final audio and subtitles. A valid Markdown file, compile success, or hosted-player resource alone is not proof of a finished video.
|
|
62
62
|
|
|
63
63
|
If the user asks only for a script or structure, stop at the requested stage. Do not trigger expensive generation or claim final video delivery without a requested rendered artifact. A project-specific agent owns its own editorial or approval decisions; Markcut supplies authoring, playback and revision capabilities.
|
|
@@ -26,8 +26,8 @@ markcut verify /absolute/video.md
|
|
|
26
26
|
markcut preview /absolute/video.md --delivery event --event-template /tmp/review-event.json
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
The CLI
|
|
29
|
+
The CLI submits to Neo Master’s durable review inbox. The existing APNs provider notifies the registered iPhone; the phone syncs outstanding reviews when opened or when a push arrives. **There is no phone MCP dependency.** Options: `--title`, `--group-id`, `--group-title`, `--request-id <UUID>`, `--timeout-ms`.
|
|
30
30
|
|
|
31
|
-
It starts the same detached Markcut MCP compile worker, waits for an immutable revision, and calls the phone's `review.request`. On phone acceptance it prints JSON, including `status: "review_requested"`, `requestId`, `contentHash`, and `revisionId`. It **does not wait for a human decision**. The phone
|
|
31
|
+
It starts the same detached Markcut MCP compile worker, waits for an immutable revision, and calls the phone's `review.request`. On phone acceptance it prints JSON, including `status: "review_requested"`, `requestId`, `contentHash`, and `revisionId`. It **does not wait for a human decision**. The phone can be offline or Neo can be suspended. The Master stores the review, with APNs as a best-effort wake-up hint. A rejected/missing ACK exits nonzero. If reattempting after an uncertain ACK, supply the **same** request UUID to avoid duplicate phone requests. Phone users can inspect the compiled scenes and submit `approved` or `changes_requested`, which publishes `task.interactive_decision` through the existing authenticated Events MCP. The Event's `data.interactive` includes the exact reviewed hash, scene/timestamp comments, and idempotency key.
|
|
32
32
|
|
|
33
33
|
Relay's Event receiver and Graph decide whether to resume/revise the original Task. **A successful phone enqueue is not a human approval or a resumed Codex thread.** Do not mark the Task complete until a real human decision was correlated to the correct immutable revision and the downstream workflow actually completed. For a local browser-only preview, omit `--delivery event` and use normal `markcut preview`.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Library:** Markcut (`markcut.preview` and Neo Mobile review clients)
|
|
4
4
|
**Created:** 2026-11-05
|
|
5
|
-
**Status:** Implemented —
|
|
5
|
+
**Status:** Implemented — uniform Master-to-iPhone Preview delivery; independent Text/Event Review Result delivery
|
|
6
6
|
**Decision:** Use exactly two delivery modes, `text` and `event`. No callback registry, callback dispatcher, or Markcut-owned Relay workflow.
|
|
7
7
|
|
|
8
8
|
## Goal and boundaries
|
|
@@ -11,7 +11,8 @@ Let the same Markcut Preview player collect human review decisions, scene/timest
|
|
|
11
11
|
|
|
12
12
|
- `text` (default): send the Review Result to the opening Agent conversation using the existing MCP App `ui/message` route.
|
|
13
13
|
- `event`: the caller supplies an event template to the Markcut Provider. On Submit, the Preview UI fills the review-only fields and publishes it through the existing authorized Events MCP tool. The event consumer (Relay or another application) decides what to do next.
|
|
14
|
-
-
|
|
14
|
+
- **Preview request delivery is independent from result delivery.** Every successful `markcut.preview` hosted MCP invocation and every Codex CLI Event Preview stores an immutable request in Neo Master's durable APNs review inbox. Apple receives only a request ID as a notification. iPhone fetches the request via authenticated `review.push.pending` on foreground/notification tap. No inbound iPhone MCP is needed.
|
|
15
|
+
- Neo Mobile uses the caller-bound Event Template to fill standard `data.interactive` decision/feedback and publishes through the already authenticated Events MCP connection. It calls `review.push.complete` after transport acceptance. A default ChatGPT Text Preview without an owning thread is mirrored on iPhone **for viewing only**; its text Review Result continues in the ChatGPT UI. Do not synthesize unauthorized Relay event identity.
|
|
15
16
|
- Do not add `callback`, a callback dispatcher, a Markcut review inbox, or direct Relay SQLite/Graph access inside Markcut.
|
|
16
17
|
|
|
17
18
|
## User stories and acceptance scenarios
|
|
@@ -38,10 +39,10 @@ Let the same Markcut Preview player collect human review decisions, scene/timest
|
|
|
38
39
|
|
|
39
40
|
### US-4: Trigger Event-mode Preview from Codex CLI (P1)
|
|
40
41
|
|
|
41
|
-
1. Given a current Relay execution and a caller-authored JSON Event Template, when Codex runs `markcut preview <video.md> --delivery event --event-template <file.json>`, the CLI
|
|
42
|
-
2. The CLI
|
|
42
|
+
1. Given a current Relay execution and a caller-authored JSON Event Template, when Codex runs `markcut preview <video.md> --delivery event --event-template <file.json>`, the CLI validates the template, compiles/publishes the same immutable Markcut Preview assets as the MCP provider, then persists a review request on Neo Master.
|
|
43
|
+
2. The CLI and hosted MCP compiler use the same Neo Master push adapter; CLI requires `{stored:true,requestId}` from the durable queue. APNs `accepted` is optional and does not prove phone delivery. No direct phone URL, ChatGPT iframe, or callback registry is involved.
|
|
43
44
|
3. The CLI exits after mobile receipt, rather than waiting for human action. User submission on iPhone publishes the canonical `task.interactive_decision` using the frozen template. **Event Bus transport acceptance is not Relay Graph completion or Codex continuation.**
|
|
44
|
-
4.
|
|
45
|
+
4. The iPhone may be asleep or offline; the request remains on Master even if APNs rejects the notification. App foreground/notification taps synchronize the pending list. Failed durable storage is an explicit error, never a success receipt or text fallback.
|
|
45
46
|
5. On retry after an uncertain ACK, reuse the same mobile `--request-id` (UUID) so the phone can deduplicate the request. Never repurpose an old revision's approval to a changed source.
|
|
46
47
|
|
|
47
48
|
## Public contract (proposed)
|
|
@@ -130,13 +131,16 @@ Relay's canonical Event Contract is at `agents-relay/skills/agents-relay/contrac
|
|
|
130
131
|
- **FR-010**: Preserve review and approval scope per exact immutable revision. A new video revision requires fresh human approval; an Agent review cannot substitute for it.
|
|
131
132
|
- **FR-011**: Make submission failures visible and retryable, with no success banner until an actual accepted receipt. Do not change delivery modes automatically on failure.
|
|
132
133
|
- **FR-012**: Text is the existing Agent conversation path; Event is exclusively the canonical Relay `task.interactive_decision`. Old Markcut-specific event types are rejected. Existing Neo Mobile legacy storage fields do not define an additional public delivery mode.
|
|
133
|
-
- **FR-013**: Provide a headless `markcut preview --delivery event` CLI for Codex and terminal agents, using the same publisher/compiler, and
|
|
134
|
+
- **FR-013**: Provide a headless `markcut preview --delivery event` CLI for Codex and terminal agents, using the same publisher/compiler, and persist through Neo Master `review.push.notify`. Validate the caller-owned template and require a durable Master receipt.
|
|
135
|
+
- **FR-014**: Preview delivery must be performed once on successful compilation for every Markcut MCP/CLI Preview, independent from result Text/Event mode. APNs notification contains only the request UUID, not the Event Template; Master stores the full immutable request and supports authenticated pending/complete operations. An offline phone must be able to fetch outstanding reviews later.
|
|
136
|
+
- **FR-015**: Neo Mobile `review.push.complete` follows successful Events MCP result submission. Replay after completed human review must not restore an obsolete pending request.
|
|
134
137
|
|
|
135
138
|
## Ownership and downstream behavior
|
|
136
139
|
|
|
137
|
-
- **Markcut Provider**:
|
|
140
|
+
- **Markcut Provider and CLI**: compile/publish immutable media and deliver every Preview request to Neo Master (APNs notifier), independently of any user result.
|
|
138
141
|
- **Markcut Preview UI**: gathers comments and decision, fills review fields, dispatches either text or event, displays honest receipt/failure state.
|
|
139
|
-
- **Neo
|
|
142
|
+
- **Neo Master/APNs**: persist pending Preview requests and notify Apple with the request ID. Provide authenticated `pending`/`complete` API; do not claim APNs acceptance as iPhone receipt.
|
|
143
|
+
- **Neo Mobile**: synchronizes stored requests into its local Inbox, shows the same immutable revision, submits result Event through authenticated Neo MCP, then acknowledges completion. Offline local feedback retry remains.
|
|
140
144
|
- **Caller/Event consumer**: owns authorization, durable business processing, any Relay Event → original Producer Agent continuation, rereview, workflow transitions, and video delivery. `task.interactive_decision` is Relay human-interaction input, **not** Relay task-completion authority. No alternate or legacy review event type is accepted by the Preview provider.
|
|
141
145
|
|
|
142
146
|
## Edge cases and compatibility
|
|
@@ -167,6 +171,6 @@ Relay's canonical Event Contract is at `agents-relay/skills/agents-relay/contrac
|
|
|
167
171
|
|
|
168
172
|
- Markcut's MCP tool supports both `text` and canonical Relay `event` delivery. The hosted Review UI and the Neo Mobile Event requester use the immutable `data.interactive` field names.
|
|
169
173
|
- Codex/terminal users can now call `markcut preview <video.md> --delivery event --event-template <file.json>`; this route starts the same hosted-preview compiler and sends the accepted revision to Neo Mobile using its `review.request` MCP, without invoking a ChatGPT iframe.
|
|
170
|
-
- The
|
|
171
|
-
- The CLI
|
|
174
|
+
- The earlier direct-phone Codex CLI → physical iPhone 17 → Events Bus test (isolated Job `999999993`) returned `review_requested` and accepted the Event Template. The iPhone Review Inbox displayed the request and the phone submitted `changes_requested` with precise revision metadata, producing one persisted `task.interactive_decision`. This proves the transport and mobile UI paths, **not** real Relay Graph job continuation.
|
|
175
|
+
- The CLI does not call the phone's MCP server. Master holds pending reviews durably; APNs notification is a best-effort alert. A reachable Master is required to persist the review, but the phone can be offline.
|
|
172
176
|
- Events Bus assigns the transport `event_id`; the mobile review result carries a stable `data.interactive.idempotencyKey`, and Relay consumes the canonical Task event. Code-level Graph/worker continuation verification remains owned by Relay.
|
package/src/mcp/bridge.mjs
CHANGED
|
@@ -180,8 +180,15 @@ async function trackOperation(data){
|
|
|
180
180
|
if(!response.ok)throw new Error('HTTP '+response.status);
|
|
181
181
|
const progress=await response.json();
|
|
182
182
|
if(generation!==operationGeneration)return;
|
|
183
|
-
if(progress.state==='ready'&&progress.result){
|
|
184
|
-
|
|
183
|
+
if(progress.state==='ready'&&progress.result){
|
|
184
|
+
await renderRevision({...progress.result,requestedPath:data.requestedPath||data.path,
|
|
185
|
+
requestId:progress.result.requestId||data.requestId,review:progress.result.review||data.review,relay:data.relay});
|
|
186
|
+
if(progress.mobileDelivery?.stored===false)
|
|
187
|
+
status.textContent='iPhone Preview delivery failed: '+(progress.mobileDelivery.error||'unknown error');
|
|
188
|
+
else if(progress.mobileDelivery?.stored===true&&progress.mobileDelivery.accepted===false)
|
|
189
|
+
status.textContent='Preview saved on Neo Master; APNs notification not confirmed. Open Neo on iPhone to sync.';
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
185
192
|
if(progress.state==='failed'){reviewReadonly(true,'Compilation failed: '+progress.error);return;}
|
|
186
193
|
const elapsed=Math.round((Date.now()-(progress.startedAt||Date.now()))/1000);
|
|
187
194
|
status.textContent='Compiling · '+(progress.stage||'working')+' · '+elapsed+'s';
|
|
@@ -27,7 +27,7 @@ export function writeOperation(id,data){
|
|
|
27
27
|
writeFileSync(temp,JSON.stringify(data),{mode:0o644});
|
|
28
28
|
renameSync(temp,join(folder,id+".json"));
|
|
29
29
|
}
|
|
30
|
-
export function startCompileOperation(path,relay,review={delivery:"text"}){
|
|
30
|
+
export function startCompileOperation(path,relay,review={delivery:"text"},mobileOptions={}){
|
|
31
31
|
const valid=validateMarkdownPath(resolvePreviewPath(path));
|
|
32
32
|
if(!statSync(valid).isFile())throw new Error("Preview source must be a Markdown file");
|
|
33
33
|
const input=fingerprintInputs(valid);
|
|
@@ -36,7 +36,7 @@ export function startCompileOperation(path,relay,review={delivery:"text"}){
|
|
|
36
36
|
const id=randomUUID(),startedAt=Date.now();
|
|
37
37
|
writeOperation(id,{id,state:"compiling",stage:"queued",startedAt,requestedPath:path});
|
|
38
38
|
const worker=fileURLToPath(new URL("./compile-worker.mjs",import.meta.url));
|
|
39
|
-
const child=spawn(process.execPath,[worker,id,valid,path,JSON.stringify(relay||null),sourceHash,JSON.stringify(review)],{detached:true,stdio:"ignore"});
|
|
39
|
+
const child=spawn(process.execPath,[worker,id,valid,path,JSON.stringify(relay||null),sourceHash,JSON.stringify(review),JSON.stringify(mobileOptions)],{detached:true,stdio:"ignore"});
|
|
40
40
|
child.on("error",e=>{
|
|
41
41
|
writeOperation(id,{id,state:"failed",stage:"failed",startedAt,requestedPath:path,error:e.message});
|
|
42
42
|
});
|
|
@@ -3,9 +3,11 @@ import {ensureVideoPreview} from "./preview.mjs";
|
|
|
3
3
|
import {publishPreviewRevision} from "./remote-assets.mjs";
|
|
4
4
|
import {writeOperation} from "./compile-operation.mjs";
|
|
5
5
|
import {fingerprintInputs} from "./source-fingerprint.mjs";
|
|
6
|
-
|
|
6
|
+
import {buildPhoneReviewRequest,sendMasterReviewRequest} from "./phone-notification.mjs";
|
|
7
|
+
const [id,path,requestedPath,relayText,sourceHash,reviewText,mobileOptionsText]=process.argv.slice(2);
|
|
7
8
|
const startedAt=Date.now();
|
|
8
9
|
const review=JSON.parse(reviewText||'{"delivery":"text"}');
|
|
10
|
+
const mobileOptions=JSON.parse(mobileOptionsText||"{}");
|
|
9
11
|
function update(stage){writeOperation(id,{id,state:"compiling",stage,startedAt,updatedAt:Date.now(),requestedPath});}
|
|
10
12
|
try{
|
|
11
13
|
update("resolving-and-compiling");
|
|
@@ -15,7 +17,24 @@ try{
|
|
|
15
17
|
const result=await ensureVideoPreview(path,{onProgress:update});
|
|
16
18
|
update("publishing");
|
|
17
19
|
publishPreviewRevision(requestedPath,{...result,requestedPath});
|
|
18
|
-
|
|
20
|
+
update("notifying-iphone");
|
|
21
|
+
let mobileDelivery;
|
|
22
|
+
try{
|
|
23
|
+
const request=buildPhoneReviewRequest(id,{...result,requestedPath},review,mobileOptions);
|
|
24
|
+
mobileDelivery=await sendMasterReviewRequest(request);
|
|
25
|
+
}catch(error){
|
|
26
|
+
mobileDelivery={stored:false,error:String(error?.message||error)};
|
|
27
|
+
}
|
|
28
|
+
// A compiled video is not a delivered Preview. Never silently claim success
|
|
29
|
+
// if the canonical Master inbox could not persist the mobile request.
|
|
30
|
+
if(mobileDelivery.stored!==true){
|
|
31
|
+
writeOperation(id,{id,state:"failed",stage:"mobile-delivery",startedAt,updatedAt:Date.now(),
|
|
32
|
+
requestedPath,error:mobileDelivery.error||"Neo Master could not persist review request"});
|
|
33
|
+
process.exitCode=1;
|
|
34
|
+
}else{
|
|
35
|
+
writeOperation(id,{id,state:"ready",stage:"complete",startedAt,updatedAt:Date.now(),requestedPath,
|
|
36
|
+
mobileDelivery,result:{...result,requestedPath,requestId:id,review,relay:JSON.parse(relayText)}});
|
|
37
|
+
}
|
|
19
38
|
}catch(e){
|
|
20
39
|
writeOperation(id,{id,state:"failed",stage:"failed",startedAt,updatedAt:Date.now(),requestedPath,error:e?.message||String(e)});
|
|
21
40
|
process.exitCode=1;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/** Codex/terminal human-review bridge. The phone publishes the caller-owned Event after Submit. */
|
|
3
|
-
import {spawn} from 'node:child_process';
|
|
4
|
-
import {randomUUID} from 'node:crypto';
|
|
5
3
|
import {readFileSync} from 'node:fs';
|
|
6
|
-
import {
|
|
4
|
+
import {join,resolve} from 'node:path';
|
|
7
5
|
import {pathToFileURL} from 'node:url';
|
|
8
6
|
import {normalizeReviewConfig} from './review-delivery.mjs';
|
|
9
7
|
|
|
@@ -11,17 +9,18 @@ const delay = ms => new Promise(done => setTimeout(done,ms));
|
|
|
11
9
|
const UUID = /^[a-f0-9-]{36}$/i;
|
|
12
10
|
|
|
13
11
|
export function parseEventPreviewOptions(argv) {
|
|
14
|
-
if (argv[0] !== 'preview' || !argv[1] || argv[1].startsWith('--')) throw new Error('Usage: markcut preview <file.md> --delivery event --event-template <file.json>
|
|
15
|
-
const allowed=new Set(['--delivery','--event-template','--
|
|
12
|
+
if (argv[0] !== 'preview' || !argv[1] || argv[1].startsWith('--')) throw new Error('Usage: markcut preview <file.md> --delivery event --event-template <file.json>');
|
|
13
|
+
const allowed=new Set(['--delivery','--event-template','--title','--group-id','--group-title','--request-id','--timeout-ms']);
|
|
16
14
|
const options={file:resolve(argv[1])};
|
|
17
15
|
for(let i=2;i<argv.length;i+=2){
|
|
18
16
|
const flag=argv[i],value=argv[i+1];
|
|
19
17
|
if(!allowed.has(flag) || !value || value.startsWith('--'))throw new Error('Missing or unsupported preview event flag: '+flag);
|
|
20
|
-
const key={'--delivery':'delivery','--event-template':'eventTemplatePath','--
|
|
18
|
+
const key={'--delivery':'delivery','--event-template':'eventTemplatePath','--title':'title','--group-id':'groupId','--group-title':'groupTitle','--request-id':'requestId','--timeout-ms':'timeoutMs'}[flag];
|
|
21
19
|
if(Object.hasOwn(options,key))throw new Error('Duplicate flag: '+flag);
|
|
22
20
|
options[key]=value;
|
|
23
21
|
}
|
|
24
|
-
if(
|
|
22
|
+
if(!['text','event'].includes(options.delivery) || (options.delivery==='event')!==Boolean(options.eventTemplatePath))
|
|
23
|
+
throw new Error('Event delivery requires --event-template; Text delivery must omit it');
|
|
25
24
|
if(options.requestId && !UUID.test(options.requestId))throw new Error('--request-id must be a UUID');
|
|
26
25
|
const limit=options.timeoutMs===undefined ? 300000 : Number(options.timeoutMs);
|
|
27
26
|
if(!Number.isSafeInteger(limit) || limit<1000 || limit>1800000)throw new Error('--timeout-ms must be 1000..1800000');
|
|
@@ -29,87 +28,14 @@ export function parseEventPreviewOptions(argv) {
|
|
|
29
28
|
return options;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
export function phoneUrlFromDnsSdText(text){
|
|
33
|
-
const m=text.match(/can be reached at ([a-z0-9._-]+):([0-9]{1,5})\b/i);
|
|
34
|
-
if(!m)return null;
|
|
35
|
-
const host=m[1].replace(/\.+$/,'');
|
|
36
|
-
if(!host.endsWith('.local') || Number(m[2])<1 || Number(m[2])>65535)return null;
|
|
37
|
-
return `http://${host}:${m[2]}/mcp`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function discoverPhoneUrl(timeoutMs=4000){
|
|
41
|
-
return await new Promise((resolveDiscovery,rejectDiscovery)=>{
|
|
42
|
-
const proc=spawn('dns-sd',['-L','neox','_mcp._tcp','local'],{stdio:['ignore','pipe','pipe']});
|
|
43
|
-
let output='',settled=false;
|
|
44
|
-
const done=(error,value)=>{
|
|
45
|
-
if(settled)return;settled=true;clearTimeout(timeout);proc.kill('SIGTERM');
|
|
46
|
-
if(error)rejectDiscovery(error);else resolveDiscovery(value);
|
|
47
|
-
};
|
|
48
|
-
const timeout=setTimeout(()=>done(new Error('Neo Mobile not discoverable; launch Neo on iPhone or provide --phone-url')),timeoutMs);
|
|
49
|
-
proc.stdout.on('data',c=>{output+=String(c);if(output.length>8192)output=output.slice(-8192);const url=phoneUrlFromDnsSdText(output);if(url)done(null,url);});
|
|
50
|
-
proc.stderr.on('data',c=>{output+=String(c);});
|
|
51
|
-
proc.on('error',e=>done(e));
|
|
52
|
-
proc.on('exit',()=>done(new Error('Neo Mobile Bonjour discovery stopped before resolution')));
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function validatePhoneUrl(input){
|
|
57
|
-
const u=new URL(input);
|
|
58
|
-
if(u.username || u.password || u.search || u.hash || u.pathname!=='/mcp')throw new Error('Phone MCP URL must have only /mcp path');
|
|
59
|
-
const h=u.hostname.toLowerCase();
|
|
60
|
-
const local=h==='localhost'||h.endsWith('.local')||h==='127.0.0.1'||h.startsWith('10.')||h.startsWith('192.168.')||
|
|
61
|
-
/^172\.(1[6-9]|2[0-9]|3[01])\./.test(h);
|
|
62
|
-
if((u.protocol!=='http:' || !local) && u.protocol!=='https:')throw new Error('Phone MCP URL must be local HTTP or HTTPS');
|
|
63
|
-
return u.toString();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function buildMobileReviewRequest(operation,template,options={}){
|
|
67
|
-
const config=normalizeReviewConfig({delivery:'event',eventTemplate:template});
|
|
68
|
-
const result=operation.result;
|
|
69
|
-
if(operation.state!=='ready' || !result || !/^[a-f0-9]{64}$/.test(result.contentHash||'') ||
|
|
70
|
-
!result.revisionId || !result.id)throw new Error('Compiled preview is not ready');
|
|
71
|
-
const details=config.eventTemplate.data.interactive;
|
|
72
|
-
const id=options.requestId??operation.id;
|
|
73
|
-
if(!UUID.test(id))throw new Error('Invalid review request identity');
|
|
74
|
-
const title=options.title?.trim() || basename(options.file??result.requestedPath??'Preview','.md');
|
|
75
|
-
return {
|
|
76
|
-
id,contentHash:result.contentHash,revisionId:result.revisionId,previewId:result.id,
|
|
77
|
-
title,groupId:options.groupId ?? `job/${details.jobId}/task/${details.taskId}`,
|
|
78
|
-
groupTitle:options.groupTitle ?? title,jobId:details.jobId,
|
|
79
|
-
delivery:'event',eventTemplate:config.eventTemplate,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export async function sendMobileReviewRequest(phoneUrl,request,{fetchImpl=fetch}={}){
|
|
84
|
-
const url=validatePhoneUrl(phoneUrl);
|
|
85
|
-
const payload={jsonrpc:'2.0',id:1,method:'tools/call',params:{name:'review.request',arguments:request}};
|
|
86
|
-
let lastError;
|
|
87
|
-
for(let attempt=0;attempt<2;attempt++){
|
|
88
|
-
try{
|
|
89
|
-
const response=await fetchImpl(url,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(payload),signal:AbortSignal.timeout(9000)});
|
|
90
|
-
if(!response.ok)throw new Error(`Phone MCP returned HTTP ${response.status}`);
|
|
91
|
-
const body=await response.json();
|
|
92
|
-
if(body.error || body.result?.isError)throw new Error('Phone MCP rejected review.request');
|
|
93
|
-
const text=body.result?.content?.find(item=>item.type==='text')?.text;
|
|
94
|
-
let receipt;
|
|
95
|
-
try{receipt=JSON.parse(text);}catch{throw new Error('Phone MCP returned no structured review receipt');}
|
|
96
|
-
if(receipt.accepted!==true || receipt.id!==request.id)throw new Error('Phone rejected the review request: '+String(text).slice(0,130));
|
|
97
|
-
return receipt;
|
|
98
|
-
}catch(e){lastError=e;if(attempt===0)await delay(400);}
|
|
99
|
-
}
|
|
100
|
-
throw lastError;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
31
|
export async function runMobilePreview(argv){
|
|
104
32
|
const opts=parseEventPreviewOptions(argv);
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
// Check phone reachability before starting potentially expensive compilation.
|
|
108
|
-
const phoneUrl=validatePhoneUrl(opts.phoneUrl || process.env.NEOX_MCP_URL || await discoverPhoneUrl());
|
|
33
|
+
const config=opts.delivery==='event' ? normalizeReviewConfig({delivery:'event',
|
|
34
|
+
eventTemplate:JSON.parse(readFileSync(resolve(opts.eventTemplatePath),'utf8'))}) : {delivery:'text'};
|
|
109
35
|
const [{startCompileOperation},{EXPORT_ROOT}]=await Promise.all([
|
|
110
36
|
import('./compile-operation.mjs'),import('./remote-assets.mjs'),
|
|
111
37
|
]);
|
|
112
|
-
const operation=startCompileOperation(opts.file,undefined,config);
|
|
38
|
+
const operation=startCompileOperation(opts.file,undefined,config,opts);
|
|
113
39
|
const stateFile=join(EXPORT_ROOT,'operations',operation.operationId+'.json');
|
|
114
40
|
let state;
|
|
115
41
|
const until=Date.now()+opts.timeoutMs;
|
|
@@ -120,12 +46,13 @@ export async function runMobilePreview(argv){
|
|
|
120
46
|
await delay(300);
|
|
121
47
|
}
|
|
122
48
|
if(state?.state!=='ready')throw new Error('Preview compile timed out; operation '+operation.operationId);
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
status:'review_requested',operationId:operation.operationId,requestId:
|
|
127
|
-
contentHash:
|
|
128
|
-
delivery
|
|
49
|
+
const receipt=state.mobileDelivery;
|
|
50
|
+
if(receipt?.stored!==true)throw new Error('Master review delivery failed: '+(receipt?.error||'no durable receipt'));
|
|
51
|
+
return {stored:true,apnsAccepted:receipt.accepted===true,duplicate:receipt.duplicate===true,
|
|
52
|
+
status:'review_requested',operationId:operation.operationId,requestId:receipt.requestId,
|
|
53
|
+
contentHash:state.result.contentHash,revisionId:state.result.revisionId,
|
|
54
|
+
...(config.delivery==='event' ? {jobId:config.eventTemplate.data.interactive.jobId} : {}),
|
|
55
|
+
delivery:config.delivery,destination:'Neo Master/Neo Mobile'};
|
|
129
56
|
}
|
|
130
57
|
|
|
131
58
|
if(process.argv[1] && import.meta.url===pathToFileURL(resolve(process.argv[1])).href){
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Shared mobile-review delivery for both hosted MCP and Codex CLI previews. */
|
|
2
|
+
import {spawn} from 'node:child_process';
|
|
3
|
+
import {existsSync} from 'node:fs';
|
|
4
|
+
import {join,basename} from 'node:path';
|
|
5
|
+
import {homedir} from 'node:os';
|
|
6
|
+
import {normalizeReviewConfig} from './review-delivery.mjs';
|
|
7
|
+
const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
const SHA=/^[0-9a-f]{64}$/;
|
|
9
|
+
|
|
10
|
+
export function buildPhoneReviewRequest(operationId,result,review,options={}){
|
|
11
|
+
const config=normalizeReviewConfig(review);
|
|
12
|
+
if(!UUID.test(operationId) || !result || !SHA.test(result.contentHash||'') ||
|
|
13
|
+
!result.revisionId || !result.id)throw new Error('Immutable Preview is not ready');
|
|
14
|
+
const id=options.requestId||operationId;
|
|
15
|
+
if(!UUID.test(id))throw new Error('Invalid phone request UUID');
|
|
16
|
+
const title=options.title || basename(result.requestedPath||'video.md','.md');
|
|
17
|
+
const request={id,contentHash:result.contentHash,revisionId:result.revisionId,
|
|
18
|
+
previewId:result.id,title,delivery:config.delivery};
|
|
19
|
+
if(config.delivery==='event'){
|
|
20
|
+
const fixed=config.eventTemplate.data.interactive;
|
|
21
|
+
request.eventTemplate=config.eventTemplate;
|
|
22
|
+
request.jobId=fixed.jobId;
|
|
23
|
+
request.groupId=options.groupId||`job/${fixed.jobId}/task/${fixed.taskId}`;
|
|
24
|
+
}else{
|
|
25
|
+
// A ChatGPT text-only preview has no Relay event identity or owning thread.
|
|
26
|
+
// Mirror the video to iPhone as view-only; ChatGPT still owns its text review.
|
|
27
|
+
request.groupId=options.groupId||result.requestedPath;
|
|
28
|
+
}
|
|
29
|
+
if(options.groupTitle)request.groupTitle=options.groupTitle;
|
|
30
|
+
return request;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function sendMasterReviewRequest(request,{bridge=process.env.NEOX_APNS_BRIDGE,timeoutMs=20000}={}){
|
|
34
|
+
const binary=bridge || join(homedir(),'Workspace/neox/NeoxAPNs/review-cli.mjs');
|
|
35
|
+
if(!existsSync(binary))throw new Error('Neo Master APNs review bridge unavailable: '+binary);
|
|
36
|
+
return await new Promise((resolve,reject)=>{
|
|
37
|
+
const child=spawn(process.execPath,[binary,'notify'],{stdio:['pipe','pipe','pipe']});
|
|
38
|
+
let out='',err='',done=false;
|
|
39
|
+
const finish=(error,result)=>{if(done)return;done=true;clearTimeout(timer);if(error)reject(error);else resolve(result);};
|
|
40
|
+
const timer=setTimeout(()=>{child.kill('SIGTERM');finish(new Error('Master review push timed out'));},timeoutMs);
|
|
41
|
+
child.stdout.on('data',d=>{out+=d; if(out.length>256000)child.kill('SIGTERM');});
|
|
42
|
+
child.stderr.on('data',d=>{if(err.length<1000)err+=d;});
|
|
43
|
+
child.on('error',e=>finish(e));
|
|
44
|
+
child.on('exit',code=>{
|
|
45
|
+
if(code!==0)return finish(new Error('Master review delivery failed: '+err.slice(0,250)));
|
|
46
|
+
let parsed;try{parsed=JSON.parse(out);}catch{return finish(new Error('Invalid Master review receipt'));}
|
|
47
|
+
if(parsed.stored!==true || parsed.requestId!==request.id)return finish(new Error('Master did not persist review request'));
|
|
48
|
+
finish(null,parsed);
|
|
49
|
+
});
|
|
50
|
+
child.stdin.end(JSON.stringify(request));
|
|
51
|
+
});
|
|
52
|
+
}
|
package/src/mcp/preview.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { externalizePreviewMedia, publicOrigin, resolveMountedFile, resolvePrevi
|
|
|
9
9
|
import {fingerprintInputs} from "./source-fingerprint.mjs";
|
|
10
10
|
|
|
11
11
|
export const TOOL_NAME = "markcut.preview";
|
|
12
|
-
export const RESOURCE_URI = "ui://markcut/video-preview-
|
|
12
|
+
export const RESOURCE_URI = "ui://markcut/video-preview-v44.html";
|
|
13
13
|
const PREVIEW_VERSION = RESOURCE_URI.match(/video-preview-(v\d+)/)?.[1] ?? "unknown";
|
|
14
14
|
// Legacy entrypoints remain registered, but serve the current implementation.
|
|
15
15
|
export const LEGACY_RESOURCE_URIS = [
|
|
@@ -51,6 +51,7 @@ export const LEGACY_RESOURCE_URIS = [
|
|
|
51
51
|
"ui://markcut/video-preview-v40.html",
|
|
52
52
|
"ui://markcut/video-preview-v41.html",
|
|
53
53
|
"ui://markcut/video-preview-v42.html",
|
|
54
|
+
"ui://markcut/video-preview-v43.html",
|
|
54
55
|
"ui://markcut/video-preview-v39.html",
|
|
55
56
|
"ui://markcut/video-preview-v38.html",
|
|
56
57
|
];
|
package/src/render/cli.mjs
CHANGED
|
@@ -66,7 +66,7 @@ Commands:
|
|
|
66
66
|
preview <file.json|.md> Open player with live preview
|
|
67
67
|
--delivery event Headless human review via Neo Mobile (requires .md)
|
|
68
68
|
--event-template <file.json> Relay task.interactive_decision envelope from current Task
|
|
69
|
-
|
|
69
|
+
(No phone URL) Neo Master stores and notifies through APNs
|
|
70
70
|
--title <text> Optional title displayed in Review Inbox
|
|
71
71
|
--group-id <id> Stable video group; later revisions supersede earlier ones
|
|
72
72
|
--request-id <uuid> Stable mobile request UUID for retry after uncertain ACK
|
|
@@ -1,62 +1,47 @@
|
|
|
1
|
-
import {describe,it,expect
|
|
1
|
+
import {describe,it,expect} from 'vitest';
|
|
2
2
|
import {randomUUID} from 'node:crypto';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from '../src/mcp/mobile-review-cli.mjs';
|
|
3
|
+
import {mkdtempSync,writeFileSync,rmSync} from 'node:fs';
|
|
4
|
+
import {tmpdir} from 'node:os';
|
|
5
|
+
import {join} from 'node:path';
|
|
6
|
+
import {parseEventPreviewOptions} from '../src/mcp/mobile-review-cli.mjs';
|
|
7
|
+
import {buildPhoneReviewRequest,sendMasterReviewRequest} from '../src/mcp/phone-notification.mjs';
|
|
7
8
|
const hash='a'.repeat(64);
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
}};
|
|
11
|
-
const id
|
|
12
|
-
const operation={id,state:'ready',result:{id:hash,contentHash:hash,revisionId:hash,requestedPath:'/tmp/preview.md'}};
|
|
9
|
+
const operationId=randomUUID();
|
|
10
|
+
const template={type:'task.interactive_decision',source:'job/j1/task/producer/execution/e1',
|
|
11
|
+
data:{interactive:{jobId:'j1',taskId:'producer',executionId:'e1',invocationId:'review1'}}};
|
|
12
|
+
const result={id:hash,contentHash:hash,revisionId:hash,requestedPath:'/tmp/preview.md'};
|
|
13
13
|
|
|
14
|
-
describe('
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
expect(fakeFetch).toHaveBeenCalledTimes(1);
|
|
48
|
-
});
|
|
49
|
-
it('reuses the same request identity on uncertain transport retries and refuses false success',async()=>{
|
|
50
|
-
const request=buildMobileReviewRequest(operation,eventTemplate,{requestId:id});
|
|
51
|
-
const stable=[];
|
|
52
|
-
const fakeFetch=vi.fn(async(_url,opts)=>{
|
|
53
|
-
stable.push(JSON.parse(opts.body).params.arguments.id);
|
|
54
|
-
if(stable.length===1)throw new Error('lost ACK');
|
|
55
|
-
return {ok:true,json:async()=>({result:{content:[{type:'text',text:JSON.stringify({accepted:true,duplicate:true,id})}]}})};
|
|
56
|
-
});
|
|
57
|
-
expect((await sendMobileReviewRequest('http://17.local:9223/mcp',request,{fetchImpl:fakeFetch})).duplicate).toBe(true);
|
|
58
|
-
expect(stable).toEqual([id,id]);
|
|
59
|
-
const reject=vi.fn(async()=>({ok:true,json:async()=>({result:{content:[{type:'text',text:'Error: invalid review request'}]}})}));
|
|
60
|
-
await expect(sendMobileReviewRequest('http://17.local:9223/mcp',request,{fetchImpl:reject})).rejects.toThrow(/no structured review receipt/);
|
|
61
|
-
});
|
|
14
|
+
describe('Unified Master review notification from both MCP and CLI',()=>{
|
|
15
|
+
it('enforces event CLI template without phone URL dependency',()=>{
|
|
16
|
+
expect(parseEventPreviewOptions(['preview','video.md','--delivery','event','--event-template','template.json']).delivery).toBe('event');
|
|
17
|
+
expect(()=>parseEventPreviewOptions(['preview','video.md','--delivery','event'])).toThrow();
|
|
18
|
+
expect(()=>parseEventPreviewOptions(['preview','video.md','--delivery','event','--event-template','a','--phone-url','http://phone'])).toThrow();
|
|
19
|
+
expect(parseEventPreviewOptions(['preview','video.md','--delivery','text']).delivery).toBe('text');
|
|
20
|
+
expect(()=>parseEventPreviewOptions(['preview','video.md','--delivery','text','--event-template','a'])).toThrow();
|
|
21
|
+
});
|
|
22
|
+
it('event request freezes caller template and immutable revision identity',()=>{
|
|
23
|
+
const request=buildPhoneReviewRequest(operationId,result,{delivery:'event',eventTemplate:template});
|
|
24
|
+
expect(request).toMatchObject({id:operationId,contentHash:hash,revisionId:hash,previewId:hash,
|
|
25
|
+
title:'preview',delivery:'event',jobId:'j1',groupId:'job/j1/task/producer',eventTemplate:template});
|
|
26
|
+
expect(request.eventTemplate.data.interactive).not.toHaveProperty('decision');
|
|
27
|
+
expect(()=>buildPhoneReviewRequest(operationId,result,{delivery:'event',eventTemplate:{...template,type:'markcut.review.submitted'}})).toThrow();
|
|
28
|
+
expect(()=>buildPhoneReviewRequest(operationId,{...result,contentHash:'bad'},{delivery:'event',eventTemplate:template})).toThrow();
|
|
29
|
+
});
|
|
30
|
+
it('default ChatGPT text Preview is still mirrored to phone as view-only',()=>{
|
|
31
|
+
const request=buildPhoneReviewRequest(operationId,result,{delivery:'text'});
|
|
32
|
+
expect(request).toMatchObject({id:operationId,delivery:'text',contentHash:hash,groupId:'/tmp/preview.md'});
|
|
33
|
+
expect(request).not.toHaveProperty('eventTemplate');
|
|
34
|
+
expect(request).not.toHaveProperty('ownerCallbackTool');
|
|
35
|
+
});
|
|
36
|
+
it('uses the local Master APNs bridge, requires durable storage acknowledgment',async()=>{
|
|
37
|
+
const tmp=mkdtempSync(join(tmpdir(),'markcut-master-bridge-'));
|
|
38
|
+
const script=join(tmp,'bridge.mjs');
|
|
39
|
+
const request=buildPhoneReviewRequest(operationId,result,{delivery:'event',eventTemplate:template});
|
|
40
|
+
try{
|
|
41
|
+
writeFileSync(script,`import fs from 'node:fs';const data=JSON.parse(fs.readFileSync(0,'utf8'));process.stdout.write(JSON.stringify({stored:true,accepted:false,requestId:data.id}));`);
|
|
42
|
+
expect(await sendMasterReviewRequest(request,{bridge:script})).toMatchObject({stored:true,accepted:false,requestId:operationId});
|
|
43
|
+
writeFileSync(script,`process.stdout.write(JSON.stringify({stored:false,requestId:'${operationId}'}));`);
|
|
44
|
+
await expect(sendMasterReviewRequest(request,{bridge:script})).rejects.toThrow(/persist/);
|
|
45
|
+
}finally{rmSync(tmp,{recursive:true,force:true});}
|
|
46
|
+
});
|
|
62
47
|
});
|