Share Artifacts (publish local files and pasted content as links) (part 3)
The publish pipeline is in src/main/services/share-artifact/share-artifact-service.ts — single chokepoint for both the renderer IPC (SHAREPUBLISHARTIFACT) and the CLI POST /share/publish. Both routes pass through createShareArtifactService({ publisher }) so they share one storage publisher.
On this page
What it is
This is part 3 of the Share Artifacts (publish local files and pasted content as links) page. It carries the next stretch of the material on that page, moved here because a single page is capped at 40,000 characters.
Where to find it
Reach this part through Share Artifacts (publish local files and pasted content as links) — it lists every part and explains where the feature lives in the product. Everything below is reached from the same place.
How it behaves
Everything below is the behaviour, detail and edge cases that belong to this stretch of the Share Artifacts (publish local files and pasted content as links) page.
A link handed to Omniscio cannot be deleted by a person. When a video is added as an onboarding tutorial card, the app hands that link to Omniscio itself: the share's owner becomes Omniscio, and it disappears from your own Shares list. That is deliberate — it is what stops a later cleanup from taking down a tutorial video the whole product depends on. From then on, asking the app to delete that link answers 403 “This link belongs to another owner … so it cannot be deleted from here.”, permanently; it is a decided state rather than a failure, so it is logged quietly and never reported as a crash. Deleting a different link you do own is unaffected.
How it works
The publish pipeline is in share-artifact-service.ts — single chokepoint for both the renderer IPC (SHARE_PUBLISH_ARTIFACT) and the CLI POST /share/publish. Both routes pass through createShareArtifactService({ publisher }) so they share one storage publisher. After upload, publishArtifact() CONFIRMS the Firestore mirror doc landed (the public gate keys on it) and, on a permanent/persistent failure, fails the publish — rolling back the upload + the row — rather than return a URL that 404s (contract publish-confirms-the-mirror; the entry points no longer mirror publishes themselves).
The detector and HTML builder live at share-artifact-builder.ts. Detection is extension-first, then magic-byte-second; the builder uses marked + highlight.js for Markdown / code, base64-inlines images and PDFs, and HTML-escapes plain text. The page shell also embeds the Omniscio app icon as a data: favicon, sourced from the shared share-favicon.ts constant (the same icon used by conversation + digest shares).
Path validation against the active-workdirs + user-data allow-list is in share-path-validator.ts — symlinks resolve through fs.realpath before the check.
The share publisher is in firebase-publisher.ts — but it holds no Firebase key. It is a thin seam over share-relay-client.ts: every method delegates to the share relay in the amc-back share-api (share-relay.ts, served at amcback.jls.dev/share; the old Firebase shareRelay Cloud Function was retired on 2026-11-20), authed by the signed-in user's global-auth Firebase ID token. The relay (holding the agentmc-share-uploader key in Secret Manager) mints the share token + short-lived v4 signed PUT URLs, and the app uploads the bytes straight to Cloud Storage (bucket agentmc-shares-artifacts, prefix shares/) — so a large video has no 32 MB function-relay cap, and the per-kind security headers (content-type / cache-control / content-disposition) are pinned on the signed URL server-side. The relay also OWNS the token (closing the client-minted-token overwrite hole) and tears shares down (unpublish deletes the objects + mirror doc + events in one ownerUid-gated call). Because publishing needs sign-in, a signed-out publish fails with sign-in-required ("sign in to share"), never silently. (This retired the desktop's Firebase admin "master" key for Shares — the old client-side GCS REST + google-auth-library JWT uploader is gone.)
The Firestore mirror — the shares/{token} doc the public gate reads, written on publish/revoke/delete — is in share-firestore-mirror.ts. It keeps the same public API but routes every write/read/delete through the same share relay (relayMirrorWrite / relayMirrorRead / relayUnpublish); the client sends only the policy fields and never the server-owned ownerUid / jwtSecret / viewCount. (This subsumed the earlier client-side REST/JWT mirror — itself the 2026-06-29 fix for a packaged build where firebase-admin's gRPC auth presented the wrong identity to Firestore, every consumer 7 PERMISSION_DENIED, silently 404'ing every share for ~12h: postmortem.) The publish-time confirmation + fail-loud rollback live in share-publish-confirm.ts (it reads the mirror doc back via mirrorDocExists, so a write-ack without a serve-visible doc never returns success — the 2026-08-11 transient-relay incident); the self-heal backfill — on startup AND every ~30 min — in share-mirror-backfill.ts; the single deduped "cloud features degraded" alert (shared with the agent-email consumer) in firebase-health-alert.ts.
DB schema is in queries-share.ts — insertSharePending → markSharePublished two-phase write, findActiveByContentHash for dedup, revokeShare / deleteShare for lifecycle.
The renderer entry points are FilePeekOverlay.tsx (the Share2 button in the file-peek toolbar), PastePublishModal.tsx (the paste modal, lazy-loaded from ShareManager.tsx per the heavy-modal lazy-load rule), and agent-markdown-helpers.tsx (CopyableLink — the right-click menu on every file path / attachment link that Claude produces in chat). The three entry points all call the same IPC.SHARE_PUBLISH_ARTIFACT handler — the difference is only the payload shape (sourcePath vs pastedContent vs attachmentRef) and the origin discriminator that drives the sourceType telemetry split.
Telemetry fires from inside publishArtifact() on both branches — dedup-hit (reused: true) and fresh-publish (reused: false) — so the Stats view reflects all publish intents. The allow-list for the telemetry metadata is ['artifactType', 'reused', 'sourceType', 'autoStaged'] per the registry in feature-registry/.
Auto-stage lives in share-artifact-pastes.ts as stageExternalForPublish(sourcePath, context), which calls autoStageExternal(sourcePath, userDataDir): if the first validateSharePath() returns valid: false with reason 'path outside allowed roots', without the internal refusedSensitive flag, AND sourceType !== 'cli', the service checks the gesture token and then stageExternalForPublish() copies the source bytes to <userData>/published-pastes/<uuid>/<real file name> and re-validates. Three details are load-bearing. (1) Two independent layers refuse a secret (secret-refusal-is-never-rescued): the service does not offer a flagged refusal to auto-stage, and the staging step itself refuses a credential-shaped file from its REAL name (symlinks followed) before it reads or writes a byte, so a .env, or a harmlessly named symlink pointing at one, is never copied even when the validator withholds the flag for a path outside the allow-list. (2) The staged copy keeps the file's REAL leaf name inside a fresh UUID directory, so the post-stage re-validation still sees what the file is (auto-stage-keeps-the-real-name); naming it <uuid><ext> after the old flat scheme, or after a symlink, destroyed exactly that. (3) A refused or failed stage removes its own stage directory (a-refused-stage-leaves-nothing-behind). The one sweep reclaims an aged stage directory whole, and at startup it also removes any stage directory holding a credential-shaped copy, whatever its age. Any failure of the stage step (ENOENT, EACCES, ENOSPC) collapses back to outside-allowlist so the closed error-string contract is preserved. The full invariant set + safe-change checklist lives in share-artifacts-contract.md.
The dead-link warning when you paste a share link
If you paste a share link that no longer works — deleted, revoked, expired, or out of views — the app tells you right away, and the paste itself is never blocked, slowed or changed. This covers the session message box (desktop, pop-out, and the inbox reply card), Team Chat, the phone message box, and KMS notes, and it catches both an ordinary paste and the ones that come through Windows' clipboard-history popup (Win+V), the emoji panel, an input method, or a phone keyboard.
Only a confirmed death warns. The app asks the share server whether the link still exists, and asks with a HEAD request — the share host counts only GETs as views, so the check can never use up the last view of a view-capped share. A share answers at two addresses — its page and the page that plays it — and being alive at either one is enough, because a recording hands its link out the moment it starts and puts its page up only when the video lands: that link is alive from the first second, even though its page is not there yet. The second address is asked only when the first answers "there is no page here yet"; a revoked, expired or view-limited share is settled by the first answer alone, so nothing has to be checked twice. Three answers are possible:
- works — a normal page, or the password page, at either address: a password-protected share is alive, never flagged, and a link whose video is still uploading is alive too.
- gone — the share was deleted, revoked, expired, or ran out of views.
- not sure — offline, a timeout, a server error, or too many checks in a row. Nothing is shown, so a working link is never called dead.
It works on the link's ID alone. The app never opens the pasted address: it rebuilds the share address on the fixed share domain from the ID, so a crafted link cannot make the app contact anything else. Several dead links in one paste produce one warning, and at most five links are checked per paste; a link checked in the last ten seconds is not checked again.
The check lives in share-link-probe.ts (reached from the renderer over the share:probe-links channel), with the paste side in warn-dead-pasted-shares.ts. The promise is pinned by the shares contract's pasted-dead-share-link-warns rule.
Saved state (shares remember viewers' choices)
An interactive HTML or React share remembers what each viewer did. Ticked checkboxes, picked radio buttons and dropdown options, typed text and opened <details> sections come back when that viewer reloads or returns. It is kept on that viewer's own device only: nothing is sent anywhere, and two viewers never see each other's ticks. The author writes no code for this.
What is never kept. Password, hidden and file inputs; any field with autocomplete="off" or a cc-*, password or one-time-code autocomplete token; everything inside an element marked data-omniscio-forget; and every control on a page that carries <meta name="omniscio-remember" content="off">. A control is only kept when it differs from how the page started, so a page that changes its defaults is never fought.
Give controls stable names. A control is remembered by its id, else by its name (a radio group by its name, a checkbox by name plus value). A control with neither is not remembered, and renaming one between publishes forgets it.
Keeping anything else. A page can keep its own data through OmniscioShare.state.load() (a promise of the saved string, or null) and OmniscioShare.state.save(value) (a string, or null to forget). Values are capped at 65,536 characters per share; a bigger save is refused with a console warning, and all shares on one browser share a 1,048,576-character budget, least recently used dropped first. load() answers within about 1.5 seconds even when nothing is listening, and a bare /run link (no share page around it) always answers null. The share adds this API after the page's own markup, so an inline script must reach for it once the document has parsed (in a DOMContentLoaded listener, or later); at the top of an inline script window.OmniscioShare does not exist yet.
How it works. The author's page runs in a sandbox that cannot store anything, so the share page around it keeps the state in its own localStorage and hands it down over postMessage. The fit and responsive layouts, which nest the page one frame deeper, relay it. In the app, your own shares load from memory that is cleared on restart, so main keeps its own copy in <userData>/share-saved-state.json and seeds the page when its /run frame loads.
The switch. Settings → Sharing → Shares remember viewers' choices (shareSavedStateEnabled, on by default). Off means new shares are built without the scripts and the in-app viewer stops remembering; pages already published keep what they were built with. The switch is part of the dedup key, so re-publishing the same bytes with it flipped mints a new link.
Rollout. A page published with this works in the app at once. In a browser it starts saving once the share functions are deployed with the bridge's script hash; until then the page simply forgets, as before.
Code: share-saved-state-scripts.ts (the page bridge, relay and author helper) and share-saved-state.ts (the in-app copy). Contract: share-saved-state-contract.md.
Related
The overview, the other parts, and everything else worth reading next all sit on Share Artifacts (publish local files and pasted content as links).
Last verified 2026-10-22