@zalom/plastic 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/PLASTIC.md +75 -552
  2. package/README.md +3 -2
  3. package/agents/plastic-intent-curator.md +2 -2
  4. package/deprecations.yml +10 -2
  5. package/hooks/{links-gate → edit-gates} +1 -1
  6. package/hooks/hooks.json +4 -44
  7. package/hooks/power-tools +8 -0
  8. package/package.json +1 -2
  9. package/scripts/codex-hook +17 -22
  10. package/scripts/doctor.rb +85 -3
  11. package/scripts/hook-code-gate +13 -28
  12. package/scripts/hook-create-gate +10 -57
  13. package/scripts/hook-edit-gates +58 -0
  14. package/scripts/hook-links-gate +8 -31
  15. package/scripts/hook-lock-gate +13 -58
  16. package/scripts/hook-power-tools +38 -0
  17. package/scripts/hook-savepoint-pre +8 -11
  18. package/scripts/lib/bridge.rb +2 -2
  19. package/scripts/lib/edit_gates.rb +342 -0
  20. package/scripts/lib/hook_registry.rb +61 -29
  21. package/scripts/lib/installer_core.rb +99 -17
  22. package/scripts/lib/qmd_hook.rb +21 -41
  23. package/scripts/lib/qmd_sync.rb +0 -15
  24. package/scripts/lib/revisions_writer.rb +1 -1
  25. package/scripts/restore-intent-v1 +16 -11
  26. package/skills/auto/SKILL.md +10 -0
  27. package/skills/auto/evals/evals.json +2 -2
  28. package/skills/conventions/SKILL.md +31 -0
  29. package/skills/conventions/references/completion-and-done.md +40 -0
  30. package/skills/conventions/references/gates-and-enforcement.md +23 -0
  31. package/skills/conventions/references/knowledge-graph.md +47 -0
  32. package/skills/conventions/references/lifecycle-and-savepoints.md +11 -0
  33. package/skills/conventions/references/locks-and-worktrees.md +113 -0
  34. package/skills/conventions/references/maintenance-and-revisions.md +170 -0
  35. package/skills/conventions/references/roadmaps.md +44 -0
  36. package/skills/conventions/references/tiers-and-dispatch.md +134 -0
  37. package/skills/doctor/SKILL.md +9 -1
  38. package/skills/intent-brainstorming/SKILL.md +4 -0
  39. package/skills/intent-continuing/SKILL.md +4 -0
  40. package/skills/intent-creating/SKILL.md +7 -2
  41. package/skills/intent-ending/SKILL.md +4 -0
  42. package/skills/intent-executing/SKILL.md +10 -0
  43. package/skills/intent-linking/SKILL.md +4 -0
  44. package/skills/intent-locking/SKILL.md +4 -0
  45. package/skills/intent-planning/SKILL.md +7 -0
  46. package/skills/intent-savepoint/SKILL.md +4 -0
  47. package/skills/intent-speccing/SKILL.md +4 -0
  48. package/skills/intent-starting/SKILL.md +10 -0
  49. package/skills/project-creating/references/project-scaffolding.md +2 -2
  50. package/skills/roadmap/SKILL.md +4 -0
  51. package/skills/roadmap-continuing/SKILL.md +4 -0
  52. package/skills/skill-creating/SKILL.md +3 -0
  53. package/skills/skill-creating/references/defaults-first.md +23 -0
  54. package/skills/skill-creating/references/hooks.md +4 -1
  55. package/skills/store-curating/SKILL.md +8 -0
  56. package/skills/store-indexing/SKILL.md +8 -0
  57. package/skills/tutorial/references/track-2-auto.md +2 -3
  58. package/PLASTIC-reference.md +0 -138
  59. package/hooks/code-gate +0 -27
  60. package/hooks/create-gate +0 -3
  61. package/hooks/lock-gate +0 -21
  62. package/hooks/qmd-search +0 -8
  63. package/hooks/retrieval-gate +0 -10
  64. package/hooks/savepoint-pre +0 -10
  65. package/scripts/hook-qmd-search +0 -44
  66. package/scripts/hook-retrieval-gate +0 -148
  67. package/scripts/lib/retrieval_gate.rb +0 -211
