@cyber-dash-tech/revela 0.13.0 → 0.15.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 +75 -55
- package/README.zh-CN.md +75 -55
- package/lib/command-intent.ts +59 -0
- package/lib/commands/brief.ts +1 -1
- package/lib/commands/designs.ts +1 -1
- package/lib/commands/domains.ts +1 -1
- package/lib/commands/edit.ts +7 -5
- package/lib/commands/enable.ts +6 -6
- package/lib/commands/help.ts +19 -10
- package/lib/commands/init.ts +1 -1
- package/lib/commands/inspect.ts +7 -5
- package/lib/commands/research.ts +66 -0
- package/lib/commands/review.ts +3 -3
- package/lib/decks-state.ts +5 -5
- package/lib/inspect/prompt.ts +15 -2
- package/lib/inspect/requests.ts +21 -2
- package/lib/inspection-context/compile.ts +71 -5
- package/lib/inspection-context/match.ts +71 -1
- package/lib/inspection-context/project.ts +116 -13
- package/lib/inspection-context/result.ts +183 -0
- package/lib/narrative-state/queries.ts +1 -0
- package/lib/refine/server.ts +91 -13
- package/package.json +1 -1
- package/plugin.ts +252 -53
- package/skill/NARRATIVE_SKILL.md +103 -25
- package/skill/SKILL.md +1 -1
- package/tools/edit.ts +10 -8
- package/tools/inspection-result.ts +37 -0
|
@@ -4,6 +4,8 @@ import type { InspectionPromptProjection } from "./project"
|
|
|
4
4
|
export type InspectionResultStatus = "success" | "no_match"
|
|
5
5
|
export type InspectionPurposeStatus = "clear" | "weak" | "misplaced" | "unknown"
|
|
6
6
|
export type InspectionSourceStatus = "supported" | "weak" | "unsupported" | "not_needed" | "unknown"
|
|
7
|
+
export type NarrativeReadingStatus = "matched" | "no_match"
|
|
8
|
+
export type ExploratoryReadingStatus = "available" | "limited" | "unavailable"
|
|
7
9
|
|
|
8
10
|
export interface InspectionResult {
|
|
9
11
|
version: 1
|
|
@@ -16,6 +18,8 @@ export interface InspectionResult {
|
|
|
16
18
|
}
|
|
17
19
|
matchConfidence: InspectionMatchConfidence
|
|
18
20
|
cards: {
|
|
21
|
+
reading?: NarrativeReadingCard
|
|
22
|
+
exploratory?: ExploratoryReadingCard
|
|
19
23
|
purpose: PurposeCard
|
|
20
24
|
source: SourceCard
|
|
21
25
|
}
|
|
@@ -53,6 +57,47 @@ export interface SourceCard {
|
|
|
53
57
|
rationale: string
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
export interface NarrativeReadingCard {
|
|
61
|
+
status: NarrativeReadingStatus
|
|
62
|
+
claimId?: string
|
|
63
|
+
canonicalClaimId?: string
|
|
64
|
+
claimText?: string
|
|
65
|
+
evidenceStatus?: string
|
|
66
|
+
evidenceBindingIds: string[]
|
|
67
|
+
supportedScope?: string
|
|
68
|
+
unsupportedScope?: string
|
|
69
|
+
caveats: string[]
|
|
70
|
+
relatedObjections: string[]
|
|
71
|
+
relatedRisks: string[]
|
|
72
|
+
artifactCoverage: NarrativeReadingArtifactCoverage[]
|
|
73
|
+
rationale: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface NarrativeReadingArtifactCoverage {
|
|
77
|
+
artifactId: string
|
|
78
|
+
type: string
|
|
79
|
+
outputPath?: string
|
|
80
|
+
coverageStatus: "current" | "stale" | "partial" | "missing"
|
|
81
|
+
containsClaim: boolean
|
|
82
|
+
stale: boolean
|
|
83
|
+
staleReason?: string
|
|
84
|
+
locations: string[]
|
|
85
|
+
note?: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ExploratoryReadingCard {
|
|
89
|
+
status: ExploratoryReadingStatus
|
|
90
|
+
official: false
|
|
91
|
+
audience?: string
|
|
92
|
+
claimFocus?: string
|
|
93
|
+
objectionPrompts: string[]
|
|
94
|
+
audienceReframe: string
|
|
95
|
+
appendixLeads: string[]
|
|
96
|
+
meetingPrep: string[]
|
|
97
|
+
boundaries: string[]
|
|
98
|
+
rationale: string
|
|
99
|
+
}
|
|
100
|
+
|
|
56
101
|
export function buildDeterministicInspectionResult(
|
|
57
102
|
projection: InspectionPromptProjection,
|
|
58
103
|
options: { requestId?: string; staleReason?: string } = {},
|
|
@@ -72,6 +117,8 @@ export function buildDeterministicInspectionResult(
|
|
|
72
117
|
slide: slide ? { index: slide.index, title: slide.title } : undefined,
|
|
73
118
|
matchConfidence: projection.match.confidence,
|
|
74
119
|
cards: {
|
|
120
|
+
reading: narrativeReadingCard(projection, noMatch),
|
|
121
|
+
exploratory: exploratoryReadingCard(projection, noMatch),
|
|
75
122
|
purpose: {
|
|
76
123
|
status: purposeStatus(projection, noMatch),
|
|
77
124
|
role: projection.cards.objective.narrativeRole,
|
|
@@ -101,6 +148,126 @@ export function buildDeterministicInspectionResult(
|
|
|
101
148
|
}
|
|
102
149
|
}
|
|
103
150
|
|
|
151
|
+
function exploratoryReadingCard(projection: InspectionPromptProjection, noMatch: boolean): ExploratoryReadingCard {
|
|
152
|
+
const claimText = projection.match.claim?.text ?? projection.cards.evidence.matchedClaim
|
|
153
|
+
const caveats = projection.cards.caveats.caveats
|
|
154
|
+
const unsupportedScope = projection.match.claim?.unsupportedScope ?? firstPresent(projection.cards.evidence.traces.map((item) => item.unsupportedScope))
|
|
155
|
+
const objectionPrompts = exploratoryObjections(projection, unsupportedScope)
|
|
156
|
+
const appendixLeads = exploratoryAppendixLeads(projection)
|
|
157
|
+
const meetingPrep = exploratoryMeetingPrep(projection, unsupportedScope)
|
|
158
|
+
return {
|
|
159
|
+
status: noMatch ? "unavailable" : claimText ? "available" : "limited",
|
|
160
|
+
official: false,
|
|
161
|
+
audience: projection.cards.objective.audience,
|
|
162
|
+
claimFocus: claimText,
|
|
163
|
+
objectionPrompts,
|
|
164
|
+
audienceReframe: exploratoryAudienceFrame(projection, claimText),
|
|
165
|
+
appendixLeads,
|
|
166
|
+
meetingPrep,
|
|
167
|
+
boundaries: exploratoryBoundaries(projection, noMatch),
|
|
168
|
+
rationale: exploratoryRationale(projection, noMatch, objectionPrompts.length + appendixLeads.length + meetingPrep.length),
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function exploratoryObjections(projection: InspectionPromptProjection, unsupportedScope: string | undefined): string[] {
|
|
173
|
+
const items = projection.cards.appendix.relatedObjections.map((item) => `Prepare for this objection using recorded support only: ${item}`)
|
|
174
|
+
if (unsupportedScope) items.push(`Expect questions about unsupported scope: ${unsupportedScope}`)
|
|
175
|
+
for (const gap of projection.cards.evidence.gaps) items.push(`Treat this as an evidence gap, not as support: ${gap.message}`)
|
|
176
|
+
return dedupe(items).slice(0, 4)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function exploratoryAudienceFrame(projection: InspectionPromptProjection, claimText: string | undefined): string {
|
|
180
|
+
const audience = projection.cards.objective.audience
|
|
181
|
+
const beliefAfter = projection.cards.objective.audienceBeliefAfter
|
|
182
|
+
const decision = projection.cards.objective.decisionOrAction
|
|
183
|
+
if (!claimText) return "No specific claim is matched, so audience reframing is limited to the selected slide context."
|
|
184
|
+
if (audience && beliefAfter) return `For ${audience}, frame this claim as support for the desired belief: ${beliefAfter}`
|
|
185
|
+
if (audience && decision) return `For ${audience}, connect this claim to the recorded decision or action: ${decision}`
|
|
186
|
+
if (audience) return `For ${audience}, keep the wording inside the recorded claim boundary: ${claimText}`
|
|
187
|
+
return "Audience-specific reframing is limited because no audience is recorded in the projection."
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function exploratoryAppendixLeads(projection: InspectionPromptProjection): string[] {
|
|
191
|
+
const sourceLeads = projection.cards.evidence.traces.map((trace) => {
|
|
192
|
+
const where = trace.location || trace.page || trace.url || trace.sourcePath || trace.findingsFile
|
|
193
|
+
return where ? `${trace.source}: ${where}` : trace.source
|
|
194
|
+
})
|
|
195
|
+
const appendixCandidates = projection.cards.appendix.candidates.map((candidate) => `Slide ${candidate.slideIndex}: ${candidate.slideTitle} (${candidate.reason})`)
|
|
196
|
+
return dedupe([...sourceLeads, ...appendixCandidates]).slice(0, 5)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function exploratoryMeetingPrep(projection: InspectionPromptProjection, unsupportedScope: string | undefined): string[] {
|
|
200
|
+
const items: string[] = []
|
|
201
|
+
for (const risk of projection.cards.appendix.relatedRisks) items.push(`Risk to be ready for: ${risk}`)
|
|
202
|
+
for (const caveat of projection.cards.caveats.caveats) items.push(`Caveat to say plainly: ${caveat}`)
|
|
203
|
+
if (unsupportedScope) items.push(`Do not overstate beyond: ${unsupportedScope}`)
|
|
204
|
+
for (const warning of projection.cards.source.weakSourceGaps) items.push(`Source trace is weak: ${warning.message}`)
|
|
205
|
+
for (const gap of projection.cards.source.missingSourceGaps) items.push(`Missing support: ${gap.message}`)
|
|
206
|
+
return dedupe(items).slice(0, 5)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function exploratoryBoundaries(projection: InspectionPromptProjection, noMatch: boolean): string[] {
|
|
210
|
+
const boundaries = [
|
|
211
|
+
"Exploratory reading is non-official and does not change canonical narrative state or artifact content.",
|
|
212
|
+
"Use only recorded claims, evidence, caveats, risks, objections, and artifact coverage from this inspection projection.",
|
|
213
|
+
]
|
|
214
|
+
if (noMatch) boundaries.push("No matched slide or claim is available, so exploratory reading cannot infer support.")
|
|
215
|
+
if (projection.cards.evidence.gaps.length > 0) boundaries.push("Evidence gaps must remain visible and cannot be filled by generated reading text.")
|
|
216
|
+
return boundaries
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function exploratoryRationale(projection: InspectionPromptProjection, noMatch: boolean, signalCount: number): string {
|
|
220
|
+
if (noMatch) return "Exploratory reading is unavailable because the selection did not match a slide or claim."
|
|
221
|
+
if (signalCount > 0) return "This bounded reading layer derives objection, audience, appendix, and meeting-prep cues from recorded inspection context only."
|
|
222
|
+
if (projection.match.claim) return "A matched claim exists, but little supporting exploratory context is recorded beyond the claim itself."
|
|
223
|
+
return "Exploratory reading is limited because the selection maps to slide context but not to a specific claim."
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function narrativeReadingCard(projection: InspectionPromptProjection, noMatch: boolean): NarrativeReadingCard {
|
|
227
|
+
const claim = projection.match.claim
|
|
228
|
+
const evidenceBindingIds = dedupe([
|
|
229
|
+
...(claim?.evidenceBindingIds ?? []),
|
|
230
|
+
...projection.cards.evidence.traces.map((item) => item.evidenceBindingId).filter((item): item is string => Boolean(item)),
|
|
231
|
+
])
|
|
232
|
+
return {
|
|
233
|
+
status: noMatch ? "no_match" : "matched",
|
|
234
|
+
claimId: claim?.id,
|
|
235
|
+
canonicalClaimId: claim?.canonicalClaimId,
|
|
236
|
+
claimText: claim?.text ?? projection.cards.evidence.matchedClaim,
|
|
237
|
+
evidenceStatus: claim?.evidenceSupport ?? projection.cards.evidence.evidenceSupport,
|
|
238
|
+
evidenceBindingIds,
|
|
239
|
+
supportedScope: claim?.supportedScope ?? firstPresent(projection.cards.evidence.traces.map((item) => item.supportScope)),
|
|
240
|
+
unsupportedScope: claim?.unsupportedScope ?? firstPresent(projection.cards.evidence.traces.map((item) => item.unsupportedScope)),
|
|
241
|
+
caveats: projection.cards.caveats.caveats,
|
|
242
|
+
relatedObjections: projection.cards.appendix.relatedObjections,
|
|
243
|
+
relatedRisks: projection.cards.appendix.relatedRisks,
|
|
244
|
+
artifactCoverage: artifactCoverage(projection),
|
|
245
|
+
rationale: narrativeReadingRationale(projection, noMatch),
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function artifactCoverage(projection: InspectionPromptProjection): NarrativeReadingArtifactCoverage[] {
|
|
250
|
+
return projection.cards.artifacts.artifacts.map((artifact) => ({
|
|
251
|
+
artifactId: artifact.artifactId,
|
|
252
|
+
type: artifact.type,
|
|
253
|
+
outputPath: artifact.outputPath,
|
|
254
|
+
coverageStatus: artifact.coverageStatus,
|
|
255
|
+
containsClaim: artifact.containsClaim,
|
|
256
|
+
stale: artifact.stale,
|
|
257
|
+
staleReason: artifact.staleReason,
|
|
258
|
+
locations: artifact.locations.map((location) => `Slide ${location.slideIndex}: ${location.slideTitle} (${location.role}, ${location.match}:${location.location})`),
|
|
259
|
+
note: artifact.note ?? artifact.staleReasons[0],
|
|
260
|
+
}))
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function narrativeReadingRationale(projection: InspectionPromptProjection, noMatch: boolean): string {
|
|
264
|
+
if (noMatch) return "No matched slide or claim is available for narrative reading."
|
|
265
|
+
const claim = projection.match.claim
|
|
266
|
+
if (claim?.canonicalClaimId) return "The selection resolves to a canonical narrative claim, so Refine can show claim, evidence-boundary, caveat, objection, and risk context before any generated judgment."
|
|
267
|
+
if (claim) return "The selection resolves to a slide claim candidate. Canonical narrative linkage is not recorded for this element, so reading context falls back to slide claim and source trace."
|
|
268
|
+
return "The selection resolves to a slide but not a specific claim; narrative reading is limited to slide purpose, role, and surrounding evidence context."
|
|
269
|
+
}
|
|
270
|
+
|
|
104
271
|
function purposeStatus(projection: InspectionPromptProjection, noMatch: boolean): InspectionPurposeStatus {
|
|
105
272
|
if (noMatch) return "unknown"
|
|
106
273
|
if (projection.cards.objective.narrativeRole || projection.cards.objective.slidePurpose) return "clear"
|
|
@@ -158,3 +325,19 @@ function sourceCaveats(projection: InspectionPromptProjection): string[] {
|
|
|
158
325
|
...projection.cards.appendix.relatedObjections,
|
|
159
326
|
].slice(0, 10)
|
|
160
327
|
}
|
|
328
|
+
|
|
329
|
+
function firstPresent(values: Array<string | undefined>): string | undefined {
|
|
330
|
+
return values.find((value) => Boolean(value?.trim()))
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function dedupe(values: string[]): string[] {
|
|
334
|
+
const seen = new Set<string>()
|
|
335
|
+
const result: string[] = []
|
|
336
|
+
for (const value of values) {
|
|
337
|
+
const key = value.trim()
|
|
338
|
+
if (!key || seen.has(key)) continue
|
|
339
|
+
seen.add(key)
|
|
340
|
+
result.push(key)
|
|
341
|
+
}
|
|
342
|
+
return result
|
|
343
|
+
}
|
|
@@ -352,6 +352,7 @@ function pushSlideRef(refs: ClaimSlideRef[], seen: Set<string>, claim: Narrative
|
|
|
352
352
|
function claimSlideRefsForTarget(target: RenderTarget, currentHtmlRefs: ClaimSlideRef[], htmlCoverageByPath: Map<string, ClaimSlideRef[]>): ClaimSlideRef[] {
|
|
353
353
|
const stored = parseStoredClaimSlideRefs(target)
|
|
354
354
|
if (stored.length > 0) return stored
|
|
355
|
+
if (target.type === "brief" || target.type === "executive_brief") return []
|
|
355
356
|
if (target.type === "html_deck") return currentHtmlRefs
|
|
356
357
|
const sourceOutputPath = typeof target.data?.sourceOutputPath === "string" ? target.data.sourceOutputPath : undefined
|
|
357
358
|
if (sourceOutputPath) return htmlCoverageByPath.get(sourceOutputPath) ?? currentHtmlRefs
|
package/lib/refine/server.ts
CHANGED
|
@@ -459,6 +459,7 @@ async function handleInspect(req: Request, session: EditSession): Promise<Respon
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
const snapshot = normalizeSnapshot(body?.snapshot ?? body)
|
|
462
|
+
const language = normalizeInspectLanguage(body?.language)
|
|
462
463
|
const requestId = typeof body?.requestId === "string" && body.requestId.trim() ? body.requestId.trim() : randomBytes(10).toString("base64url")
|
|
463
464
|
const version = readDeckVersion(session).version
|
|
464
465
|
const staleReason = typeof body?.deckVersion === "string" && body.deckVersion !== version
|
|
@@ -480,6 +481,7 @@ async function handleInspect(req: Request, session: EditSession): Promise<Respon
|
|
|
480
481
|
text: buildInspectionPrompt({
|
|
481
482
|
requestId,
|
|
482
483
|
file: session.file,
|
|
484
|
+
language,
|
|
483
485
|
projection: staleReason
|
|
484
486
|
? { ...projection, stale: { stale: true, reason: staleReason } } as any
|
|
485
487
|
: projection,
|
|
@@ -491,7 +493,7 @@ async function handleInspect(req: Request, session: EditSession): Promise<Respon
|
|
|
491
493
|
failInspectRequest(requestId, message)
|
|
492
494
|
})
|
|
493
495
|
|
|
494
|
-
return jsonResponse({ ok: true, requestId, deckVersion: version, status: "pending", preprocess })
|
|
496
|
+
return jsonResponse({ ok: true, requestId, deckVersion: version, status: "pending", language, preprocess })
|
|
495
497
|
} catch (error) {
|
|
496
498
|
const message = error instanceof Error ? error.message : String(error)
|
|
497
499
|
failInspectRequest(requestId, message)
|
|
@@ -510,6 +512,11 @@ function handleInspectResult(requestId: string | null, session: EditSession): Re
|
|
|
510
512
|
return jsonResponse({ ok: true, requestId, status: request.status, deckVersion: request.deckVersion })
|
|
511
513
|
}
|
|
512
514
|
|
|
515
|
+
function normalizeInspectLanguage(input: unknown): string {
|
|
516
|
+
const value = typeof input === "string" ? input.trim() : ""
|
|
517
|
+
return value || "Auto"
|
|
518
|
+
}
|
|
519
|
+
|
|
513
520
|
function normalizeSnapshot(input: any): InspectionElementSnapshot {
|
|
514
521
|
return {
|
|
515
522
|
scope: input?.scope === "selection" || input?.scope === "slide" || input?.scope === "element" ? input.scope : undefined,
|
|
@@ -657,6 +664,9 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
657
664
|
.comment-bubble.stale .comment-bubble-state { color: #a16207; }
|
|
658
665
|
.comment-bubble.failed .comment-bubble-state { color: #b91c1c; }
|
|
659
666
|
.inspect-actions { display: flex; flex-direction: column; gap: 8px; }
|
|
667
|
+
.inspect-options { display: flex; flex-direction: column; gap: 5px; }
|
|
668
|
+
.inspect-options label { color: #64748b; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
|
|
669
|
+
.inspect-select { width: 100%; padding: 10px 11px; border: 1px solid #d7e0ea; border-radius: 12px; background: #fff; color: #0f172a; font-weight: 700; }
|
|
660
670
|
.inspect-cards { display: flex; flex-direction: column; gap: 12px; }
|
|
661
671
|
.inspect-card { border: 1px solid #d7e0ea; border-radius: 16px; background: #fff; padding: 13px; box-shadow: 0 10px 24px rgba(15,23,42,.05); }
|
|
662
672
|
.inspect-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
|
|
@@ -681,7 +691,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
681
691
|
<aside>
|
|
682
692
|
<div>
|
|
683
693
|
<h1><span class="wordmark">REVELA</span> Refine</h1>
|
|
684
|
-
<p class="hint">Cmd/Ctrl-click slide elements once, then use Edit for fast changes or Inspect for Source
|
|
694
|
+
<p class="hint">Cmd/Ctrl-click slide elements once, then use Edit for fast changes or Inspect for Narrative Reading, Exploratory Reading, Source, and Purpose review.</p>
|
|
685
695
|
</div>
|
|
686
696
|
<div id="selectionSummary" class="selection-summary"><strong>Selection</strong><span>No references selected.</span><div id="selectionChips" class="selection-chips"></div></div>
|
|
687
697
|
<div class="tabs" role="tablist" aria-label="Refine mode">
|
|
@@ -698,10 +708,11 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
698
708
|
</div>
|
|
699
709
|
<div id="inspectPanel" class="tab-panel">
|
|
700
710
|
<div class="inspect-actions">
|
|
711
|
+
<div class="inspect-options"><label for="inspectLanguage">Display Language</label><select id="inspectLanguage" class="inspect-select"><option>Auto</option><option>English</option><option>简体中文</option><option>繁體中文</option><option>日本語</option><option>Deutsch</option><option>Français</option><option>Español</option><option>Português</option><option>Arabic</option></select></div>
|
|
701
712
|
<button id="inspectButton" disabled>Inspect Selection</button>
|
|
702
713
|
<div id="inspectStale"></div>
|
|
703
714
|
</div>
|
|
704
|
-
<div id="inspectCards" class="inspect-cards"><div class="inspect-empty">Select one or more deck elements, then inspect them for Source and Purpose. This does not edit the deck.</div></div>
|
|
715
|
+
<div id="inspectCards" class="inspect-cards"><div class="inspect-empty">Select one or more deck elements, then inspect them for Narrative Reading, Exploratory Reading, Source, and Purpose. This does not edit the deck.</div></div>
|
|
705
716
|
</div>
|
|
706
717
|
<div id="status" class="status"></div>
|
|
707
718
|
</aside>
|
|
@@ -744,6 +755,8 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
744
755
|
mode: defaultMode === 'inspect' ? 'inspect' : 'edit',
|
|
745
756
|
inspecting: false,
|
|
746
757
|
activeInspectRequestId: '',
|
|
758
|
+
inspectLanguage: 'Auto',
|
|
759
|
+
inspectFallback: null,
|
|
747
760
|
};
|
|
748
761
|
const els = {
|
|
749
762
|
frame: null,
|
|
@@ -759,6 +772,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
759
772
|
commentThread: null,
|
|
760
773
|
send: null,
|
|
761
774
|
inspectButton: null,
|
|
775
|
+
inspectLanguage: null,
|
|
762
776
|
inspectCards: null,
|
|
763
777
|
inspectStale: null,
|
|
764
778
|
status: null,
|
|
@@ -792,7 +806,9 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
792
806
|
els.inspectStale = document.getElementById('inspectStale');
|
|
793
807
|
els.status = document.getElementById('status');
|
|
794
808
|
|
|
795
|
-
|
|
809
|
+
els.inspectLanguage = document.getElementById('inspectLanguage');
|
|
810
|
+
|
|
811
|
+
if (!els.frame || !els.hitbox || !els.resizeHandle || !els.selectionSummary || !els.selectionChips || !els.editTab || !els.inspectTab || !els.editPanel || !els.inspectPanel || !els.comment || !els.commentThread || !els.send || !els.inspectButton || !els.inspectLanguage || !els.inspectCards || !els.inspectStale || !els.status) {
|
|
796
812
|
throw new Error('Editor boot failed: required DOM nodes are missing.');
|
|
797
813
|
}
|
|
798
814
|
|
|
@@ -840,6 +856,9 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
840
856
|
els.resizeHandle.addEventListener('dblclick', resetEditorWidth);
|
|
841
857
|
els.send.addEventListener('click', sendComment);
|
|
842
858
|
els.inspectButton.addEventListener('click', inspectCurrentSelection);
|
|
859
|
+
els.inspectLanguage.addEventListener('change', () => {
|
|
860
|
+
state.inspectLanguage = els.inspectLanguage.value || 'Auto';
|
|
861
|
+
});
|
|
843
862
|
els.editTab.addEventListener('click', () => setMode('edit'));
|
|
844
863
|
els.inspectTab.addEventListener('click', () => setMode('inspect'));
|
|
845
864
|
}
|
|
@@ -1075,7 +1094,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1075
1094
|
renderReferenceOutlines();
|
|
1076
1095
|
updateSendState();
|
|
1077
1096
|
renderSelectionSummary();
|
|
1078
|
-
resetInspectCards('References ready. Open Inspect and click Inspect Selection when you want Source
|
|
1097
|
+
resetInspectCards('References ready. Open Inspect and click Inspect Selection when you want Narrative Reading, Exploratory Reading, Source, and Purpose review.');
|
|
1079
1098
|
setStatus('Inserted @' + label + '. ' + state.references.length + ' reference' + (state.references.length === 1 ? '' : 's') + ' will be sent.');
|
|
1080
1099
|
}
|
|
1081
1100
|
|
|
@@ -1286,22 +1305,28 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1286
1305
|
updateSendState();
|
|
1287
1306
|
setMode('inspect');
|
|
1288
1307
|
els.inspectStale.innerHTML = '';
|
|
1289
|
-
|
|
1308
|
+
state.inspectFallback = null;
|
|
1309
|
+
els.inspectCards.innerHTML = '<div class="inspect-loading"><b>Reading selection...</b><br>Sending grounded selection context to OpenCode. Deterministic context is kept as fallback if generation fails.</div>';
|
|
1290
1310
|
try {
|
|
1291
1311
|
const res = await fetch('/api/inspect?token=' + encodeURIComponent(token), {
|
|
1292
1312
|
method: 'POST',
|
|
1293
1313
|
headers: { 'content-type': 'application/json' },
|
|
1294
|
-
body: JSON.stringify({ snapshot, deckVersion: state.deckVersion }),
|
|
1314
|
+
body: JSON.stringify({ snapshot, deckVersion: state.deckVersion, language: state.inspectLanguage }),
|
|
1295
1315
|
});
|
|
1296
1316
|
const body = await res.json().catch(() => ({}));
|
|
1297
1317
|
if (!res.ok || !body.ok) throw new Error(body.error || 'Inspection failed');
|
|
1298
1318
|
state.deckVersion = body.deckVersion || state.deckVersion;
|
|
1299
1319
|
state.activeInspectRequestId = body.requestId;
|
|
1300
|
-
|
|
1301
|
-
els.inspectCards.
|
|
1320
|
+
state.inspectFallback = body.preprocess || null;
|
|
1321
|
+
els.inspectCards.innerHTML = '<div class="inspect-loading"><b>Reading selection...</b><br>Waiting for localized structured reading cards.</div>';
|
|
1302
1322
|
await pollInspectResult(body.requestId);
|
|
1303
1323
|
} catch (error) {
|
|
1304
|
-
|
|
1324
|
+
if (state.inspectFallback) {
|
|
1325
|
+
renderInspectResult(state.inspectFallback, 'Deterministic fallback');
|
|
1326
|
+
els.inspectCards.insertAdjacentHTML('afterbegin', '<div class="inspect-warning">Generated inspection failed or timed out. Showing deterministic fallback context only.</div>');
|
|
1327
|
+
} else {
|
|
1328
|
+
resetInspectCards(error && error.message ? error.message : String(error));
|
|
1329
|
+
}
|
|
1305
1330
|
} finally {
|
|
1306
1331
|
state.inspecting = false;
|
|
1307
1332
|
updateSendState();
|
|
@@ -1309,7 +1334,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1309
1334
|
}
|
|
1310
1335
|
|
|
1311
1336
|
async function pollInspectResult(requestId) {
|
|
1312
|
-
for (
|
|
1337
|
+
for (let attempt = 0; attempt < 80; attempt++) {
|
|
1313
1338
|
await delay(900);
|
|
1314
1339
|
const res = await fetch('/api/inspect-result?token=' + encodeURIComponent(token) + '&requestId=' + encodeURIComponent(requestId));
|
|
1315
1340
|
const body = await res.json().catch(() => ({}));
|
|
@@ -1321,6 +1346,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1321
1346
|
}
|
|
1322
1347
|
if (body.status === 'failed' || body.status === 'expired') throw new Error(body.error || 'Inspection failed');
|
|
1323
1348
|
}
|
|
1349
|
+
throw new Error('Inspection timed out while waiting for OpenCode result');
|
|
1324
1350
|
}
|
|
1325
1351
|
|
|
1326
1352
|
function collectReferenceSnapshot() {
|
|
@@ -1351,6 +1377,8 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1351
1377
|
else els.inspectStale.innerHTML = '';
|
|
1352
1378
|
els.inspectCards.innerHTML = [
|
|
1353
1379
|
'<div class="status">' + escapeHtml(phase || 'Inspection') + '</div>',
|
|
1380
|
+
result.cards.reading ? renderInspectCard('Narrative Reading', result.cards.reading.status, result.cards.reading.rationale, renderReading(result.cards.reading)) : '',
|
|
1381
|
+
result.cards.exploratory ? renderInspectCard('Exploratory Reading', result.cards.exploratory.status, result.cards.exploratory.rationale, renderExploratory(result.cards.exploratory)) : '',
|
|
1354
1382
|
renderInspectCard('Purpose', result.cards.purpose.status, result.cards.purpose.rationale, renderPurpose(result.cards.purpose)),
|
|
1355
1383
|
renderInspectCard('Source', result.cards.source.status, result.cards.source.rationale, renderSource(result.cards.source)),
|
|
1356
1384
|
].join('');
|
|
@@ -1364,6 +1392,49 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1364
1392
|
return '<div class="inspect-item">' + field('Role', card.role) + field('Why it matters', card.whyItMatters) + '</div>';
|
|
1365
1393
|
}
|
|
1366
1394
|
|
|
1395
|
+
function renderReading(card) {
|
|
1396
|
+
return '<div class="inspect-item">'
|
|
1397
|
+
+ field('Claim ID', card.claimId)
|
|
1398
|
+
+ field('Canonical claim ID', card.canonicalClaimId)
|
|
1399
|
+
+ field('Claim', card.claimText)
|
|
1400
|
+
+ field('Evidence status', card.evidenceStatus)
|
|
1401
|
+
+ field('Evidence bindings', card.evidenceBindingIds && card.evidenceBindingIds.length ? card.evidenceBindingIds.join(', ') : '')
|
|
1402
|
+
+ field('Supported scope', card.supportedScope)
|
|
1403
|
+
+ field('Unsupported scope', card.unsupportedScope)
|
|
1404
|
+
+ '</div>'
|
|
1405
|
+
+ renderSectionList('Caveats', card.caveats)
|
|
1406
|
+
+ renderSectionList('Objections', card.relatedObjections)
|
|
1407
|
+
+ renderSectionList('Risks', card.relatedRisks)
|
|
1408
|
+
+ renderArtifactCoverage(card.artifactCoverage);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
function renderArtifactCoverage(items) {
|
|
1412
|
+
if (!items || !items.length) return '';
|
|
1413
|
+
return '<div class="label">Artifact Coverage</div>' + items.map((item) => {
|
|
1414
|
+
const title = (item.type || 'artifact') + (item.outputPath ? ' · ' + item.outputPath : '');
|
|
1415
|
+
const status = (item.coverageStatus || 'unknown') + (item.containsClaim ? ' · contains claim' : ' · claim not rendered');
|
|
1416
|
+
return '<div class="inspect-item"><b>' + escapeHtml(title) + '</b>'
|
|
1417
|
+
+ field('Coverage', status)
|
|
1418
|
+
+ field('Stale', item.stale ? (item.staleReason || 'stale') : '')
|
|
1419
|
+
+ field('Note', item.note)
|
|
1420
|
+
+ renderSectionList('Locations', item.locations)
|
|
1421
|
+
+ '</div>';
|
|
1422
|
+
}).join('');
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
function renderExploratory(card) {
|
|
1426
|
+
return '<div class="inspect-item"><b>Non-official reading aid</b>'
|
|
1427
|
+
+ field('Official artifact content', card.official === false ? 'No' : '')
|
|
1428
|
+
+ field('Audience', card.audience)
|
|
1429
|
+
+ field('Claim focus', card.claimFocus)
|
|
1430
|
+
+ field('Audience reframe boundary', card.audienceReframe)
|
|
1431
|
+
+ '</div>'
|
|
1432
|
+
+ renderSectionList('Objection Prep', card.objectionPrompts)
|
|
1433
|
+
+ renderSectionList('Appendix Leads', card.appendixLeads)
|
|
1434
|
+
+ renderSectionList('Meeting Prep', card.meetingPrep)
|
|
1435
|
+
+ renderSectionList('Boundaries', card.boundaries);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1367
1438
|
function renderSource(card) {
|
|
1368
1439
|
return renderSources(card.sources) + renderWarnings(card.warnings) + renderSectionList('Gaps', card.gaps) + renderSectionList('Caveats', card.caveats);
|
|
1369
1440
|
}
|
|
@@ -1422,7 +1493,7 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1422
1493
|
state.references = [];
|
|
1423
1494
|
if (removeChips) els.comment.querySelectorAll('.ref-chip').forEach((chip) => chip.remove());
|
|
1424
1495
|
renderSelectionSummary();
|
|
1425
|
-
resetInspectCards('Select one or more deck elements, then inspect them for Source and Purpose. This does not edit the deck.');
|
|
1496
|
+
resetInspectCards('Select one or more deck elements, then inspect them for Narrative Reading, Exploratory Reading, Source, and Purpose. This does not edit the deck.');
|
|
1426
1497
|
}
|
|
1427
1498
|
|
|
1428
1499
|
function getCommentText() {
|
|
@@ -1525,10 +1596,17 @@ export function renderRefineShell(token: string, defaultMode: RefineMode = "edit
|
|
|
1525
1596
|
}
|
|
1526
1597
|
|
|
1527
1598
|
function findSlide(node) {
|
|
1528
|
-
|
|
1599
|
+
if (!node || !node.closest) return null;
|
|
1600
|
+
return node.closest('.slide[data-slide-index]')
|
|
1601
|
+
|| node.closest('.slide')
|
|
1602
|
+
|| node.closest('[slide-qa]')
|
|
1603
|
+
|| node.closest('.slide-canvas')
|
|
1604
|
+
|| node.closest('.page');
|
|
1529
1605
|
}
|
|
1530
1606
|
|
|
1531
1607
|
function getSlides(doc) {
|
|
1608
|
+
const canonicalSlides = Array.from(doc.querySelectorAll('.slide[data-slide-index]'));
|
|
1609
|
+
if (canonicalSlides.length) return canonicalSlides;
|
|
1532
1610
|
const slides = Array.from(doc.querySelectorAll('.slide'));
|
|
1533
1611
|
if (slides.length) return slides;
|
|
1534
1612
|
const qaSlides = Array.from(doc.querySelectorAll('[slide-qa]'));
|