@skrr-ai/cli 0.1.164 → 0.1.165

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.
Files changed (88) hide show
  1. package/README.md +13 -0
  2. package/dist/base-command.d.ts +14 -1
  3. package/dist/base-command.js +166 -46
  4. package/dist/commands/agent/message/send.d.ts +1 -0
  5. package/dist/commands/agent/message/send.js +3 -0
  6. package/dist/commands/agents/mini-computer/app/set.js +1 -1
  7. package/dist/commands/agents/mini-computer/tasks-view.js +1 -1
  8. package/dist/commands/apps/check.js +3 -8
  9. package/dist/commands/apps/data/batch.d.ts +1 -0
  10. package/dist/commands/apps/data/batch.js +19 -2
  11. package/dist/commands/apps/data/delete.d.ts +1 -0
  12. package/dist/commands/apps/data/delete.js +14 -2
  13. package/dist/commands/apps/data/patch.d.ts +1 -0
  14. package/dist/commands/apps/data/patch.js +11 -2
  15. package/dist/commands/apps/data/put.d.ts +1 -0
  16. package/dist/commands/apps/data/put.js +17 -3
  17. package/dist/commands/apps/install.js +7 -2
  18. package/dist/commands/apps/installations/compatibility.d.ts +13 -0
  19. package/dist/commands/apps/installations/compatibility.js +60 -0
  20. package/dist/commands/apps/installations/show.js +9 -3
  21. package/dist/commands/apps/installations/snapshot.js +5 -2
  22. package/dist/commands/apps/operations/check.d.ts +16 -0
  23. package/dist/commands/apps/operations/check.js +127 -0
  24. package/dist/commands/apps/publish/propose.js +33 -4
  25. package/dist/commands/apps/reconsent.js +7 -1
  26. package/dist/commands/apps/reference.d.ts +4 -2
  27. package/dist/commands/apps/reference.js +7 -4
  28. package/dist/commands/apps/rollback.d.ts +9 -0
  29. package/dist/commands/apps/rollback.js +81 -2
  30. package/dist/commands/apps/upgrade.d.ts +8 -0
  31. package/dist/commands/apps/upgrade.js +67 -2
  32. package/dist/commands/apps/version/cat.d.ts +22 -0
  33. package/dist/commands/apps/version/cat.js +220 -0
  34. package/dist/commands/apps/version/show.js +3 -1
  35. package/dist/commands/commerce/incidents/release.d.ts +24 -0
  36. package/dist/commands/commerce/incidents/release.js +46 -0
  37. package/dist/commands/duties/cases.js +12 -1
  38. package/dist/commands/duties/hypotheses.js +10 -3
  39. package/dist/commands/duties/observations.d.ts +4 -0
  40. package/dist/commands/duties/observations.js +14 -3
  41. package/dist/commands/outbox/list.d.ts +11 -4
  42. package/dist/commands/outbox/list.js +56 -9
  43. package/dist/commands/outbox/retry.d.ts +8 -2
  44. package/dist/commands/outbox/retry.js +76 -16
  45. package/dist/commands/outbox/show.d.ts +20 -0
  46. package/dist/commands/outbox/show.js +83 -0
  47. package/dist/commands/proposals/list.js +13 -9
  48. package/dist/commands/requests/show.d.ts +12 -0
  49. package/dist/commands/requests/show.js +42 -23
  50. package/dist/commands/spaces/deletion/cancel.d.ts +21 -0
  51. package/dist/commands/spaces/deletion/cancel.js +70 -0
  52. package/dist/commands/spaces/workflows/run.js +12 -0
  53. package/dist/commands/widgets/check.d.ts +9 -0
  54. package/dist/commands/widgets/check.js +16 -3
  55. package/dist/generated/agent-guides.json +17 -17
  56. package/dist/lib/api-fetch.d.ts +5 -0
  57. package/dist/lib/api-fetch.js +53 -21
  58. package/dist/lib/appCompatibility.d.ts +31 -0
  59. package/dist/lib/appCompatibility.js +66 -0
  60. package/dist/lib/appData.d.ts +46 -4
  61. package/dist/lib/appData.js +156 -31
  62. package/dist/lib/appInstallations.d.ts +32 -5
  63. package/dist/lib/appInstallations.js +197 -34
  64. package/dist/lib/appVersionFile.d.ts +82 -0
  65. package/dist/lib/appVersionFile.js +195 -0
  66. package/dist/lib/apps-command.d.ts +14 -3
  67. package/dist/lib/apps-command.js +68 -60
  68. package/dist/lib/appsCheck.js +16 -2
  69. package/dist/lib/commerce.d.ts +6 -0
  70. package/dist/lib/commerce.js +9 -0
  71. package/dist/lib/duties.d.ts +15 -1
  72. package/dist/lib/duties.js +21 -3
  73. package/dist/lib/json-output.d.ts +2 -0
  74. package/dist/lib/json-output.js +8 -4
  75. package/dist/lib/node-adapter.d.ts +2 -0
  76. package/dist/lib/node-adapter.js +35 -8
  77. package/dist/lib/outbox.d.ts +110 -1
  78. package/dist/lib/outbox.js +261 -35
  79. package/dist/lib/space-deletion-cancel.d.ts +47 -0
  80. package/dist/lib/space-deletion-cancel.js +141 -0
  81. package/dist/lib/widgetCheck.js +1 -1
  82. package/dist/lib/widgetStaticScan.d.ts +11 -5
  83. package/dist/lib/widgetStaticScan.js +73 -165
  84. package/dist/lib/write-outcome.d.ts +74 -0
  85. package/dist/lib/write-outcome.js +176 -0
  86. package/dist/node_modules/@skrr-ai/data-provider/index.js +11839 -11318
  87. package/oclif.manifest.json +1940 -16
  88. package/package.json +9 -3
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PAT_ROUTE_NOT_ALLOWED = exports.SPACE_LOOP_TEARDOWN_PENDING = exports.SPACE_MEMORY_DELETION_PENDING = exports.SPACE_DELETION_CANCELLATION_UNAVAILABLE = void 0;
4
+ exports.readDeletionCancelAnswer = readDeletionCancelAnswer;
5
+ exports.deletionCancelLines = deletionCancelLines;
6
+ exports.describeDeletionCancelRefusal = describeDeletionCancelRefusal;
7
+ /**
8
+ * `skrr spaces deletion cancel` (OSK-24060): the words for each answer of
9
+ * `POST /api/spaces/:spaceId/deletion-reservation/cancel`.
10
+ *
11
+ * The route is the Web's "stop deleting this Space" for a deletion that took a
12
+ * reservation. It is for a SIGNED-IN PERSON and nobody else: it is classified
13
+ * not-for-PAT in `personalAccessTokenRoutes.json`, so an automation token cannot
14
+ * undo a deletion a person ordered. The CLI's own credential after `skrr login`
15
+ * is a `scope: 'cli'` session JWT, which the route's `requireJwtAuth` accepts and
16
+ * `canAccessSpaceResource` then judges by the Space's DELETE permission.
17
+ *
18
+ * What the route answers, and what this module says for it:
19
+ *
20
+ * 200 { cancelled: true } the reservation was removed; the Space lives on
21
+ * 200 { cancelled: false } nothing was reserved; idempotent, NOT an error
22
+ * 403 PAT_* a personal access token was presented
23
+ * 403 no DELETE permission on the Space (relayed as is)
24
+ * 409 SPACE_MEMORY_DELETION_PENDING too late: memory clearing has begun
25
+ * 409 SPACE_LOOP_TEARDOWN_PENDING loop cleanup still running; retry
26
+ * 503 SPACE_DELETION_CANCELLATION_UNAVAILABLE the deployment has no reservations
27
+ *
28
+ * Kept out of the command so it can be tested without the command base class,
29
+ * and so the one wording for "nothing was pending" lives in one place.
30
+ */
31
+ const http_error_1 = require("./http-error");
32
+ /** The 503 code of a deployment that does not take deletion reservations. */
33
+ exports.SPACE_DELETION_CANCELLATION_UNAVAILABLE = 'SPACE_DELETION_CANCELLATION_UNAVAILABLE';
34
+ /** The server's reason a reservation can no longer be cancelled: memory clearing has begun. */
35
+ exports.SPACE_MEMORY_DELETION_PENDING = 'SPACE_MEMORY_DELETION_PENDING';
36
+ /** The server's reason a reservation cannot be cancelled yet: released loops are still being torn down. */
37
+ exports.SPACE_LOOP_TEARDOWN_PENDING = 'SPACE_LOOP_TEARDOWN_PENDING';
38
+ /** The code a not-for-PAT route answers a personal access token with. */
39
+ exports.PAT_ROUTE_NOT_ALLOWED = 'PAT_ROUTE_NOT_ALLOWED';
40
+ /**
41
+ * Read the route's 200 body, or `null` when it is not the shape the route sends.
42
+ *
43
+ * `null` is deliberate and the caller must fail on it: a body that does not say
44
+ * `cancelled` either way cannot be read as "cancelled" or as "nothing pending",
45
+ * and guessing either would tell a person their Space is safe (or not) on no
46
+ * evidence.
47
+ */
48
+ function readDeletionCancelAnswer(answer) {
49
+ if (!answer || typeof answer !== 'object')
50
+ return null;
51
+ const { cancelled, releasedLoopsRemainStopped } = answer;
52
+ if (typeof cancelled !== 'boolean')
53
+ return null;
54
+ return {
55
+ outcome: cancelled ? 'cancelled' : 'nothing_pending',
56
+ cancelled,
57
+ // The route always sends `true`. Absent is read as the route's own contract, not as "unknown":
58
+ // a released loop is never recreated by this call, so there is no state in which it is false.
59
+ releasedLoopsRemainStopped: releasedLoopsRemainStopped !== false,
60
+ };
61
+ }
62
+ /** The lines printed for a 200, so the human output and the tests share one set of words. */
63
+ function deletionCancelLines(answer, spaceRef, bin) {
64
+ if (!answer.cancelled) {
65
+ return [`No deletion is pending for space ${spaceRef}. Nothing was changed.`];
66
+ }
67
+ return [
68
+ `Cancelled the pending deletion of space ${spaceRef}. The space was not deleted.`,
69
+ 'Loops the deletion had already released stay stopped. Cancelling does not restart them; ' +
70
+ `resume each one you want running with \`${bin} duties resume <duty-id>\`.`,
71
+ ];
72
+ }
73
+ /** The code an error body carries, in either spelling the routes use (`code`, or upper-case `error`). */
74
+ function refusalCode(body) {
75
+ for (const key of ['code', 'error']) {
76
+ const value = body?.[key];
77
+ if (typeof value === 'string' && /^[A-Z][A-Z0-9_]+$/.test(value))
78
+ return value;
79
+ }
80
+ return undefined;
81
+ }
82
+ /**
83
+ * The refusal to print for a failed cancel, or `null` when the standard API error handler already
84
+ * says it well (404, 401, a plain permission 403, a real outage).
85
+ *
86
+ * The server's own 403 for a personal access token is accurate but stops at "Sign in to do this",
87
+ * and for a token held in `SKRR_TOKEN` that is not enough: the environment outranks the stored
88
+ * sign-in, so `skrr login` alone changes nothing until the variable is gone. The token is
89
+ * recognised by the server's `PAT_*` code, never by guessing from the credential: a PAT is judged
90
+ * by the route policy before anything else, so every 403 it meets here carries one.
91
+ */
92
+ function describeDeletionCancelRefusal(err, context) {
93
+ const status = (0, http_error_1.httpStatusOf)(err);
94
+ const code = refusalCode((0, http_error_1.httpBodyOf)(err));
95
+ const { spaceRef, bin } = context;
96
+ if (status === 503 && code === exports.SPACE_DELETION_CANCELLATION_UNAVAILABLE) {
97
+ return {
98
+ message: 'Cancelling a Space deletion is not enabled on this server, so there is no pending ' +
99
+ 'deletion to cancel and nothing was changed. This is a deployment setting rather than a ' +
100
+ 'fault, so retrying will not change it.',
101
+ code: exports.SPACE_DELETION_CANCELLATION_UNAVAILABLE,
102
+ status,
103
+ exit: 1,
104
+ retryable: false,
105
+ };
106
+ }
107
+ if (status === 403 && code?.startsWith('PAT_')) {
108
+ return {
109
+ message: 'An access token cannot cancel a Space deletion: only a signed-in person can undo a ' +
110
+ 'deletion. Nothing was changed.\n' +
111
+ `→ Unset SKRR_TOKEN and OVERSKY_TOKEN, then sign in with \`${bin} login\` and run this again.`,
112
+ code: code ?? exports.PAT_ROUTE_NOT_ALLOWED,
113
+ status,
114
+ exit: 3,
115
+ retryable: false,
116
+ };
117
+ }
118
+ if (status === 409 && code === exports.SPACE_MEMORY_DELETION_PENDING) {
119
+ return {
120
+ message: `Space ${spaceRef} can no longer be cancelled: its deletion has already started clearing ` +
121
+ 'the space’s memory. Nothing was changed.\n' +
122
+ `→ Finish the deletion with \`${bin} spaces delete ${spaceRef}\`.`,
123
+ code,
124
+ status,
125
+ exit: 1,
126
+ retryable: false,
127
+ };
128
+ }
129
+ if (status === 409 && code === exports.SPACE_LOOP_TEARDOWN_PENDING) {
130
+ return {
131
+ message: `Space ${spaceRef} cannot be cancelled yet: loops its deletion released are still being ` +
132
+ 'stopped. Nothing was changed.\n' +
133
+ `→ Run \`${bin} spaces deletion cancel ${spaceRef}\` again in a few minutes.`,
134
+ code,
135
+ status,
136
+ exit: 1,
137
+ retryable: true,
138
+ };
139
+ }
140
+ return null;
141
+ }
@@ -265,7 +265,7 @@ function contentIssues(parts) {
265
265
  source: 'static',
266
266
  code: 'static/template-script-unchecked',
267
267
  section: 'html',
268
- message: 'Scripts in templates do not run at initial load; if widget code activates them later, their syntax and static findings have not been checked.',
268
+ message: 'Scripts and event handlers in templates do not run at initial load; if widget code activates them later, their syntax and static findings have not been checked.',
269
269
  heuristic: true,
270
270
  });