@@ -1,211 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
-
4
- require_relative "bridge"
5
-
6
- # RetrievalGate — the single, pure decision for Lever 2 of intent 84, redesigned
7
- # operation-based in intent 89a.
8
- #
9
- # Given an agent tool call (Bash/Read/Grep/Glob) and injected capability signals,
10
- # it decides whether to BLOCK the call (returning a redirect-to-QMD reason String)
11
- # or ALLOW it (returning nil). All capability/freshness signals are injected by the
12
- # caller (the hook); this module shells out to nothing, reads no globals, and runs
13
- # no binaries. Mirrors bridge.rb's decision-fn convention (reason String to block,
14
- # nil to allow).
15
- #
16
- # Operation-based policy (intent 89, ## Redesign):
17
- # - The gate distinguishes DISCOVERY (content search) from READING a known target.
18
- # - Only CONTENT SEARCH over store markdown is hard-gated -> QMD.
19
- # - Reading a known target (Read, cat/head/tail) and structural discovery (Glob,
20
- # find, ls) are ALWAYS allowed, including over the store.
21
- # - Code navigation is a soft prompt MANDATE (PowerTools / UserPromptSubmit), not a
22
- # hard gate here. Content grep over code is allowed (Serena cannot grep strings).
23
- #
24
- # Content-search vectors (the only ones that can be gated):
25
- # - the Grep tool (its `path` search root)
26
- # - bash `grep`/`rg`/`ag` (their path args; the first bareword is the PATTERN)
27
- #
28
- # QMD enforcement is BINARY (no advisory tier):
29
- # - store-md content search: QMD detected+fresh -> BLOCK; detected+stale -> fire
30
- # reindex, ALLOW this turn; absent/broken -> ALLOW (the hook warns on broken).
31
- #
32
- # Bypass: a TRAILING `# qmd-ok` shell comment on a Bash command (not a substring; a
33
- # quoted/echoed occurrence does not bypass). It is the auditable seam for "I tried
34
- # discovery and it did not serve me" (empty, low, or wrongly-scored results).
35
- #
36
- # Scope: only the agent's own tool calls. Ruby `File.read` inside scripts is invisible
37
- # to a PreToolUse hook and is explicitly out of scope (no exemptions).
38
- module RetrievalGate
39
- module_function
40
-
41
- # A `# qmd-ok` token that is a real TRAILING shell comment, after stripping a
42
- # trailing newline. The token must be preceded by whitespace (or start the
43
- # command) and run to end-of-string. `echo "# qmd-ok"` does NOT match: the token
44
- # there is followed by a closing quote, not end-of-string.
45
- BYPASS_RE = /(?:\A|\s)#\s*qmd-ok\s*\z/.freeze
46
-
47
- # Bash utilities that perform CONTENT SEARCH (scan file CONTENT for a pattern).
48
- # These are the only bash read-vectors that can be gated; readers (cat/head/tail)
49
- # and structural tools (find/ls) are never gated.
50
- CONTENT_SEARCH_UTILS = %w[grep rg ag].freeze
51
-
52
- # Decide. Returns nil to ALLOW, or a reason String to BLOCK.
53
- # capabilities: { qmd:, qmd_fresh: } (booleans).
54
- # reindex: no-arg callable fired once when a QMD-class target is STALE.
55
- # When bypassed, returns nil and (if given) yields :bypass to the optional block
56
- # so the caller can log it.
57
- def decision(tool_name:, tool_input:, plastic_home:, cwd:,
58
- capabilities:, reindex: -> {})
59
- targets = extract_targets(tool_name, tool_input, cwd: cwd)
60
- return nil if targets.empty?
61
-
62
- if bypass?(tool_name, tool_input)
63
- yield(:bypass) if block_given?
64
- return nil
65
- end
66
-
67
- stale_seen = false
68
- targets.each do |path|
69
- next unless classify(path, plastic_home: plastic_home) == :qmd
70
-
71
- if capabilities[:qmd] && capabilities[:qmd_fresh]
72
- return qmd_reason(path)
73
- elsif capabilities[:qmd] # present but stale
74
- stale_seen = true
75
- end
76
- # absent/broken -> allow this target
77
- end
78
-
79
- reindex.call if stale_seen
80
- nil
81
- end
82
-
83
- # --- classification ---
84
-
85
- # Operation-based: the store tree is the only gated class (content search whose
86
- # target is at/under a store routes to QMD). Everything else is allowed.
87
- def classify(path, plastic_home:)
88
- return :allow if path.nil? || path.empty?
89
- store_path?(path, plastic_home: plastic_home) ? :qmd : :allow
90
- end
91
-
92
- # A path AT or UNDER the global store or a project store. We gate the whole store
93
- # tree (not just `*.md`) because a content search root is usually a directory:
94
- # grepping the store scans its markdown, which is exactly what QMD should serve.
95
- def store_path?(path, plastic_home:)
96
- abs = absolutize(path)
97
- home = File.expand_path(plastic_home)
98
- global = File.join(home, "store")
99
- return true if abs == global || abs.start_with?("#{global}/")
100
-
101
- projects = File.join(home, "projects")
102
- return false unless abs.start_with?("#{projects}/")
103
- tail = abs[(projects.length + 1)..].to_s.split(File::SEPARATOR)
104
- tail.length >= 2 && tail[1] == "store"
105
- end
106
-
107
- def absolutize(path)
108
- File.absolute_path?(path) ? path : File.expand_path(path)
109
- end
110
-
111
- # --- bypass ---
112
-
113
- # Only Bash commands carry a trailing `# qmd-ok` comment. The token must be a real
114
- # trailing comment (BYPASS_RE), so a quoted/echoed occurrence does not bypass.
115
- def bypass?(tool_name, tool_input)
116
- return false unless tool_name.to_s == "Bash"
117
- cmd = tool_input.is_a?(Hash) ? tool_input["command"].to_s : ""
118
- BYPASS_RE.match?(cmd.chomp)
119
- end
120
-
121
- # --- target extraction ---
122
-
123
- # Paths a CONTENT-SEARCH operation scans. Reads (Read, cat/head/tail) and
124
- # structural discovery (Glob, find, ls) are NOT content search -> no targets ->
125
- # always allowed. Only the Grep tool and bash grep/rg/ag can be gated. Read
126
- # vectors only (this is a READ gate); write vectors are bridge.rb's job.
127
- def extract_targets(tool_name, tool_input, cwd:)
128
- input = tool_input.is_a?(Hash) ? tool_input : {}
129
- case tool_name.to_s
130
- when "Grep"
131
- # The search root is the target; the query text is not a path.
132
- [input["path"]].compact.reject { |s| s.to_s.empty? }
133
- when "Bash"
134
- bash_search_targets(input["command"].to_s)
135
- else
136
- # Read, Glob, and every other tool: read / structural op -> never gated.
137
- []
138
- end
139
- end
140
-
141
- # CONTENT-SEARCH path args across a compound command. Conservative: missing an
142
- # exotic form is fine; never flag /dev/null or pure pipes.
143
- def bash_search_targets(command)
144
- return [] unless command.is_a?(String) && !command.empty?
145
- targets = []
146
- command.split(/[;\n]|&&|\|\||\|/).each do |segment|
147
- targets.concat(segment_search_targets(segment))
148
- end
149
- targets.reject { |t| t.nil? || t.empty? || dev_path?(t) }.uniq
150
- end
151
-
152
- def segment_search_targets(segment)
153
- tokens = tokenize(segment)
154
- return [] if tokens.empty?
155
-
156
- # Skip leading env-style assignments (FOO=bar cmd ...).
157
- idx = 0
158
- idx += 1 while tokens[idx] && tokens[idx].include?("=") && tokens[idx] !~ /\A-/
159
- util = File.basename(tokens[idx].to_s)
160
- return [] unless CONTENT_SEARCH_UTILS.include?(util)
161
-
162
- args = tokens[(idx + 1)..] || []
163
- path_args_for(args)
164
- end
165
-
166
- # Collect path-shaped arguments for a content-search util. Flags are skipped; the
167
- # first non-flag bareword is the PATTERN, not a path.
168
- def path_args_for(args)
169
- paths = []
170
- pattern_consumed = false
171
- args.each do |a|
172
- next if a.start_with?("-")
173
- unless pattern_consumed
174
- pattern_consumed = true
175
- next
176
- end
177
- paths << a
178
- end
179
- paths
180
- end
181
-
182
- # Minimal tokenizer: split on whitespace, strip surrounding matching quotes off
183
- # each token. Good enough for the conservative read-vector parse.
184
- def tokenize(segment)
185
- segment.to_s.strip.split(/\s+/).map { |t| strip_quotes(t) }
186
- end
187
-
188
- def strip_quotes(token)
189
- if (token.start_with?('"') && token.end_with?('"')) ||
190
- (token.start_with?("'") && token.end_with?("'"))
191
- token[1..-2].to_s
192
- else
193
- token
194
- end
195
- end
196
-
197
- def dev_path?(path)
198
- path == "/dev/null" || path.start_with?("/dev/")
199
- end
200
-
201
- # --- reasons ---
202
-
203
- def qmd_reason(path)
204
- "retrieval gate: search the store via QMD, not a raw content scan. Reading a " \
205
- "known file and listing/globbing the store are fine; only CONTENT SEARCH over " \
206
- "store markdown routes through QMD. Use `qmd search`/`qmd query` over the " \
207
- "`plastic-*` collections (or `scripts/qmd-sync search`) instead of scanning " \
208
- "#{path}. If QMD's results do not answer your need (your reading of the " \
209
- "snippets, not their score), append a trailing `# qmd-ok` to a Bash command."
210
- end
211
- end