noonsight 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 (115) hide show
  1. package/.claude-plugin/marketplace.json +19 -0
  2. package/.claude-plugin/plugin.json +14 -0
  3. package/LICENSE +21 -0
  4. package/README.md +281 -2
  5. package/dist/src/adapters/claude-code/classifier.js +138 -0
  6. package/dist/src/adapters/claude-code/code-edit.js +108 -0
  7. package/dist/src/adapters/claude-code/compat.js +31 -0
  8. package/dist/src/adapters/claude-code/definitions.js +347 -0
  9. package/dist/src/adapters/claude-code/fork.js +132 -0
  10. package/dist/src/adapters/claude-code/hook.js +652 -0
  11. package/dist/src/adapters/claude-code/install.js +186 -0
  12. package/dist/src/adapters/claude-code/launch.js +270 -0
  13. package/dist/src/adapters/claude-code/launcher.js +252 -0
  14. package/dist/src/adapters/claude-code/locations.js +115 -0
  15. package/dist/src/adapters/claude-code/managed.js +75 -0
  16. package/dist/src/adapters/claude-code/plugin-files.js +88 -0
  17. package/dist/src/adapters/claude-code/plugins.js +117 -0
  18. package/dist/src/adapters/claude-code/pointer.js +48 -0
  19. package/dist/src/adapters/claude-code/predict.js +271 -0
  20. package/dist/src/adapters/claude-code/routing.js +88 -0
  21. package/dist/src/adapters/claude-code/settings.js +189 -0
  22. package/dist/src/adapters/claude-code/subagents.js +666 -0
  23. package/dist/src/adapters/claude-code/triggers.js +88 -0
  24. package/dist/src/cli.js +157 -0
  25. package/dist/src/commands/accept.js +115 -0
  26. package/dist/src/commands/check.js +529 -0
  27. package/dist/src/commands/hook.js +73 -0
  28. package/dist/src/commands/init.js +29 -0
  29. package/dist/src/commands/install.js +370 -0
  30. package/dist/src/commands/models.js +213 -0
  31. package/dist/src/commands/receives.js +84 -0
  32. package/dist/src/commands/report.js +386 -0
  33. package/dist/src/commands/resolve.js +32 -0
  34. package/dist/src/commands/run.js +168 -0
  35. package/dist/src/commands/trust.js +70 -0
  36. package/dist/src/commands/usage.js +10 -0
  37. package/dist/src/commands/watch.js +154 -0
  38. package/dist/src/config/create.js +51 -0
  39. package/dist/src/config/json-schema.js +207 -0
  40. package/dist/src/config/load.js +758 -0
  41. package/dist/src/config/paths.js +42 -0
  42. package/dist/src/config/preset-changes.js +190 -0
  43. package/dist/src/config/project.js +354 -0
  44. package/dist/src/config/rewrite.js +112 -0
  45. package/dist/src/core/backtracking.js +330 -0
  46. package/dist/src/core/classify.js +66 -0
  47. package/dist/src/core/normalize.js +24 -0
  48. package/dist/src/core/overlap.js +39 -0
  49. package/dist/src/core/regex-sample.js +278 -0
  50. package/dist/src/core/resolve.js +201 -0
  51. package/dist/src/core/route.js +93 -0
  52. package/dist/src/core/scope.js +77 -0
  53. package/dist/src/core/triggers.js +30 -0
  54. package/dist/src/core/types.js +74 -0
  55. package/dist/src/state/agents.js +200 -0
  56. package/dist/src/state/claims.js +80 -0
  57. package/dist/src/state/files.js +84 -0
  58. package/dist/src/state/installs.js +29 -0
  59. package/dist/src/state/log.js +90 -0
  60. package/dist/src/state/node.js +35 -0
  61. package/dist/src/state/sessions.js +109 -0
  62. package/dist/src/state/triggers.js +57 -0
  63. package/dist/src/version.js +24 -0
  64. package/dist/src/watch/service.js +172 -0
  65. package/dist/src/watch/watcher.js +130 -0
  66. package/dist/src/wording.js +11 -0
  67. package/hooks/hooks.json +118 -0
  68. package/package.json +60 -4
  69. package/presets/claude/SOURCES.md +485 -0
  70. package/presets/claude/preset.json +432 -0
  71. package/presets/claude/rules/fable-5-2/code-ownership.md +1 -0
  72. package/presets/claude/rules/fable-5-2/finish-work.md +1 -0
  73. package/presets/claude/rules/fable-5-2/low-context-report.md +1 -0
  74. package/presets/claude/rules/fable-5-2/progress-updates.md +1 -0
  75. package/presets/claude/rules/haiku-5-5/carry-through.md +1 -0
  76. package/presets/claude/rules/haiku-5-5/search-recent-facts.md +1 -0
  77. package/presets/claude/rules/haiku-5-5/verify-changes.md +1 -0
  78. package/presets/claude/rules/opus-5-5/explore-before-acting.md +1 -0
  79. package/presets/claude/rules/opus-5-5/progress-updates.md +1 -0
  80. package/presets/claude/rules/opus-5-5/unattended-run.md +1 -0
  81. package/presets/claude/rules/sonnet-5-5/carry-through.md +1 -0
  82. package/presets/claude/rules/sonnet-5-5/check-current-facts.md +1 -0
  83. package/presets/claude/rules/sonnet-5-5/ideas-first.md +1 -0
  84. package/presets/claude/rules/sonnet-5-5/no-self-review-rounds.md +1 -0
  85. package/presets/claude/rules/sonnet-5-5/stay-in-scope.md +1 -0
  86. package/presets/claude/rules/sonnet-5-5/verify-changes.md +1 -0
  87. package/presets/claude/versions/1.3.0/preset.json +432 -0
  88. package/presets/claude/versions/1.3.0/rules/fable-5-2/code-ownership.md +1 -0
  89. package/presets/claude/versions/1.3.0/rules/fable-5-2/finish-work.md +1 -0
  90. package/presets/claude/versions/1.3.0/rules/fable-5-2/low-context-report.md +1 -0
  91. package/presets/claude/versions/1.3.0/rules/fable-5-2/progress-updates.md +1 -0
  92. package/presets/claude/versions/1.3.0/rules/haiku-5-5/carry-through.md +1 -0
  93. package/presets/claude/versions/1.3.0/rules/haiku-5-5/search-recent-facts.md +1 -0
  94. package/presets/claude/versions/1.3.0/rules/haiku-5-5/verify-changes.md +1 -0
  95. package/presets/claude/versions/1.3.0/rules/opus-5-5/explore-before-acting.md +1 -0
  96. package/presets/claude/versions/1.3.0/rules/opus-5-5/progress-updates.md +1 -0
  97. package/presets/claude/versions/1.3.0/rules/opus-5-5/unattended-run.md +1 -0
  98. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/carry-through.md +1 -0
  99. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/check-current-facts.md +1 -0
  100. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/ideas-first.md +1 -0
  101. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/no-self-review-rounds.md +1 -0
  102. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/stay-in-scope.md +1 -0
  103. package/presets/claude/versions/1.3.0/rules/sonnet-5-5/verify-changes.md +1 -0
  104. package/schema/noonsight-project.schema.json +394 -0
  105. package/schema/noonsight.schema.json +425 -0
  106. package/schema/preset.schema.json +194 -0
  107. package/scripts/noonsight +68 -0
  108. package/skills/accept/SKILL.md +11 -0
  109. package/skills/check/SKILL.md +11 -0
  110. package/skills/models/SKILL.md +11 -0
  111. package/skills/report/SKILL.md +11 -0
  112. package/skills/resolve/SKILL.md +12 -0
  113. package/skills/setup/SKILL.md +15 -0
  114. package/skills/trust/SKILL.md +12 -0
  115. package/skills/untrust/SKILL.md +12 -0