271
271
  }
@@ -21,8 +21,10 @@
21
21
  * calls and names run over the code view only, so `"eval( is blocked"` in a label and
22
22
  * a comment that says "do not call fetch()" are not findings, and the rules about
23
23
  * what a string SAYS (a URL, markup that loads one) run over the literals only. No
24
- * regular expression here can backtrack on the size the widget limits allow, and
25
- * HTML is walked with `indexOf`, not with a lazy regex.
24
+ * regular expression here can backtrack on the size the widget limits allow. HTML is
25
+ * not tokenized here at all: the elements come from the shared parser pass
26
+ * (`analyzeAppHtml`), the one a browser would make, so that this scan and the parser
27
+ * cannot disagree about where a comment ends or what a `<noscript>` holds.
26
28
  *
27
29
  * The eval's static checks (`api/.../eval/generativeUi/staticChecks.js`) ask most
28
30
  * of the same questions with a lexer of their own (`sourceLexers.js`), because this
@@ -60,7 +62,13 @@ export interface StaticScanResult {
60
62
  inlineScripts: InlineScript[];
61
63
  /** Inline module bodies, separately so classic-only widget syntax checks remain unchanged. */
62
64
  inlineModules: InlineScript[];
63
- /** False when template-contained script could be activated later by app code. */
65
+ /**
66
+ * Inline event attributes (`onclick="..."`) and `javascript:` addresses: code the frame runs with no `<script>`
67
+ * (its policy allows inline script). Scanned with the same rules as a script and handed back for the caller's
68
+ * own readers (the capability scan), but never for a syntax check: a handler's body is not a script.
69
+ */
70
+ inlineHandlers: InlineScript[];
71
+ /** False when template-contained script or a handler could be activated later by app code. */
64
72
  inlineCoverageComplete: boolean;
65
73
  }
