instar 1.3.2029 → 1.3.2030

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,3 @@
1
+ /** Shared by new and updated hook writers. Unknown syntax keeps the SQL check. */
2
+ export declare const SQL_COMMAND_CONTEXT_CHECK: string;
3
+ //# sourceMappingURL=sqlCommandContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlCommandContext.d.ts","sourceRoot":"","sources":["../../src/core/sqlCommandContext.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,eAAO,MAAM,yBAAyB,QAwKrC,CAAC"}
@@ -0,0 +1,171 @@
1
+ /** Shared by new and updated hook writers. Unknown syntax keeps the SQL check. */
2
+ export const SQL_COMMAND_CONTEXT_CHECK = String.raw `# SQL context: only proven literal data operations bypass the SQL-shaped matcher.
3
+ sql_command_is_literal_data() {
4
+ python3 - "$INPUT" <<'INSTAR_SQL_CONTEXT_PY'
5
+ import ast, json, os, re, shlex, sys
6
+
7
+ def active_expansion(source):
8
+ quote = None
9
+ i = 0
10
+ while i < len(source):
11
+ c = source[i]
12
+ if quote == "'":
13
+ if c == "'": quote = None
14
+ elif c == '\\':
15
+ return True
16
+ elif c == "'" and quote is None:
17
+ quote = "'"
18
+ elif c == '"':
19
+ quote = None if quote == '"' else '"'
20
+ elif ord(c) == 96 or c == '$':
21
+ return True
22
+ elif quote is None and c in '*?[{~#':
23
+ return True
24
+ elif quote is None and (source.startswith('<(', i) or source.startswith('>(', i)):
25
+ return True
26
+ i += 1
27
+ return quote is not None
28
+
29
+ def tokens(source, posix=True):
30
+ lexer = shlex.shlex(source, posix=posix, punctuation_chars=';&|()<>\n')
31
+ lexer.whitespace = ' \t\r'
32
+ lexer.commenters = ''
33
+ return list(lexer)
34
+
35
+ def quoted_operator(source):
36
+ for raw in tokens(source, posix=False):
37
+ if raw and raw[0] in ("'", '"'):
38
+ values = shlex.split(raw, posix=True)
39
+ if len(values) == 1 and values[0] and all(c in ';&|()<>\n' for c in values[0]): return True
40
+ return False
41
+
42
+ def python_file_data(source):
43
+ tree = ast.parse(source)
44
+ if len(list(ast.walk(tree))) > 4096: return False
45
+ bindings = {}
46
+ constructors = set()
47
+
48
+ def kind(node):
49
+ if isinstance(node, ast.Constant):
50
+ return 'text' if isinstance(node.value, str) else 'bytes' if isinstance(node.value, bytes) else 'number' if isinstance(node.value, (int, float)) else None
51
+ if isinstance(node, ast.Name): return bindings.get(node.id)
52
+ if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):
53
+ left, right = kind(node.left), kind(node.right)
54
+ return left if left == right and left in ('text', 'bytes') else None
55
+ if not isinstance(node, ast.Call) or any(k.arg is None for k in node.keywords): return None
56
+ if isinstance(node.func, ast.Name) and node.func.id == 'Path' and 'Path' in constructors:
57
+ return 'path' if node.args and all(kind(a) == 'text' for a in node.args) and not node.keywords else None
58
+ if isinstance(node.func, ast.Attribute):
59
+ owner, method = node.func.value, node.func.attr
60
+ if isinstance(owner, ast.Name) and owner.id == 'pathlib' and 'pathlib' in constructors and method == 'Path':
61
+ return 'path' if node.args and all(kind(a) == 'text' for a in node.args) and not node.keywords else None
62
+ receiver = kind(owner)
63
+ args = [kind(a) for a in node.args]
64
+ if any(kind(k.value) != 'text' or k.arg not in ('encoding', 'errors') for k in node.keywords): return None
65
+ if receiver == 'path':
66
+ if method == 'read_text' and not args: return 'text'
67
+ if method == 'read_bytes' and not args and not node.keywords: return 'bytes'
68
+ if method == 'write_text' and args == ['text']: return 'number'
69
+ if method == 'write_bytes' and args == ['bytes'] and not node.keywords: return 'number'
70
+ if receiver == 'text' and method == 'replace' and args == ['text', 'text'] and not node.keywords: return 'text'
71
+ return None
72
+
73
+ for statement in tree.body:
74
+ if isinstance(statement, ast.ImportFrom) and statement.module == 'pathlib' and statement.level == 0:
75
+ if any(a.name != 'Path' or a.asname for a in statement.names): return False
76
+ constructors.add('Path')
77
+ elif isinstance(statement, ast.Import):
78
+ if any(a.name != 'pathlib' or a.asname for a in statement.names): return False
79
+ constructors.add('pathlib')
80
+ elif isinstance(statement, ast.Assign):
81
+ value = kind(statement.value)
82
+ if value is None or any(not isinstance(t, ast.Name) or t.id in ('Path', 'pathlib') for t in statement.targets): return False
83
+ for target in statement.targets: bindings[target.id] = value
84
+ elif isinstance(statement, ast.Expr):
85
+ if kind(statement.value) is None: return False
86
+ else: return False
87
+ return True
88
+
89
+ def safe_command(raw, depth):
90
+ values = list(raw)
91
+ # Environment overrides can change a tool's execution configuration.
92
+ if values and re.match(r'^[A-Za-z_][A-Za-z0-9_]*=', values[0]): return False
93
+ if not values: return True
94
+ if values[0] == 'command':
95
+ values.pop(0)
96
+ if values and values[0] == '--': values.pop(0)
97
+ if not values: return False
98
+ name = os.path.basename(values[0])
99
+ args = values[1:]
100
+ if name in ('sh', 'bash'):
101
+ if os.environ.get('BASH_ENV') or os.environ.get('ENV'): return False
102
+ return len(args) == 2 and args[0] == '-c' and data_only(args[1], depth + 1)
103
+ if name in ('python', 'python3'):
104
+ return len(args) == 2 and args[0] == '-c' and python_file_data(args[1])
105
+ if name == 'rg' and (os.environ.get('RIPGREP_CONFIG_PATH') or any(a == '--pre' or a.startswith('--pre=') or a == '--hostname-bin' or a.startswith('--hostname-bin=') for a in args)): return False
106
+ if name == 'printf' and any(a.startswith('-v') for a in args): return False
107
+ return name in ('rg', 'grep', 'egrep', 'fgrep', 'cat', 'printf', 'echo', 'tee', 'head', 'tail', 'wc', 'true', 'false')
108
+
109
+ def safe_tokens(parts, depth):
110
+ command = []
111
+ i = 0
112
+ for_end = (';', '&&', '||', '|', '&', '\n')
113
+ while i < len(parts):
114
+ token = parts[i]
115
+ if token in for_end:
116
+ if command and not safe_command(command, depth): return False
117
+ command = []
118
+ elif token in ('>', '>>', '<'):
119
+ i += 1
120
+ if i >= len(parts) or parts[i] in for_end or parts[i] in ('(', ')', '<', '>', '>>', '<<'): return False
121
+ elif token and all(c in ';&|()<>\n' for c in token):
122
+ return False
123
+ else: command.append(token)
124
+ i += 1
125
+ return not command or safe_command(command, depth)
126
+
127
+ def data_only(source, depth=0):
128
+ if depth > 8 or len(source) > 262144: return False
129
+ if any((ord(c) < 32 and c not in ('\n', '\t')) or ord(c) in (127, 133, 8232, 8233) for c in source): return False
130
+ lines = source.splitlines(keepends=True)
131
+ first = tokens(lines[0].rstrip('\r\n')) if lines else []
132
+ if '<<' in first:
133
+ # Raw anchoring rejects quote concatenation and unsupported headers;
134
+ # semantic argv alone does not retain heredoc quoting provenance.
135
+ header = re.fullmatch(r'''[ \t]*(cat|tee|python3?)(?:[ \t]+-)?[ \t]*<<[ \t]*(['"])([A-Za-z_][A-Za-z0-9_]*)\2[ \t]*(?:>>?[ \t]*[A-Za-z0-9_./-]+[ \t]*)?''', lines[0].rstrip('\n'))
136
+ if header is None: return False
137
+ marker = header.group(3)
138
+ end = next((n for n in range(1, len(lines)) if lines[n].rstrip('\r\n') == marker), None)
139
+ if end is None: return False
140
+ body = ''.join(lines[1:end])
141
+ name = header.group(1)
142
+ if name in ('python', 'python3'):
143
+ if not python_file_data(body): return False
144
+ return data_only(''.join(lines[end + 1:]), depth + 1)
145
+ return not active_expansion(source) and not quoted_operator(source) and safe_tokens(tokens(source), depth)
146
+
147
+ try:
148
+ source = sys.argv[1]
149
+ try:
150
+ payload = json.loads(source)
151
+ if isinstance(payload, dict):
152
+ tool = payload.get('tool_input')
153
+ if tool is not None and not isinstance(tool, dict): sys.exit(1)
154
+ candidates = []
155
+ for container in (payload, tool or {}):
156
+ for field in ('command', 'cmd'):
157
+ value = container.get(field)
158
+ if value is not None and value != '':
159
+ if not isinstance(value, str): sys.exit(1)
160
+ candidates.append(value)
161
+ if len(set(candidates)) > 1: sys.exit(1)
162
+ source = candidates[0] if candidates else ''
163
+ except (ValueError, TypeError): pass
164
+ sys.exit(0 if isinstance(source, str) and data_only(source) else 1)
165
+ except Exception:
166
+ sys.exit(1)
167
+ INSTAR_SQL_CONTEXT_PY
168
+ }
169
+ SQL_LITERAL_DATA=""
170
+ `;
171
+ //# sourceMappingURL=sqlCommandContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlCommandContext.js","sourceRoot":"","sources":["../../src/core/sqlCommandContext.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwKlD,CAAC"}
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "generatedFrom": "source-tree",
4
4
  "registrySha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
