joycraft 0.7.16 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -156
- package/dist/cli.js +1593 -373
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/joycraft-release.json +1 -1
- package/package.json +9 -3
- package/payload/.agents/skills/joycraft-context/SKILL.md +36 -0
- package/payload/.agents/skills/joycraft-decompose/SKILL.md +68 -0
- package/payload/.agents/skills/joycraft-entry/SKILL.md +103 -0
- package/payload/.agents/skills/joycraft-implement/SKILL.md +106 -0
- package/payload/.agents/skills/joycraft-retro/SKILL.md +54 -0
- package/payload/.agents/skills/joycraft-retro/agents/openai.yaml +5 -0
- package/payload/.agents/skills/joycraft-session-end/SKILL.md +78 -0
- package/payload/.agents/skills/joycraft-testing/SKILL.md +60 -0
- package/payload/.agents/skills/joycraft-ui-slice/SKILL.md +59 -0
- package/payload/.agents/skills/joycraft-ui-slice/scripts/serve.mjs +97 -0
- package/payload/.agents/skills/joycraft-verify/SKILL.md +103 -0
- package/payload/.claude/agents/joycraft-implementer.md +31 -0
- package/payload/.claude/agents/joycraft-reviewer.md +30 -0
- package/payload/.joycraft/assets/artifacts/kit.css +102 -0
- package/payload/.joycraft/assets/artifacts/kit.js +301 -0
- package/payload/.joycraft/assets/artifacts/transports.js +236 -0
- package/payload/.joycraft/contracts/types.d.ts +185 -0
- package/payload/.joycraft/references/architecture.md +90 -0
- package/payload/.joycraft/references/archive.md +211 -0
- package/payload/.joycraft/references/artifacts.md +176 -0
- package/payload/.joycraft/references/completion.md +109 -0
- package/payload/.joycraft/references/context.md +80 -0
- package/payload/.joycraft/references/delivery.md +32 -0
- package/payload/.joycraft/references/dispatch.md +226 -0
- package/payload/.joycraft/references/recurring-failures.md +33 -0
- package/payload/.joycraft/references/retro.md +94 -0
- package/payload/.joycraft/references/setup.md +279 -0
- package/payload/.joycraft/references/testing.md +120 -0
- package/payload/.joycraft/references/update.md +44 -0
- package/payload/.joycraft/references/workflow.md +113 -0
- package/payload/.joycraft/references/worktrees.md +148 -0
- package/payload/.joycraft/runtime/archive.mjs +463 -0
- package/payload/.joycraft/runtime/artifacts/cli.mjs +61 -0
- package/payload/.joycraft/runtime/artifacts/decisions.mjs +214 -0
- package/payload/.joycraft/runtime/artifacts/model.mjs +161 -0
- package/payload/.joycraft/runtime/artifacts/preferences.mjs +127 -0
- package/payload/.joycraft/runtime/artifacts/render.mjs +21 -0
- package/payload/.joycraft/runtime/artifacts/server.mjs +40 -0
- package/payload/.joycraft/runtime/completion.mjs +300 -0
- package/payload/.joycraft/runtime/context/cli.mjs +75 -0
- package/payload/.joycraft/runtime/context/index.mjs +29 -0
- package/payload/.joycraft/runtime/context/search.mjs +149 -0
- package/payload/.joycraft/runtime/delivery.mjs +142 -0
- package/payload/.joycraft/runtime/dispatch-preflight.mjs +535 -0
- package/payload/.joycraft/runtime/dispatch-start.mjs +98 -0
- package/payload/.joycraft/runtime/evidence.mjs +137 -0
- package/payload/.joycraft/runtime/identity.mjs +486 -0
- package/payload/.joycraft/runtime/kickoff.mjs +174 -0
- package/payload/.joycraft/runtime/redact.mjs +9 -0
- package/payload/.joycraft/runtime/retro.mjs +151 -0
- package/payload/.joycraft/runtime/review-tools.json +34 -0
- package/payload/.joycraft/runtime/review-tools.mjs +331 -0
- package/payload/.joycraft/runtime/scope.mjs +129 -0
- package/payload/.joycraft/runtime/update-check.mjs +142 -0
- package/payload/.joycraft/templates/README.md +7 -0
- package/payload/.joycraft/templates/artifact.json +33 -0
- package/payload/.joycraft/templates/brief.md +35 -0
- package/payload/.joycraft/templates/decisions.md +13 -0
- package/payload/.joycraft/templates/project-context.md +36 -0
- package/payload/.joycraft/templates/queue.json +27 -0
- package/payload/.joycraft/templates/spec.md +39 -0
- package/payload/.joycraft/templates/ui-slice.html +71 -0
- package/payload/PIN +74 -0
- package/payload/scripts/export.mjs +301 -0
- package/payload/scripts/hook-paths.mjs +35 -0
- package/payload/scripts/legacy-hooks.mjs +128 -0
- package/payload/scripts/legacy-inventory.json +117 -0
- package/dist/chunk-35RQLGKM.js +0 -2167
- package/dist/chunk-35RQLGKM.js.map +0 -1
- package/dist/chunk-7BPB2IKY.js +0 -255
- package/dist/chunk-7BPB2IKY.js.map +0 -1
- package/dist/chunk-B73DPYYC.js +0 -377
- package/dist/chunk-B73DPYYC.js.map +0 -1
- package/dist/chunk-GTP7Z52K.js +0 -3942
- package/dist/chunk-GTP7Z52K.js.map +0 -1
- package/dist/chunk-K4AI6FKB.js +0 -417
- package/dist/chunk-K4AI6FKB.js.map +0 -1
- package/dist/chunk-KKDKC4FM.js +0 -115
- package/dist/chunk-KKDKC4FM.js.map +0 -1
- package/dist/chunk-OMFGDJW4.js +0 -97
- package/dist/chunk-OMFGDJW4.js.map +0 -1
- package/dist/chunk-Z5JFEGWG.js +0 -563
- package/dist/chunk-Z5JFEGWG.js.map +0 -1
- package/dist/init-MUB5CC6L.js +0 -60
- package/dist/init-MUB5CC6L.js.map +0 -1
- package/dist/init-autofix-2DMBO4QN.js +0 -122
- package/dist/init-autofix-2DMBO4QN.js.map +0 -1
- package/dist/install-manifest-EQHT4474.js +0 -37
- package/dist/install-manifest-EQHT4474.js.map +0 -1
- package/dist/release-artifact-4TL5L2ZY.js +0 -14
- package/dist/release-artifact-4TL5L2ZY.js.map +0 -1
- package/dist/release-resolver-P2H46QTU.js +0 -293
- package/dist/release-resolver-P2H46QTU.js.map +0 -1
- package/dist/telemetry-store-IBO5GRTA.js +0 -14
- package/dist/telemetry-store-IBO5GRTA.js.map +0 -1
- package/dist/update-LFLQTPUA.js +0 -19
- package/dist/update-LFLQTPUA.js.map +0 -1
- package/dist/update-check-YT765NE7.js +0 -36
- package/dist/update-check-YT765NE7.js.map +0 -1
- package/dist/upgrade-L5WERK4X.js +0 -28
- package/dist/upgrade-L5WERK4X.js.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joycraft-verify
|
|
3
|
+
description: Independently review an in-review Joycraft spec and produce an evidence-backed completion report for the guarded local helper.
|
|
4
|
+
compatibility: Requires Node.js 22+, the installed .joycraft runtime, and Git for revision-bound completion. A separate reviewer context completes a spec; UI inspection is needed only for visual criteria.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Joycraft Verify
|
|
8
|
+
|
|
9
|
+
Use this skill after an implementer has finished an authorized spec and placed it in `in-review`.
|
|
10
|
+
|
|
11
|
+
An artifact can make the current brief's decisions and review summary easier to
|
|
12
|
+
inspect; it does not verify behavior or change a queue status. Read
|
|
13
|
+
`.joycraft/references/artifacts.md` only when that view is part of the
|
|
14
|
+
review material. A read-only artifact status cannot mark a spec done.
|
|
15
|
+
|
|
16
|
+
For work that used a worker tree, prepare the subject from the coordinator's
|
|
17
|
+
final integrated bytes, not the implementer's pre-integration tree. A stable
|
|
18
|
+
source-read-only review may use that fixed tree and write its declared report
|
|
19
|
+
and receipts outside frozen inputs; it cannot modify governing inputs. Runtime
|
|
20
|
+
checks that mutate caches, browser profiles, or other state need independent
|
|
21
|
+
mutable runtime state. Read [worker isolation](../../../.joycraft/references/worktrees.md)
|
|
22
|
+
when this boundary applies. Worktree separation does not establish a separate
|
|
23
|
+
reviewer context, so retain the dispatch requirements below.
|
|
24
|
+
|
|
25
|
+
When called from the implementer's context, launch the independent reviewer with
|
|
26
|
+
only current raw brief/spec/queue/input sources plus scoped owning decisions; do
|
|
27
|
+
not pass an expected verdict, reasoning, or proposed report. A parent may
|
|
28
|
+
prepare a source packet for a manual boundary, but it must not bind the child
|
|
29
|
+
using the parent's identity. After launch, the reviewer child bootstraps at its
|
|
30
|
+
actual root and runs `dispatch-start.mjs --role reviewer` with its own actual
|
|
31
|
+
native identity, which captures the subject, preflights delivery, writes the
|
|
32
|
+
bounded packet, and binds it. If the real ID, available authority, or a separate
|
|
33
|
+
reviewer context is unavailable, leave the spec `in-review`; do not manufacture
|
|
34
|
+
any of them. A hooks-disabled/manual workflow can still be ready; an unenforced
|
|
35
|
+
result holds only the claimed review, not unrelated work.
|
|
36
|
+
Write packets and snapshots beneath a confirmed Git-ignored project-local
|
|
37
|
+
directory so they do not create unrelated scope paths.
|
|
38
|
+
|
|
39
|
+
Dispatch `collaboration.spawn_agent` with `fork_turns: "none"` and the packet's raw sources and output contract. Do not give the reviewer an intended verdict, conclusion, or implementer reasoning. In Claude Code, use its `Agent` tool with the same limited inputs and the `joycraft-reviewer` agent type when installed (otherwise the project-selected reviewer model); a fresh worker is the separate review context. Otherwise use a separate accessible review context. Record its returned native host, session and child agent identity; a shared parent session does not make two native actors the same. Follow the actor-report fields in the dispatch reference. Do not invent IDs or create a worktree solely to obtain a different session string.
|
|
40
|
+
|
|
41
|
+
When already dispatched as the independent reviewer, perform the review directly; do not recursively dispatch another reviewer. Read the parent brief, spec, queue entry, declared criteria and exact verification inputs. Use the supplied subject, set independence truthfully, and do not self-certify implementation from your own context.
|
|
42
|
+
|
|
43
|
+
Inspect any hook rule/test-gap findings alongside the actual changes and
|
|
44
|
+
requirements. Resolve supported concerns with observed evidence; a classifier
|
|
45
|
+
score or clean hook receipt cannot establish acceptance. Check changed tests for
|
|
46
|
+
weakened assertions that could hide the requested behavior.
|
|
47
|
+
|
|
48
|
+
Review scope as well as behavior: determine whether the listed inputs and criteria cover the requested work, including relevant newly changed files. For a cross-boundary change, inspect the combined observable behavior across the relevant producer, consumer, state or storage boundary; separate green helpers, snapshots, or assertion counts do not establish that behavior. If a material counterpart or owning decision/context source was omitted, report the scope gap and require its exact path to be added before a fresh current review subject is prepared. Preserve the snapshot's implementation revision as provenance while checking its current bound inputs. A changed, missing, or renamed input makes the subject stale; do not substitute a newer HEAD as its identity.
|
|
49
|
+
|
|
50
|
+
Create a schema-v1 verification report tied to that subject, using the shared fields in [.joycraft/contracts/types.d.ts](../../../.joycraft/contracts/types.d.ts). For every declared criterion, provide PASS observations for its required evidence kinds. Keep unfiltered command output and its real exit status in hashed, project-relative receipts. A source scan supports only structural observations. Visual observations require a reviewer-inspected render plus route, state, viewport, interactions, and outcomes; take the render with the tools and start command in the packet's `reviewLoop` (the `Review loop` section of `AGENTS.md`), and mark a claim whose tool is skipped or missing `UNVERIFIED`. Mark unavailable inspection, a failing result, or an unresolved concern as `UNVERIFIED` or `FAIL` truthfully.
|
|
51
|
+
|
|
52
|
+
Run each test command once in single-run mode with `CI=1` and a 300000 ms
|
|
53
|
+
timeout; follow [running tests](../../../.joycraft/references/testing.md#running-tests)
|
|
54
|
+
when one times out. Record an unresolved hang as `UNVERIFIED` with its receipt.
|
|
55
|
+
|
|
56
|
+
Run the dispatch helper's `check-report` before completion. It reuses the same
|
|
57
|
+
subject, receipt, and evidence validators without changing a queue status. If
|
|
58
|
+
it rejects a packaging or report problem, return the correction to this same
|
|
59
|
+
reviewer; do not invent observations or replace the independent identity.
|
|
60
|
+
|
|
61
|
+
Items under a spec's "Deferred until deploy" section are not criteria. Do not
|
|
62
|
+
fail or hold the spec for them; list them in the report as open for the owner.
|
|
63
|
+
|
|
64
|
+
Report every finding with a severity and the criterion it touches. A finding
|
|
65
|
+
blocks only when it shows a stated criterion failing, or a reproducible
|
|
66
|
+
correctness defect or regression in the changed code, with file:line or a
|
|
67
|
+
receipt. A case the spec does not decide is "decision needed" for the
|
|
68
|
+
coordinator, not a FAIL. A probe outside the spec's named check set is a
|
|
69
|
+
non-blocking follow-up unless it regresses against the base. Name the class of a
|
|
70
|
+
defect once; do not repeat a finding from an earlier round as new.
|
|
71
|
+
|
|
72
|
+
Set a PASS verdict only when scope is reviewed, all required evidence is sufficient, and no blocking finding or unresolved UNVERIFIED evidence remains. Then run guarded completion:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
node .joycraft/runtime/completion.mjs finalize-review --queue <queue-path> --spec <id> --report <report.json>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`finalize-review` is the primary command and has exactly the validation of the
|
|
79
|
+
legacy-compatible `complete` alias. Completion validates the report and receipt
|
|
80
|
+
hashes, distinct native implementer/reviewer actors (or legacy distinct session
|
|
81
|
+
IDs), independent-review attestation, subject freshness, and evidence
|
|
82
|
+
sufficiency. It may reject an otherwise green suite. Do not edit the queue or
|
|
83
|
+
spec to make a report fit. For rejections or interrupted writes, follow
|
|
84
|
+
[completion guidance](../../../.joycraft/references/completion.md).
|
|
85
|
+
Once it returns, let the implementer continue the autonomous ready queue; do not
|
|
86
|
+
hold independent work behind an unrelated failed branch.
|
|
87
|
+
|
|
88
|
+
For scope-enabled work, completion compares the recorded base and inferred
|
|
89
|
+
relevant paths with the current change topology. Do not replace the base with
|
|
90
|
+
current `HEAD`. Give every unrelated changed path an explicit, narrow exclusion
|
|
91
|
+
and reason; never add an entire branch or directory blindly. A deletion is a
|
|
92
|
+
deliberate non-requirement input with `state: 'absent'`; requirements must remain
|
|
93
|
+
present, and a rename binds both the old absent and new present paths.
|
|
94
|
+
|
|
95
|
+
For a current `FAIL` or `UNVERIFIED` report, preserve the evidence, receipt,
|
|
96
|
+
subject identity, and explicit limits. Do not solicit owner acceptance as part
|
|
97
|
+
of review or soften the verdict. The implementer may repair it or, after a
|
|
98
|
+
trusted human explicitly accepts this spec's current findings, use the separate
|
|
99
|
+
owner-acceptance completion path described in [completion guidance](../../../.joycraft/references/completion.md). That path validates bindings and
|
|
100
|
+
receipts, not the authenticity of a human instruction; it never turns this
|
|
101
|
+
report into PASS or verified evidence.
|
|
102
|
+
|
|
103
|
+
Report the reviewer identity, checks and observed outcomes, receipt paths, verdict, helper result, and limitations without claiming evidence that was not observed.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joycraft-implementer
|
|
3
|
+
description: Implements one authorized Joycraft spec or review fix in a fresh context, writes one focused test per acceptance check, runs the project's checks, and sets the spec to in-review.
|
|
4
|
+
model: inherit
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You implement one authorized spec or fix. The task prompt names the spec, the
|
|
8
|
+
files, the allowed writes and the finish steps; follow it exactly.
|
|
9
|
+
|
|
10
|
+
Read the project's `AGENTS.md` (or `CLAUDE.md`), the parent brief, the spec, its
|
|
11
|
+
queue entry and its declared verification inputs, then follow
|
|
12
|
+
`.claude/skills/joycraft-implement/SKILL.md`. For a new spec dispatch, run
|
|
13
|
+
`dispatch-start.mjs` from your actual worker root as
|
|
14
|
+
`.joycraft/references/dispatch.md` describes, before any edit. Never
|
|
15
|
+
invent identity or authority to make startup pass. Run each `git` command and
|
|
16
|
+
each Joycraft runtime call as its own plain shell command, never chained with
|
|
17
|
+
`&&`, `;`, `|` or `$(git …)`; your worktree isolation refuses Git inside a
|
|
18
|
+
compound command. Paste literal paths and revisions instead.
|
|
19
|
+
|
|
20
|
+
Write one focused test per acceptance `Check:`, taken from the spec rather than
|
|
21
|
+
from your code, sized like neighboring tests. Run each test command once in
|
|
22
|
+
single-run mode with `CI=1` and a 300000 ms timeout; on a timeout follow
|
|
23
|
+
`.joycraft/references/testing.md#running-tests`. Never wait in a
|
|
24
|
+
foreground loop, never weaken an existing test, and never change the spec's acceptance:
|
|
25
|
+
if a criterion or test looks wrong, report it as a spec gap.
|
|
26
|
+
|
|
27
|
+
For a user-facing change, render and inspect it as `joycraft-testing` describes.
|
|
28
|
+
Before you finish, run the project's own test, typecheck and lint commands named
|
|
29
|
+
in `AGENTS.md`, commit by file name, and report each command with its exit
|
|
30
|
+
status and the commit it ran on. Keep the final message short: what changed,
|
|
31
|
+
checks and results, open gaps.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: joycraft-reviewer
|
|
3
|
+
description: Independent reviewer for one in-review Joycraft spec. Judges the change against each acceptance check, blocks only on failing criteria or reproducible defects, writes the schema-v1 report, and never fixes code.
|
|
4
|
+
model: inherit
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You are an independent reviewer in a fresh context. You review; you do not fix
|
|
8
|
+
code and you do not dispatch other agents. The task prompt names the spec, the
|
|
9
|
+
subject, the allowed writes and the report path; follow it exactly.
|
|
10
|
+
|
|
11
|
+
Read the project's `AGENTS.md` (or `CLAUDE.md`), `.claude/skills/joycraft-verify/SKILL.md`,
|
|
12
|
+
`.joycraft/references/completion.md` and
|
|
13
|
+
`.joycraft/contracts/types.d.ts`. Run `dispatch-start.mjs --role reviewer`
|
|
14
|
+
from your actual worker root before reviewing, as the dispatch reference describes.
|
|
15
|
+
Run each `git` command and each Joycraft runtime call as its own plain shell
|
|
16
|
+
command, never chained with `&&`, `;`, `|` or `$(git …)`; your worktree
|
|
17
|
+
isolation refuses Git inside a compound command. Paste literal paths and revisions instead.
|
|
18
|
+
|
|
19
|
+
Judge the current code against every acceptance bullet and its `Check:`, and
|
|
20
|
+
against the owner intent in the brief. Reuse a suite receipt bound to the same
|
|
21
|
+
revision instead of rerunning the full suite; run the spec's own tests once in
|
|
22
|
+
single-run mode with `CI=1` and a 300000 ms timeout. Never give a verdict while
|
|
23
|
+
a command you started is still running.
|
|
24
|
+
|
|
25
|
+
Report every finding with a severity and the criterion it touches. Only a failing
|
|
26
|
+
stated criterion, or a reproducible defect or regression in the changed code with
|
|
27
|
+
file:line or a receipt, blocks. A case the spec does not decide is "decision
|
|
28
|
+
needed", not FAIL. Do not repeat an earlier round's finding as new. Record only
|
|
29
|
+
what you observed; mark anything unobserved UNVERIFIED. Keep the final message
|
|
30
|
+
short: verdict, blocking findings, decision-needed items, report path.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
:root, .joycraft-artifact {
|
|
2
|
+
--canvas: #f3f6fb;
|
|
3
|
+
--paper: #ffffff;
|
|
4
|
+
--surface: #f6f8fc;
|
|
5
|
+
--ink: #182337;
|
|
6
|
+
--muted: #516078;
|
|
7
|
+
--line: #d5deea;
|
|
8
|
+
--control-line: #8593a9;
|
|
9
|
+
--accent: #2456a6;
|
|
10
|
+
--accent-hover: #1d4485;
|
|
11
|
+
--accent-text: #ffffff;
|
|
12
|
+
--accent-soft: #eaf1ff;
|
|
13
|
+
--focus: #275ec5;
|
|
14
|
+
--error: #9f2735;
|
|
15
|
+
--error-bg: #fff0f2;
|
|
16
|
+
--caution: #855718;
|
|
17
|
+
--input: #ffffff;
|
|
18
|
+
color-scheme: light;
|
|
19
|
+
}
|
|
20
|
+
[data-jca-theme="dark"] {
|
|
21
|
+
--canvas: #0e1522;
|
|
22
|
+
--paper: #151f30;
|
|
23
|
+
--surface: #1b293f;
|
|
24
|
+
--ink: #eff4fc;
|
|
25
|
+
--muted: #b9c6d9;
|
|
26
|
+
--line: #34465f;
|
|
27
|
+
--control-line: #6b819f;
|
|
28
|
+
--accent: #a9c9ff;
|
|
29
|
+
--accent-hover: #c4d9ff;
|
|
30
|
+
--accent-text: #13233d;
|
|
31
|
+
--accent-soft: #243b5e;
|
|
32
|
+
--focus: #91bbff;
|
|
33
|
+
--error: #ffb4bd;
|
|
34
|
+
--error-bg: #402532;
|
|
35
|
+
--caution: #f1c986;
|
|
36
|
+
--input: #101b2d;
|
|
37
|
+
color-scheme: dark;
|
|
38
|
+
}
|
|
39
|
+
html[data-jca-theme] body { margin: 0; background: var(--canvas); color: var(--ink); }
|
|
40
|
+
.joycraft-artifact {
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
max-width: 880px;
|
|
43
|
+
margin: 1.5rem auto;
|
|
44
|
+
padding: clamp(1.2rem, 3vw, 2.25rem);
|
|
45
|
+
border: 1px solid var(--line);
|
|
46
|
+
border-radius: 18px;
|
|
47
|
+
background: var(--paper);
|
|
48
|
+
color: var(--ink);
|
|
49
|
+
font: 16px/1.55 ui-sans-serif, system-ui, sans-serif;
|
|
50
|
+
}
|
|
51
|
+
.joycraft-artifact *, .joycraft-artifact *::before, .joycraft-artifact *::after { box-sizing: inherit; }
|
|
52
|
+
.joycraft-artifact h1, .joycraft-artifact h2, .joycraft-artifact h3 { line-height: 1.1; }
|
|
53
|
+
.joycraft-artifact h1 { max-width: 30ch; margin: .1rem 0 .6rem; font: 400 clamp(1.8rem, 4vw, 2.6rem)/1.05 Georgia, 'Times New Roman', serif; letter-spacing: -.04em; }
|
|
54
|
+
.joycraft-artifact h2 { margin: .2rem 0 .8rem; font: 400 clamp(1.35rem, 4vw, 2.1rem)/1.05 Georgia, 'Times New Roman', serif; }
|
|
55
|
+
.jca-header { border-bottom: 1px solid var(--line); padding-bottom: .35rem; }
|
|
56
|
+
.jca-eyebrow, .jca-question-kicker, .jca-review-result { color: var(--accent); font-size: .72rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
|
|
57
|
+
.jca-summary { max-width: 58ch; font-size: 1.1rem; color: var(--muted); }
|
|
58
|
+
.jca-source, .jca-caption { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
|
|
59
|
+
.jca-message { margin: 1.2rem 0; padding: .7rem .85rem; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; background: var(--surface); font-size: .9rem; }
|
|
60
|
+
.jca-message-error { color: var(--error); border-color: var(--error); background: var(--error-bg); }
|
|
61
|
+
.jca-message-success { border-color: var(--accent); background: var(--accent-soft); }
|
|
62
|
+
.jca-message-quiet { color: var(--muted); }
|
|
63
|
+
.jca-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin: .8rem 0 1rem; }
|
|
64
|
+
.joycraft-artifact button { appearance: none; border: 1px solid var(--control-line); border-radius: 8px; padding: .56rem .82rem; color: var(--accent); background: var(--paper); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
|
|
65
|
+
.joycraft-artifact button:hover { border-color: var(--accent); background: var(--accent-soft); }
|
|
66
|
+
.joycraft-artifact .jca-save-one, .joycraft-artifact [data-jca-save-all] { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
|
|
67
|
+
.joycraft-artifact .jca-save-one:hover, .joycraft-artifact [data-jca-save-all]:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
|
|
68
|
+
.joycraft-artifact button:disabled { cursor: not-allowed; color: var(--muted); background: var(--surface); border-color: var(--line); }
|
|
69
|
+
.joycraft-artifact button:focus-visible, .joycraft-artifact input:focus-visible, .joycraft-artifact textarea:focus-visible, .joycraft-artifact summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
|
|
70
|
+
.jca-question { padding: 1.2rem 0; border-top: 1px solid var(--line); }
|
|
71
|
+
.jca-status { display: inline-block; margin: 0 0 1rem; padding: .2rem .55rem; border-radius: 5px; color: var(--accent); background: var(--accent-soft); font-size: .76rem; font-weight: 700; }
|
|
72
|
+
.jca-status-backlogged, .jca-status-discarded, .jca-status-settled { color: var(--muted); background: var(--surface); }
|
|
73
|
+
.jca-recorded { margin: 0 0 1rem; color: var(--muted); font-size: .9rem; }
|
|
74
|
+
.jca-details { margin: .8rem 0 1rem; color: var(--muted); }
|
|
75
|
+
.jca-details summary { color: var(--accent); cursor: pointer; font-weight: 650; }
|
|
76
|
+
.jca-details p { margin: .55rem 0; }
|
|
77
|
+
.jca-options { display: grid; gap: .55rem; margin: 1.25rem 0; padding: 0; border: 0; }
|
|
78
|
+
.jca-options legend { margin-bottom: .6rem; font-weight: 700; }
|
|
79
|
+
.jca-option { display: grid; grid-template-columns: auto 1fr; gap: .65rem; align-items: start; padding: .8rem; border: 1px solid var(--control-line); border-radius: 10px; background: var(--paper); cursor: pointer; }
|
|
80
|
+
.jca-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
|
|
81
|
+
.jca-option input { margin-top: .28rem; accent-color: var(--accent); }
|
|
82
|
+
.jca-option strong, .jca-option small { display: block; }
|
|
83
|
+
.jca-option small { margin-top: .1rem; color: var(--muted); }
|
|
84
|
+
.jca-note-label { display: block; margin-bottom: .35rem; font-size: .88rem; font-weight: 700; }
|
|
85
|
+
.jca-note { display: block; width: 100%; resize: vertical; border: 1px solid var(--control-line); border-radius: 8px; padding: .7rem; color: var(--ink); background: var(--input); font: inherit; }
|
|
86
|
+
.jca-note::placeholder { color: var(--muted); opacity: 1; }
|
|
87
|
+
.jca-note:disabled { opacity: 1; color: var(--muted); }
|
|
88
|
+
.jca-save-one { margin-top: .7rem; }
|
|
89
|
+
.jca-section-title { margin-top: 2.7rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
|
|
90
|
+
.jca-comparison, .jca-review { margin: 1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
|
|
91
|
+
.jca-comparison h2 { font-size: 1.3rem; }
|
|
92
|
+
.jca-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 1rem; }
|
|
93
|
+
.jca-images figure { margin: 0; }
|
|
94
|
+
.jca-images img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
|
|
95
|
+
.jca-images figcaption { margin-top: .45rem; font-weight: 700; }
|
|
96
|
+
.jca-review-pass { border-left: 4px solid var(--accent); }
|
|
97
|
+
.jca-review-fail { border-left: 4px solid var(--error); }
|
|
98
|
+
.jca-review-unverified { border-left: 4px solid var(--caution); }
|
|
99
|
+
.jca-review h3 { margin: .1rem 0 .4rem; font-size: 1rem; }
|
|
100
|
+
.jca-footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }
|
|
101
|
+
.jca-copy-fallback { width: 100%; min-height: 10rem; margin-top: 1rem; padding: .75rem; border: 2px solid var(--accent); border-radius: 8px; color: var(--ink); background: var(--input); font-family: ui-monospace, monospace; font-size: .78rem; }
|
|
102
|
+
@media (max-width: 520px) { .joycraft-artifact { margin: 0; padding: 1.2rem; border: 0; border-radius: 0; } .jca-actions button { flex: 1 1 40%; } }
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
(function artifactKit(global) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function node(tag, attributes, children) {
|
|
5
|
+
var element = document.createElement(tag);
|
|
6
|
+
Object.keys(attributes || {}).forEach(function (key) {
|
|
7
|
+
var value = attributes[key];
|
|
8
|
+
if (value === undefined || value === null || value === false) return;
|
|
9
|
+
if (key === 'class') element.className = value;
|
|
10
|
+
else if (key === 'text') element.textContent = value;
|
|
11
|
+
else if (key.indexOf('on') === 0) element.addEventListener(key.slice(2), value);
|
|
12
|
+
else if (key === 'checked' || key === 'disabled' || key === 'required') element[key] = Boolean(value);
|
|
13
|
+
else element.setAttribute(key, String(value));
|
|
14
|
+
});
|
|
15
|
+
(children || []).forEach(function (child) {
|
|
16
|
+
if (child !== null && child !== undefined) element.append(child);
|
|
17
|
+
});
|
|
18
|
+
return element;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function text(value) { return document.createTextNode(value == null ? '' : String(value)); }
|
|
22
|
+
|
|
23
|
+
function responseMap(responses) {
|
|
24
|
+
return (responses || []).reduce(function (map, response) {
|
|
25
|
+
if (response && response.id && response.answer) map[response.id] = { answer: response.answer, note: response.note || '' };
|
|
26
|
+
return map;
|
|
27
|
+
}, Object.create(null));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function copiedResponses(map) {
|
|
31
|
+
return Object.keys(map).filter(function (id) { return map[id].answer; }).map(function (id) {
|
|
32
|
+
return { id: id, answer: map[id].answer, note: map[id].note || undefined };
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function sameResponses(left, right) {
|
|
37
|
+
var ids = new Set(Object.keys(left).concat(Object.keys(right)));
|
|
38
|
+
return Array.from(ids).every(function (id) {
|
|
39
|
+
var a = left[id] || {}; var b = right[id] || {};
|
|
40
|
+
return (a.answer || '') === (b.answer || '') && (a.note || '') === (b.note || '');
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function mount(config) {
|
|
45
|
+
if (!config || !config.element) throw new Error('JoycraftArtifacts.mount requires an element.');
|
|
46
|
+
var root = config.element;
|
|
47
|
+
var model = config.model || { schemaVersion: 1, title: 'Artifact', questions: [] };
|
|
48
|
+
var transport = config.transport;
|
|
49
|
+
var saved = Object.create(null);
|
|
50
|
+
var draft = Object.create(null);
|
|
51
|
+
var revision = model.source && model.source.revision;
|
|
52
|
+
var viewRevision = model.source && model.source.viewRevision;
|
|
53
|
+
var writable = false;
|
|
54
|
+
var storage = 'memory';
|
|
55
|
+
var loading = false;
|
|
56
|
+
var saving = false;
|
|
57
|
+
var destroyed = false;
|
|
58
|
+
var copyFallback = '';
|
|
59
|
+
var sourceChanged = false;
|
|
60
|
+
var message = transport ? 'Loading saved responses…' : 'Read-only preview. A response transport is not available.';
|
|
61
|
+
var messageKind = transport ? 'quiet' : 'notice';
|
|
62
|
+
|
|
63
|
+
function isReadOnly(question) {
|
|
64
|
+
return !writable || ['clarified', 'settled', 'backlogged', 'discarded'].indexOf(question.status) !== -1;
|
|
65
|
+
}
|
|
66
|
+
function dirty() { return !sameResponses(draft, saved); }
|
|
67
|
+
function setMessage(kind, value) { messageKind = kind; message = value; }
|
|
68
|
+
function statusLabel(status) {
|
|
69
|
+
if (status === 'clarified') return 'Recorded in brief';
|
|
70
|
+
if (status === 'backlogged') return 'Backlogged';
|
|
71
|
+
if (status === 'discarded') return 'Discarded';
|
|
72
|
+
if (status === 'settled') return 'Settled';
|
|
73
|
+
return status === 'open' ? 'Open for response' : (status || 'Open for response');
|
|
74
|
+
}
|
|
75
|
+
function validation(question) {
|
|
76
|
+
var answer = draft[question.id];
|
|
77
|
+
if (!answer || !answer.answer) return 'Choose an option before saving.';
|
|
78
|
+
var option = (question.options || []).filter(function (item) { return item.value === answer.answer; })[0];
|
|
79
|
+
if (option && option.requiresNote && !String(answer.note || '').trim()) return 'Add a note for this custom response.';
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
function envelope() {
|
|
83
|
+
var answers = copiedResponses(saved);
|
|
84
|
+
if (transport && typeof transport.exportResponses === 'function') return transport.exportResponses(answers);
|
|
85
|
+
return { schemaVersion: 1, kind: 'joycraft-artifact-responses', artifactId: model.artifactId, source: model.source, answers: answers };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function unsavedAnswers() { return copiedResponses(draft).filter(function (item) {
|
|
89
|
+
var q = model.questions.find(function (candidate) { return candidate.id === item.id; });
|
|
90
|
+
return q && !isReadOnly(q) && !sameResponses({ value: item }, { value: saved[item.id] || {} });
|
|
91
|
+
}); }
|
|
92
|
+
|
|
93
|
+
async function save(question) {
|
|
94
|
+
if (!transport || !writable || saving || loading || sourceChanged) return;
|
|
95
|
+
var pendingAnswers = unsavedAnswers();
|
|
96
|
+
var problem = question ? validation(question) : pendingAnswers.map(function (item) {
|
|
97
|
+
var q = (model.questions || []).filter(function (candidate) { return candidate.id === item.id; })[0];
|
|
98
|
+
return q && validation(q);
|
|
99
|
+
}).filter(Boolean)[0];
|
|
100
|
+
if (problem) { setMessage('error', problem); render(); return; }
|
|
101
|
+
var answers = question ? (draft[question.id] && draft[question.id].answer ? [{ id: question.id, answer: draft[question.id].answer, note: draft[question.id].note || undefined }] : []) : pendingAnswers;
|
|
102
|
+
if (!answers.length) { setMessage('quiet', 'No new answers to save.'); render(); return; }
|
|
103
|
+
saving = true; setMessage('quiet', 'Saving selected responses…'); render();
|
|
104
|
+
try {
|
|
105
|
+
var result = await transport.save({ revision: revision, answers: answers });
|
|
106
|
+
if (destroyed) return;
|
|
107
|
+
applyLoaded(result, Boolean(question), answers.map(function (answer) { return answer.id; }));
|
|
108
|
+
setMessage('success', (result && result.message) || 'Saved in artifact — awaiting brief sync.');
|
|
109
|
+
} catch (error) {
|
|
110
|
+
setMessage('error', 'Could not save. Your edits are still here. ' + (error && error.message ? error.message : 'Try refreshing before saving again.'));
|
|
111
|
+
} finally { saving = false; render(); }
|
|
112
|
+
}
|
|
113
|
+
function applyLoaded(result, preserveDraft, confirmedIds) {
|
|
114
|
+
confirmedIds = confirmedIds || [];
|
|
115
|
+
if (!result) throw new Error('The response transport returned no state.');
|
|
116
|
+
var oldRevision = revision;
|
|
117
|
+
var oldViewRevision = viewRevision;
|
|
118
|
+
var pending = Object.assign(Object.create(null), draft);
|
|
119
|
+
var previouslySaved = Object.assign(Object.create(null), saved);
|
|
120
|
+
model = result.model || model;
|
|
121
|
+
revision = model.source && model.source.revision;
|
|
122
|
+
viewRevision = model.source && model.source.viewRevision;
|
|
123
|
+
writable = Boolean(result.writable);
|
|
124
|
+
storage = result.storage || storage;
|
|
125
|
+
saved = responseMap(result.responses);
|
|
126
|
+
draft = Object.assign(Object.create(null), saved);
|
|
127
|
+
var changedSource = oldViewRevision !== viewRevision || (!confirmedIds.length && oldRevision && revision && oldRevision !== revision);
|
|
128
|
+
if (preserveDraft && !sameResponses(pending, previouslySaved)) {
|
|
129
|
+
Object.keys(pending).forEach(function (id) {
|
|
130
|
+
if (confirmedIds.indexOf(id) !== -1 || !model.questions.some(function (q) { return q.id === id && !isReadOnly(q); })) return;
|
|
131
|
+
var before = previouslySaved[id] || { answer: '', note: '' };
|
|
132
|
+
var after = pending[id] || { answer: '', note: '' };
|
|
133
|
+
if (before.answer !== after.answer || (before.note || '') !== (after.note || '')) {
|
|
134
|
+
if (changedSource) draft[id] = { answer: '', note: after.note || '' };
|
|
135
|
+
else draft[id] = after;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (changedSource) {
|
|
139
|
+
sourceChanged = true;
|
|
140
|
+
setMessage('notice', 'The source changed. Your unsaved note text remains, but choose responses again before saving.');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (result.message && !sourceChanged) setMessage('notice', result.message);
|
|
144
|
+
}
|
|
145
|
+
async function refresh() {
|
|
146
|
+
if (!transport || typeof transport.load !== 'function' || loading) return;
|
|
147
|
+
loading = true; setMessage('quiet', 'Refreshing saved responses…'); render();
|
|
148
|
+
try {
|
|
149
|
+
var result = await transport.load();
|
|
150
|
+
if (destroyed) return;
|
|
151
|
+
applyLoaded(result, true);
|
|
152
|
+
if (!result.message) setMessage('quiet', dirty() ? 'Saved responses refreshed; unsaved edits remain on screen.' : 'Saved responses refreshed.');
|
|
153
|
+
} catch (error) {
|
|
154
|
+
setMessage('error', 'Could not load saved responses. Nothing on screen was marked as saved. ' + (error && error.message ? error.message : ''));
|
|
155
|
+
} finally { loading = false; render(); }
|
|
156
|
+
}
|
|
157
|
+
async function copySaved() {
|
|
158
|
+
var payload = JSON.stringify(envelope(), null, 2);
|
|
159
|
+
copyFallback = '';
|
|
160
|
+
if (dirty()) setMessage('notice', 'Copy includes saved responses only. Unsaved edits are not included.');
|
|
161
|
+
try {
|
|
162
|
+
if (!navigator.clipboard || !navigator.clipboard.writeText) throw new Error('Clipboard access is unavailable.');
|
|
163
|
+
await navigator.clipboard.writeText(payload);
|
|
164
|
+
setMessage('success', dirty() ? 'Saved responses copied. Unsaved edits were not included.' : 'Saved responses copied.');
|
|
165
|
+
} catch (error) {
|
|
166
|
+
setMessage('notice', 'Clipboard was unavailable. Copy the saved-response text below.');
|
|
167
|
+
copyFallback = payload;
|
|
168
|
+
}
|
|
169
|
+
render();
|
|
170
|
+
}
|
|
171
|
+
function downloadSaved() {
|
|
172
|
+
if (dirty()) setMessage('notice', 'Download includes saved responses only. Unsaved edits are not included.');
|
|
173
|
+
var blob = new Blob([JSON.stringify(envelope(), null, 2)], { type: 'application/json' });
|
|
174
|
+
var link = node('a', { href: URL.createObjectURL(blob), download: (model.artifactId || 'artifact') + '-responses.json' });
|
|
175
|
+
document.body.append(link); link.click(); link.remove(); URL.revokeObjectURL(link.href); render();
|
|
176
|
+
}
|
|
177
|
+
function countText() {
|
|
178
|
+
var count = copiedResponses(saved).length;
|
|
179
|
+
var total = (model.questions || []).length;
|
|
180
|
+
if (storage === 'brief') return count + ' of ' + total + ' recorded in brief';
|
|
181
|
+
if (storage === 'claude') return count + ' of ' + total + ' saved in artifact — awaiting brief sync';
|
|
182
|
+
return count + ' of ' + total + ' prepared for export (not saved)';
|
|
183
|
+
}
|
|
184
|
+
function syncLiveUi() {
|
|
185
|
+
var messageNode = root.querySelector('.jca-message');
|
|
186
|
+
if (messageNode) { messageNode.className = 'jca-message jca-message-' + messageKind; messageNode.textContent = message; }
|
|
187
|
+
var footer = root.querySelector('.jca-footer');
|
|
188
|
+
if (footer) footer.textContent = writable ? (dirty() ? 'Unsaved response edits are on this page.' : countText() + '.') : 'Responses are read-only in this artifact.';
|
|
189
|
+
root.querySelectorAll('[data-jca-save-all]').forEach(function (button) { button.disabled = !writable || saving || sourceChanged || !unsavedAnswers().length; });
|
|
190
|
+
}
|
|
191
|
+
function renderQuestion(question, index) {
|
|
192
|
+
var current = draft[question.id] || { answer: '', note: '' };
|
|
193
|
+
var readOnly = isReadOnly(question);
|
|
194
|
+
var body = node('section', { class: 'jca-question', id: 'jca-question-' + question.id });
|
|
195
|
+
body.append(node('div', { class: 'jca-question-kicker', text: 'Decision ' + (index + 1) }), node('h2', { text: question.question }));
|
|
196
|
+
body.append(node('p', { class: 'jca-status jca-status-' + (question.status || 'open'), text: statusLabel(question.status) }));
|
|
197
|
+
if (question.answer) body.append(node('p', { class: 'jca-recorded', text: 'Brief record: ' + question.answer }));
|
|
198
|
+
(model.comparisons || []).filter(function (comparison) { return comparison.decisionId === question.id; }).forEach(function (comparison) { body.append(renderComparison(comparison)); });
|
|
199
|
+
if (question.context || question.why || (question.affected || []).length) {
|
|
200
|
+
var detail = node('details', { class: 'jca-details' }, [node('summary', { text: 'Context and impact' })]);
|
|
201
|
+
if (question.context) detail.append(node('p', { text: question.context }));
|
|
202
|
+
if (question.why) detail.append(node('p', { text: question.why }));
|
|
203
|
+
if ((question.affected || []).length) detail.append(node('p', { text: 'Affected: ' + question.affected.join(', ') }));
|
|
204
|
+
body.append(detail);
|
|
205
|
+
}
|
|
206
|
+
var fieldset = node('fieldset', { class: 'jca-options', disabled: readOnly });
|
|
207
|
+
fieldset.append(node('legend', { text: readOnly ? 'Responses are read-only' : 'Choose one response' }));
|
|
208
|
+
(question.options || []).forEach(function (option) {
|
|
209
|
+
var id = 'jca-' + question.id + '-' + option.value;
|
|
210
|
+
var radio = node('input', { type: 'radio', id: id, name: 'jca-answer-' + question.id, value: option.value, checked: current.answer === option.value,
|
|
211
|
+
onchange: function () { draft[question.id] = { answer: option.value, note: (draft[question.id] || {}).note || '' }; setMessage('quiet', 'Unsaved changes.'); syncLiveUi(); syncNoteRequirement(); } });
|
|
212
|
+
var label = node('label', { class: 'jca-option', for: id }, [radio, node('span', { class: 'jca-option-copy' }, [node('strong', { text: option.label }), option.description ? node('small', { text: option.description }) : null])]);
|
|
213
|
+
fieldset.append(label);
|
|
214
|
+
});
|
|
215
|
+
body.append(fieldset);
|
|
216
|
+
var note = node('textarea', { class: 'jca-note', id: 'jca-note-' + question.id, rows: 3, disabled: readOnly, placeholder: 'Optional note' });
|
|
217
|
+
note.value = current.note || '';
|
|
218
|
+
function syncNoteRequirement() {
|
|
219
|
+
var selected = (question.options || []).find(function (option) { return option.value === (draft[question.id] || {}).answer; });
|
|
220
|
+
var required = Boolean(selected && selected.requiresNote);
|
|
221
|
+
note.required = required; note.setAttribute('aria-required', String(required));
|
|
222
|
+
note.placeholder = required ? 'Describe your answer' : 'Optional note';
|
|
223
|
+
noteLabel.textContent = required ? 'Note (required for this answer)' : 'Note';
|
|
224
|
+
}
|
|
225
|
+
var noteLabel = node('label', { class: 'jca-note-label', for: note.id, text: 'Note' });
|
|
226
|
+
syncNoteRequirement();
|
|
227
|
+
note.addEventListener('input', function () { draft[question.id] = { answer: (draft[question.id] || {}).answer || '', note: note.value }; setMessage('quiet', 'Unsaved changes.'); syncLiveUi(); });
|
|
228
|
+
body.append(noteLabel, note);
|
|
229
|
+
if (question.answer && question.note) body.append(node('p', { class: 'jca-recorded', text: 'Brief note: ' + question.note }));
|
|
230
|
+
if (!readOnly) body.append(node('button', { class: 'jca-save-one', type: 'button', text: 'Save this response', disabled: saving || loading || sourceChanged, onclick: function () { save(question); } }));
|
|
231
|
+
return body;
|
|
232
|
+
}
|
|
233
|
+
function renderComparison(comparison) {
|
|
234
|
+
var section = node('section', { class: 'jca-comparison' }, [node('h2', { text: comparison.title || 'Comparison' })]);
|
|
235
|
+
if (comparison.decisionId) section.append(node('p', { class: 'jca-caption', text: 'Decision: ' + comparison.decisionId }));
|
|
236
|
+
var images = node('div', { class: 'jca-images' });
|
|
237
|
+
(comparison.images || []).forEach(function (image) {
|
|
238
|
+
var figure = node('figure');
|
|
239
|
+
figure.append(node('img', { src: image.src, alt: image.alt || image.label || 'Comparison screenshot', loading: 'lazy' }));
|
|
240
|
+
figure.append(node('figcaption', { text: image.label || image.caption || 'Screenshot' }));
|
|
241
|
+
if (image.caption) figure.append(node('p', { class: 'jca-caption', text: image.caption }));
|
|
242
|
+
images.append(figure);
|
|
243
|
+
});
|
|
244
|
+
section.append(images); return section;
|
|
245
|
+
}
|
|
246
|
+
function renderReview(review) {
|
|
247
|
+
var section = node('section', { class: 'jca-review jca-review-' + String(review.result || 'UNVERIFIED').toLowerCase() });
|
|
248
|
+
section.append(node('p', { class: 'jca-review-result', text: 'Recorded ' + (review.result || 'UNVERIFIED') }), node('h3', { text: review.title || 'Verification' }), node('p', { text: review.summary || '' }), node('p', { class: 'jca-caption', text: 'Historical record; not revalidated by this view.' }));
|
|
249
|
+
if ((review.details || []).length || review.source) {
|
|
250
|
+
var details = node('details', { class: 'jca-details' }, [node('summary', { text: 'Verification details' })]);
|
|
251
|
+
(review.details || []).forEach(function (item) { details.append(node('p', { text: item })); });
|
|
252
|
+
if (review.source) details.append(node('p', { text: 'Source: ' + review.source }));
|
|
253
|
+
section.append(details);
|
|
254
|
+
}
|
|
255
|
+
return section;
|
|
256
|
+
}
|
|
257
|
+
function render() {
|
|
258
|
+
if (destroyed) return;
|
|
259
|
+
var focusedId = document.activeElement && root.contains(document.activeElement) ? document.activeElement.id : '';
|
|
260
|
+
root.replaceChildren();
|
|
261
|
+
var page = node('article', { class: 'joycraft-artifact', 'data-jca-theme': model.theme === 'dark' ? 'dark' : 'light' });
|
|
262
|
+
if (document.documentElement.hasAttribute('data-jca-theme')) document.documentElement.setAttribute('data-jca-theme', model.theme === 'dark' ? 'dark' : 'light');
|
|
263
|
+
var header = node('header', { class: 'jca-header' }, [node('p', { class: 'jca-eyebrow', text: 'Decision artifact' }), node('h1', { text: model.title || 'Artifact' })]);
|
|
264
|
+
if (model.summary) header.append(node('p', { class: 'jca-summary', text: model.summary }));
|
|
265
|
+
if (model.source && model.source.path) {
|
|
266
|
+
var provenance = node('details', { class: 'jca-details jca-source' }, [node('summary', { text: 'Source provenance' }), node('p', { text: model.source.path }), model.source.revision ? node('p', { text: 'Revision: ' + model.source.revision }) : null]);
|
|
267
|
+
header.append(provenance);
|
|
268
|
+
}
|
|
269
|
+
page.append(header);
|
|
270
|
+
page.append(node('p', { class: 'jca-message jca-message-' + messageKind, role: messageKind === 'error' ? 'alert' : 'status', text: message }));
|
|
271
|
+
var actions = node('div', { class: 'jca-actions' });
|
|
272
|
+
if (transport) actions.append(node('button', { type: 'button', text: loading ? 'Refreshing…' : 'Refresh', disabled: loading || saving, onclick: refresh }));
|
|
273
|
+
actions.append(node('button', { type: 'button', 'data-jca-save-all': '', text: 'Save selected answers', disabled: !writable || saving || sourceChanged || !unsavedAnswers().length, onclick: function () { save(); } }));
|
|
274
|
+
if (sourceChanged) actions.append(node('button', { type: 'button', text: 'I reviewed the updated source', onclick: function () { sourceChanged = false; setMessage('notice', 'Review acknowledged. Select a response where needed, then save.'); render(); } }));
|
|
275
|
+
actions.append(node('button', { type: 'button', text: 'Copy saved', onclick: copySaved }), node('button', { type: 'button', text: 'Download saved', onclick: downloadSaved }));
|
|
276
|
+
page.append(actions);
|
|
277
|
+
(model.questions || []).forEach(function (question, index) { page.append(renderQuestion(question, index)); });
|
|
278
|
+
var unattachedComparisons = (model.comparisons || []).filter(function (comparison) { return !comparison.decisionId; });
|
|
279
|
+
if (unattachedComparisons.length) { page.append(node('h2', { class: 'jca-section-title', text: 'Screenshots' })); unattachedComparisons.forEach(function (item) { page.append(renderComparison(item)); }); }
|
|
280
|
+
if ((model.reviews || []).length) { page.append(node('h2', { class: 'jca-section-title', text: 'Verification summary' })); model.reviews.forEach(function (item) { page.append(renderReview(item)); }); }
|
|
281
|
+
page.append(node('footer', { class: 'jca-footer', text: writable ? (dirty() ? 'Unsaved response edits are on this page.' : countText() + '.') : 'Responses are read-only in this artifact.' }));
|
|
282
|
+
root.append(page);
|
|
283
|
+
if (focusedId) {
|
|
284
|
+
var focusTarget = document.getElementById(focusedId);
|
|
285
|
+
if (focusTarget && !focusTarget.disabled) focusTarget.focus({ preventScroll: true });
|
|
286
|
+
}
|
|
287
|
+
if (copyFallback) {
|
|
288
|
+
var fallback = node('textarea', { class: 'jca-copy-fallback', 'aria-label': 'Saved response data to copy' });
|
|
289
|
+
fallback.value = copyFallback;
|
|
290
|
+
root.append(fallback);
|
|
291
|
+
fallback.focus(); fallback.select();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
render();
|
|
295
|
+
if (transport && typeof transport.load === 'function') refresh();
|
|
296
|
+
return { refresh: refresh, destroy: function () { destroyed = true; root.replaceChildren(); } };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
global.JoycraftArtifacts = global.JoycraftArtifacts || {};
|
|
300
|
+
global.JoycraftArtifacts.mount = mount;
|
|
301
|
+
})(window);
|