@yunhozz/arc 0.0.0-stage → 0.1.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.
Files changed (125) hide show
  1. package/MANIFEST.sha256 +96 -0
  2. package/README.md +265 -2
  3. package/bin/arc.mjs +3 -0
  4. package/claude/agents/arc-coder.md +67 -0
  5. package/claude/agents/arc-planner.md +74 -0
  6. package/claude/agents/arc-qa.md +68 -0
  7. package/claude/agents/arc-reviewer.md +65 -0
  8. package/claude/agents/arc-scouter.md +63 -0
  9. package/claude/skill/SKILL.md +370 -0
  10. package/claude/skill/hooks/git-policy.json +208 -0
  11. package/claude/skill/hooks/role-git-guard.mjs +98 -0
  12. package/claude/skill/models.toml +64 -0
  13. package/claude/skill/references/commit.md +77 -0
  14. package/claude/skill/references/git-recovery.md +46 -0
  15. package/claude/skill/references/handoff-prep.md +102 -0
  16. package/claude/skill/references/handoff.md +100 -0
  17. package/claude/skill/references/limits.md +42 -0
  18. package/claude/skill/references/planning.md +250 -0
  19. package/claude/skill/references/superpowers/LICENSE +21 -0
  20. package/claude/skill/references/superpowers/brainstorming/SKILL.md +225 -0
  21. package/claude/skill/references/superpowers/brainstorming/builder-check-prompt.md +23 -0
  22. package/claude/skill/references/superpowers/brainstorming/scripts/frame-template.html +213 -0
  23. package/claude/skill/references/superpowers/brainstorming/scripts/helper.js +167 -0
  24. package/claude/skill/references/superpowers/brainstorming/scripts/server.cjs +723 -0
  25. package/claude/skill/references/superpowers/brainstorming/scripts/start-server.sh +209 -0
  26. package/claude/skill/references/superpowers/brainstorming/scripts/stop-server.sh +120 -0
  27. package/claude/skill/references/superpowers/brainstorming/visual-companion.md +299 -0
  28. package/claude/skill/references/superpowers/provenance.json +26 -0
  29. package/claude/skill/references/superpowers/test-driven-development/SKILL.md +330 -0
  30. package/claude/skill/references/superpowers/test-driven-development/writing-good-tests.md +198 -0
  31. package/claude/skill/references/superpowers/writing-plans/SKILL.md +204 -0
  32. package/claude/skill/references/verification.md +125 -0
  33. package/claude/skill/references/visual-companion.md +16 -0
  34. package/claude/skill/scripts/apply-models.py +31 -0
  35. package/claude/skill/scripts/model_config.py +211 -0
  36. package/codex/agents/arc-coder.toml +37 -0
  37. package/codex/agents/arc-planner.toml +38 -0
  38. package/codex/agents/arc-qa.toml +24 -0
  39. package/codex/agents/arc-reviewer.toml +25 -0
  40. package/codex/agents/arc-scouter.toml +37 -0
  41. package/codex/skill/SKILL.md +356 -0
  42. package/codex/skill/models.toml +64 -0
  43. package/codex/skill/references/commit.md +100 -0
  44. package/codex/skill/references/git-recovery.md +64 -0
  45. package/codex/skill/references/handoff-prep.md +153 -0
  46. package/codex/skill/references/handoff-worktree.md +93 -0
  47. package/codex/skill/references/handoff.md +181 -0
  48. package/codex/skill/references/limits.md +43 -0
  49. package/codex/skill/references/planning.md +287 -0
  50. package/codex/skill/references/superpowers/LICENSE +21 -0
  51. package/codex/skill/references/superpowers/brainstorming/SKILL.md +225 -0
  52. package/codex/skill/references/superpowers/brainstorming/builder-check-prompt.md +23 -0
  53. package/codex/skill/references/superpowers/brainstorming/scripts/frame-template.html +213 -0
  54. package/codex/skill/references/superpowers/brainstorming/scripts/helper.js +167 -0
  55. package/codex/skill/references/superpowers/brainstorming/scripts/server.cjs +723 -0
  56. package/codex/skill/references/superpowers/brainstorming/scripts/start-server.sh +209 -0
  57. package/codex/skill/references/superpowers/brainstorming/scripts/stop-server.sh +120 -0
  58. package/codex/skill/references/superpowers/brainstorming/visual-companion.md +299 -0
  59. package/codex/skill/references/superpowers/provenance.json +26 -0
  60. package/codex/skill/references/superpowers/test-driven-development/SKILL.md +330 -0
  61. package/codex/skill/references/superpowers/test-driven-development/writing-good-tests.md +198 -0
  62. package/codex/skill/references/superpowers/writing-plans/SKILL.md +204 -0
  63. package/codex/skill/references/verification.md +163 -0
  64. package/codex/skill/references/visual-companion.md +23 -0
  65. package/codex/skill/scripts/apply-models.py +207 -0
  66. package/codex/skill/scripts/model_config.py +362 -0
  67. package/install.command +5 -0
  68. package/lib/cli/choices.mjs +47 -0
  69. package/lib/cli/completion.mjs +53 -0
  70. package/lib/cli/index.mjs +55 -0
  71. package/lib/cli/preset.mjs +29 -0
  72. package/lib/cli/progress.mjs +10 -0
  73. package/lib/cli/root.mjs +20 -0
  74. package/lib/cli/uninstall.mjs +17 -0
  75. package/lib/installer/acquisition.mjs +77 -0
  76. package/lib/installer/global-config.mjs +43 -0
  77. package/lib/installer/install.mjs +28 -0
  78. package/lib/installer/language.mjs +13 -0
  79. package/lib/installer/limits.mjs +21 -0
  80. package/lib/installer/manifest.mjs +37 -0
  81. package/lib/installer/package-references.mjs +32 -0
  82. package/lib/installer/plan.mjs +62 -0
  83. package/lib/installer/preset.mjs +26 -0
  84. package/lib/installer/runtime-config.mjs +85 -0
  85. package/lib/installer/shell-completion.mjs +29 -0
  86. package/lib/installer/stage-cleanup.mjs +40 -0
  87. package/lib/installer/superpowers.mjs +113 -0
  88. package/lib/installer/targets.mjs +55 -0
  89. package/lib/installer/transaction.mjs +91 -0
  90. package/lib/installer/uninstall.mjs +32 -0
  91. package/lib/limits.mjs +13 -0
  92. package/lib/models/config.mjs +58 -0
  93. package/lib/models/index.mjs +2 -0
  94. package/lib/models/profiles.mjs +111 -0
  95. package/lib/policy/claude-hook.mjs +40 -0
  96. package/lib/policy/render.mjs +74 -0
  97. package/lib/policy/role-policy.json +577 -0
  98. package/lib/safe-fs/index.mjs +67 -0
  99. package/lib/safe-fs/native.mjs +54 -0
  100. package/native/binding.c +157 -0
  101. package/native/binding.gyp +1 -0
  102. package/package.json +43 -4
  103. package/prebuilds/darwin-arm64/arc_safe_fs.node +0 -0
  104. package/prebuilds/darwin-x64/arc_safe_fs.node +0 -0
  105. package/prebuilds/index.json +64 -0
  106. package/prebuilds/linux-arm64-gnu/arc_safe_fs.node +0 -0
  107. package/prebuilds/linux-x64-gnu/arc_safe_fs.node +0 -0
  108. package/scripts/build-native.mjs +36 -0
  109. package/scripts/check-installer-parity.mjs +59 -0
  110. package/scripts/update-manifest.mjs +28 -0
  111. package/scripts/update-role-policy.mjs +15 -0
  112. package/scripts/update-superpowers.mjs +4 -0
  113. package/scripts/vendor-toml.mjs +40 -0
  114. package/vendor/toml/LICENSE +24 -0
  115. package/vendor/toml/dist/date.js +156 -0
  116. package/vendor/toml/dist/error.js +67 -0
  117. package/vendor/toml/dist/extract.js +293 -0
  118. package/vendor/toml/dist/index.js +34 -0
  119. package/vendor/toml/dist/parse.js +164 -0
  120. package/vendor/toml/dist/primitive.js +151 -0
  121. package/vendor/toml/dist/stringify.js +219 -0
  122. package/vendor/toml/dist/struct.js +156 -0
  123. package/vendor/toml/dist/util.js +57 -0
  124. package/vendor/toml/package.json +6 -0
  125. package/vendor/toml/provenance.json +35 -0