@@ -0,0 +1,154 @@
1
+ // noonsight watch: the opt-in watcher that installs noonsight's hooks into each new Claude Code
2
+ // configuration directory. It is off until `noonsight watch enable` writes its per-user service.
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { runsFromPlugin } from '../adapters/claude-code/plugins.js';
7
+ import { CLI_FILE, stateDir } from '../config/paths.js';
8
+ import { writeFileAtomic } from '../state/files.js';
9
+ import { isLoaded, isOurs, manager, readServiceFile, serviceContent, watchService, WatchUnsupported } from '../watch/service.js';
10
+ import { startWatcher } from '../watch/watcher.js';
11
+ import { PLUGIN_COPY_REFUSED, runInstall } from './install.js';
12
+ import { UsageError } from './usage.js';
13
+ export const WATCH_USAGE = `usage: noonsight watch enable
14
+ noonsight watch disable
15
+
16
+ The watcher is off unless you turn it on. \`noonsight watch enable\` writes a per-user service (a
17
+ launchd agent on macOS, a systemd user service on Linux) that starts at login and keeps one small
18
+ process running. It watches only the entries directly in the home directory: when a new Claude Code
19
+ configuration directory appears there, it installs noonsight's hooks into that directory, as
20
+ \`noonsight install --account <dir>\` does. \`noonsight watch disable\` stops it and removes the service
21
+ file. \`noonsight check\` says whether it is on.
22
+
23
+ The first session of a brand-new login can still start without the rules; see docs/install.md.`;
24
+ export function runWatch(args, env, io) {
25
+ const [action, ...rest] = args;
26
+ if (rest.length)
27
+ throw new UsageError(`unexpected argument "${rest[0]}"`, WATCH_USAGE);
28
+ switch (action) {
29
+ case 'enable':
30
+ case 'disable': {
31
+ if (action === 'enable' && runsFromPlugin(env)) {
32
+ io.err(`noonsight: ${PLUGIN_COPY_REFUSED}`);
33
+ return 1;
34
+ }
35
+ let service;
36
+ try {
37
+ service = watchService(env, os.homedir());
38
+ }
39
+ catch (e) {
40
+ if (!(e instanceof WatchUnsupported))
41
+ throw e;
42
+ io.err(`noonsight: ${e.message}`);
43
+ return 1;
44
+ }
45
+ return action === 'enable' ? enable(service, io) : disable(service, io);
46
+ }
47
+ // What the service runs; not meant to be run by hand.
48
+ case 'run':
49
+ return run(env, io);
50
+ case undefined:
51
+ throw new UsageError('missing enable or disable', WATCH_USAGE);
52
+ default:
53
+ throw new UsageError(`unknown watch action "${action}"`, WATCH_USAGE);
54
+ }
55
+ }
56
+ function enable(service, io) {
57
+ const home = os.homedir();
58
+ const runtime = { node: process.execPath, cli: fs.realpathSync(CLI_FILE) };
59
+ const content = serviceContent(service, runtime);
60
+ const old = readServiceFile(service);
61
+ if (old !== null && !isOurs(old)) {
62
+ io.err(`noonsight: ${service.file} was not written by noonsight, so it is left alone; nothing was changed`);
63
+ return 1;
64
+ }
65
+ if (old === content && manager.running(service) === 'running') {
66
+ io.out(`watcher: already on (${service.file})`);
67
+ return 0;
68
+ }
69
+ // A running watcher is stopped before its service file is replaced or started again.
70
+ if (isLoaded(manager.running(service))) {
71
+ const stopped = manager.unload(service);
72
+ if (!stopped.ok) {
73
+ io.err(`noonsight: could not stop the watcher to update it (${stopped.detail}); nothing was changed`);
74
+ return 1;
75
+ }
76
+ }
77
+ // The log's directory, made before the service starts and writes to it.
78
+ fs.mkdirSync(stateDir(home), { recursive: true, mode: 0o700 });
79
+ fs.mkdirSync(path.dirname(service.file), { recursive: true, mode: 0o755 });
80
+ if (old !== content)
81
+ writeFileAtomic(service.file, content, 0o644);
82
+ const started = manager.load(service);
83
+ if (!started.ok) {
84
+ if (old === null) {
85
+ fs.rmSync(service.file, { force: true });
86
+ manager.forget(service);
87
+ }
88
+ else if (old !== content)
89
+ writeFileAtomic(service.file, old, 0o644);
90
+ const restored = old === null ? 'the service file was removed again' : 'the service file was put back as it was; run `noonsight watch enable` again once the cause is fixed';
91
+ io.err(`noonsight: could not start the watcher (${started.detail}); the watcher is stopped, and ${restored}`);
92
+ return 1;
93
+ }
94
+ io.out([
95
+ `watcher: on (${service.file})`,
96
+ `It runs ${runtime.node} ${runtime.cli} watch run, starts at every login, and logs to ${service.log}.`,
97
+ 'note: it adds the hooks to Claude Code configuration directories made from now on; for ones that exist already, run `noonsight install`.',
98
+ 'note: the first session of a brand-new login can still start without the rules (see docs/install.md); turn the watcher off with `noonsight watch disable`.',
99
+ ].join('\n'));
100
+ return 0;
101
+ }
102
+ function disable(service, io) {
103
+ const old = readServiceFile(service);
104
+ if (old !== null && !isOurs(old)) {
105
+ io.err(`noonsight: ${service.file} was not written by noonsight, so it is left alone; nothing was changed`);
106
+ return 1;
107
+ }
108
+ if (old === null && !isLoaded(manager.running(service))) {
109
+ io.out(`watcher: already off (no ${service.file})`);
110
+ return 0;
111
+ }
112
+ const stopped = manager.unload(service);
113
+ // launchctl refuses to stop a service that is not loaded; that is already the state we want.
114
+ if (!stopped.ok && !(service.platform === 'darwin' && manager.running(service) === 'off')) {
115
+ io.err(`noonsight: could not stop the watcher (${stopped.detail}); nothing was changed`);
116
+ return 1;
117
+ }
118
+ fs.rmSync(service.file, { force: true });
119
+ manager.forget(service);
120
+ if (old !== null)
121
+ io.out(`watcher: off; removed ${service.file}`);
122
+ else if (service.platform === 'linux')
123
+ io.out(`watcher: off; it was running without ${service.file}; a link to it may remain in ${path.join(path.dirname(service.file), 'default.target.wants')}, which can be removed by hand`);
124
+ else
125
+ io.out(`watcher: off; it was running without ${service.file}`);
126
+ return 0;
127
+ }
128
+ function run(env, io) {
129
+ const log = (text) => {
130
+ const ts = new Date().toISOString();
131
+ io.out(text
132
+ .split('\n')
133
+ .map((line) => `${ts} ${line}`)
134
+ .join('\n'));
135
+ };
136
+ const home = os.homedir();
137
+ try {
138
+ startWatcher({
139
+ home,
140
+ log,
141
+ install: (dir) => {
142
+ const status = runInstall('install', ['--account', dir], env, { out: log, err: log }, { hooksOnly: true });
143
+ // A summary last, so the last line of the log, which `noonsight check` shows, says how it went.
144
+ log(status === 0 ? `new Claude Code configuration ${dir}: installed` : `problem: install into ${dir} failed; see the lines above`);
145
+ },
146
+ });
147
+ }
148
+ catch (e) {
149
+ log(`problem: watching ${home} did not start: ${e instanceof Error ? e.message : String(e)}`);
150
+ return 1;
151
+ }
152
+ return 0;
153
+ }
154
+ //# sourceMappingURL=watch.js.map
@@ -0,0 +1,51 @@
1
+ // The first configuration file, written from the preset: every model the preset has rules for, declared
2
+ // with "use": "preset". `noonsight init`, `noonsight install` and a plugin's first session start write it;
3
+ // none of them ever replaces a file.
4
+ import fs from 'node:fs';
5
+ import os from 'node:os';
6
+ import path from 'node:path';
7
+ import { createFileAtomic } from '../state/files.js';
8
+ import { DEFAULT_PRESET, loadConfigDetails, readPreset } from './load.js';
9
+ import { configPath } from './paths.js';
10
+ /** Where the published configuration schema lives, for editors that validate and complete the file. */
11
+ export const CONFIG_SCHEMA_URL = 'https://unpkg.com/noonsight@0/schema/noonsight.schema.json';
12
+ /**
13
+ * Write the configuration file from the preset and describe what was written, or return null when a
14
+ * file already exists, which is never replaced. `noonsight install` composes this with the hooks.
15
+ */
16
+ export function writeConfig(env, home = os.homedir()) {
17
+ const file = configPath(env, home);
18
+ if (exists(file))
19
+ return null;
20
+ const preset = readPreset(DEFAULT_PRESET, {}, env);
21
+ const content = {
22
+ $schema: CONFIG_SCHEMA_URL,
23
+ version: 1,
24
+ preset: preset.name,
25
+ preset_version: preset.version,
26
+ models: Object.fromEntries([...preset.models.keys()].map((key) => [key, { use: 'preset' }])),
27
+ };
28
+ fs.mkdirSync(path.dirname(file), { recursive: true });
29
+ // A file that appeared since the check above is never replaced, and a session that starts now reads all of it or none.
30
+ if (!createFileAtomic(file, `${JSON.stringify(content, null, 2)}\n`))
31
+ return null;
32
+ const { preset: loaded } = loadConfigDetails(file, {}, env);
33
+ const lines = [`wrote ${file}: preset ${preset.name} ${preset.version}, ${preset.models.size} models declared with "use": "preset"`];
34
+ for (const [key, rules] of loaded?.models ?? []) {
35
+ const on = rules.filter((r) => r.enabled).length;
36
+ lines.push(` ${key}: ${on} of ${rules.length} rules on`);
37
+ }
38
+ return lines;
39
+ }
40
+ function exists(file) {
41
+ try {
42
+ fs.lstatSync(file);
43
+ return true;
44
+ }
45
+ catch (e) {
46
+ if (e.code === 'ENOENT')
47
+ return false;
48
+ throw e;
49
+ }
50
+ }
51
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1,207 @@
1
+ // A small JSON Schema (draft 2020-12) validator for the subset the noonsight schemas use.
2
+ // The published schemas own the shape of the configuration and of a preset; this validator applies
3
+ // them at run time so the shape is written once. A keyword outside the subset is a programming
4
+ // error and throws, so a schema can never rely on a rule this validator silently skips.
5
+ const ANNOTATIONS = new Set(['$schema', '$id', '$defs', '$comment', 'title', 'description', 'default', 'examples']);
6
+ const ASSERTIONS = new Set([
7
+ '$ref',
8
+ 'type',
9
+ 'const',
10
+ 'enum',
11
+ 'pattern',
12
+ 'minLength',
13
+ 'minimum',
14
+ 'maximum',
15
+ 'properties',
16
+ 'patternProperties',
17
+ 'additionalProperties',
18
+ 'propertyNames',
19
+ 'required',
20
+ 'items',
21
+ 'minItems',
22
+ 'uniqueItems',
23
+ 'allOf',
24
+ 'if',
25
+ 'then',
26
+ // Not a standard keyword: a sentence appended to every error raised directly by this schema node.
27
+ 'x-hint',
28
+ ]);
29
+ /** Validate a value; returns one readable message per problem, or an empty list. */
30
+ export function validateSchema(root, value) {
31
+ const errors = [];
32
+ check(root, root, value, '', errors);
33
+ return errors;
34
+ }
35
+ /** Throws when a schema uses a keyword this validator does not implement. */
36
+ export function assertSupported(root) {
37
+ const visit = (s, at) => {
38
+ if (typeof s === 'boolean')
39
+ return;
40
+ if (!isObject(s))
41
+ throw new Error(`schema node at ${at || '/'} is not an object or boolean`);
42
+ for (const [k, v] of Object.entries(s)) {
43
+ if (!ANNOTATIONS.has(k) && !ASSERTIONS.has(k))
44
+ throw new Error(`unsupported schema keyword "${k}" at ${at || '/'}`);
45
+ if (k === '$defs' || k === 'properties' || k === 'patternProperties')
46
+ for (const [name, sub] of Object.entries(v))
47
+ visit(sub, `${at}/${k}/${name}`);
48
+ else if (k === 'allOf')
49
+ v.forEach((sub, i) => visit(sub, `${at}/allOf/${i}`));
50
+ else if (['additionalProperties', 'propertyNames', 'items', 'if', 'then'].includes(k))
51
+ visit(v, `${at}/${k}`);
52
+ }
53
+ };
54
+ visit(root, '');
55
+ }
56
+ function check(root, schema, value, at, errors) {
57
+ if (schema === true)
58
+ return;
59
+ if (schema === false) {
60
+ errors.push(`${where(at)}: not allowed here`);
61
+ return;
62
+ }
63
+ const hint = typeof schema['x-hint'] === 'string' ? ` (${schema['x-hint']})` : '';
64
+ const fail = (message) => {
65
+ errors.push(`${where(at)}: ${message}${hint}`);
66
+ };
67
+ if (typeof schema.$ref === 'string')
68
+ check(root, deref(root, schema.$ref), value, at, errors);
69
+ if (schema.type !== undefined) {
70
+ const types = Array.isArray(schema.type) ? schema.type : [schema.type];
71
+ if (!types.some((t) => hasType(value, t))) {
72
+ fail(`must be ${types.map(article).join(' or ')}`);
73
+ return; // Further keywords would only repeat the same problem.
74
+ }
75
+ }
76
+ if ('const' in schema && !deepEqual(schema.const, value))
77
+ fail(`must be ${JSON.stringify(schema.const)}`);
78
+ if (Array.isArray(schema.enum) && !schema.enum.some((e) => deepEqual(e, value)))
79
+ fail(`must be one of ${schema.enum.map((e) => JSON.stringify(e)).join(', ')}`);
80
+ if (typeof value === 'number') {
81
+ if (typeof schema.minimum === 'number' && value < schema.minimum)
82
+ fail(`must be at least ${schema.minimum}`);
83
+ if (typeof schema.maximum === 'number' && value > schema.maximum)
84
+ fail(`must be at most ${schema.maximum}`);
85
+ }
86
+ if (typeof value === 'string') {
87
+ if (typeof schema.minLength === 'number' && [...value].length < schema.minLength)
88
+ fail(schema.minLength === 1 ? 'must not be empty' : `must have at least ${schema.minLength} characters`);
89
+ if (typeof schema.pattern === 'string' && !new RegExp(schema.pattern, 'u').test(value))
90
+ fail(`${JSON.stringify(value)} does not have the expected form`);
91
+ }
92
+ if (Array.isArray(value)) {
93
+ if (typeof schema.minItems === 'number' && value.length < schema.minItems)
94
+ fail(schema.minItems === 1 ? 'must not be empty' : `must have at least ${schema.minItems} items`);
95
+ if (schema.uniqueItems === true) {
96
+ const seen = new Set();
97
+ for (const item of value) {
98
+ const k = JSON.stringify(item);
99
+ if (seen.has(k))
100
+ fail(`lists ${k} more than once`);
101
+ seen.add(k);
102
+ }
103
+ }
104
+ if (schema.items !== undefined)
105
+ value.forEach((item, i) => check(root, schema.items, item, `${at}/${i}`, errors));
106
+ }
107
+ if (isObject(value)) {
108
+ if (Array.isArray(schema.required))
109
+ for (const k of schema.required)
110
+ if (!(k in value))
111
+ fail(`missing required key "${k}"`);
112
+ const props = (schema.properties ?? {});
113
+ const patterns = Object.entries((schema.patternProperties ?? {})).map(([p, s]) => [new RegExp(p, 'u'), s]);
114
+ for (const [k, v] of Object.entries(value)) {
115
+ const keyAt = `${at}/${escapePointer(k)}`;
116
+ if (schema.propertyNames !== undefined) {
117
+ const keyErrors = [];
118
+ check(root, schema.propertyNames, k, keyAt, keyErrors);
119
+ if (keyErrors.length) {
120
+ const prefix = `${where(keyAt)}: `;
121
+ errors.push(...keyErrors.map((e) => (e.startsWith(prefix) ? `${prefix}key ${e.slice(prefix.length)}` : e)));
122
+ continue; // An invalid key says enough; its value is not checked.
123
+ }
124
+ }
125
+ let known = false;
126
+ if (Object.hasOwn(props, k)) {
127
+ known = true;
128
+ check(root, props[k], v, keyAt, errors);
129
+ }
130
+ for (const [re, s] of patterns)
131
+ if (re.test(k)) {
132
+ known = true;
133
+ check(root, s, v, keyAt, errors);
134
+ }
135
+ if (!known && schema.additionalProperties !== undefined) {
136
+ if (schema.additionalProperties === false)
137
+ errors.push(`${where(keyAt)}: unknown key${hint}`);
138
+ else
139
+ check(root, schema.additionalProperties, v, keyAt, errors);
140
+ }
141
+ }
142
+ }
143
+ if (Array.isArray(schema.allOf))
144
+ for (const s of schema.allOf)
145
+ check(root, s, value, at, errors);
146
+ if (schema.if !== undefined && schema.then !== undefined) {
147
+ const probe = [];
148
+ check(root, schema.if, value, at, probe);
149
+ if (probe.length === 0)
150
+ check(root, schema.then, value, at, errors);
151
+ }
152
+ }
153
+ function deref(root, ref) {
154
+ if (!ref.startsWith('#/'))
155
+ throw new Error(`only local schema references are supported: ${ref}`);
156
+ let node = root;
157
+ for (const part of ref.slice(2).split('/')) {
158
+ node = isObject(node) ? node[part.replace(/~1/g, '/').replace(/~0/g, '~')] : undefined;
159
+ }
160
+ if (node === undefined)
161
+ throw new Error(`unresolved schema reference ${ref}`);
162
+ return node;
163
+ }
164
+ function hasType(value, type) {
165
+ switch (type) {
166
+ case 'object':
167
+ return isObject(value);
168
+ case 'array':
169
+ return Array.isArray(value);
170
+ case 'string':
171
+ return typeof value === 'string';
172
+ case 'boolean':
173
+ return typeof value === 'boolean';
174
+ case 'integer':
175
+ return Number.isInteger(value);
176
+ case 'number':
177
+ return typeof value === 'number' && Number.isFinite(value);
178
+ case 'null':
179
+ return value === null;
180
+ default:
181
+ throw new Error(`unsupported schema type "${type}"`);
182
+ }
183
+ }
184
+ function isObject(value) {
185
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
186
+ }
187
+ function deepEqual(a, b) {
188
+ if (a === b)
189
+ return true;
190
+ if (Array.isArray(a) && Array.isArray(b))
191
+ return a.length === b.length && a.every((x, i) => deepEqual(x, b[i]));
192
+ if (isObject(a) && isObject(b)) {
193
+ const ka = Object.keys(a);
194
+ return ka.length === Object.keys(b).length && ka.every((k) => Object.hasOwn(b, k) && deepEqual(a[k], b[k]));
195
+ }
196
+ return false;
197
+ }
198
+ function article(type) {
199
+ return /^[aeiou]/.test(type) ? `an ${type}` : `a ${type}`;
200
+ }
201
+ function escapePointer(key) {
202
+ return key.replace(/~/g, '~0').replace(/\//g, '~1');
203
+ }
204
+ function where(at) {
205
+ return at === '' ? '(top level)' : at;
206
+ }
207
+ //# sourceMappingURL=json-schema.js.map