66
74
  export interface WidgetSource {
@@ -107,8 +115,6 @@ export declare function lexJs(src: string): LexedJs;
107
115
  export declare function maskJsComments(src: string): string;
108
116
  /** Blank the block comments of CSS, stepping over quoted strings. */
109
117
  export declare function maskCssComments(src: string): string;
110
- /** Blank `<!-- … -->` comments of HTML. */
111
- export declare function maskHtmlComments(src: string): string;
112
118
  type UrlKind = 'external' | 'inline' | 'relative' | 'empty';
113
119
  /** A URL the frame cannot fetch from, a self-contained one, or one with no base to resolve against. */
114
120
  export declare function classifyUrl(raw: string): UrlKind;
@@ -4,7 +4,6 @@ exports.checkModuleSyntax = checkModuleSyntax;
4
4
  exports.lexJs = lexJs;
5
5
  exports.maskJsComments = maskJsComments;
6
6
  exports.maskCssComments = maskCssComments;
7
- exports.maskHtmlComments = maskHtmlComments;
8
7
  exports.classifyUrl = classifyUrl;
9
8
  exports.scanWidgetSource = scanWidgetSource;
10
9
  /**
@@ -30,8 +29,10 @@ exports.scanWidgetSource = scanWidgetSource;
30
29
  * calls and names run over the code view only, so `"eval( is blocked"` in a label and
31
30
  * a comment that says "do not call fetch()" are not findings, and the rules about
32
31
  * what a string SAYS (a URL, markup that loads one) run over the literals only. No
33
- * regular expression here can backtrack on the size the widget limits allow, and
34
- * HTML is walked with `indexOf`, not with a lazy regex.
32
+ * regular expression here can backtrack on the size the widget limits allow. HTML is
33
+ * not tokenized here at all: the elements come from the shared parser pass
34
+ * (`analyzeAppHtml`), the one a browser would make, so that this scan and the parser
35
+ * cannot disagree about where a comment ends or what a `<noscript>` holds.
35
36
  *
36
37
  * The eval's static checks (`api/.../eval/generativeUi/staticChecks.js`) ask most
37
38
  * of the same questions with a lexer of their own (`sourceLexers.js`), because this
@@ -39,7 +40,6 @@ exports.scanWidgetSource = scanWidgetSource;
39
40
  * both over one corpus and fails when they disagree about what the frame refuses.
40
41
  */
41
42
  const data_provider_1 = require("@skrr-ai/data-provider");
42
- const entities_1 = require("entities");
43
43
  const decode_1 = require("entities/decode");
44
44
  const acorn_1 = require("acorn");
45
45
  /** Parse as an actual ECMAScript module without executing author code. */
@@ -68,7 +68,11 @@ const BROKER_FETCH_OFFSETS_RE = /\s/;
68
68
  const SCAN_JS_INTO_RE = /\bopenLink\b/;
69
69
  const SCAN_JS_INTO_RE_2 = /<\/script(?=[\t\n\f\r />])/i;
70
70
  const SRCSET_SPACE_RE = /[\t\n\f\r ]/;
71
- const TEMPLATE_CONDITION = 'If this template content is inserted into the page: ';
71
+ /** What a finding in markup the page does not show at first load says about when it would matter. */
72
+ const DORMANT_CONDITION = {
73
+ template: 'If this template content is inserted into the page: ',
74
+ noscript: 'If this <noscript> fallback is shown (scripting off): ',
75
+ };
72
76
  const OPEN_LINK = 'window.skrr.openLink(url)';
73
77
  // ── small text helpers ──────────────────────────────────────────────────────
74
78
  /** ASCII-only lowercase: the same length as the input, so offsets stay valid. */
@@ -115,9 +119,6 @@ function lineAt(starts, index) {
115
119
  function isSpace(c) {
116
120
  return c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
117
121
  }
118
- function isAsciiLetter(c) {
119
- return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
120
- }
121
122
  // ── comment masking ─────────────────────────────────────────────────────────
122
123
  /** Replace `from..to` with spaces, keeping line breaks so line numbers stay valid. */
123
124
  function blank(chars, from, to, javascript = false) {
@@ -338,18 +339,6 @@ function maskCssComments(src) {
338
339
  }
339
340
  return chars.join('');
340
341
  }
341
- /** Blank `<!-- … -->` comments of HTML. */
342
- function maskHtmlComments(src) {
343
- const chars = src.split('');
344
- let i = src.indexOf('<!--');
345
- while (i !== -1) {
346
- const end = src.indexOf('-->', i + 4);
347
- const to = end === -1 ? src.length : end + 3;
348
- blank(chars, i, to);
349
- i = src.indexOf('<!--', to);
350
- }
351
- return chars.join('');
352
- }
353
342
  /** A URL the frame cannot fetch from, a self-contained one, or one with no base to resolve against. */
354
343
  function classifyUrl(raw) {
355
344
  const value = raw.trim();
@@ -672,115 +661,19 @@ function scanJsInto(source, baseLine, out, parsedFromHtml = false, sourceLines,
672
661
  addAt('warn', 'element-close', at, 'The text contains a closing script tag, which can end the script early depending on how the frame embeds it.', 'Write it as <\\/script> inside a string.');
673
662
  }
674
663
  }
675
- const RAW_TEXT_ELEMENTS = new Set(['script', 'style', 'textarea', 'title']);
676
- function attr(tag, name) {
677
- for (const a of tag.attrs) {
664
+ // ── HTML ────────────────────────────────────────────────────────────────────
665
+ /** The attribute of that name, as the parser read it. A name that repeats keeps its first, as the browser does. */
666
+ function attr(element, name) {
667
+ for (const a of element.attributes) {
678
668
  if (a.name === name) {
679
- return a.value;
669
+ return a;
680
670
  }
681
671
  }
682
672
  return undefined;
683
673
  }
684
- /** Walk markup for best-effort resource and style heuristics. */
685
- function walkHtml(html, scriptEnds) {
686
- const lower = asciiLower(html);
687
- const tags = [];
688
- const raws = [];
689
- const n = html.length;
690
- let i = 0;
691
- while (i < n) {
692
- const lt = html.indexOf('<', i);
693
- if (lt === -1) {
694
- break;
695
- }
696
- const next = html.charCodeAt(lt + 1);
697
- if (html.startsWith('<!--', lt)) {
698
- const end = html.indexOf('-->', lt + 4);
699
- i = end === -1 ? n : end + 3;
700
- continue;
701
- }
702
- if (next === 33 || next === 63 || next === 47) {
703
- const end = html.indexOf('>', lt + 2);
704
- i = end === -1 ? n : end + 1;
705
- continue;
706
- }
707
- if (!isAsciiLetter(next)) {
708
- i = lt + 1;
709
- continue;
710
- }
711
- let p = lt + 1;
712
- while (p < n && !isSpace(html.charCodeAt(p)) && html[p] !== '>' && html[p] !== '/') {
713
- p += 1;
714
- }
715
- const tag = { name: lower.slice(lt + 1, p), index: lt, attrs: [] };
716
- while (p < n) {
717
- while (p < n && (isSpace(html.charCodeAt(p)) || html[p] === '/')) {
718
- p += 1;
719
- }
720
- if (p >= n) {
721
- break;
722
- }
723
- if (html[p] === '>') {
724
- p += 1;
725
- break;
726
- }
727
- const nameStart = p;
728
- while (p < n && !isSpace(html.charCodeAt(p)) && !'=>/'.includes(html.charAt(p))) {
729
- p += 1;
730
- }
731
- const name = lower.slice(nameStart, p);
732
- while (p < n && isSpace(html.charCodeAt(p))) {
733
- p += 1;
734
- }
735
- let value = '';
736
- if (html[p] === '=') {
737
- p += 1;
738
- while (p < n && isSpace(html.charCodeAt(p))) {
739
- p += 1;
740
- }
741
- const quote = html.charAt(p);
742
- if (quote === '"' || quote === "'") {
743
- const end = html.indexOf(quote, p + 1);
744
- value = html.slice(p + 1, end === -1 ? n : end);
745
- p = end === -1 ? n : end + 1;
746
- }
747
- else {
748
- const valueStart = p;
749
- while (p < n && !isSpace(html.charCodeAt(p)) && html[p] !== '>') {
750
- p += 1;
751
- }
752
- value = html.slice(valueStart, p);
753
- }
754
- }
755
- if (name) {
756
- tag.attrs.push({ name, value });
757
- }
758
- else if (p === nameStart) {
759
- p += 1;
760
- }
761
- }
762
- tags.push(tag);
763
- i = p;
764
- if (RAW_TEXT_ELEMENTS.has(tag.name)) {
765
- const endTag = `</${tag.name}`;
766
- let close = lower.indexOf(endTag, p);
767
- while (close !== -1) {
768
- const boundary = lower.charAt(close + endTag.length);
769
- if (boundary === '>' || boundary === '/' || isSpace(boundary.charCodeAt(0)))
770
- break;
771
- close = lower.indexOf(endTag, close + endTag.length);
772
- }
773
- // The browser's script-data tokenizer, unlike a substring search, keeps
774
- // </script> inside double-escaped content. Avoid inventing tags there.
775
- const parsedEnd = tag.name === 'script' ? scriptEnds.get(tag.index) : undefined;
776
- // An offset from the parser is only an end if it is not before the text it ends: `end < p` would put `i` before this
777
- // tag again and the walk would revisit it forever (one unclosed `<script>` used to exhaust the heap that way).
778
- const end = parsedEnd !== undefined && parsedEnd >= p ? parsedEnd : close === -1 ? n : close;
779
- raws.push({ tag, content: html.slice(p, end), contentIndex: p });
780
- i = end;
781
- }
782
- }
783
- return { tags, raws };
674
+ /** What the browser holds for an attribute: the parser has already decoded its character references. */
675
+ function attrValue(element, name) {
676
+ return attr(element, name)?.value;
784
677
  }
785
678
  const RESOURCE_ATTRIBUTES = ['src', 'srcset', 'poster', 'data', 'background', 'xlink:href', 'href'];
786
679
  /** Decode once in HTML attribute mode and retain the raw source of every UTF-16 unit. */
@@ -862,21 +755,21 @@ function srcsetUrls(value) {
862
755
  return urls;
863
756
  }
864
757
  const STYLESHEET_LIKE_REL = /\b(?:stylesheet|preload|modulepreload|prefetch|icon|manifest)\b/i;
865
- function scanTag(tag, line, out, allowAppLocalReferences) {
866
- const name = tag.name;
758
+ function scanTag(element, line, out, allowAppLocalReferences) {
759
+ const name = element.tagName;
867
760
  if (name === 'base') {
868
761
  out.add('error', 'base-element', line, 'The base element is blocked: base-uri is none in the frame.', 'Remove it; use absolute data: URIs or none at all.');
869
762
  return;
870
763
  }
871
764
  if (name === 'meta') {
872
- const equiv = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'http-equiv') ?? '')).trim();
765
+ const equiv = asciiLower(attrValue(element, 'http-equiv') ?? '').trim();
873
766
  if (equiv === 'refresh') {
874
767
  out.add('error', 'navigation', line, 'A meta refresh navigates the frame itself: the host allows one load and removes the widget on the second.', 'Remove it; update the page with script instead.');
875
768
  }
876
769
  return;
877
770
  }
878
771
  if (name === 'form') {
879
- const action = attr(tag, 'action');
772
+ const action = attrValue(element, 'action');
880
773
  if (action !== undefined && action.trim() !== '') {
881
774
  out.add('error', 'form-action', line, 'A form with an action: form-action is none in the frame, so submitting is blocked.', 'Drop the action and handle the input and change events in script.');
882
775
  }
@@ -886,33 +779,32 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
886
779
  return;
887
780
  }
888
781
  if (name === 'iframe' || name === 'frame') {
889
- const src = (0, entities_1.decodeHTMLAttribute)(attr(tag, 'src') ?? '');
782
+ const src = attrValue(element, 'src') ?? '';
890
783
  const external = classifyUrl(src) === 'external';
891
784
  out.add(external ? 'error' : 'warn', 'nested-frame', line, external
892
785
  ? `<${name}> of a URL: frame-src is none in the frame, so it is blocked.`
893
786
  : `<${name}>: frame-src is none in the frame; nested frames are not supported.`, 'Render the content directly in this widget.');
894
787
  return;
895
788
  }
896
- const formaction = attr(tag, 'formaction');
789
+ const formaction = attrValue(element, 'formaction');
897
790
  if (formaction !== undefined && formaction.trim() !== '') {
898
791
  out.add('error', 'form-action', line, 'formaction: form-action is none in the frame, so submitting is blocked.', 'Handle the click in script.');
899
792
  }
900
793
  if (name === 'a' || name === 'area') {
901
- const rawHref = attr(tag, 'href');
902
- const href = rawHref === undefined ? undefined : (0, entities_1.decodeHTMLAttribute)(rawHref);
794
+ const href = attrValue(element, 'href');
903
795
  if (href !== undefined && classifyUrl(href) === 'external') {
904
796
  out.add('warn', 'external-link', line, 'A link to a URL: following it would navigate the frame itself, and the host removes the widget on that second load.', `Use a button that calls ${OPEN_LINK}.`);
905
797
  }
906
- const target = asciiLower((0, entities_1.decodeHTMLAttribute)(attr(tag, 'target') ?? '')).trim();
798
+ const target = asciiLower(attrValue(element, 'target') ?? '').trim();
907
799
  if (target === '_blank' || target === '_top' || target === '_parent') {
908
800
  out.add('warn', 'popup', line, `target="${target}": the sandbox has no allow-popups or top navigation, so nothing opens.`, `Use ${OPEN_LINK}.`);
909
801
  }
910
802
  return;
911
803
  }
912
- const rel = (0, entities_1.decodeHTMLAttribute)(attr(tag, 'rel') ?? '');
804
+ const rel = attrValue(element, 'rel') ?? '';
913
805
  for (const attribute of RESOURCE_ATTRIBUTES) {
914
- const value = attr(tag, attribute);
915
- if (value === undefined) {
806
+ const found = attr(element, attribute);
807
+ if (found === undefined) {
916
808
  continue;
917
809
  }
918
810
  if (attribute === 'href' && name === 'link' && !STYLESHEET_LIKE_REL.test(rel)) {
@@ -921,17 +813,21 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
921
813
  if (attribute === 'data' && name !== 'object') {
922
814
  continue;
923
815
  }
924
- // HTML decodes character references before interpreting resource URLs. Only
925
- // exempt literal app references: the package resolver reads the raw source
926
- // and cannot promise to replace a reference written using entities.
927
- const decoded = decodedAttribute(value);
928
- const trimmed = decoded.text.trim();
929
- const leading = decoded.text.length - decoded.text.trimStart().length;
816
+ // HTML decodes character references before interpreting resource URLs, and the parser has: `found.value` is the
817
+ // address the browser resolves. Only exempt literal app references: the package resolver reads the raw source
818
+ // and cannot promise to replace a reference written using entities. `decodedAttribute` maps the decoded text back
819
+ // to the source for that and is trusted for nothing else: when it does not give back the parser's text, no
820
+ // exemption applies.
821
+ const decoded = decodedAttribute(found.raw);
822
+ const literal = decoded.text === found.value;
823
+ const text = found.value;
824
+ const trimmed = text.trim();
825
+ const leading = text.length - text.trimStart().length;
930
826
  const candidates = attribute === 'srcset'
931
- ? srcsetUrls(decoded.text)
827
+ ? srcsetUrls(text)
932
828
  : [{ url: trimmed, start: leading, end: leading + trimmed.length }];
933
829
  for (const { url, start, end } of candidates) {
934
- const raw = end > start ? value.slice(decoded.starts[start], decoded.ends[end - 1]) : '';
830
+ const raw = literal && end > start ? found.raw.slice(decoded.starts[start], decoded.ends[end - 1]) : '';
935
831
  const kind = isAppLocalReference(url, allowAppLocalReferences && raw === url)
936
832
  ? 'inline'
937
833
  : classifyUrl(url);
@@ -946,20 +842,20 @@ function scanTag(tag, line, out, allowAppLocalReferences) {
946
842
  }
947
843
  function scanHtmlInto(html, out, allowAppLocalReferences) {
948
844
  const starts = lineStarts(html);
949
- // walkHtml skips real markup comments while preserving script/style raw text;
950
- // globally masking comments would erase `<!--` inside JavaScript strings.
845
+ // Every element, script, style and handler below comes from this one parse, which reads comments, raw text and
846
+ // attribute values the way a browser does. There is no second tokenizer here to disagree with it, and a parse that
847
+ // cannot finish throws: the caller reports an incomplete scan, never a clean one.
951
848
  const parsed = (0, data_provider_1.analyzeAppHtml)(html);
952
849
  const parsedScripts = parsed.scripts;
953
- const activeElements = new Map(parsed.elements.map((element) => [element.start, element.active]));
954
- const { tags, raws } = walkHtml(html, new Map(parsedScripts.map((script) => [script.start, script.end])));
955
850
  const inlineScripts = [];
956
851
  const inlineModules = [];
852
+ const inlineHandlers = [];
957
853
  let inlineCoverageComplete = true;
958
854
  // Defer dormant findings so an active finding on the same line and with the
959
855
  // same code wins deduplication even when both have warning severity.
960
856
  const conditionalFindings = [];
961
- const scanMarkupPart = (active, scan) => {
962
- if (active) {
857
+ const scanMarkupPart = (dormant, scan) => {
858
+ if (dormant === null) {
963
859
  scan(out);
964
860
  return;
965
861
  }
@@ -969,26 +865,26 @@ function scanHtmlInto(html, out, allowAppLocalReferences) {
969
865
  conditionalFindings.push({
970
866
  ...finding,
971
867
  severity: 'warn',
972
- message: `${TEMPLATE_CONDITION}${finding.message}`,
868
+ message: `${DORMANT_CONDITION[dormant]}${finding.message}`,
973
869
  });
974
870
  }
975
871
  };
976
- for (const tag of tags) {
977
- scanMarkupPart(activeElements.get(tag.index) !== false, (collector) => {
978
- scanTag(tag, lineAt(starts, tag.index), collector, allowAppLocalReferences);
979
- const style = attr(tag, 'style');
872
+ for (const element of parsed.elements) {
873
+ scanMarkupPart(element.dormant, (collector) => {
874
+ const line = lineAt(starts, element.start);
875
+ scanTag(element, line, collector, allowAppLocalReferences);
876
+ const style = attrValue(element, 'style');
980
877
  if (style)
981
- scanCssInto(style, lineAt(starts, tag.index), collector, allowAppLocalReferences);
878
+ scanCssInto(style, line, collector, allowAppLocalReferences);
982
879
  });
983
880
  }
984
- for (const raw of raws) {
985
- const line = lineAt(starts, raw.contentIndex);
986
- if (raw.tag.name === 'style') {
987
- scanMarkupPart(activeElements.get(raw.tag.index) !== false, (collector) => scanCssInto(raw.content, line, collector, allowAppLocalReferences));
988
- }
881
+ for (const element of parsed.elements) {
882
+ const text = element.text;
883
+ if (text === undefined)
884
+ continue;
885
+ scanMarkupPart(element.dormant, (collector) => scanCssInto(text.content, lineAt(starts, text.offset), collector, allowAppLocalReferences));
989
886
  }
990
- // Script content must come from the HTML tokenizer, not the heuristic walker:
991
- // a literal </script> can occur in script-data's double-escaped state.
887
+ // Script content comes from the same parse: a literal </script> can occur in script-data's double-escaped state.
992
888
  for (const script of parsedScripts) {
993
889
  // A foreign attribute such as xlink:type is not the DOM's "type" attribute.
994
890
  const get = (name) => script.attributes.find((a) => a.name === name && !a.prefix && !a.namespace)?.value;
@@ -1022,10 +918,21 @@ function scanHtmlInto(html, out, allowAppLocalReferences) {
1022
918
  sourceLines: script.sourceLines,
1023
919
  });
1024
920
  }
921
+ // Inline event attributes and javascript: addresses come from the same parse as the scripts, so the two agree on what
922
+ // is markup. The frame's policy allows inline script, and these are inline script.
923
+ for (const handler of parsed.handlers) {
924
+ if (!handler.active) {
925
+ inlineCoverageComplete = false;
926
+ continue;
927
+ }
928
+ const line = handler.sourceLines[0];
929
+ scanJsInto(handler.content, line, out, true, handler.sourceLines, handler.offset);
930
+ inlineHandlers.push({ content: handler.content, line, sourceLines: handler.sourceLines });
931
+ }
1025
932
  for (const finding of conditionalFindings) {
1026
933
  out.add(finding.severity, finding.code, finding.line, finding.message, finding.fix, true);
1027
934
  }
1028
- return { inlineScripts, inlineModules, inlineCoverageComplete };
935
+ return { inlineScripts, inlineModules, inlineHandlers, inlineCoverageComplete };
1029
936
  }
1030
937
  // ── entry point ─────────────────────────────────────────────────────────────
1031
938
  /** Findings per (section, code) before the rest collapse into one line. */
@@ -1100,12 +1007,13 @@ function scanWidgetSource(source, options = {}) {
1100
1007
  const js = new Collector('js');
1101
1008
  const allowAppLocalReferences = options.allowAppLocalReferences === true;
1102
1009
  scanCssInto(source.css, 1, css, allowAppLocalReferences);
1103
- const { inlineScripts, inlineModules, inlineCoverageComplete } = scanHtmlInto(source.html, html, allowAppLocalReferences);
1010
+ const { inlineScripts, inlineModules, inlineHandlers, inlineCoverageComplete } = scanHtmlInto(source.html, html, allowAppLocalReferences);
1104
1011
  scanJsInto(source.js, 1, js);
1105
1012
  return {
1106
1013
  findings: tidy([...css.findings, ...html.findings, ...js.findings]),
1107
1014
  inlineScripts,
1108
1015
  inlineModules,
1016
+ inlineHandlers,
1109
1017
  inlineCoverageComplete,
1110
1018
  };
1111
1019
  }