@@ -0,0 +1,164 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { parseKey } from './struct.js';
29
+ import { extractValue } from './extract.js';
30
+ import { skipVoid } from './util.js';
31
+ import { TomlError } from './error.js';
32
+ function peekTable(ctx, key, table, meta, type) {
33
+ let t = table;
34
+ let m = meta;
35
+ let k;
36
+ let hasOwn = false;
37
+ let state;
38
+ for (let i = 0; i < key.length; i++) {
39
+ if (i) {
40
+ t = hasOwn ? t[k] : (t[k] = Object.create(null));
41
+ m = (state = m[k]).c;
42
+ if (type === 0 /* Type.DOTTED */ && (state.t === 1 /* Type.EXPLICIT */ || state.t === 2 /* Type.ARRAY */)) {
43
+ return null;
44
+ }
45
+ if (state.t === 2 /* Type.ARRAY */) {
46
+ let l = t.length - 1;
47
+ t = t[l];
48
+ m = m[l].c;
49
+ }
50
+ }
51
+ k = key[i];
52
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 /* Type.DOTTED */ && m[k]?.d) {
53
+ return null;
54
+ }
55
+ if (!hasOwn) {
56
+ let unsafe = k === '__proto__';
57
+ if (ctx.uk && (unsafe || k === 'constructor'))
58
+ return false;
59
+ if (unsafe) {
60
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
61
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
62
+ }
63
+ m[k] = {
64
+ t: i < key.length - 1 && type === 2 /* Type.ARRAY */
65
+ ? 3 /* Type.ARRAY_DOTTED */ : type,
66
+ d: false,
67
+ i: 0,
68
+ c: Object.create(null),
69
+ };
70
+ }
71
+ }
72
+ state = m[k];
73
+ if (state.t !== type && !(type === 1 /* Type.EXPLICIT */ && state.t === 3 /* Type.ARRAY_DOTTED */)) {
74
+ // Bad key type!
75
+ return null;
76
+ }
77
+ if (type === 2 /* Type.ARRAY */) {
78
+ if (!state.d) {
79
+ state.d = true;
80
+ t[k] = [];
81
+ }
82
+ t[k].push(t = Object.create(null));
83
+ state.c[state.i++] = (state = { t: 1 /* Type.EXPLICIT */, d: false, i: 0, c: Object.create(null) });
84
+ }
85
+ if (state.d) {
86
+ // Redefining a table!
87
+ return null;
88
+ }
89
+ state.d = true;
90
+ if (type === 1 /* Type.EXPLICIT */) {
91
+ t = hasOwn ? t[k] : (t[k] = Object.create(null));
92
+ }
93
+ else if (type === 0 /* Type.DOTTED */ && hasOwn) {
94
+ return null;
95
+ }
96
+ return [k, t, state.c];
97
+ }
98
+ function validateTablePeek(ctx, peek, ptr) {
99
+ if (peek === null || ctx.uk === 2)
100
+ TomlError.x(peek === null
101
+ ? 'trying to redefine an already defined table or value'
102
+ : 'document contains an unsafe property', ctx, ptr);
103
+ }
104
+ export function parse(toml, options = {}) {
105
+ let ctx = {
106
+ s: toml,
107
+ p: 0,
108
+ d: options.maxDepth ?? 1000,
109
+ bi: options.integersAsBigInt ?? false,
110
+ ld: options.useLegacyDate ?? true,
111
+ uk: options.unsafeKeyBehaviour === 'throw' ? 2 : options.unsafeKeyBehaviour === 'drop' ? 1 : 0,
112
+ };
113
+ let res = Object.create(null);
114
+ let meta = Object.create(null);
115
+ let tmp;
116
+ let skipping = false;
117
+ let tbl = res;
118
+ let m = meta;
119
+ // BOM is allowed, skip.
120
+ // JS is UTF-16, so we have to check for the UTF-16 BOM instead of the UTF-8 BOM sequence!
121
+ if (toml.charCodeAt(0) === 0xfeff)
122
+ ctx.p++;
123
+ skipVoid(ctx);
124
+ while (ctx.p < toml.length) {
125
+ if (toml.charCodeAt(ctx.p) === 0x5b /* [ */) {
126
+ let isTableArray = toml.charCodeAt(++ctx.p) === 0x5b; /* [ */
127
+ tmp = ctx.p += +isTableArray;
128
+ skipping = false;
129
+ let k = parseKey(ctx, 0x5d /* ] */);
130
+ if (isTableArray) {
131
+ if (toml.charCodeAt(ctx.p) !== 0x5d /* ] */) {
132
+ TomlError.x('expected end of table array declaration', ctx);
133
+ }
134
+ ctx.p++;
135
+ }
136
+ let p = peekTable(ctx, k, res, meta, isTableArray ? 2 /* Type.ARRAY */ : 1 /* Type.EXPLICIT */);
137
+ if (!p) {
138
+ validateTablePeek(ctx, p, tmp);
139
+ skipping = true;
140
+ }
141
+ else {
142
+ m = p[2];
143
+ tbl = p[1];
144
+ }
145
+ }
146
+ else {
147
+ tmp = ctx.p;
148
+ let k = parseKey(ctx);
149
+ let p = peekTable(ctx, k, tbl, m, 0 /* Type.DOTTED */);
150
+ if (!p && !skipping)
151
+ validateTablePeek(ctx, p, tmp);
152
+ skipVoid(ctx, true, true);
153
+ let v = extractValue(ctx, void 0);
154
+ if (p && !skipping)
155
+ p[1][p[0]] = v;
156
+ }
157
+ skipVoid(ctx, true);
158
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 0xa /* \n */ && (tmp !== 0xd /* \r */ || toml.charCodeAt(ctx.p + 1) !== 0xa /* \n */)) {
159
+ TomlError.x('each key-value declaration must be followed by an end-of-line', ctx);
160
+ }
161
+ skipVoid(ctx);
162
+ }
163
+ return res;
164
+ }
@@ -0,0 +1,151 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ import { TomlError } from './error.js';
29
+ /** @internal */
30
+ export function parseString(ctx) {
31
+ let startPtr = ctx.p;
32
+ let c = ctx.s.charCodeAt(ctx.p++);
33
+ let first = c;
34
+ let isLiteral = c === 0x27; /* ' */
35
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
36
+ if (isMultiline) {
37
+ // Trim initial newline
38
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 0xa /* \n */)
39
+ ctx.p++;
40
+ else if (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */)
41
+ ctx.p += 2;
42
+ }
43
+ // For the record: it is not worth it to use a fast-path for literal strings using `indexOf`.
44
+ // Doing a char-by-char iteration ends up dispatching less instructions, for the same wall-clock runtime.
45
+ let parsed = '';
46
+ let sliceStart = ctx.p;
47
+ // states:
48
+ // 0 - decoding
49
+ // 1 - decoding escape
50
+ // 2 - whitespace escape (no newline encountered yet, must fail on non-whitespace)
51
+ // 3 - whitespace escape (newline encountered, allowed to transition back to normal decode)
52
+ let state = 0;
53
+ for (; ctx.p < ctx.s.length; ctx.p++) {
54
+ c = ctx.s.charCodeAt(ctx.p);
55
+ // Deal with newlines first, since that simplifies control character checking and handling across all states
56
+ if (isMultiline && (c === 0xa /* \n */ || (c === 0xd /* \r */ && ctx.s.charCodeAt(ctx.p + 1) === 0xa /* \n */))) {
57
+ state = state && 3;
58
+ }
59
+ // Control characters are banned in TOML, so we throw an error if we encounter them
60
+ else if ((c < 0x20 && c !== 0x9 /* \t */) || c === 0x7f) {
61
+ TomlError.x('control characters are not allowed in strings', ctx);
62
+ }
63
+ // The string might terminate while we're parsing through a newline escape.
64
+ // It must have encountered a newline; otherwise, it'll simply fail in another branch.
65
+ else if ((!state || state === 3) && c === first && (!isMultiline || (ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first))) {
66
+ if (isMultiline) {
67
+ // If the string ends with 4-5 quotes, then the first 1-2 are part of the string
68
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
69
+ ctx.p++;
70
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
71
+ ctx.p++;
72
+ }
73
+ // If we're in a newline escape still, then there's nothing to add.
74
+ if (!state) {
75
+ // Avoid a useless concat operation if the string can be used as-is.
76
+ let s = ctx.s.slice(sliceStart, ctx.p);
77
+ parsed = parsed ? parsed + s : s;
78
+ }
79
+ ctx.p += isMultiline ? 3 : 1;
80
+ return parsed;
81
+ }
82
+ // Baseline state; keep moving forward unless an escape sequence starts
83
+ else if (!state) {
84
+ if (!isLiteral && c === 0x5c /* \ */) {
85
+ parsed += ctx.s.slice(sliceStart, (sliceStart = ctx.p));
86
+ state = 1;
87
+ }
88
+ }
89
+ else if (state === 1) {
90
+ if (c === 0x78 /* x */ || c === 0x75 /* u */ || c === 0x55 /* U */) { // Unicode escape
91
+ let errPtr = ctx.p++ - 1;
92
+ let value = 0;
93
+ let len = c === 0x78 /* x */ ? 2 : c === 0x75 /* u */ ? 4 : 8;
94
+ for (let j = 0; j < len; j++, ctx.p++) {
95
+ let hex = ctx.s.charCodeAt(ctx.p);
96
+ let digit =
97
+ /* 0-9 */ hex >= 0x30 && hex <= 0x39 ? hex - 0x30 :
98
+ /* A-F */ hex >= 0x41 && hex <= 0x46 ? hex - 0x41 + 10 :
99
+ /* a-f */ hex >= 0x61 && hex <= 0x66 ? hex - 0x61 + 10 : -1;
100
+ if (digit < 0)
101
+ TomlError.x('invalid non-hex character in unicode escape', ctx);
102
+ value = (value << 4) | digit;
103
+ }
104
+ // Because JS does bitwise on signed 32bit integers, all 0xfzzzzzzz values are actually seen as negative
105
+ if (value < 0 || value > 0x10ffff || (value >= 0xd800 && value <= 0xdfff)) {
106
+ TomlError.x('invalid unicode escape', ctx, errPtr);
107
+ }
108
+ parsed += String.fromCodePoint(value);
109
+ sliceStart = ctx.p--;
110
+ state = 0;
111
+ }
112
+ // Newline escape sequence. We only need to care about spaces and tabs; newlines are dealt with earlier
113
+ else if (isMultiline && (c === 0x20 || c === 0x9 /* \t */)) {
114
+ state = 2;
115
+ }
116
+ // Basic escape sequence
117
+ else {
118
+ if (c === 0x62 /* b */)
119
+ parsed += '\b';
120
+ else if (c === 0x74 /* t */)
121
+ parsed += '\t';
122
+ else if (c === 0x6e /* n */)
123
+ parsed += '\n';
124
+ else if (c === 0x66 /* f */)
125
+ parsed += '\f';
126
+ else if (c === 0x72 /* r */)
127
+ parsed += '\r';
128
+ else if (c === 0x65 /* e */)
129
+ parsed += '\x1b';
130
+ else if (c === 0x22 /* " */)
131
+ parsed += '"';
132
+ else if (c === 0x5c /* \ */)
133
+ parsed += '\\';
134
+ else
135
+ TomlError.x('unrecognised escape sequence', ctx);
136
+ sliceStart = ctx.p + 1;
137
+ state = 0;
138
+ }
139
+ }
140
+ // Newline escape continuation: keep moving forward until the first non-whitespace char
141
+ else if (c !== 0x20 && c !== 0x9 /* \t */) {
142
+ if (state === 2)
143
+ TomlError.x('invalid escape: only line-ending whitespace may be escaped', ctx, sliceStart);
144
+ // State cannot be zero, or we'd have branched earlier already.
145
+ // If it's a backslash, immediately transition to the escape state so it can be processed.
146
+ state = !isLiteral && c === 0x5c /* \ */ ? 1 : 0;
147
+ sliceStart = ctx.p;
148
+ }
149
+ }
150
+ TomlError.x('unfinished string', ctx, startPtr);
151
+ }
@@ -0,0 +1,219 @@
1
+ /*!
2
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
3
+ * SPDX-License-Identifier: BSD-3-Clause
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ * 3. Neither the name of the copyright holder nor the names of its contributors
14
+ * may be used to endorse or promote products derived from this software without
15
+ * specific prior written permission.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+ let BARE_KEY = /^[a-z0-9-_]+$/i;
29
+ let HAS_WELLFORMED = !!(''.isWellFormed);
30
+ function extendedTypeOf(obj) {
31
+ let type = typeof obj;
32
+ if (type === 'object') {
33
+ if (Array.isArray(obj))
34
+ return 'array';
35
+ if (typeof obj.getUTCDate === 'function' && obj instanceof Date)
36
+ return 'date';
37
+ if (globalThis.Temporal) {
38
+ if (obj.until) {
39
+ if (obj instanceof Temporal.ZonedDateTime)
40
+ return 'temporal/tz+uc';
41
+ if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
42
+ return 'temporal/uc';
43
+ if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
44
+ return 'temporal';
45
+ if (obj instanceof Temporal.PlainYearMonth)
46
+ return 'temporal/x';
47
+ }
48
+ else if ((obj.toPlainDate && obj instanceof Temporal.PlainMonthDay) ||
49
+ (obj.negated && obj instanceof Temporal.Duration)) {
50
+ return 'temporal/x';
51
+ }
52
+ }
53
+ }
54
+ return type;
55
+ }
56
+ function isArrayOfTables(obj) {
57
+ for (let i = 0; i < obj.length; i++) {
58
+ if (extendedTypeOf(obj[i]) !== 'object')
59
+ return false;
60
+ }
61
+ return obj.length != 0;
62
+ }
63
+ function formatWellFormedStringUnchecked(s) {
64
+ return JSON.stringify(s).replaceAll('\x7f', '\\u007f');
65
+ }
66
+ function formatString(s) {
67
+ return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
68
+ }
69
+ function formatKey(s) {
70
+ if (BARE_KEY.test(s))
71
+ return s;
72
+ if (HAS_WELLFORMED && !s.isWellFormed())
73
+ throw new RangeError('key contains illegal lone surrogates');
74
+ return formatWellFormedStringUnchecked(s);
75
+ }
76
+ function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
77
+ if (depth === 0) {
78
+ throw new Error('Could not stringify the object: maximum object depth exceeded');
79
+ }
80
+ switch (type) {
81
+ // @ts-expect-error -- intentional fallthrough case
82
+ case 'number':
83
+ if (isNaN(val))
84
+ return 'nan';
85
+ if (val === Infinity)
86
+ return 'inf';
87
+ if (val === -Infinity)
88
+ return '-inf';
89
+ if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
90
+ return val.toFixed(1);
91
+ case 'bigint':
92
+ case 'boolean':
93
+ case 'temporal':
94
+ return val.toString();
95
+ case 'string':
96
+ return formatString(val);
97
+ case 'date':
98
+ if (isNaN(val.getTime()))
99
+ throw new TypeError('cannot serialize invalid date');
100
+ return val.toISOString();
101
+ case 'object':
102
+ return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
103
+ case 'array':
104
+ return stringifyArray(val, depth, numberAsFloat, strictTemporal);
105
+ // @ts-expect-error -- intentional fallthrough case
106
+ case 'temporal/tz+uc':
107
+ if (strictTemporal) {
108
+ let tz = val.timeZoneId;
109
+ let tzc = tz.charCodeAt(0);
110
+ if (
111
+ // Classic offset
112
+ tzc !== 0x2b /* + */ && tzc !== 0x2d /* - */ &&
113
+ (
114
+ // Fast pre-check pass; see below for the actually accepted values
115
+ (tzc !== 0x55 /* U */ && tzc !== 0x47 /* G */ && tzc !== 0x5a /* Z */ && tzc !== 0x45 /* E */) ||
116
+ (
117
+ // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
118
+ tz !== 'UTC' && tz !== 'UCT' && tz !== 'Universal' && tz !== 'Zulu' &&
119
+ // GMT is a TZ but it's for all intents and purposes equivalent to UTC. Safe to downgrade.
120
+ !tz.startsWith('GMT') && tz !== 'Greenwich' &&
121
+ // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
122
+ !tz.startsWith('Etc/')))) {
123
+ throw new TypeError('Temporal objects with an IANA timezone are not allowed in Temporal strict mode');
124
+ }
125
+ }
126
+ case 'temporal/uc':
127
+ if (strictTemporal && val.calendarId !== 'iso8601')
128
+ throw new TypeError('Temporal objects with a non-default calendar are not allowed in Temporal strict mode');
129
+ return val.toString({
130
+ calendarName: 'never',
131
+ timeZoneName: 'never',
132
+ });
133
+ case 'temporal/x':
134
+ throw new TypeError('Unsupported ' + val[Symbol.toStringTag]);
135
+ }
136
+ }
137
+ function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
138
+ let keys = Object.keys(obj);
139
+ if (keys.length === 0)
140
+ return '{}';
141
+ let res = '{ ';
142
+ for (let i = 0; i < keys.length; i++) {
143
+ let k = keys[i];
144
+ if (i)
145
+ res += ', ';
146
+ res += formatKey(k) + ' = ' + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
147
+ }
148
+ return res + ' }';
149
+ }
150
+ function stringifyArray(array, depth, numberAsFloat, strictTemporal) {
151
+ if (array.length === 0)
152
+ return '[]';
153
+ let res = '[ ';
154
+ for (let i = 0; i < array.length; i++) {
155
+ if (i)
156
+ res += ', ';
157
+ if (array[i] === null || array[i] === void 0) {
158
+ throw new TypeError('arrays cannot contain null or undefined values');
159
+ }
160
+ res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat, strictTemporal);
161
+ }
162
+ return res + ' ]';
163
+ }
164
+ function stringifyArrayTable(array, key, depth, numberAsFloat, strictTemporal) {
165
+ if (depth === 0) {
166
+ throw new Error('Could not stringify the object: maximum object depth exceeded');
167
+ }
168
+ let res = '';
169
+ for (let i = 0; i < array.length; i++) {
170
+ res += `${res && '\n'}[[${key}]]\n`;
171
+ res += stringifyTable(0, array[i], key, depth, numberAsFloat, strictTemporal);
172
+ }
173
+ return res;
174
+ }
175
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
176
+ if (depth === 0) {
177
+ throw new Error('Could not stringify the object: maximum object depth exceeded');
178
+ }
179
+ let preamble = '';
180
+ let tables = '';
181
+ let keys = Object.keys(obj);
182
+ for (let i = 0; i < keys.length; i++) {
183
+ let k = keys[i];
184
+ if (obj[k] !== null && obj[k] !== void 0) {
185
+ let type = extendedTypeOf(obj[k]);
186
+ if (type === 'symbol' || type === 'function') {
187
+ throw new TypeError(`cannot serialize values of type '${type}'`);
188
+ }
189
+ let key = formatKey(k);
190
+ if (type === 'array' && isArrayOfTables(obj[k])) {
191
+ tables += (tables && '\n') + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
192
+ }
193
+ else if (type === 'object') {
194
+ let tblKey = prefix ? `${prefix}.${key}` : key;
195
+ tables += (tables && '\n') + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
196
+ }
197
+ else {
198
+ preamble += key;
199
+ preamble += ' = ';
200
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
201
+ preamble += '\n';
202
+ }
203
+ }
204
+ }
205
+ if (tableKey && (preamble || !tables)) // Create table only if necessary
206
+ preamble = preamble ? `[${tableKey}]\n${preamble}` : `[${tableKey}]`;
207
+ return preamble && tables
208
+ ? `${preamble}\n${tables}`
209
+ : preamble || tables;
210
+ }
211
+ export function stringify(obj, { maxDepth = 1000, numbersAsFloat = false, strictTemporal = false } = {}) {
212
+ if (extendedTypeOf(obj) !== 'object') {
213
+ throw new TypeError('stringify can only be called with an object');
214
+ }
215
+ let str = stringifyTable(0, obj, '', maxDepth, numbersAsFloat, strictTemporal);
216
+ if (str[str.length - 1] !== '\n')
217
+ return str + '\n';
218
+ return str;
219
+ }