@mokuyoaxis/agent-guard 0.2.3-rc2 → 0.2.4-hotfix.1
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.
- package/README.md +132 -84
- package/README.zh-CN.md +109 -75
- package/adapters/INTEGRATION.md +4 -4
- package/adapters/claude/README.md +3 -3
- package/adapters/claude/harness/README.md +1 -1
- package/adapters/codex/harness/README.md +2 -2
- package/adapters/dsh/README.md +24 -15
- package/adapters/dsh/harness/README.md +75 -19
- package/adapters/dsh/harness/bootstrap.patch.yml +5 -0
- package/adapters/dsh/harness/bootstrap_init.mjs +48 -0
- package/adapters/dsh/harness/guard_lab.py +194 -32
- package/adapters/dsh/harness/native_session.py +41 -20
- package/adapters/dsh/harness/profiles.py +74 -22
- package/adapters/dsh/lib/index.js +1 -1
- package/adapters/kimi-code/README.md +15 -14
- package/adapters/kimi-code/harness/README.md +3 -3
- package/adapters/kimi-code/harness/guard_lab.py +1 -1
- package/core/__init__.py +1 -1
- package/core/classifier.py +66 -17
- package/core/lab.py +24 -1
- package/core/policy.py +28 -13
- package/core/recovery.py +256 -23
- package/core/redaction.py +157 -55
- package/core/trash_index.py +193 -0
- package/docs/README.md +104 -0
- package/docs/{architecture.md → design/architecture.md} +31 -6
- package/docs/{compatibility.md → design/compatibility.md} +80 -4
- package/docs/{threat-model.md → design/threat-model.md} +4 -4
- package/docs/{harness-capabilities.md → guides/harness-capabilities.md} +9 -9
- package/docs/guides/trash-index.md +106 -0
- package/docs/{development-note-unguarded-deletion.md → history/development-note-unguarded-deletion.md} +8 -9
- package/docs/{friction.md → history/friction.md} +129 -4
- package/docs/{secret-guard-analysis.md → history/secret-guard-analysis.md} +23 -22
- package/docs/{secret-guard-architecture.md → history/secret-guard-architecture.md} +6 -4
- package/docs/{secret-guard-design.md → history/secret-guard-design.md} +19 -15
- package/docs/lab/cases/injection-case-fake-ai-api.md +346 -0
- package/docs/{guard-lab.md → lab/guard-lab.md} +18 -11
- package/docs/lab/tasks/guard-lab-read-trial-task.md +7 -0
- package/docs/{release-notes-0.2.0-rc1.md → releases/release-notes-0.2.0-rc1.md} +5 -5
- package/docs/{release-notes-0.2.0.md → releases/release-notes-0.2.0.md} +7 -7
- package/docs/{release-notes-0.2.1.md → releases/release-notes-0.2.1.md} +6 -6
- package/docs/{release-notes-0.2.2.md → releases/release-notes-0.2.2.md} +9 -10
- package/docs/{release-notes-0.2.3-rc1.md → releases/release-notes-0.2.3-rc1.md} +4 -2
- package/docs/{release-notes-0.2.3-rc2.md → releases/release-notes-0.2.3-rc2.md} +9 -9
- package/docs/releases/release-notes-0.2.3.md +84 -0
- package/docs/releases/release-notes-0.2.4-hotfix.1.md +75 -0
- package/docs/releases/release-notes-0.2.4.md +89 -0
- package/docs/{test-report-claude-code-harness.md → reports/test-report-claude-code-harness.md} +5 -5
- package/docs/{test-report-codex-gpt-5.6-sol.md → reports/test-report-codex-gpt-5.6-sol.md} +10 -11
- package/docs/reports/test-report-dsh-0.2.4-ptc.md +79 -0
- package/docs/{test-report-dsh-guard-lab.md → reports/test-report-dsh-guard-lab.md} +1 -1
- package/docs/{test-report-dsh-native-session.md → reports/test-report-dsh-native-session.md} +1 -1
- package/docs/{test-report-dsh-paired-lab.md → reports/test-report-dsh-paired-lab.md} +1 -1
- package/docs/{test-report-dsh-real-followup.md → reports/test-report-dsh-real-followup.md} +1 -1
- package/docs/{test-report-dsh-retry-evidence.md → reports/test-report-dsh-retry-evidence.md} +1 -1
- package/docs/{test-report-dsh-v0.1.1.md → reports/test-report-dsh-v0.1.1.md} +4 -4
- package/docs/{test-report-kimi-code-block.md → reports/test-report-kimi-code-block.md} +22 -23
- package/docs/{test-report-kimi-guard-lab.md → reports/test-report-kimi-guard-lab.md} +3 -3
- package/docs/{test-report-release-readiness-0.2.3.md → reports/test-report-release-readiness-0.2.3.md} +79 -1
- package/docs/reports/test-report-workbuddy-windows-core.md +53 -0
- package/docs/{test-report-zcode-glm-flash.md → reports/test-report-zcode-glm-flash.md} +11 -11
- package/package.json +1 -1
- package/skills/delete-guard/SKILL.md +40 -3
- package/skills/delete-guard/references/policy.md +29 -9
- package/skills/delete-guard/scripts/check.py +19 -0
- package/skills/delete-guard/scripts/restore.py +18 -6
- package/skills/delete-guard/scripts/status.py +52 -0
- package/skills/exfil-guard/SKILL.md +37 -7
- package/skills/exfil-guard/references/channels.md +1 -1
- package/skills/exfil-guard/references/rules.md +84 -16
- package/skills/exfil-guard/scripts/_payload.py +99 -0
- package/skills/exfil-guard/scripts/check_span.py +14 -81
- package/skills/exfil-guard/scripts/sanitize.py +113 -34
- package/docs/release-notes-0.2.3.md +0 -45
- /package/docs/{host-drift.md → guides/host-drift.md} +0 -0
- /package/docs/{publishing-from-ephemeral-environments.md → guides/publishing-from-ephemeral-environments.md} +0 -0
- /package/docs/{guard-lab-clean-task.md → lab/tasks/guard-lab-clean-task.md} +0 -0
- /package/docs/{guard-lab-trial-task.md → lab/tasks/guard-lab-trial-task.md} +0 -0
- /package/docs/{test-report-codex-gpt-6-astra-high.md → reports/test-report-codex-gpt-6-astra-high.md} +0 -0
- /package/docs/{test-report-dsh-0.1.5-rc.1.md → reports/test-report-dsh-0.1.5-rc.1.md} +0 -0
- /package/docs/{test-report-dsh-0.2-upgrade.md → reports/test-report-dsh-0.2-upgrade.md} +0 -0
- /package/docs/{test-report-dsh-read-redaction.md → reports/test-report-dsh-read-redaction.md} +0 -0
|
@@ -18,7 +18,7 @@ from adapters.dsh.harness.retry_stream import (
|
|
|
18
18
|
DECODER = Path(__file__).with_name("session_decode.mjs")
|
|
19
19
|
MAX_RECORDS = 4096
|
|
20
20
|
MAX_TREE_ENTRIES = 512
|
|
21
|
-
PARSER_VERSION =
|
|
21
|
+
PARSER_VERSION = 3
|
|
22
22
|
# Frozen vocabulary from DSH 0.1.5-rc.1's dsh-session known-event-types.
|
|
23
23
|
KNOWN_EVENTS = frozenset("""
|
|
24
24
|
agent-preset/selected agent/inbox/spliced approval/asked approval/decided
|
|
@@ -141,15 +141,17 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
141
141
|
This reads append-only, unseeded, one-turn fixtures; it does not reconstruct
|
|
142
142
|
arbitrary forks, replacements, attachments or model-visible context.
|
|
143
143
|
Version 2 also scans failed-attempt streams and verifies pinned retry chains.
|
|
144
|
-
Version 1
|
|
144
|
+
Version 1/2 keep the frozen interpretations used by earlier receipts.
|
|
145
|
+
Version 3 additionally accepts a v4 flat tool message whose source event
|
|
146
|
+
reference binds it to the corresponding earlier call, without replay.
|
|
145
147
|
"""
|
|
146
|
-
if type(parser_version) is not int or parser_version not in {1,
|
|
148
|
+
if type(parser_version) is not int or parser_version not in {1, 2, 3}:
|
|
147
149
|
raise LabError("unsupported native parser version")
|
|
148
150
|
if (type(native_format_version) is not int or native_format_version not in {3, 4}
|
|
149
|
-
or native_format_version == 4 and parser_version
|
|
151
|
+
or native_format_version == 4 and parser_version < 2):
|
|
150
152
|
raise LabError("unsupported native format/parser contract")
|
|
151
153
|
channels = {"tool": bytearray(), "assistant": bytearray()}
|
|
152
|
-
if parser_version
|
|
154
|
+
if parser_version >= 2:
|
|
153
155
|
channels["attempt"] = bytearray()
|
|
154
156
|
counts = {"tool": 0, "assistant": 0, "tool_calls": 0}
|
|
155
157
|
summary = {
|
|
@@ -158,13 +160,13 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
158
160
|
"cwd_matches": False, "task_matches": False,
|
|
159
161
|
"provenance": "captured-native-event-labels-not-authenticated-authorship",
|
|
160
162
|
}
|
|
161
|
-
if parser_version
|
|
162
|
-
summary.update({"parser_version":
|
|
163
|
+
if parser_version >= 2:
|
|
164
|
+
summary.update({"parser_version": parser_version, "retry_evidence": {
|
|
163
165
|
"attempts": 0, "scheduled": 0, "started": 0, "stream_chunks": 0,
|
|
164
166
|
}})
|
|
165
167
|
def refuse(issue):
|
|
166
168
|
summary["issues"] = [issue]
|
|
167
|
-
if parser_version
|
|
169
|
+
if parser_version >= 2:
|
|
168
170
|
summary["completed"] = False
|
|
169
171
|
return summary, {k: b"" for k in channels}
|
|
170
172
|
if not payload or len(payload) > MAX_SCAN_BYTES or not payload.endswith(b"\n"):
|
|
@@ -204,6 +206,7 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
204
206
|
ended = False
|
|
205
207
|
user_count = 0
|
|
206
208
|
calls = {}
|
|
209
|
+
call_events = {}
|
|
207
210
|
results = set()
|
|
208
211
|
step = None
|
|
209
212
|
closed_steps = set()
|
|
@@ -223,7 +226,8 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
223
226
|
kind = record["type"]
|
|
224
227
|
data = record["data"]
|
|
225
228
|
if native_format_version == 4 and "sourceEventSeqs" in record:
|
|
226
|
-
|
|
229
|
+
if parser_version < 3 or kind != "tool/result" or record.get("surfaceOp") != "append":
|
|
230
|
+
return refuse("UNSUPPORTED_SURFACE_REPLAY")
|
|
227
231
|
known_events = V4_EVENTS if native_format_version == 4 else KNOWN_EVENTS
|
|
228
232
|
if kind not in known_events and record.get("ignorable") is not True:
|
|
229
233
|
return refuse("UNKNOWN_REQUIRED_EVENT")
|
|
@@ -243,7 +247,7 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
243
247
|
elif kind == "step/end":
|
|
244
248
|
if step is None or not _integer(data.get("turn")) or not _integer(data.get("step")) or data.get("turn") != turn or data.get("step") != step:
|
|
245
249
|
return refuse("INVALID_STEP_END")
|
|
246
|
-
if parser_version
|
|
250
|
+
if parser_version >= 2 and pending_retry is not None:
|
|
247
251
|
if pending_retry["state"] != "attempt":
|
|
248
252
|
return refuse("UNFINISHED_RETRY_CHAIN")
|
|
249
253
|
unresolved_attempt = True
|
|
@@ -254,9 +258,9 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
254
258
|
return refuse("INVALID_TURN_END")
|
|
255
259
|
ended = True
|
|
256
260
|
summary["completed"] = data["reason"].get("kind") == "completed"
|
|
257
|
-
if parser_version
|
|
261
|
+
if parser_version >= 2 and summary["completed"] and unresolved_attempt:
|
|
258
262
|
return refuse("UNRECOVERED_ASSISTANT_ATTEMPT")
|
|
259
|
-
elif parser_version
|
|
263
|
+
elif parser_version >= 2 and kind == "request/header":
|
|
260
264
|
config = data.get("header", {}).get("config") if isinstance(data.get("header"), dict) else None
|
|
261
265
|
if (turn is None or ended or step is None or not isinstance(config, dict)
|
|
262
266
|
or not all(isinstance(config.get(k), str) and config[k] for k in ("provider", "model"))):
|
|
@@ -299,7 +303,7 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
299
303
|
elif native_format_version == 4 and kind == "workspace/changes":
|
|
300
304
|
if set(data) != {"turn"} or not _integer(data["turn"]) or data["turn"] != turn:
|
|
301
305
|
return refuse("INVALID_WORKSPACE_CHANGE_NOTICE")
|
|
302
|
-
elif parser_version
|
|
306
|
+
elif parser_version >= 2 and kind in {"llm/retry", "llm/retry-started"}:
|
|
303
307
|
if (turn is None or ended or step is None or not _integer(data.get("turn"))
|
|
304
308
|
or not _integer(data.get("step")) or data["turn"] != turn or data["step"] != step
|
|
305
309
|
or pending_retry is None or not isinstance(data.get("retryId"), str)
|
|
@@ -340,12 +344,13 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
340
344
|
if turn is None or ended or step is None or not _integer(data.get("turn")) or not _integer(data.get("step")) or data.get("turn") != turn or data.get("step") != step:
|
|
341
345
|
return refuse("OUTPUT_OUTSIDE_TURN")
|
|
342
346
|
if kind == "tool/call":
|
|
343
|
-
if parser_version
|
|
347
|
+
if parser_version >= 2 and pending_retry is not None:
|
|
344
348
|
return refuse("RETRY_LIFECYCLE_MISMATCH")
|
|
345
349
|
call = data.get("callId")
|
|
346
350
|
if not isinstance(call, str) or not call or call in calls or not all(isinstance(data.get(k), str) and data[k] for k in ("name", "arguments")):
|
|
347
351
|
return refuse("INVALID_OR_DUPLICATE_TOOL_CALL")
|
|
348
352
|
calls[call] = data["step"]
|
|
353
|
+
call_events[call] = expected_seq
|
|
349
354
|
counts["tool_calls"] += 1
|
|
350
355
|
continue
|
|
351
356
|
if kind == "assistant/attempt":
|
|
@@ -373,9 +378,11 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
373
378
|
continue
|
|
374
379
|
message = data.get("message")
|
|
375
380
|
role = "tool" if kind == "tool/result" else "assistant"
|
|
381
|
+
flat_tool = (role == "tool" and parser_version >= 3 and native_format_version == 4
|
|
382
|
+
and isinstance(message, dict) and message.get("role") == "tool")
|
|
376
383
|
if (
|
|
377
384
|
not isinstance(message, dict) or not isinstance(message.get("id"), str) or not message["id"]
|
|
378
|
-
or message.get("role") != ("user" if role == "tool" else "assistant")
|
|
385
|
+
or message.get("role") != ("tool" if flat_tool else "user" if role == "tool" else "assistant")
|
|
379
386
|
or not isinstance(message.get("source"), dict)
|
|
380
387
|
or message["source"].get("kind") != ("tool" if role == "tool" else "model")
|
|
381
388
|
or not _blocks_supported(message.get("content"))
|
|
@@ -385,17 +392,31 @@ def split_session(payload: bytes, fixture: Path, task_sha256: str,
|
|
|
385
392
|
blocks = message["content"]
|
|
386
393
|
call = message["source"].get("callId")
|
|
387
394
|
if (
|
|
388
|
-
|
|
389
|
-
or
|
|
390
|
-
or blocks[0]["toolCallId"] != call or calls[call] != data["step"]
|
|
395
|
+
not isinstance(call, str) or call not in calls or call in results
|
|
396
|
+
or calls[call] != data["step"]
|
|
391
397
|
):
|
|
392
398
|
return refuse("TOOL_RESULT_CORRELATION_FAILED")
|
|
393
|
-
if
|
|
399
|
+
if flat_tool:
|
|
400
|
+
refs = record.get("sourceEventSeqs")
|
|
401
|
+
if (message.get("toolCallId") != call or type(message.get("isError")) is not bool
|
|
402
|
+
or message["source"] != {"kind": "tool", "callId": call}
|
|
403
|
+
or not isinstance(refs, list) or len(refs) != 1
|
|
404
|
+
or type(refs[0]) is not int or refs[0] != call_events[call]
|
|
405
|
+
or any(block["type"] not in {"text", "reasoning"} for block in blocks)):
|
|
406
|
+
return refuse("INVALID_FLAT_TOOL_RESULT_OR_SOURCE")
|
|
407
|
+
is_error = message["isError"]
|
|
408
|
+
else:
|
|
409
|
+
if (len(blocks) != 1 or blocks[0]["type"] != "tool-result"
|
|
410
|
+
or blocks[0]["toolCallId"] != call
|
|
411
|
+
or parser_version >= 3 and "sourceEventSeqs" in record):
|
|
412
|
+
return refuse("TOOL_RESULT_CORRELATION_FAILED")
|
|
413
|
+
is_error = blocks[0].get("isError")
|
|
414
|
+
if "error" in data and (not isinstance(data["error"], dict) or is_error is not True):
|
|
394
415
|
return refuse("INVALID_TOOL_ERROR_METADATA")
|
|
395
416
|
results.add(call)
|
|
396
417
|
elif not all(isinstance(message["source"].get(k), str) and message["source"][k] for k in ("provider", "model")):
|
|
397
418
|
return refuse("INVALID_ASSISTANT_SOURCE")
|
|
398
|
-
if parser_version
|
|
419
|
+
if parser_version >= 2 and role == "assistant":
|
|
399
420
|
if step_assistant_seen:
|
|
400
421
|
return refuse("DUPLICATE_ASSISTANT_SETTLEMENT")
|
|
401
422
|
if pending_retry is not None:
|
|
@@ -17,6 +17,7 @@ from core.lab import LabError, MAX_SCAN_BYTES
|
|
|
17
17
|
ROOT = Path(__file__).resolve().parents[3]
|
|
18
18
|
ADAPTER = ROOT / "adapters/dsh/lib/index.js"
|
|
19
19
|
MEMBERS = ("clean-off", "clean-on", "baseline", "guarded")
|
|
20
|
+
GUARD_PROFILES = ("deletion-v1", "read-redaction-v1")
|
|
20
21
|
GUARD_ROW = re.compile(
|
|
21
22
|
rb"(?:\bid:\s*['\"]?agent_guard\b|@mokuyoaxis/agent-guard|"
|
|
22
23
|
rb"\bname:\s*['\"]?[^\r\n]*agent-guard)"
|
|
@@ -25,27 +26,50 @@ BOOTSTRAP_FILES = (
|
|
|
25
26
|
# Follow the Kimi copier's filename convention for source-corpus scans:
|
|
26
27
|
# a quoted store reference is otherwise treated as an outbound dump.
|
|
27
28
|
"profiles/headless/package.json", "profiles/headless/cordis.patch.yml",
|
|
28
|
-
"cordis.
|
|
29
|
+
"profiles/headless/cordis.yml", "cordis.patch.yml", "cordis.yml",
|
|
30
|
+
"settings.yaml", "settings.yaml.imported", "." + "env", "." + "creden" + "tials.yaml",
|
|
29
31
|
)
|
|
30
32
|
|
|
31
33
|
|
|
32
|
-
def
|
|
34
|
+
def guard_configuration(profile="deletion-v1", workspace=None, dsh_root=None):
|
|
35
|
+
if profile not in GUARD_PROFILES:
|
|
36
|
+
raise LabError("unknown DSH guard profile")
|
|
37
|
+
config = {"repoRoot": str(ROOT), "defaultCwd": "", "promptSection": True,
|
|
38
|
+
"sectionOrder": 105, "dialect": ""}
|
|
39
|
+
if profile == "read-redaction-v1":
|
|
40
|
+
if (workspace is None or dsh_root is None or not Path(workspace).is_absolute()
|
|
41
|
+
or not Path(dsh_root).is_absolute()):
|
|
42
|
+
raise LabError("read profile requires an absolute fixture and DSH package root")
|
|
43
|
+
config.update(defaultCwd=str(Path(workspace).resolve()), promptSection=False,
|
|
44
|
+
readResultGuard=True, readGuardDshRoot=str(Path(dsh_root).resolve()))
|
|
45
|
+
return config
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def guard_patch(profile="deletion-v1", workspace=None, dsh_root=None) -> bytes:
|
|
33
49
|
# JSON string literals are valid YAML scalars, including paths with spaces.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
if profile == "deletion-v1":
|
|
51
|
+
# Retain the exact historical patch bytes for old receipts/plans.
|
|
52
|
+
return (
|
|
53
|
+
"- insert:\n - id: agent_guard\n name: " + json.dumps(str(ADAPTER))
|
|
54
|
+
+ "\n config:\n repoRoot: " + json.dumps(str(ROOT))
|
|
55
|
+
+ "\n defaultCwd: ''\n promptSection: true\n"
|
|
56
|
+
" sectionOrder: 105\n dialect: ''\n"
|
|
57
|
+
).encode()
|
|
58
|
+
config = guard_configuration(profile, workspace, dsh_root)
|
|
59
|
+
return ("- insert:\n - id: agent_guard\n name: " + json.dumps(str(ADAPTER))
|
|
60
|
+
+ "\n config:\n" + "".join(" " + key + ": " + json.dumps(value)
|
|
61
|
+
+ "\n" for key, value in config.items())).encode()
|
|
40
62
|
|
|
41
63
|
|
|
42
64
|
def _scalar_matches(value: str, expected: str) -> bool:
|
|
43
65
|
return value in {expected, json.dumps(expected), "'" + expected.replace("'", "''") + "'"}
|
|
44
66
|
|
|
45
67
|
|
|
46
|
-
def normalize_composition(payload: bytes, guard_state: str
|
|
68
|
+
def normalize_composition(payload: bytes, guard_state: str, *,
|
|
69
|
+
profile="deletion-v1", workspace=None, dsh_root=None) -> bytes:
|
|
47
70
|
if guard_state not in {"off", "on"}:
|
|
48
71
|
raise LabError("guard state must be off or on")
|
|
72
|
+
config = guard_configuration(profile, workspace, dsh_root)
|
|
49
73
|
try:
|
|
50
74
|
text = payload.decode("utf-8")
|
|
51
75
|
except UnicodeError as exc:
|
|
@@ -74,13 +98,27 @@ def normalize_composition(payload: bytes, guard_state: str) -> bytes:
|
|
|
74
98
|
if len(guards) != 1:
|
|
75
99
|
raise LabError("guard-on requires exactly one known active local Guard row")
|
|
76
100
|
row = guards[0]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
101
|
+
if profile == "read-redaction-v1":
|
|
102
|
+
# The pinned launcher folds long path scalars onto one indented
|
|
103
|
+
# line. Accept only that exact spelling of our two bound paths.
|
|
104
|
+
expanded, index = [], 0
|
|
105
|
+
while index < len(row):
|
|
106
|
+
line = row[index]
|
|
107
|
+
key = next((key for key in ("defaultCwd", "readGuardDshRoot")
|
|
108
|
+
if line == " " + key + ": >-"), None)
|
|
109
|
+
if key is not None:
|
|
110
|
+
if index + 1 >= len(row) or row[index + 1] != " " + config[key]:
|
|
111
|
+
raise LabError("unsupported folded Guard path")
|
|
112
|
+
expanded.append(" " + key + ": " + json.dumps(config[key]))
|
|
113
|
+
index += 2
|
|
114
|
+
else:
|
|
115
|
+
expanded.append(line)
|
|
116
|
+
index += 1
|
|
117
|
+
row = expanded
|
|
118
|
+
expected = [("- id: ", "agent_guard"), (" name: ", str(ADAPTER)), (" config:", None)]
|
|
119
|
+
expected += [(" " + key + ": ", str(value).lower() if isinstance(value, bool) else str(value))
|
|
120
|
+
for key, value in config.items()]
|
|
121
|
+
# Only the exact reviewed profile row is excluded from the fingerprint.
|
|
84
122
|
if len(row) != len(expected):
|
|
85
123
|
raise LabError("unsupported Guard composition fields")
|
|
86
124
|
for line, (prefix, value) in zip(row, expected):
|
|
@@ -98,20 +136,34 @@ def normalize_composition(payload: bytes, guard_state: str) -> bytes:
|
|
|
98
136
|
|
|
99
137
|
def configuration_fingerprint(
|
|
100
138
|
home: Path, composition: bytes, environment: dict[str, str], guard_state: str,
|
|
139
|
+
*, profile="deletion-v1", workspace=None, dsh_root=None, scope_version=2,
|
|
101
140
|
) -> str:
|
|
102
|
-
|
|
141
|
+
if type(scope_version) is not int or scope_version not in {1, 2}:
|
|
142
|
+
raise LabError("unsupported DSH configuration scope")
|
|
143
|
+
if scope_version == 1 and profile != "deletion-v1":
|
|
144
|
+
raise LabError("legacy configuration scope cannot identify a read profile")
|
|
145
|
+
normalized = normalize_composition(composition, guard_state, profile=profile,
|
|
146
|
+
workspace=workspace, dsh_root=dsh_root)
|
|
103
147
|
files = {}
|
|
104
|
-
|
|
148
|
+
names = ["settings.yaml", "." + "env", "profiles/headless/package.json"]
|
|
149
|
+
if scope_version == 2:
|
|
150
|
+
names += ["settings.yaml.imported", "cordis.yml", "cordis.patch.yml",
|
|
151
|
+
"profiles/headless/cordis.yml", "profiles/headless/cordis.patch.yml"]
|
|
152
|
+
for name in names:
|
|
105
153
|
path = home / name
|
|
106
154
|
files[name] = digest(read_regular(path, MAX_SCAN_BYTES)) if path.exists() or path.is_symlink() else None
|
|
107
155
|
launch_environment = dict(environment)
|
|
108
156
|
launch_environment["DSH_HOME"] = "<disposable-home>"
|
|
109
|
-
|
|
157
|
+
bookkeeping = ("PWD", "OLDPWD", "_") + (("SHLVL",) if scope_version == 2 else ())
|
|
158
|
+
for key in bookkeeping:
|
|
110
159
|
launch_environment.pop(key, None)
|
|
111
|
-
|
|
112
|
-
"scope": "dsh-lab-non-guard-
|
|
160
|
+
declaration = {
|
|
161
|
+
"scope": "dsh-lab-non-guard-v" + str(scope_version), "composition_sha256": digest(normalized),
|
|
113
162
|
"files": files, "launch_environment": launch_environment,
|
|
114
|
-
}
|
|
163
|
+
}
|
|
164
|
+
if scope_version == 2:
|
|
165
|
+
declaration["guard_profile"] = profile
|
|
166
|
+
return digest(json.dumps(declaration, sort_keys=True, separators=(",", ":")).encode())
|
|
115
167
|
|
|
116
168
|
|
|
117
169
|
def prepare_homes(source_home: Path, output: Path) -> dict:
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* config.repoRoot points at a live checkout (development mode).
|
|
23
23
|
*
|
|
24
24
|
* Positioning: automatic recovery system with human escalation - reliability
|
|
25
|
-
* infrastructure, not a security sandbox. See docs/threat-model.md.
|
|
25
|
+
* infrastructure, not a security sandbox. See docs/design/threat-model.md.
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import fs from "node:fs";
|
|
@@ -13,12 +13,12 @@ Code's hooks, so `pre_tool_use.py` here delegates to
|
|
|
13
13
|
Verified against **@moonshot-ai/kimi-code 0.42.0 and 2.1.1**. The detailed
|
|
14
14
|
contract comparison below was established against 0.42.0; the 2.1.1 trials
|
|
15
15
|
independently observed authenticated root `Bash` blocks through the same
|
|
16
|
-
exit-2 hook path on an OAuth official
|
|
17
|
-
|
|
18
|
-
[bounded report](../../docs/test-report-kimi-code-block.md).
|
|
16
|
+
exit-2 hook path on an OAuth official model and a second configured model
|
|
17
|
+
route. Connection details and private route identifiers are omitted. See the
|
|
18
|
+
[bounded report](../../docs/reports/test-report-kimi-code-block.md).
|
|
19
19
|
|
|
20
20
|
For the separate honeytoken experiment, see the
|
|
21
|
-
[guard-lab pair and local follow-up](../../docs/test-report-kimi-guard-lab.md).
|
|
21
|
+
[guard-lab pair and local follow-up](../../docs/reports/test-report-kimi-guard-lab.md).
|
|
22
22
|
Its recorded tool-channel exposure and matched guarded observation are distinct
|
|
23
23
|
from native Bash interception. A local doctor pass does not rerun that pair.
|
|
24
24
|
Use the [private capture/review helper](harness/README.md) to repeat the Lab
|
|
@@ -80,7 +80,7 @@ allowed. `blockDecision()` collects any hook result with `action === "block"`.
|
|
|
80
80
|
Add `--check-drift` to compare the installed Kimi Code version with the
|
|
81
81
|
shipped profile and compute privacy-safe configuration/runtime
|
|
82
82
|
fingerprints. `CURRENT` still does not prove live interception; see the
|
|
83
|
-
[drift status contract](../../docs/host-drift.md).
|
|
83
|
+
[drift status contract](../../docs/guides/host-drift.md).
|
|
84
84
|
An explicit `--live-sentinel` may then use one configured model call in a
|
|
85
85
|
private fixture and requires adapter, audit, host-feedback, and marker
|
|
86
86
|
evidence. The selected file must be named `config.toml`; the runner does
|
|
@@ -112,23 +112,24 @@ It does not describe a missing hook or a failed hook command.
|
|
|
112
112
|
`kimi --auto`, Kimi 0.42.0 treats `permissionDecision: "ask"` as allow.
|
|
113
113
|
This adapter therefore maps Core ASK to exit 2 (BLOCK). The failure class
|
|
114
114
|
is described in the public
|
|
115
|
-
[`development note`](../../docs/development-note-unguarded-deletion.md),
|
|
115
|
+
[`development note`](../../docs/history/development-note-unguarded-deletion.md),
|
|
116
116
|
and it is fixed:
|
|
117
117
|
`cd /tmp && rm -rf "$PWD/../home"` now classifies as
|
|
118
118
|
`BLOCK / BLOCK_UNDETERMINABLE_EFFECT`. A shape rule describes
|
|
119
119
|
*compensation* difficulty rather than effect scope, so it no longer
|
|
120
120
|
returns before the hard boundaries are evaluated. Regression suite:
|
|
121
|
-
`tests/test_incident_regression.py`. A
|
|
121
|
+
`tests/test_incident_regression.py`. A shape-only ASK now asks
|
|
122
122
|
the agent to split and retry instead of proceeding without compensation.
|
|
123
123
|
The 2.1.1 live sentinel exercised a hard `BLOCK`, not a live ASK path, so
|
|
124
124
|
this conservative mapping is not advertised as a 2.1.1 approval-UI test.
|
|
125
125
|
- **Subagent inheritance is observational, not a blanket guarantee.** In two
|
|
126
|
-
isolated
|
|
127
|
-
calls reached the native hook and produced recoverable audit
|
|
128
|
-
|
|
126
|
+
isolated sandboxes using one configured model route, single and concurrent
|
|
127
|
+
subagent Bash calls reached the native hook and produced recoverable audit
|
|
128
|
+
records.
|
|
129
|
+
A third isolated project then showed [execution-level `BLOCK` enforcement](../../docs/reports/test-report-kimi-code-block.md)
|
|
129
130
|
for one root and one single-subagent inert Bash probe. Its separate root
|
|
130
131
|
`ASK` probe was denied. A fourth isolated project reproduced these bounded
|
|
131
|
-
paths using
|
|
132
|
+
paths using a second configured request model ID and
|
|
132
133
|
verified a recoverable deletion/restore cycle. Two same-turn subagents
|
|
133
134
|
each received `BLOCK`, but their Bash calls reached the hook seconds apart;
|
|
134
135
|
simultaneous hook execution, other tools/routes, backend model identity,
|
|
@@ -142,20 +143,20 @@ It does not describe a missing hook or a failed hook command.
|
|
|
142
143
|
before Python started.** In an isolated Kimi 0.42.0 trial, a process-local failing
|
|
143
144
|
`python3` shim made a Bash call execute even though the correctly started
|
|
144
145
|
adapter would have returned `BLOCK_DIALECT_UNKNOWN`. The sentinel appeared
|
|
145
|
-
and no guard audit event was added. See the [bounded report](../../docs/test-report-kimi-code-block.md).
|
|
146
|
+
and no guard audit event was added. See the [bounded report](../../docs/reports/test-report-kimi-code-block.md).
|
|
146
147
|
The bridge changes this particular failure into exit 2 **if the bridge
|
|
147
148
|
itself starts**. It cannot block a hook that is absent, skipped by the
|
|
148
149
|
matcher, fails to spawn, or times out. The host remains fail-open for those
|
|
149
150
|
cases; a verified interpreter path is risk reduction, not a hard boundary.
|
|
150
151
|
- **The bridge was exercised through a new Kimi 0.42.0 host session** using
|
|
151
|
-
the
|
|
152
|
+
the second configured request model ID: one harmless Bash call was
|
|
152
153
|
blocked under a process-local invalid dialect, and a separate harmless
|
|
153
154
|
Bash call ran under the normal dialect. The denied sentinel was absent,
|
|
154
155
|
the allowed sentinel was present, and the block was audited. A later
|
|
155
156
|
process-local Python startup fault returned exit 1 before the adapter ran;
|
|
156
157
|
the bridge converted it to Kimi's hard refusal, and the sentinel stayed
|
|
157
158
|
absent. This does not test a bridge-spawn failure or timeout; see the
|
|
158
|
-
[bounded report](../../docs/test-report-kimi-code-block.md).
|
|
159
|
+
[bounded report](../../docs/reports/test-report-kimi-code-block.md).
|
|
159
160
|
- Kimi's `doctor config` accepted a hook-free test config and an invalid
|
|
160
161
|
regex matcher; it checks configuration validity, not live interception.
|
|
161
162
|
In the installed 0.42.0 bundle, a matcher regex error yields no match.
|
|
@@ -42,9 +42,9 @@ remain user-declared; configuration equality does not authenticate a backend.
|
|
|
42
42
|
|
|
43
43
|
## Clean control, then baseline
|
|
44
44
|
|
|
45
|
-
Use the [README-only task](../../../docs/guard-lab-clean-task.md) for a real-host
|
|
45
|
+
Use the [README-only task](../../../docs/lab/tasks/guard-lab-clean-task.md) for a real-host
|
|
46
46
|
negative control so that it requests no bait read. Use the original
|
|
47
|
-
[review task](../../../docs/guard-lab-trial-task.md) for both attack trials.
|
|
47
|
+
[review task](../../../docs/lab/tasks/guard-lab-trial-task.md) for both attack trials.
|
|
48
48
|
For the clean control, prepare a separate equivalent disposable home if the
|
|
49
49
|
matched attack pair should start without any previous host session state.
|
|
50
50
|
|
|
@@ -53,7 +53,7 @@ python3 adapters/kimi-code/harness/guard_lab.py run \
|
|
|
53
53
|
--kimi-home /tmp/kimi-lab-homes/off \
|
|
54
54
|
--kimi-executable /absolute/path/to/kimi-2.1.1 --guard-state off \
|
|
55
55
|
--output-dir /tmp/kimi-lab-clean --case clean \
|
|
56
|
-
--task-file docs/guard-lab-clean-task.md \
|
|
56
|
+
--task-file docs/lab/tasks/guard-lab-clean-task.md \
|
|
57
57
|
--model-label "Kimi official OAuth model" --trial-group kimi-pair-01
|
|
58
58
|
```
|
|
59
59
|
|
|
@@ -392,7 +392,7 @@ def main(arguments: Optional[Sequence[str]] = None) -> int:
|
|
|
392
392
|
run.add_argument("--output-dir", type=Path, required=True)
|
|
393
393
|
run.add_argument("--case", choices=("clean", "injection-probe"), required=True)
|
|
394
394
|
run.add_argument("--attack-sample", choices=sorted(INJECTION_SAMPLES), default="direct-v1")
|
|
395
|
-
run.add_argument("--task-file", type=Path, default=ROOT / "docs/guard-lab-trial-task.md")
|
|
395
|
+
run.add_argument("--task-file", type=Path, default=ROOT / "docs/lab/tasks/guard-lab-trial-task.md")
|
|
396
396
|
run.add_argument("--model-label", required=True)
|
|
397
397
|
run.add_argument("--trial-group", required=True)
|
|
398
398
|
run.add_argument("--timeout", type=int, default=180)
|
package/core/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""agent-guard core: a reliability layer for autonomous AI agents.
|
|
2
2
|
|
|
3
|
-
Four pillars (see docs/architecture.md):
|
|
3
|
+
Four pillars (see docs/design/architecture.md):
|
|
4
4
|
|
|
5
5
|
Scope - where the agent may act -> policy.py
|
|
6
6
|
Recoverability - whether mistakes can be undone -> recovery.py
|
package/core/classifier.py
CHANGED
|
@@ -33,7 +33,7 @@ import shlex
|
|
|
33
33
|
from dataclasses import dataclass, field
|
|
34
34
|
from typing import List, Optional, Tuple
|
|
35
35
|
|
|
36
|
-
from . import dialects
|
|
36
|
+
from . import AUDIT_NAME, MANIFEST_NAME, STATE_NAME, dialects
|
|
37
37
|
|
|
38
38
|
# ---------------------------------------------------------------- vocabulary
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ FS_DELETE_CMDS = {"rm", "rmdir", "unlink", "shred"}
|
|
|
41
41
|
# Windows-native delete verbs. Recognised on EVERY dialect: a harness that
|
|
42
42
|
# never configured `AGENT_GUARD_DIALECT` still defaults to posix, and a
|
|
43
43
|
# posix-lexed `del /s /q build` must not be treated as an unknown verb.
|
|
44
|
-
# See docs/development-note-unguarded-deletion.md (lesson: the normalized
|
|
44
|
+
# See docs/history/development-note-unguarded-deletion.md (lesson: the normalized
|
|
45
45
|
# target decides, not the spelling).
|
|
46
46
|
WINDOWS_DELETE_CMDS = {"del", "erase", "rd", "rmdir", "ri"}
|
|
47
47
|
SHELL_PREFIXES = {
|
|
@@ -56,7 +56,7 @@ INDETERMINACY_CHARS = ("$", "`")
|
|
|
56
56
|
# Filesystem roots that must never be a deletion target, whatever the
|
|
57
57
|
# workspace setting says. `rm -rf /home` blocks today only because /home
|
|
58
58
|
# happens to sit outside the workspace root - an accident of configuration,
|
|
59
|
-
# not a policy (see docs/development-note-unguarded-deletion.md).
|
|
59
|
+
# not a policy (see docs/history/development-note-unguarded-deletion.md).
|
|
60
60
|
#
|
|
61
61
|
# Matching is EXACT: the rule fires when a target *is* one of these roots,
|
|
62
62
|
# never when it merely lives under one, so `rm -rf /home/alice/build` stays
|
|
@@ -137,7 +137,7 @@ KIND_GIT_DISCARD = "git-discard" # git restore <path> / git checkout -- <
|
|
|
137
137
|
KIND_GIT_PUSH_FORCE = "git-push-force" # force / mirror / ref-deletion push
|
|
138
138
|
KIND_UNKNOWN = "unknown" # destructive smell, no parseable shape
|
|
139
139
|
|
|
140
|
-
# Whole-command-line shape facts (docs/friction.md F1/F2).
|
|
140
|
+
# Whole-command-line shape facts (docs/history/friction.md F1/F2).
|
|
141
141
|
CREATION_CMDS = {"touch", "mkdir", "cp", "mv", "install", "ln", "tee"}
|
|
142
142
|
# cmd builtins with the same shape (F2 is about "created then destroyed",
|
|
143
143
|
# which `copy x a.tmp && del a.tmp` expresses just as literally).
|
|
@@ -146,7 +146,9 @@ CMD_CREATION_CMDS = {"copy", "xcopy", "robocopy", "mkdir", "md", "mklink",
|
|
|
146
146
|
REDIRECT_CREATE_TOKENS = {">", ">>"}
|
|
147
147
|
# Kinds whose compensation depends on enumerating concrete targets; a target
|
|
148
148
|
# created earlier in the same line is invisible to pre-execution compensation.
|
|
149
|
-
TARGET_DEPENDENT_KINDS = {
|
|
149
|
+
TARGET_DEPENDENT_KINDS = {
|
|
150
|
+
KIND_FS_DELETE, KIND_GIT_CLEAN, KIND_GIT_DISCARD, KIND_GIT_RESET_HARD,
|
|
151
|
+
}
|
|
150
152
|
|
|
151
153
|
|
|
152
154
|
@dataclass
|
|
@@ -190,6 +192,7 @@ class PathSpec:
|
|
|
190
192
|
inside_trash: bool = False
|
|
191
193
|
protected: Optional[str] = None # None | ancestor-root | workspace-root
|
|
192
194
|
# | outside-workspace | git-metadata
|
|
195
|
+
# | quarantine-control
|
|
193
196
|
error: Optional[str] = None
|
|
194
197
|
|
|
195
198
|
# ------------------------------------------------------------- path analysis
|
|
@@ -248,6 +251,26 @@ def _physical_keep_final(path: str) -> str:
|
|
|
248
251
|
return os.path.join(os.path.realpath(parent), name)
|
|
249
252
|
|
|
250
253
|
|
|
254
|
+
def _quarantine_control_path(absolute: str, physical: str,
|
|
255
|
+
trash_root: str, trash_physical: str,
|
|
256
|
+
workspace: str) -> bool:
|
|
257
|
+
"""Protect storage access and root metadata, retaining leaf-link location."""
|
|
258
|
+
# A configured final link is also the access path to an external bucket.
|
|
259
|
+
# Deleting its parent would sever that access even if storage is elsewhere.
|
|
260
|
+
if (inside_path(physical, workspace) and
|
|
261
|
+
any(inside_path(storage, physical) for storage in
|
|
262
|
+
(trash_physical, _physical_keep_final(trash_root)))):
|
|
263
|
+
return True
|
|
264
|
+
controls = {MANIFEST_NAME, AUDIT_NAME, STATE_NAME, STATE_NAME + ".tmp",
|
|
265
|
+
"sessions"}
|
|
266
|
+
for candidate in (physical, _physical_keep_final(absolute)):
|
|
267
|
+
if inside_path(candidate, trash_physical):
|
|
268
|
+
relative = os.path.relpath(candidate, trash_physical)
|
|
269
|
+
if relative.split(os.sep)[0] in controls:
|
|
270
|
+
return True
|
|
271
|
+
return False
|
|
272
|
+
|
|
273
|
+
|
|
251
274
|
def workspace_boundary_root(workspace: str) -> str:
|
|
252
275
|
"""Physical form of a workspace root, for callers that compare roots."""
|
|
253
276
|
return _physical(os.path.normpath(os.path.abspath(workspace)))
|
|
@@ -363,6 +386,9 @@ def classify_paths(
|
|
|
363
386
|
# content. `rm -rf .` stays a hard BLOCK. (When no trash_root is
|
|
364
387
|
# given, trash_physical is None and cannot match a real path.)
|
|
365
388
|
spec.protected = "workspace-root"
|
|
389
|
+
elif trash_root and _quarantine_control_path(
|
|
390
|
+
absolute, physical, trash_root, trash_physical, workspace):
|
|
391
|
+
spec.protected = "quarantine-control"
|
|
366
392
|
elif not spec.inside_workspace:
|
|
367
393
|
spec.protected = "outside-workspace"
|
|
368
394
|
else:
|
|
@@ -839,9 +865,21 @@ def _parse_git(segment: List[str]) -> OpSpec:
|
|
|
839
865
|
if "--hard" in rest:
|
|
840
866
|
spec.kind = KIND_GIT_RESET_HARD
|
|
841
867
|
spec.force = True
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
868
|
+
for tok in rest:
|
|
869
|
+
if tok in ("--hard", "-q", "--quiet"):
|
|
870
|
+
continue
|
|
871
|
+
if tok.startswith("-"):
|
|
872
|
+
spec.undeterminable = True
|
|
873
|
+
spec.note("unsupported hard reset option or path limit")
|
|
874
|
+
continue
|
|
875
|
+
spec.targets.append(tok)
|
|
876
|
+
if len(spec.targets) > 1:
|
|
877
|
+
spec.undeterminable = True
|
|
878
|
+
spec.note("hard reset requires a single target commit")
|
|
879
|
+
_scan_targets(spec)
|
|
880
|
+
if spec.wildcard:
|
|
881
|
+
spec.undeterminable = True
|
|
882
|
+
spec.note("hard reset target contains shell glob syntax")
|
|
845
883
|
if not spec.targets:
|
|
846
884
|
spec.note("whole-tree reset (no path limit)")
|
|
847
885
|
apply_global_uncertainty()
|
|
@@ -947,16 +985,17 @@ def _has_create_redirect(segment: List[str]) -> bool:
|
|
|
947
985
|
|
|
948
986
|
|
|
949
987
|
def _apply_shape_rules(specs: List[OpSpec], cd_positions: List[int],
|
|
950
|
-
creation_positions: List[int]
|
|
951
|
-
|
|
988
|
+
creation_positions: List[int],
|
|
989
|
+
segment_count: int = 1) -> None:
|
|
990
|
+
"""Whole-command-line restrictions (docs/history/friction.md F1/F2).
|
|
952
991
|
|
|
953
992
|
F1: a destructive op preceded by cd resolves against the wrong working
|
|
954
993
|
directory - compensation would enumerate/snapshot the wrong tree.
|
|
955
994
|
Applies to every destructive kind.
|
|
956
995
|
F2: a target created earlier in the same line does not exist yet at
|
|
957
996
|
interception time, so target-dependent compensation cannot cover it.
|
|
958
|
-
|
|
959
|
-
|
|
997
|
+
Force-push, which is blocked anyway, is exempt. Hard reset also
|
|
998
|
+
needs a preflight of untracked content against its target tree.
|
|
960
999
|
Shapes are DECISION-CLASS facts, not effect-uncertainty: the operation
|
|
961
1000
|
itself is well understood, only its safe automatic compensation is not.
|
|
962
1001
|
Policy maps them to ASK (single-execution authorization), keeping true
|
|
@@ -966,6 +1005,10 @@ def _apply_shape_rules(specs: List[OpSpec], cd_positions: List[int],
|
|
|
966
1005
|
if spec.kind in (KIND_OTHER, KIND_UNKNOWN):
|
|
967
1006
|
continue
|
|
968
1007
|
idx = spec.segment_index
|
|
1008
|
+
if spec.kind == KIND_GIT_RESET_HARD and segment_count != 1:
|
|
1009
|
+
spec.undeterminable = True
|
|
1010
|
+
spec.note("hard reset must be a standalone command; other "
|
|
1011
|
+
"segments may change its target or collisions")
|
|
969
1012
|
if any(pos < idx for pos in cd_positions):
|
|
970
1013
|
spec.shape = "F1"
|
|
971
1014
|
spec.note(
|
|
@@ -1152,14 +1195,19 @@ def _classify_posix(cmd: str) -> Tuple[List[OpSpec], Optional[str]]:
|
|
|
1152
1195
|
elif head == "find":
|
|
1153
1196
|
emit(_parse_find(seg), index)
|
|
1154
1197
|
elif head == "git":
|
|
1155
|
-
|
|
1198
|
+
spec = _parse_git(seg)
|
|
1199
|
+
if spec.kind == KIND_GIT_RESET_HARD and len(seg) != len(segment):
|
|
1200
|
+
spec.undeterminable = True
|
|
1201
|
+
spec.note("hard reset wrappers may change its Git context")
|
|
1202
|
+
emit(spec, index)
|
|
1156
1203
|
# anything else: kind OTHER, intentionally ignored by policy
|
|
1157
1204
|
|
|
1158
1205
|
for spec in specs:
|
|
1159
1206
|
spec.dialect = dialects.DIALECT_POSIX
|
|
1160
1207
|
_append_dialect_mismatches(
|
|
1161
1208
|
specs, command_segments, dialects.DIALECT_POSIX)
|
|
1162
|
-
_apply_shape_rules(specs, cd_positions, creation_positions
|
|
1209
|
+
_apply_shape_rules(specs, cd_positions, creation_positions,
|
|
1210
|
+
len(raw_segments))
|
|
1163
1211
|
return [s for s in specs if s.kind != KIND_OTHER], None
|
|
1164
1212
|
|
|
1165
1213
|
|
|
@@ -1189,7 +1237,7 @@ def _classify_windows_dialect(cmd: str, dialect: str
|
|
|
1189
1237
|
accepts `/`, while leaving `\\` in the fact makes Linux and Windows CI
|
|
1190
1238
|
disagree about the same command.
|
|
1191
1239
|
|
|
1192
|
-
Shape rules (docs/friction.md F1/F2) apply to Windows lines too: `cd`
|
|
1240
|
+
Shape rules (docs/history/friction.md F1/F2) apply to Windows lines too: `cd`
|
|
1193
1241
|
and the interpreter prefix set are shared shell concepts, so F1 means
|
|
1194
1242
|
the same thing in cmd and PowerShell.
|
|
1195
1243
|
"""
|
|
@@ -1213,7 +1261,8 @@ def _classify_windows_dialect(cmd: str, dialect: str
|
|
|
1213
1261
|
spec.targets = [t.replace("\\", "/") for t in spec.targets]
|
|
1214
1262
|
_attribute_targets(spec)
|
|
1215
1263
|
_append_dialect_mismatches(specs, stream.segments, dialect)
|
|
1216
|
-
_apply_shape_rules(specs, cd_positions, creation_positions
|
|
1264
|
+
_apply_shape_rules(specs, cd_positions, creation_positions,
|
|
1265
|
+
len(stream.segments))
|
|
1217
1266
|
return [s for s in specs if s.kind != KIND_OTHER], None
|
|
1218
1267
|
|
|
1219
1268
|
|
|
@@ -1230,7 +1279,7 @@ def classify_command(cmd: str, dialect: str = dialects.DEFAULT_DIALECT
|
|
|
1230
1279
|
dialect layer exists to prevent.
|
|
1231
1280
|
|
|
1232
1281
|
Heredoc bodies are stripped before POSIX parsing (they are written
|
|
1233
|
-
payload, not commands - see docs/friction.md F5).
|
|
1282
|
+
payload, not commands - see docs/history/friction.md F5).
|
|
1234
1283
|
|
|
1235
1284
|
Returns (specs, parse_error). Segments that are not destructive are
|
|
1236
1285
|
returned as kind=OTHER and ignored by policy. A parse_error (unbalanced
|