5
- "packageVersion": "1.3.2029",
5
+ "packageVersion": "1.3.2030",
6
6
  "guards": [
7
7
  {
8
8
  "ref": "docs/audits/phase-b/f10-triage.md",
@@ -1,5 +1,5 @@
1
1
  {
2
- "sha256": "d63f6f2b347738600fa9f90188911dc50e9564b4f4fd99bf86a670039bfa16e9",
2
+ "sha256": "eab2a6b115b673aa4bf68a3c7aa1d5722b12dc649d7f1eb32d84ef4209684ada",
3
3
  "registrySha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
4
- "packageVersion": "1.3.2029"
4
+ "packageVersion": "1.3.2030"
5
5
  }
@@ -2,5 +2,5 @@
2
2
  "sha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
3
3
  "articleCount": 102,
4
4
  "generatedFrom": "docs/STANDARDS-REGISTRY.md",
5
- "packageVersion": "1.3.2029"
5
+ "packageVersion": "1.3.2030"
6
6
  }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "1.3.2029",
3
+ "version": "1.3.2030",
4
4
  "description": "Coherence infrastructure for self-evolving AI agents — on the Claude Code or Codex subscription you already have.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: SQL Text In Command Data
3
+ ---
4
+
5
+ The command safety hook distinguishes recognized literal search and file-writing data from executable SQL contexts. Unknown syntax, variables, executable expansions, rg subprocess flags and unsupported programs still receive the existing SQL check. A hook refusal is not permission to bypass it. When investigating another false positive, preserve the exact command and refusal, add both data and real-execution regressions, and repair the shared init/update classifier through normal review and release. Custom hooks remain unchanged.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "./builtin-manifest.schema.json",
3
3
  "schemaVersion": 1,
4
- "generatedAt": "2026-11-25T05:16:34.211Z",
5
- "instarVersion": "1.3.2029",
4
+ "generatedAt": "2026-11-25T05:57:06.217Z",
5
+ "instarVersion": "1.3.2030",
6
6
  "entryCount": 210,
7
7
  "entries": {
8
8
  "hook:session-start": {
@@ -11,7 +11,7 @@
11
11
  "domain": "identity",
12
12
  "sourcePath": "src/core/PostUpdateMigrator.ts",
13
13
  "installedPath": ".instar/hooks/instar/session-start.sh",
14
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
14
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
15
15
  "since": "2025-01-01"
16
16
  },
17
17
  "hook:dangerous-command-guard": {
@@ -20,7 +20,7 @@
20
20
  "domain": "safety",
21
21
  "sourcePath": "src/core/PostUpdateMigrator.ts",
22
22
  "installedPath": ".instar/hooks/instar/dangerous-command-guard.sh",
23
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
23
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
24
24
  "since": "2025-01-01"
25
25
  },
26
26
  "hook:grounding-before-messaging": {
@@ -29,7 +29,7 @@
29
29
  "domain": "safety",
30
30
  "sourcePath": "src/core/PostUpdateMigrator.ts",
31
31
  "installedPath": ".instar/hooks/instar/grounding-before-messaging.sh",
32
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
32
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
33
33
  "since": "2025-01-01"
34
34
  },
35
35
  "hook:compaction-recovery": {
@@ -38,7 +38,7 @@
38
38
  "domain": "identity",
39
39
  "sourcePath": "src/core/PostUpdateMigrator.ts",
40
40
  "installedPath": ".instar/hooks/instar/compaction-recovery.sh",
41
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
41
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
42
42
  "since": "2025-01-01"
43
43
  },
44
44
  "hook:external-operation-gate": {
@@ -47,7 +47,7 @@
47
47
  "domain": "safety",
48
48
  "sourcePath": "src/core/PostUpdateMigrator.ts",
49
49
  "installedPath": ".instar/hooks/instar/external-operation-gate.js",
50
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
50
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
51
51
  "since": "2025-01-01"
52
52
  },
53
53
  "hook:deferral-detector": {
@@ -56,7 +56,7 @@
56
56
  "domain": "safety",
57
57
  "sourcePath": "src/core/PostUpdateMigrator.ts",
58
58
  "installedPath": ".instar/hooks/instar/deferral-detector.js",
59
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
59
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
60
60
  "since": "2025-01-01"
61
61
  },
62
62
  "hook:self-stop-guard": {
@@ -65,7 +65,7 @@
65
65
  "domain": "coherence",
66
66
  "sourcePath": "src/core/PostUpdateMigrator.ts",
67
67
  "installedPath": ".instar/hooks/instar/self-stop-guard.js",
68
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
68
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
69
69
  "since": "2025-01-01"
70
70
  },
71
71
  "hook:post-action-reflection": {
@@ -74,7 +74,7 @@
74
74
  "domain": "evolution",
75
75
  "sourcePath": "src/core/PostUpdateMigrator.ts",
76
76
  "installedPath": ".instar/hooks/instar/post-action-reflection.js",
77
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
77
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
78
78
  "since": "2025-01-01"
79
79
  },
80
80
  "hook:external-communication-guard": {
@@ -83,7 +83,7 @@
83
83
  "domain": "safety",
84
84
  "sourcePath": "src/core/PostUpdateMigrator.ts",
85
85
  "installedPath": ".instar/hooks/instar/external-communication-guard.js",
86
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
86
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
87
87
  "since": "2025-01-01"
88
88
  },
89
89
  "hook:telegram-origin-guard": {
@@ -101,7 +101,7 @@
101
101
  "domain": "coherence",
102
102
  "sourcePath": "src/core/PostUpdateMigrator.ts",
103
103
  "installedPath": ".instar/hooks/instar/scope-coherence-collector.js",
104
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
104
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
105
105
  "since": "2025-01-01"
106
106
  },
107
107
  "hook:scope-coherence-checkpoint": {
@@ -110,7 +110,7 @@
110
110
  "domain": "coherence",
111
111
  "sourcePath": "src/core/PostUpdateMigrator.ts",
112
112
  "installedPath": ".instar/hooks/instar/scope-coherence-checkpoint.js",
113
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
113
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
114
114
  "since": "2025-01-01"
115
115
  },
116
116
  "hook:free-text-guard": {
@@ -119,7 +119,7 @@
119
119
  "domain": "safety",
120
120
  "sourcePath": "src/core/PostUpdateMigrator.ts",
121
121
  "installedPath": ".instar/hooks/instar/free-text-guard.sh",
122
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
122
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
123
123
  "since": "2025-01-01"
124
124
  },
125
125
  "hook:claim-intercept": {
@@ -128,7 +128,7 @@
128
128
  "domain": "coherence",
129
129
  "sourcePath": "src/core/PostUpdateMigrator.ts",
130
130
  "installedPath": ".instar/hooks/instar/claim-intercept.js",
131
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
131
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
132
132
  "since": "2025-01-01"
133
133
  },
134
134
  "hook:claim-intercept-response": {
@@ -137,7 +137,7 @@
137
137
  "domain": "coherence",
138
138
  "sourcePath": "src/core/PostUpdateMigrator.ts",
139
139
  "installedPath": ".instar/hooks/instar/claim-intercept-response.js",
140
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
140
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
141
141
  "since": "2025-01-01"
142
142
  },
143
143
  "hook:stop-gate-router": {
@@ -146,7 +146,7 @@
146
146
  "domain": "safety",
147
147
  "sourcePath": "src/core/PostUpdateMigrator.ts",
148
148
  "installedPath": ".instar/hooks/instar/stop-gate-router.js",
149
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
149
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
150
150
  "since": "2025-01-01"
151
151
  },
152
152
  "hook:attribution-gate": {
@@ -155,7 +155,7 @@
155
155
  "domain": "safety",
156
156
  "sourcePath": "src/core/PostUpdateMigrator.ts",
157
157
  "installedPath": ".instar/hooks/instar/attribution-gate.js",
158
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
158
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
159
159
  "since": "2025-01-01"
160
160
  },
161
161
  "hook:auto-approve-permissions": {
@@ -164,7 +164,7 @@
164
164
  "domain": "safety",
165
165
  "sourcePath": "src/core/PostUpdateMigrator.ts",
166
166
  "installedPath": ".instar/hooks/instar/auto-approve-permissions.js",
167
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
167
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
168
168
  "since": "2025-01-01"
169
169
  },
170
170
  "job:health-check": {
@@ -1084,7 +1084,7 @@
1084
1084
  "type": "template",
1085
1085
  "domain": "safety",
1086
1086
  "sourcePath": "src/templates/hooks/dangerous-command-guard.sh",
1087
- "contentHash": "07f4aee354516334be55487b6d56412c13058fd360b8008e978209d0aa52b524",
1087
+ "contentHash": "9142a640087f82602c10c039e3dc95524aa7bef616c075a18c1e39a94ce6e4e9",
1088
1088
  "since": "2025-01-01"
1089
1089
  },
1090
1090
  "template:free-text-guard.sh": {
@@ -1628,7 +1628,7 @@
1628
1628
  "type": "subsystem",
1629
1629
  "domain": "updates",
1630
1630
  "sourcePath": "src/core/PostUpdateMigrator.ts",
1631
- "contentHash": "afba699ed5ed492f4ae87dc02ad3ad9de092b8ffe0852a3755850947b277670e",
1631
+ "contentHash": "b7a2ae14c60589e7aaf8f57b66fb11c0ee07ebd60c221889580d1222301e748c",
1632
1632
  "since": "2025-01-01"
1633
1633
  },
1634
1634
  "subsystem:scheduler": {
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "generatedFrom": "source-tree",
4
4
  "registrySha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
5
- "packageVersion": "1.3.2029",
5
+ "packageVersion": "1.3.2030",
6
6
  "guards": [
7
7
  {
8
8
  "ref": "docs/audits/phase-b/f10-triage.md",
@@ -1,5 +1,5 @@
1
1
  {
2
- "sha256": "d63f6f2b347738600fa9f90188911dc50e9564b4f4fd99bf86a670039bfa16e9",
2
+ "sha256": "eab2a6b115b673aa4bf68a3c7aa1d5722b12dc649d7f1eb32d84ef4209684ada",
3
3
  "registrySha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
4
- "packageVersion": "1.3.2029"
4
+ "packageVersion": "1.3.2030"
5
5
  }
@@ -2,5 +2,5 @@
2
2
  "sha256": "11e2a45ab1345e2ded6499404ee9962e4e48bcfed4677a4d31dac4492565d2fa",
3
3
  "articleCount": 102,
4
4
  "generatedFrom": "docs/STANDARDS-REGISTRY.md",
5
- "packageVersion": "1.3.2029"
5
+ "packageVersion": "1.3.2030"
6
6
  }
@@ -62,6 +62,175 @@ if echo "$INPUT" | grep -qE -e '(gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9
62
62
  exit 2
63
63
  fi
64
64
 
65
+ # SQL context: only proven literal data operations bypass the SQL-shaped matcher.
66
+ sql_command_is_literal_data() {
67
+ python3 - "$INPUT" <<'INSTAR_SQL_CONTEXT_PY'
68
+ import ast, json, os, re, shlex, sys
69
+
70
+ def active_expansion(source):
71
+ quote = None
72
+ i = 0
73
+ while i < len(source):
74
+ c = source[i]
75
+ if quote == "'":
76
+ if c == "'": quote = None
77
+ elif c == '\\':
78
+ return True
79
+ elif c == "'" and quote is None:
80
+ quote = "'"
81
+ elif c == '"':
82
+ quote = None if quote == '"' else '"'
83
+ elif ord(c) == 96 or c == '$':
84
+ return True
85
+ elif quote is None and c in '*?[{~#':
86
+ return True
87
+ elif quote is None and (source.startswith('<(', i) or source.startswith('>(', i)):
88
+ return True
89
+ i += 1
90
+ return quote is not None
91
+
92
+ def tokens(source, posix=True):
93
+ lexer = shlex.shlex(source, posix=posix, punctuation_chars=';&|()<>\n')
94
+ lexer.whitespace = ' \t\r'
95
+ lexer.commenters = ''
96
+ return list(lexer)
97
+
98
+ def quoted_operator(source):
99
+ for raw in tokens(source, posix=False):
100
+ if raw and raw[0] in ("'", '"'):
101
+ values = shlex.split(raw, posix=True)
102
+ if len(values) == 1 and values[0] and all(c in ';&|()<>\n' for c in values[0]): return True
103
+ return False
104
+
105
+ def python_file_data(source):
106
+ tree = ast.parse(source)
107
+ if len(list(ast.walk(tree))) > 4096: return False
108
+ bindings = {}
109
+ constructors = set()
110
+
111
+ def kind(node):
112
+ if isinstance(node, ast.Constant):
113
+ return 'text' if isinstance(node.value, str) else 'bytes' if isinstance(node.value, bytes) else 'number' if isinstance(node.value, (int, float)) else None
114
+ if isinstance(node, ast.Name): return bindings.get(node.id)
115
+ if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):
116
+ left, right = kind(node.left), kind(node.right)
117
+ return left if left == right and left in ('text', 'bytes') else None
118
+ if not isinstance(node, ast.Call) or any(k.arg is None for k in node.keywords): return None
119
+ if isinstance(node.func, ast.Name) and node.func.id == 'Path' and 'Path' in constructors:
120
+ return 'path' if node.args and all(kind(a) == 'text' for a in node.args) and not node.keywords else None
121
+ if isinstance(node.func, ast.Attribute):
122
+ owner, method = node.func.value, node.func.attr
123
+ if isinstance(owner, ast.Name) and owner.id == 'pathlib' and 'pathlib' in constructors and method == 'Path':
124
+ return 'path' if node.args and all(kind(a) == 'text' for a in node.args) and not node.keywords else None
125
+ receiver = kind(owner)
126
+ args = [kind(a) for a in node.args]
127
+ if any(kind(k.value) != 'text' or k.arg not in ('encoding', 'errors') for k in node.keywords): return None
128
+ if receiver == 'path':
129
+ if method == 'read_text' and not args: return 'text'
130
+ if method == 'read_bytes' and not args and not node.keywords: return 'bytes'
131
+ if method == 'write_text' and args == ['text']: return 'number'
132
+ if method == 'write_bytes' and args == ['bytes'] and not node.keywords: return 'number'
133
+ if receiver == 'text' and method == 'replace' and args == ['text', 'text'] and not node.keywords: return 'text'
134
+ return None
135
+
136
+ for statement in tree.body:
137
+ if isinstance(statement, ast.ImportFrom) and statement.module == 'pathlib' and statement.level == 0:
138
+ if any(a.name != 'Path' or a.asname for a in statement.names): return False
139
+ constructors.add('Path')
140
+ elif isinstance(statement, ast.Import):
141
+ if any(a.name != 'pathlib' or a.asname for a in statement.names): return False
142
+ constructors.add('pathlib')
143
+ elif isinstance(statement, ast.Assign):
144
+ value = kind(statement.value)
145
+ if value is None or any(not isinstance(t, ast.Name) or t.id in ('Path', 'pathlib') for t in statement.targets): return False
146
+ for target in statement.targets: bindings[target.id] = value
147
+ elif isinstance(statement, ast.Expr):
148
+ if kind(statement.value) is None: return False
149
+ else: return False
150
+ return True
151
+
152
+ def safe_command(raw, depth):
153
+ values = list(raw)
154
+ # Environment overrides can change a tool's execution configuration.
155
+ if values and re.match(r'^[A-Za-z_][A-Za-z0-9_]*=', values[0]): return False
156
+ if not values: return True
157
+ if values[0] == 'command':
158
+ values.pop(0)
159
+ if values and values[0] == '--': values.pop(0)
160
+ if not values: return False
161
+ name = os.path.basename(values[0])
162
+ args = values[1:]
163
+ if name in ('sh', 'bash'):
164
+ if os.environ.get('BASH_ENV') or os.environ.get('ENV'): return False
165
+ return len(args) == 2 and args[0] == '-c' and data_only(args[1], depth + 1)
166
+ if name in ('python', 'python3'):
167
+ return len(args) == 2 and args[0] == '-c' and python_file_data(args[1])
168
+ if name == 'rg' and (os.environ.get('RIPGREP_CONFIG_PATH') or any(a == '--pre' or a.startswith('--pre=') or a == '--hostname-bin' or a.startswith('--hostname-bin=') for a in args)): return False
169
+ if name == 'printf' and any(a.startswith('-v') for a in args): return False
170
+ return name in ('rg', 'grep', 'egrep', 'fgrep', 'cat', 'printf', 'echo', 'tee', 'head', 'tail', 'wc', 'true', 'false')
171
+
172
+ def safe_tokens(parts, depth):
173
+ command = []
174
+ i = 0
175
+ for_end = (';', '&&', '||', '|', '&', '\n')
176
+ while i < len(parts):
177
+ token = parts[i]
178
+ if token in for_end:
179
+ if command and not safe_command(command, depth): return False
180
+ command = []
181
+ elif token in ('>', '>>', '<'):
182
+ i += 1
183
+ if i >= len(parts) or parts[i] in for_end or parts[i] in ('(', ')', '<', '>', '>>', '<<'): return False
184
+ elif token and all(c in ';&|()<>\n' for c in token):
185
+ return False
186
+ else: command.append(token)
187
+ i += 1
188
+ return not command or safe_command(command, depth)
189
+
190
+ def data_only(source, depth=0):
191
+ if depth > 8 or len(source) > 262144: return False
192
+ if any((ord(c) < 32 and c not in ('\n', '\t')) or ord(c) in (127, 133, 8232, 8233) for c in source): return False
193
+ lines = source.splitlines(keepends=True)
194
+ first = tokens(lines[0].rstrip('\r\n')) if lines else []
195
+ if '<<' in first:
196
+ # Raw anchoring rejects quote concatenation and unsupported headers;
197
+ # semantic argv alone does not retain heredoc quoting provenance.
198
+ header = re.fullmatch(r'''[ \t]*(cat|tee|python3?)(?:[ \t]+-)?[ \t]*<<[ \t]*(['"])([A-Za-z_][A-Za-z0-9_]*)\2[ \t]*(?:>>?[ \t]*[A-Za-z0-9_./-]+[ \t]*)?''', lines[0].rstrip('\n'))
199
+ if header is None: return False
200
+ marker = header.group(3)
201
+ end = next((n for n in range(1, len(lines)) if lines[n].rstrip('\r\n') == marker), None)
202
+ if end is None: return False
203
+ body = ''.join(lines[1:end])
204
+ name = header.group(1)
205
+ if name in ('python', 'python3'):
206
+ if not python_file_data(body): return False
207
+ return data_only(''.join(lines[end + 1:]), depth + 1)
208
+ return not active_expansion(source) and not quoted_operator(source) and safe_tokens(tokens(source), depth)
209
+
210
+ try:
211
+ source = sys.argv[1]
212
+ try:
213
+ payload = json.loads(source)
214
+ if isinstance(payload, dict):
215
+ tool = payload.get('tool_input')
216
+ if tool is not None and not isinstance(tool, dict): sys.exit(1)
217
+ candidates = []
218
+ for container in (payload, tool or {}):
219
+ for field in ('command', 'cmd'):
220
+ value = container.get(field)
221
+ if value is not None and value != '':
222
+ if not isinstance(value, str): sys.exit(1)
223
+ candidates.append(value)
224
+ if len(set(candidates)) > 1: sys.exit(1)
225
+ source = candidates[0] if candidates else ''
226
+ except (ValueError, TypeError): pass
227
+ sys.exit(0 if isinstance(source, str) and data_only(source) else 1)
228
+ except Exception:
229
+ sys.exit(1)
230
+ INSTAR_SQL_CONTEXT_PY
231
+ }
232
+ SQL_LITERAL_DATA=""
233
+
65
234
  # --- Risky commands: behavior depends on safety level ---
66
235
  RISKY_PATTERNS=(
67
236
  "rm -rf \."
@@ -114,6 +283,14 @@ fi
114
283
 
115
284
  for pattern in "${RISKY_PATTERNS[@]}"; do
116
285
  if echo "$INPUT" | grep -qiE -e "$pattern"; then
286
+ case "$pattern" in
287
+ "D""ROP TABLE"|"D""ROP DATABASE"|"T""RUNCATE"|"D""ELETE FROM")
288
+ if [ -z "$SQL_LITERAL_DATA" ]; then
289
+ if sql_command_is_literal_data; then SQL_LITERAL_DATA=1; else SQL_LITERAL_DATA=0; fi
290
+ fi
291
+ if [ "$SQL_LITERAL_DATA" = "1" ]; then continue; fi
292
+ ;;
293
+ esac
117
294
  # Allow the safe force-with-lease-to-own-branch case past the force-push patterns.
118
295
  if [ "$FORCE_WITH_LEASE_OWN_BRANCH" -eq 1 ] && echo "$pattern" | grep -qiE 'git push (--force|-f)'; then
119
296
  continue
@@ -0,0 +1,20 @@
1
+ # Upgrade Guide — vNEXT
2
+
3
+ <!-- assembled-by: assemble-next-md -->
4
+ <!-- bump: patch -->
5
+
6
+ ## What Changed
7
+
8
+ The command safety hook recognizes literal search arguments and simple source-file output as data before applying its existing SQL rule. Executable or uncertain contexts keep the original SQL matching. Active expansions, rg execution flags, mixed commands and unsupported programs are not blanket exemptions. Shared init/update logic and a byte-identical standalone template keep installation paths aligned.
9
+
10
+ ## What to Tell Your User
11
+
12
+ Read-only searches and ordinary source-file edits no longer get mistaken for database changes just because their text resembles SQL. Existing command protections remain in place.
13
+
14
+ ## Summary of New Capabilities
15
+
16
+ No new setting or authority. This repairs how the existing safety hook interprets command data.
17
+
18
+ ## Evidence
19
+
20
+ All 27 selected baseline literal-data regressions failed across the three writers. Independent final review concurred. The patched candidate passed 158 unit, 32 native-hook integration and 1 production hook-repair lifecycle case. The first lifecycle fixture-mode failure was preserved and corrected under a fresh allocation; production source did not change. Complete coordinator verification remains required. No command in the fixtures executes database operations, and no live hook was patched.