quilltap 4.7.0-dev → 4.7.0-dev.101

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.
@@ -0,0 +1,171 @@
1
+ /**
2
+ * `qtap://` Document URI codec — CLI-local, dependency-free port.
3
+ *
4
+ * Mirrors the server codec at `lib/doc-edit/qtap-uri.ts` (same grammar, same
5
+ * encoding, same tests). Kept as its own small CommonJS module because the
6
+ * server module is not importable from the published CLI package. If the
7
+ * grammar changes, update BOTH and their tests.
8
+ *
9
+ * qtap://authority/path[#fragment][?query]
10
+ *
11
+ * Authority → { scope, mountPoint }:
12
+ * self → document_store, mountPoint 'self'
13
+ * project → project
14
+ * general → general
15
+ * else → document_store, mountPoint = the decoded authority (name or UUID)
16
+ *
17
+ * @module qtap-uri (CLI)
18
+ */
19
+
20
+ 'use strict';
21
+
22
+ const QTAP_URI_SCHEME = 'qtap://';
23
+ const SELF_VAULT_TOKEN = 'self';
24
+
25
+ class QtapUriError extends Error {
26
+ constructor(message, code) {
27
+ super(message);
28
+ this.name = 'QtapUriError';
29
+ this.code = code;
30
+ }
31
+ }
32
+
33
+ /** True iff the value starts with the qtap:// scheme (case-insensitive). */
34
+ function isQtapUri(s) {
35
+ return typeof s === 'string' && s.toLowerCase().startsWith(QTAP_URI_SCHEME);
36
+ }
37
+
38
+ function safeDecode(component) {
39
+ try {
40
+ return decodeURIComponent(component);
41
+ } catch {
42
+ throw new QtapUriError(`Malformed percent-encoding in qtap:// URI segment: "${component}"`, 'MALFORMED');
43
+ }
44
+ }
45
+
46
+ function parseFragment(fragment) {
47
+ if (fragment === '') return {};
48
+ const colonIdx = fragment.lastIndexOf(':');
49
+ if (colonIdx === -1) {
50
+ return { heading: safeDecode(fragment) };
51
+ }
52
+ const headingPart = fragment.slice(0, colonIdx);
53
+ const levelPart = fragment.slice(colonIdx + 1);
54
+ if (!/^[0-9]+$/.test(levelPart)) {
55
+ throw new QtapUriError(`Invalid heading level "${levelPart}" in qtap:// fragment; expected an integer 1–6.`, 'BAD_LEVEL');
56
+ }
57
+ const level = parseInt(levelPart, 10);
58
+ if (level < 1 || level > 6) {
59
+ throw new QtapUriError(`Heading level ${level} out of range in qtap:// fragment; expected 1–6.`, 'BAD_LEVEL');
60
+ }
61
+ return { heading: safeDecode(headingPart), level };
62
+ }
63
+
64
+ function parseQuery(query) {
65
+ if (query === '') return undefined;
66
+ const out = {};
67
+ for (const pair of query.split('&')) {
68
+ if (pair === '') continue;
69
+ const eq = pair.indexOf('=');
70
+ if (eq === -1) out[safeDecode(pair)] = '';
71
+ else out[safeDecode(pair.slice(0, eq))] = safeDecode(pair.slice(eq + 1));
72
+ }
73
+ return Object.keys(out).length > 0 ? out : undefined;
74
+ }
75
+
76
+ /** Parse a qtap:// URI into { scope, mountPoint?, path, heading?, level?, query? }. */
77
+ function parseQtapUri(uri) {
78
+ if (!isQtapUri(uri)) {
79
+ throw new QtapUriError(`Not a qtap:// URI: ${typeof uri === 'string' ? `"${uri}"` : typeof uri}`, 'NOT_A_QTAP_URI');
80
+ }
81
+ let rest = uri.slice(QTAP_URI_SCHEME.length);
82
+
83
+ let query;
84
+ const qIdx = rest.indexOf('?');
85
+ if (qIdx !== -1) {
86
+ query = parseQuery(rest.slice(qIdx + 1));
87
+ rest = rest.slice(0, qIdx);
88
+ }
89
+
90
+ let heading;
91
+ let level;
92
+ const hashIdx = rest.indexOf('#');
93
+ if (hashIdx !== -1) {
94
+ const frag = parseFragment(rest.slice(hashIdx + 1));
95
+ heading = frag.heading;
96
+ level = frag.level;
97
+ rest = rest.slice(0, hashIdx);
98
+ }
99
+
100
+ const slashIdx = rest.indexOf('/');
101
+ const rawAuthority = slashIdx === -1 ? rest : rest.slice(0, slashIdx);
102
+ const rawPath = slashIdx === -1 ? '' : rest.slice(slashIdx + 1);
103
+
104
+ const authority = safeDecode(rawAuthority);
105
+ if (authority === '') {
106
+ throw new QtapUriError('qtap:// URI has an empty authority.', 'EMPTY_AUTHORITY');
107
+ }
108
+
109
+ const path = rawPath === '' ? '' : rawPath.split('/').map((seg) => safeDecode(seg)).join('/');
110
+
111
+ const lower = authority.toLowerCase();
112
+ const parts = { scope: 'document_store', path };
113
+ if (lower === SELF_VAULT_TOKEN) {
114
+ parts.mountPoint = SELF_VAULT_TOKEN;
115
+ } else if (lower === 'project') {
116
+ parts.scope = 'project';
117
+ } else if (lower === 'general') {
118
+ parts.scope = 'general';
119
+ } else {
120
+ parts.mountPoint = authority;
121
+ }
122
+ if (heading !== undefined) parts.heading = heading;
123
+ if (level !== undefined) parts.level = level;
124
+ if (query !== undefined) parts.query = query;
125
+ return parts;
126
+ }
127
+
128
+ function encodeAuthority(parts) {
129
+ if (parts.scope === 'project') return 'project';
130
+ if (parts.scope === 'general') return 'general';
131
+ const mp = parts.mountPoint || '';
132
+ if (mp.toLowerCase() === SELF_VAULT_TOKEN) return 'self';
133
+ return encodeURIComponent(mp);
134
+ }
135
+
136
+ function encodePath(path) {
137
+ if (!path) return '';
138
+ return path.split('/').map((seg) => encodeURIComponent(seg)).join('/');
139
+ }
140
+
141
+ /** Inverse of parseQtapUri — always emits canonical encoded form (':' → %3A). */
142
+ function formatQtapUri(parts) {
143
+ const authority = encodeAuthority(parts);
144
+ let out = `${QTAP_URI_SCHEME}${authority}/${encodePath(parts.path || '')}`;
145
+ if (parts.heading !== undefined && parts.heading !== '') {
146
+ out += `#${encodeURIComponent(parts.heading)}`;
147
+ if (parts.level !== undefined) out += `:${parts.level}`;
148
+ }
149
+ if (parts.query && Object.keys(parts.query).length > 0) {
150
+ const q = Object.entries(parts.query)
151
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
152
+ .join('&');
153
+ out += `?${q}`;
154
+ }
155
+ return out;
156
+ }
157
+
158
+ /** Build a document-store URI for a store name/UUID and relative path. */
159
+ function formatDocStoreUri(authority, path) {
160
+ return formatQtapUri({ scope: 'document_store', mountPoint: authority, path: path || '' });
161
+ }
162
+
163
+ module.exports = {
164
+ QTAP_URI_SCHEME,
165
+ SELF_VAULT_TOKEN,
166
+ QtapUriError,
167
+ isQtapUri,
168
+ parseQtapUri,
169
+ formatQtapUri,
170
+ formatDocStoreUri,
171
+ };
@@ -36,6 +36,12 @@ const BLOCKED_EXTENSIONS = new Set([
36
36
  // Theme ID must be lowercase alphanumeric with hyphens
37
37
  const THEME_ID_REGEX = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
38
38
 
39
+ // Icon override names: lowercase kebab-case (mirrors the app's IconName contract)
40
+ const ICON_NAME_REGEX = /^[a-z][a-z0-9-]*$/;
41
+
42
+ // Allowed file extensions for icon override assets
43
+ const ICON_OVERRIDE_EXTENSIONS = ['.svg', '.webp'];
44
+
39
45
  // Required color keys in a palette
40
46
  const REQUIRED_COLOR_KEYS = [
41
47
  'background', 'foreground', 'primary', 'primaryForeground',
@@ -124,6 +130,35 @@ function validateManifest(manifest) {
124
130
  }
125
131
  }
126
132
 
133
+ // Icons validation (per-icon override map: name -> bundle-relative asset path).
134
+ // The canonical icon-name list lives in the app and cannot be imported here, so
135
+ // this is a soft check: structure, asset extension, and traversal safety only.
136
+ if (manifest.icons !== undefined) {
137
+ if (typeof manifest.icons !== 'object' || manifest.icons === null || Array.isArray(manifest.icons)) {
138
+ errors.push('icons must be an object mapping icon names to asset paths');
139
+ } else {
140
+ for (const [iconName, assetPath] of Object.entries(manifest.icons)) {
141
+ if (!ICON_NAME_REGEX.test(iconName)) {
142
+ // Soft warning: the app validates the actual name list, but a malformed
143
+ // name here is almost certainly a typo that will silently never match.
144
+ warnings.push(`icons.${iconName} is not a valid icon name (expected lowercase kebab-case)`);
145
+ }
146
+ if (typeof assetPath !== 'string' || assetPath.length === 0) {
147
+ errors.push(`icons.${iconName} must be a non-empty string asset path`);
148
+ continue;
149
+ }
150
+ if (assetPath.includes('..') || path.isAbsolute(assetPath)) {
151
+ errors.push(`icons.${iconName} has an unsafe asset path: ${assetPath}`);
152
+ continue;
153
+ }
154
+ const ext = path.extname(assetPath).toLowerCase();
155
+ if (!ICON_OVERRIDE_EXTENSIONS.includes(ext)) {
156
+ errors.push(`icons.${iconName} must point to a .svg or .webp file (got "${assetPath}")`);
157
+ }
158
+ }
159
+ }
160
+ }
161
+
127
162
  return { valid: errors.length === 0, errors, warnings };
128
163
  }
129
164
 
@@ -383,4 +418,6 @@ module.exports = {
383
418
  ALLOWED_EXTENSIONS,
384
419
  BLOCKED_EXTENSIONS,
385
420
  THEME_ID_REGEX,
421
+ ICON_NAME_REGEX,
422
+ ICON_OVERRIDE_EXTENSIONS,
386
423
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quilltap",
3
- "version": "4.7.0-dev",
3
+ "version": "4.7.0-dev.101",
4
4
  "description": "Self-hosted AI workspace for writers, worldbuilders, and roleplayers. Run with npx quilltap.",
5
5
  "author": {
6
6
  "name": "Charles Sebold",