devrites 3.2.9 → 3.2.10

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to DevRites are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and DevRites adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Releases are generated automatically by [semantic-release](https://semantic-release.gitbook.io/) from Conventional Commits on `main`.
4
4
 
5
+ ## [3.2.10](https://github.com/ViktorsBaikers/DevRites/compare/v3.2.9...v3.2.10) (2026-07-26)
6
+
7
+ ### Fixed
8
+
9
+ * **devrites:** allow external dispatch scratch ([fdaac3f](https://github.com/ViktorsBaikers/DevRites/commit/fdaac3f9aaf19af897c6d3d70ce01fc046a60d3e))
10
+
5
11
  ## [3.2.9](https://github.com/ViktorsBaikers/DevRites/compare/v3.2.8...v3.2.9) (2026-07-26)
6
12
 
7
13
  ### Fixed
package/README.md CHANGED
@@ -25,7 +25,7 @@ final commit, push, and tag, and it requires a typed `GO` confirmation.
25
25
  Unattended runs may create local WIP checkpoint commits along the way, but only
26
26
  Ship collapses and pushes them.
27
27
 
28
- **Status:** [`v3.2.9`](https://github.com/ViktorsBaikers/DevRites/releases/tag/v3.2.9): see [`CHANGELOG.md`](CHANGELOG.md) for release notes.
28
+ **Status:** [`v3.2.10`](https://github.com/ViktorsBaikers/DevRites/releases/tag/v3.2.10): see [`CHANGELOG.md`](CHANGELOG.md) for release notes.
29
29
 
30
30
  ## Quick start
31
31
 
@@ -75,7 +75,9 @@ window. `reconcile close` still requires the confirmed, awaited wright result
75
75
  bound to the active snapshot. While the window is armed, the root guard permits
76
76
  inspectable writes only under `.devrites` or at an absolute scratch path outside
77
77
  the project; source-tree writes, relative escapes, and opaque execution remain
78
- blocked.
78
+ blocked. The standalone A1 hook and wright-scope hook share this classification;
79
+ Codex `cmd` and Claude `command` payloads may create a literal external packet
80
+ with a patch, heredoc, or copy and may hash it without gaining source authority.
79
81
 
80
82
  The canonical-state fingerprint excludes root-owned operational records:
81
83
  `timeline.jsonl`, feature `events.jsonl`, a valid `recovery-attempts.jsonl`,
package/engine/hooks.go CHANGED
@@ -377,7 +377,7 @@ func safeReadonlyShellSegment(segment string) bool {
377
377
  "grep", "rg", "wc", "sort", "uniq", "cut", "tr", "stat", "file",
378
378
  "readlink", "realpath", "basename", "dirname", "cmp", "diff", "jq", "yq",
379
379
  "tree", "du", "df", "printenv", "which", "date", "uname", "id", "whoami",
380
- "ps", "echo", "printf", "test", "[", "cd":
380
+ "ps", "echo", "printf", "test", "[", "cd", "sha256sum", "shasum":
381
381
  return true
382
382
  case "find":
383
383
  return !hasAnyArg(args, "-delete", "-exec", "-execdir", "-ok", "-okdir", "-fprint", "-fprintf")
@@ -325,6 +325,8 @@ func redwatchSafe(cmd string) string {
325
325
  // node regex the shell guards use.
326
326
  var patchPathRe = regexp.MustCompile(`(?m)^\*\*\* (?:(?:Add|Update|Delete) File|Move to): (.+)$`)
327
327
 
328
+ var shellHeredocStartRe = regexp.MustCompile(`<<(-?)[ \t]*(?:'([A-Za-z_][A-Za-z0-9_]*)'|"([A-Za-z_][A-Za-z0-9_]*)"|([A-Za-z_][A-Za-z0-9_]*))`)
329
+
328
330
  // isEditTool reports whether a tool can write source. toolBaseName also handles
329
331
  // host-qualified names such as functions.apply_patch and MCP symbol editors.
330
332
  func isEditTool(tool string) bool {
@@ -346,6 +348,39 @@ func patchPaths(command string) []string {
346
348
  return paths
347
349
  }
348
350
 
351
+ func stripShellHeredocBodies(command string) (string, bool) {
352
+ lines := strings.Split(strings.ReplaceAll(command, "\r\n", "\n"), "\n")
353
+ out := make([]string, 0, len(lines))
354
+ for i := 0; i < len(lines); i++ {
355
+ line := lines[i]
356
+ out = append(out, line)
357
+ for _, match := range shellHeredocStartRe.FindAllStringSubmatch(line, -1) {
358
+ delimiter := match[2]
359
+ if delimiter == "" {
360
+ delimiter = match[3]
361
+ }
362
+ if delimiter == "" {
363
+ return "", false
364
+ }
365
+ found := false
366
+ for i++; i < len(lines); i++ {
367
+ candidate := lines[i]
368
+ if match[1] == "-" {
369
+ candidate = strings.TrimLeft(candidate, "\t")
370
+ }
371
+ if candidate == delimiter {
372
+ found = true
373
+ break
374
+ }
375
+ }
376
+ if !found {
377
+ return "", false
378
+ }
379
+ }
380
+ }
381
+ return strings.Join(out, "\n"), true
382
+ }
383
+
349
384
  // shellOutputRedirections removes harmless fd redirects and returns every file
350
385
  // target of >, >>, or >|. Dynamic targets are opaque and therefore unsafe.
351
386
  func shellOutputRedirections(command string) (sanitized string, paths []string, opaque bool) {
@@ -471,44 +506,13 @@ func hookA1Guard(h harness.Harness, stdin io.Reader, stdout, stderr io.Writer) i
471
506
  }
472
507
 
473
508
  in := h.ParseGuardInput(bytes.NewReader(data))
474
- if !isEditTool(in.ToolName) {
475
- return exitOK
476
- }
477
509
  // The wright may edit. Claude sends agent_id; Codex sends agent_type.
478
510
  if in.AgentID != "" || in.AgentType != "" {
479
511
  return exitOK
480
512
  }
481
-
482
- projectDir := filepath.Dir(root)
483
- target := ""
484
- if in.ToolName == "apply_patch" {
485
- sourcePatch := false
486
- for _, p := range patchPaths(in.Command) {
487
- abs := p
488
- if !filepath.IsAbs(abs) {
489
- abs = filepath.Join(projectDir, abs)
490
- }
491
- if !underDevrites(abs, root) {
492
- sourcePatch = true
493
- break
494
- }
495
- }
496
- if !sourcePatch {
497
- return exitOK
498
- }
499
- target = "apply_patch"
500
- } else {
501
- if in.FilePath == "" {
502
- return exitOK
503
- }
504
- abs := in.FilePath
505
- if !filepath.IsAbs(abs) {
506
- abs = filepath.Join(projectDir, abs)
507
- }
508
- if underDevrites(abs, root) {
509
- return exitOK // orchestrator editing its own .devrites bookkeeping
510
- }
511
- target = abs
513
+ handled, violation, target := classifyRootBuildWindowOperation(root, data, in)
514
+ if !handled || !violation {
515
+ return exitOK
512
516
  }
513
517
 
514
518
  mode := os.Getenv("DEVRITES_A1_HOOK")
@@ -842,7 +846,11 @@ func uniqueStrings(values []string) []string {
842
846
  }
843
847
 
844
848
  func wrightShellWritePaths(command string) ([]string, bool) {
845
- if strings.TrimSpace(command) == "" || wrightForbiddenShellRe.MatchString(command) {
849
+ patches := patchPaths(command)
850
+ var ok bool
851
+ command, ok = stripShellHeredocBodies(command)
852
+ if !ok || strings.TrimSpace(command) == "" || strings.Contains(command, "$(") ||
853
+ strings.ContainsRune(command, '`') || wrightForbiddenShellRe.MatchString(command) {
846
854
  return nil, true
847
855
  }
848
856
  sanitized, paths, opaque := shellOutputRedirections(command)
@@ -850,7 +858,6 @@ func wrightShellWritePaths(command string) ([]string, bool) {
850
858
  return nil, true
851
859
  }
852
860
 
853
- patches := patchPaths(command)
854
861
  if strings.Contains(command, "apply_patch") {
855
862
  if len(patches) == 0 {
856
863
  return nil, true
@@ -896,6 +903,15 @@ func wrightShellWritePaths(command string) ([]string, bool) {
896
903
  found = nonFlagArgs(args)
897
904
  case "rm", "unlink", "touch", "mkdir", "rmdir", "truncate":
898
905
  found = nonFlagArgs(args)
906
+ case "cp":
907
+ if hasAnyArg(args, "-t", "--target-directory") || hasArgPrefix(args, "--target-directory=") {
908
+ return nil, true
909
+ }
910
+ operands := nonFlagArgs(args)
911
+ if len(operands) < 2 {
912
+ return nil, true
913
+ }
914
+ found = operands[len(operands)-1:]
899
915
  default:
900
916
  return nil, true
901
917
  }
@@ -1014,14 +1030,22 @@ func guardRootBuildWindow(h harness.Harness, data []byte, in harness.GuardInput,
1014
1030
  return exitOK, false
1015
1031
  }
1016
1032
 
1017
- if isAgentDispatchTool(in.ToolName) {
1018
- return exitOK, true
1033
+ handled, violation, _ := classifyRootBuildWindowOperation(root, data, in)
1034
+ if violation {
1035
+ return denyWright(h, stdout, stderr, a1DenyReason, drvreason.HookA1Denied), true
1019
1036
  }
1037
+ return exitOK, handled
1038
+ }
1020
1039
 
1021
- projectDir := filepath.Dir(root)
1040
+ func classifyRootBuildWindowOperation(root string, data []byte, in harness.GuardInput) (handled, violation bool, target string) {
1041
+ if isAgentDispatchTool(in.ToolName) {
1042
+ return true, false, ""
1043
+ }
1022
1044
  if isOpaqueExecutionTool(in.ToolName) {
1023
- return denyWright(h, stdout, stderr, a1DenyReason, drvreason.HookA1Denied), true
1045
+ return true, true, in.ToolName
1024
1046
  }
1047
+
1048
+ projectDir := filepath.Dir(root)
1025
1049
  targets, suspicious := rootMutationTargets(data, in)
1026
1050
  for _, target := range targets {
1027
1051
  absoluteTarget := filepath.IsAbs(target)
@@ -1032,21 +1056,24 @@ func guardRootBuildWindow(h harness.Harness, data []byte, in harness.GuardInput,
1032
1056
  abs = filepath.Clean(abs)
1033
1057
  resolved, err := resolveRootMutationTarget(abs)
1034
1058
  if err != nil {
1035
- return denyWright(h, stdout, stderr, a1DenyReason, drvreason.HookA1Denied), true
1059
+ return true, true, target
1036
1060
  }
1037
1061
  insideProject := pathWithin(resolved, projectDir)
1038
1062
  if (insideProject && !underDevrites(resolved, root)) ||
1039
1063
  (!insideProject && !absoluteTarget) {
1040
- return denyWright(h, stdout, stderr, a1DenyReason, drvreason.HookA1Denied), true
1064
+ return true, true, target
1041
1065
  }
1042
1066
  }
1043
1067
  if suspicious {
1044
- return denyWright(h, stdout, stderr, a1DenyReason, drvreason.HookA1Denied), true
1068
+ return true, true, in.ToolName
1045
1069
  }
1046
1070
  if len(targets) > 0 {
1047
- return exitOK, true
1071
+ return true, false, strings.Join(targets, ",")
1072
+ }
1073
+ if isShellTool(in.ToolName) && safeReadonlyShellCommand(in.Command) {
1074
+ return true, false, ""
1048
1075
  }
1049
- return exitOK, false
1076
+ return false, false, ""
1050
1077
  }
1051
1078
 
1052
1079
  func resolveRootMutationTarget(filename string) (string, error) {
@@ -1074,7 +1101,8 @@ func rootMutationTargets(data []byte, in harness.GuardInput) ([]string, bool) {
1074
1101
  if len(targets) > 0 {
1075
1102
  return targets, false
1076
1103
  }
1077
- return nil, opaque && (reviewerMutateRe.MatchString(in.Command) || opaqueInterpreterRe.MatchString(in.Command))
1104
+ _, completeHeredoc := stripShellHeredocBodies(in.Command)
1105
+ return nil, opaque && (!completeHeredoc || reviewerMutateRe.MatchString(in.Command) || opaqueInterpreterRe.MatchString(in.Command))
1078
1106
  default:
1079
1107
  return nil, false
1080
1108
  }
@@ -214,6 +214,7 @@ func (h Harness) ParseGuardInput(r io.Reader) GuardInput {
214
214
  ToolName string `json:"tool_name"`
215
215
  ToolInput struct {
216
216
  Command string `json:"command"`
217
+ Cmd string `json:"cmd"`
217
218
  FilePath string `json:"file_path"`
218
219
  Path string `json:"path"`
219
220
  } `json:"tool_input"`
@@ -237,7 +238,7 @@ func (h Harness) ParseGuardInput(r io.Reader) GuardInput {
237
238
  }
238
239
  return GuardInput{
239
240
  ToolName: raw.ToolName,
240
- Command: raw.ToolInput.Command,
241
+ Command: firstNonEmpty(raw.ToolInput.Command, raw.ToolInput.Cmd),
241
242
  FilePath: firstNonEmpty(raw.ToolInput.FilePath, raw.ToolInput.Path),
242
243
  SessionID: raw.SessionID,
243
244
  AgentType: raw.AgentType,
@@ -113,6 +113,10 @@ func TestHarnessParsersFailOpenAndFallbacks(t *testing.T) {
113
113
  if guard.ToolName != "Edit" || guard.FilePath != "src/app.go" || guard.AgentID != "a1" || guard.ToolResponse != `{"ok":true}` {
114
114
  t.Fatalf("ParseGuardInput = %#v", guard)
115
115
  }
116
+ guard = Codex.ParseGuardInput(strings.NewReader(`{"tool_name":"functions.exec_command","tool_input":{"cmd":"sha256sum /tmp/agent-packet.yaml"}}`))
117
+ if guard.ToolName != "functions.exec_command" || guard.Command != "sha256sum /tmp/agent-packet.yaml" {
118
+ t.Fatalf("ParseGuardInput Codex cmd = %#v", guard)
119
+ }
116
120
 
117
121
  if got := Codex.SubagentAgentType(strings.NewReader(`{"agentType":"executor"}`)); got != "executor" {
118
122
  t.Fatalf("SubagentAgentType fallback = %q, want executor", got)
@@ -583,9 +583,11 @@ func TestHookWrightScopeRequiresSpawnedCodexWorkerForSourceWrites(t *testing.T)
583
583
  runGuard(`{"tool_name":"spawn_agent","tool_input":{"agent_type":"worker"}}`, false)
584
584
  runGuard(`{"tool_name":"spawn_agent","tool_input":{"agent_type":"explorer"}}`, false)
585
585
  runGuard(`{"tool_name":"Write","tool_input":{"file_path":".devrites/features/auth-tokens/state.md"}}`, false)
586
+ scratch := t.TempDir()
587
+ packet := filepath.Join(scratch, "agent-packet.yaml")
586
588
  runGuard(hookPayload(t, map[string]any{
587
589
  "tool_name": "Write",
588
- "tool_input": map[string]any{"file_path": filepath.Join(t.TempDir(), "agent-packet.yaml")},
590
+ "tool_input": map[string]any{"file_path": packet},
589
591
  }), false)
590
592
  runGuard(`{"tool_name":"Write","tool_input":{"file_path":"../outside.txt"}}`, true)
591
593
  runGuard(`{"tool_name":"Write","tool_input":{"file_path":"src/app.go"}}`, true)
@@ -649,6 +651,59 @@ func TestHookA1GuardIgnoresLegacyInlineMarker(t *testing.T) {
649
651
  }
650
652
  }
651
653
 
654
+ func TestHookA1GuardAllowsExternalDispatchScratchOnly(t *testing.T) {
655
+ root := newWorkspace(t)
656
+ writeActive(t, root, "auth-tokens")
657
+ workspace := filepath.Join(root, "features", "auth-tokens")
658
+ if err := os.WriteFile(filepath.Join(workspace, ".reconcile-base"), []byte("snapshot\n"), 0o600); err != nil {
659
+ t.Fatal(err)
660
+ }
661
+ scratch := t.TempDir()
662
+ packet := filepath.Join(scratch, "agent-packet.yaml")
663
+ env := []string{"DEVRITES_A1_HOOK=enforce"}
664
+ patch := func(tool, path string, freeform bool) string {
665
+ body := "*** Begin Patch\n*** Add File: " + path + "\n+x\n*** End Patch\n"
666
+ if freeform {
667
+ return hookPayload(t, map[string]any{"tool_name": tool, "tool_input": body})
668
+ }
669
+ return hookPayload(t, map[string]any{"tool_name": tool, "tool_input": map[string]any{"patch": body}})
670
+ }
671
+ shell := func(command string) string {
672
+ return hookPayload(t, map[string]any{
673
+ "tool_name": "functions.exec_command",
674
+ "tool_input": map[string]any{"cmd": command},
675
+ })
676
+ }
677
+
678
+ runGuard := func(input string, deny bool) {
679
+ t.Helper()
680
+ out, errOut, code := runDevritesIO(t, root, input, env,
681
+ "hook", "a1-guard", "--harness=codex")
682
+ if code != 0 {
683
+ t.Fatalf("exit=%d out=%q stderr=%q", code, out, errOut)
684
+ }
685
+ if deny {
686
+ if decision, _ := parsePermissionDecision(t, out); decision != "deny" {
687
+ t.Fatalf("expected deny, got %q", out)
688
+ }
689
+ } else if strings.TrimSpace(out) != "" {
690
+ t.Fatalf("expected allow, got %q", out)
691
+ }
692
+ }
693
+
694
+ runGuard(patch("apply_patch", packet, false), false)
695
+ runGuard(patch("functions.apply_patch", packet, true), false)
696
+ runGuard(shell("cat <<'EOF' > "+packet+"\npacket_version: agent-packet/v1\nEOF"), false)
697
+ runGuard(shell("sha256sum "+packet), false)
698
+ runGuard(shell("cp "+packet+" "+filepath.Join(scratch, "agent-packet.copy.yaml")), false)
699
+ runGuard(patch("apply_patch", "src/app.go", false), true)
700
+ runGuard(patch("functions.apply_patch", "src/app.go", true), true)
701
+ runGuard(shell("cat <<'EOF' > src/app.go\npackage src\nEOF"), true)
702
+ runGuard(shell("cat <<'EOF' > "+packet+"\nunterminated"), true)
703
+ runGuard(shell("cat <<EOF > "+packet+"\n$(cp "+packet+" src/app.go)\nEOF"), true)
704
+ runGuard(shell("cp "+packet+" src/app.go"), true)
705
+ }
706
+
652
707
  func TestHookWrightScopeFailsClosedWhenWorkspaceResolutionFails(t *testing.T) {
653
708
  root := newWorkspace(t)
654
709
  if err := os.Remove(filepath.Join(root, "ACTIVE")); err != nil && !os.IsNotExist(err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devrites",
3
- "version": "3.2.9",
3
+ "version": "3.2.10",
4
4
  "description": "DevRites: a disciplined senior-engineer workflow pack for Claude Code and Codex",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://github.com/ViktorsBaikers/DevRites#readme",