@lalalic/markcut 3.2.44 → 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/bin/markcut +11 -0
- package/docs/developer-reference.md +3 -0
- package/package.json +2 -2
- package/skills/markcut/SKILL.md +3 -1
- package/skills/markcut/references/mobile-event-preview-cli.md +33 -0
- package/specs/001-preview-review-delivery/spec.md +25 -11
- 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 +63 -0
- package/src/mcp/phone-notification.mjs +52 -0
- package/src/mcp/preview.mjs +2 -1
- package/src/render/cli.mjs +7 -0
- package/tests/mobile-preview-cli.test.ts +47 -0
package/bin/markcut
CHANGED
|
@@ -6,6 +6,17 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = dirname(__filename);
|
|
8
8
|
const root = resolve(__dirname, "..");
|
|
9
|
+
if (process.argv[2] === "preview" && process.argv.includes("--delivery")) {
|
|
10
|
+
const index=process.argv.indexOf("--delivery");
|
|
11
|
+
if (process.argv[index+1] !== "event") {
|
|
12
|
+
console.error("CLI review delivery supports only --delivery event; omit --delivery for the native preview.");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const entry=resolve(root,"src","mcp","mobile-review-cli.mjs");
|
|
16
|
+
const result=spawnSync(process.execPath,[entry,...process.argv.slice(2)],{stdio:"inherit"});
|
|
17
|
+
if(result.error)console.error(result.error.message);
|
|
18
|
+
process.exit(result.status??1);
|
|
19
|
+
}
|
|
9
20
|
if (process.argv[2] === "queue") {
|
|
10
21
|
const result = spawnSync(process.execPath, [resolve(root, "src", "queue-worker.mjs"), ...process.argv.slice(3)], { stdio: "inherit" });
|
|
11
22
|
if (result.error) console.error(result.error.message);
|
|
@@ -50,8 +50,11 @@ 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
54
|
```
|
|
54
55
|
|
|
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
|
+
|
|
55
58
|
## Project structure
|
|
56
59
|
|
|
57
60
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lalalic/markcut",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.46",
|
|
4
4
|
"description": "Markdown-to-video engine. Describe scenes in markdown, get a rendered video.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"markcut": "bin/markcut"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"render:all": "node src/render/cli.mjs render",
|
|
22
22
|
"render:demo": "node src/render/cli.mjs render src/demo-components.json",
|
|
23
23
|
"templates": "node src/render/cli.mjs templates",
|
|
24
|
-
"preview": "node
|
|
24
|
+
"preview": "node bin/markcut preview",
|
|
25
25
|
"mcp": "node src/mcp/server.mjs",
|
|
26
26
|
"build:mcp": "scripts/build-mcp-preview.sh",
|
|
27
27
|
"verify": "node src/render/cli.mjs verify",
|
package/skills/markcut/SKILL.md
CHANGED
|
@@ -16,6 +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. Neo Master stores the Preview and APNs notifies iPhone; the phone publishes the Event when the person submits. |
|
|
19
20
|
| Deliver a finished MP4 | `markcut render <file> --output <path>`; inspect the resulting video and sound. |
|
|
20
21
|
| Visualize a route or trip | Use a Markdown `map` stream; load [route/map reference](docs/map-dynamic-camera.md). |
|
|
21
22
|
|
|
@@ -56,7 +57,8 @@ Asset paths are relative to the Markdown document. A `prompt` without `src` asks
|
|
|
56
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.
|
|
57
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.
|
|
58
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.
|
|
59
|
-
4. **
|
|
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
|
+
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.
|
|
60
62
|
|
|
61
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.
|
|
62
64
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Codex / terminal → Neo Mobile Event Preview
|
|
2
|
+
|
|
3
|
+
On **Neo Master**, with a current managed Relay Task execution context, create a JSON Event Template according to `agents-relay/skills/agents-relay/contracts/event-contract.md`. **Do not invent Job/Task/Execution identity.** Use the exact execution identity supplied by Relay, and a stable, unique `invocationId` for each new video review request. Do not prefill `decision`, `feedback`, `comments`, `revision`, `contentHash`, `revisionId`, `previewId`, `requestId`, or `idempotencyKey`.
|
|
4
|
+
|
|
5
|
+
Example illustrative template file (`/tmp/review-event.json`; replace placeholders with actual Relay Task values):
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"type": "task.interactive_decision",
|
|
10
|
+
"source": "job/<jobId>/task/<taskId>/execution/<executionId>",
|
|
11
|
+
"data": {
|
|
12
|
+
"interactive": {
|
|
13
|
+
"jobId": "<jobId>",
|
|
14
|
+
"taskId": "<taskId>",
|
|
15
|
+
"executionId": "<executionId>",
|
|
16
|
+
"invocationId": "<unique-review-request-id>"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Run:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
markcut verify /absolute/video.md
|
|
26
|
+
markcut preview /absolute/video.md --delivery event --event-template /tmp/review-event.json
|
|
27
|
+
```
|
|
28
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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:**
|
|
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
|
|
@@ -36,6 +37,14 @@ Let the same Markcut Preview player collect human review decisions, scene/timest
|
|
|
36
37
|
3. Given intermittent connectivity, when a queued review is retried after reconnect or relaunch, then the original request ID, video identity and idempotency key are preserved.
|
|
37
38
|
4. Given a new published video revision, when the user views history, then approval of an older revision remains scoped to that older `contentHash` and `revisionId`.
|
|
38
39
|
|
|
40
|
+
### US-4: Trigger Event-mode Preview from Codex CLI (P1)
|
|
41
|
+
|
|
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.
|
|
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.**
|
|
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.
|
|
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.
|
|
47
|
+
|
|
39
48
|
## Public contract (proposed)
|
|
40
49
|
|
|
41
50
|
### Preview request
|
|
@@ -121,13 +130,17 @@ Relay's canonical Event Contract is at `agents-relay/skills/agents-relay/contrac
|
|
|
121
130
|
- **FR-009**: Validate template source/type permissions server-side or at the authenticated event gateway; never trust a browser-provided Relay execution identity. Review events must not be accepted as `task.completed`, `task.failed`, or Final Reviewer approval events.
|
|
122
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.
|
|
123
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.
|
|
124
|
-
- **FR-012**:
|
|
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.
|
|
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.
|
|
125
137
|
|
|
126
138
|
## Ownership and downstream behavior
|
|
127
139
|
|
|
128
|
-
- **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.
|
|
129
141
|
- **Markcut Preview UI**: gathers comments and decision, fills review fields, dispatches either text or event, displays honest receipt/failure state.
|
|
130
|
-
- **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.
|
|
131
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.
|
|
132
145
|
|
|
133
146
|
## Edge cases and compatibility
|
|
@@ -144,7 +157,7 @@ Relay's canonical Event Contract is at `agents-relay/skills/agents-relay/contrac
|
|
|
144
157
|
2. **Mobile**: both modes pass device-level submission and offline retry tests. An Event-mode review reaches a test consumer with unchanged template-owned fields and correct scene/timestamp comments.
|
|
145
158
|
3. **Safety**: stale hashes, forged source/types, missing event capability and cancelled consumer contexts cannot be misreported as accepted or approved.
|
|
146
159
|
4. **Idempotency**: duplicate submits and repeated transport delivery produce at most one consumer-side business decision per key.
|
|
147
|
-
5. **
|
|
160
|
+
5. **Compatibility**: existing text-only ChatGPT preview continues to work; no callback dispatcher or deprecated Markcut event type is required.
|
|
148
161
|
6. **End-to-end evidence**: actual hosted Preview and iPhone submissions are tested separately. Published/queued receipts alone do not prove downstream Relay execution, a fixed video, or final delivery.
|
|
149
162
|
|
|
150
163
|
## Non-goals
|
|
@@ -154,9 +167,10 @@ Relay's canonical Event Contract is at `agents-relay/skills/agents-relay/contrac
|
|
|
154
167
|
- Making Markcut decide how Relay revises, reruns, approves, or merges Tasks.
|
|
155
168
|
- Treating human Preview approval as Relay Final Reviewer approval.
|
|
156
169
|
|
|
157
|
-
## Implementation
|
|
170
|
+
## Implementation and observed evidence (2026-11-05)
|
|
158
171
|
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
- The
|
|
162
|
-
-
|
|
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.
|
|
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.
|
|
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.
|
|
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;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Codex/terminal human-review bridge. The phone publishes the caller-owned Event after Submit. */
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
import {join,resolve} from 'node:path';
|
|
5
|
+
import {pathToFileURL} from 'node:url';
|
|
6
|
+
import {normalizeReviewConfig} from './review-delivery.mjs';
|
|
7
|
+
|
|
8
|
+
const delay = ms => new Promise(done => setTimeout(done,ms));
|
|
9
|
+
const UUID = /^[a-f0-9-]{36}$/i;
|
|
10
|
+
|
|
11
|
+
export function parseEventPreviewOptions(argv) {
|
|
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']);
|
|
14
|
+
const options={file:resolve(argv[1])};
|
|
15
|
+
for(let i=2;i<argv.length;i+=2){
|
|
16
|
+
const flag=argv[i],value=argv[i+1];
|
|
17
|
+
if(!allowed.has(flag) || !value || value.startsWith('--'))throw new Error('Missing or unsupported preview event flag: '+flag);
|
|
18
|
+
const key={'--delivery':'delivery','--event-template':'eventTemplatePath','--title':'title','--group-id':'groupId','--group-title':'groupTitle','--request-id':'requestId','--timeout-ms':'timeoutMs'}[flag];
|
|
19
|
+
if(Object.hasOwn(options,key))throw new Error('Duplicate flag: '+flag);
|
|
20
|
+
options[key]=value;
|
|
21
|
+
}
|
|
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');
|
|
24
|
+
if(options.requestId && !UUID.test(options.requestId))throw new Error('--request-id must be a UUID');
|
|
25
|
+
const limit=options.timeoutMs===undefined ? 300000 : Number(options.timeoutMs);
|
|
26
|
+
if(!Number.isSafeInteger(limit) || limit<1000 || limit>1800000)throw new Error('--timeout-ms must be 1000..1800000');
|
|
27
|
+
options.timeoutMs=limit;
|
|
28
|
+
return options;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function runMobilePreview(argv){
|
|
32
|
+
const opts=parseEventPreviewOptions(argv);
|
|
33
|
+
const config=opts.delivery==='event' ? normalizeReviewConfig({delivery:'event',
|
|
34
|
+
eventTemplate:JSON.parse(readFileSync(resolve(opts.eventTemplatePath),'utf8'))}) : {delivery:'text'};
|
|
35
|
+
const [{startCompileOperation},{EXPORT_ROOT}]=await Promise.all([
|
|
36
|
+
import('./compile-operation.mjs'),import('./remote-assets.mjs'),
|
|
37
|
+
]);
|
|
38
|
+
const operation=startCompileOperation(opts.file,undefined,config,opts);
|
|
39
|
+
const stateFile=join(EXPORT_ROOT,'operations',operation.operationId+'.json');
|
|
40
|
+
let state;
|
|
41
|
+
const until=Date.now()+opts.timeoutMs;
|
|
42
|
+
while(Date.now()<until){
|
|
43
|
+
try{state=JSON.parse(readFileSync(stateFile,'utf8'));}catch{}
|
|
44
|
+
if(state?.state==='ready')break;
|
|
45
|
+
if(state?.state==='failed')throw new Error('Preview compile failed: '+state.error);
|
|
46
|
+
await delay(300);
|
|
47
|
+
}
|
|
48
|
+
if(state?.state!=='ready')throw new Error('Preview compile timed out; operation '+operation.operationId);
|
|
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'};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if(process.argv[1] && import.meta.url===pathToFileURL(resolve(process.argv[1])).href){
|
|
59
|
+
runMobilePreview(process.argv.slice(2)).then(result=>console.log(JSON.stringify(result))).catch(error=>{
|
|
60
|
+
console.error('Markcut mobile event preview failed: '+(error?.message||error));
|
|
61
|
+
process.exitCode=1;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -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
|
@@ -64,6 +64,13 @@ Commands:
|
|
|
64
64
|
verify <file> Parse + validate descriptive file
|
|
65
65
|
|
|
66
66
|
preview <file.json|.md> Open player with live preview
|
|
67
|
+
--delivery event Headless human review via Neo Mobile (requires .md)
|
|
68
|
+
--event-template <file.json> Relay task.interactive_decision envelope from current Task
|
|
69
|
+
(No phone URL) Neo Master stores and notifies through APNs
|
|
70
|
+
--title <text> Optional title displayed in Review Inbox
|
|
71
|
+
--group-id <id> Stable video group; later revisions supersede earlier ones
|
|
72
|
+
--request-id <uuid> Stable mobile request UUID for retry after uncertain ACK
|
|
73
|
+
--timeout-ms <n> Compilation timeout (default 300000)
|
|
67
74
|
--label Open label input overlay
|
|
68
75
|
--storyboard Fast structure preview: replaces TTI/TTV prompt
|
|
69
76
|
nodes with <StoryboardSlot> placeholders and
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {describe,it,expect} from 'vitest';
|
|
2
|
+
import {randomUUID} from 'node:crypto';
|
|
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';
|
|
8
|
+
const hash='a'.repeat(64);
|
|
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
|
+
|
|
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
|
+
});
|
|
47
|
+
});
|