devflow-kit 3.6.0 → 3.7.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.
- package/CHANGELOG.md +80 -1
- package/README.md +6 -2
- package/dist/agents/code.md +7 -11
- package/dist/agents/fix.md +5 -6
- package/dist/agents/refactor.md +5 -6
- package/dist/agents/review.md +2 -0
- package/dist/cli/commands/gates.js +276 -0
- package/dist/cli/commands/init-seed.js +9 -1
- package/dist/cli/commands/init.js +31 -8
- package/dist/cli/commands/memory.js +18 -0
- package/dist/cli.js +2 -0
- package/dist/commands/bug-analysis.md +2 -2
- package/dist/commands/code-review.md +52 -44
- package/dist/commands/debug.md +2 -2
- package/dist/commands/dynamic-build.md +53 -61
- package/dist/commands/dynamic-plan.md +2 -2
- package/dist/commands/dynamic-profile.md +2 -2
- package/dist/commands/dynamic-tickets.md +2 -2
- package/dist/commands/explore.md +2 -2
- package/dist/commands/implement.md +26 -31
- package/dist/commands/plan.md +15 -25
- package/dist/commands/release.md +2 -2
- package/dist/commands/research.md +2 -2
- package/dist/commands/resolve.md +2 -2
- package/dist/commands/self-review.md +2 -2
- package/dist/core/echo-value.js +42 -0
- package/dist/core/evidence-policy.js +17 -5
- package/dist/core/gate-level.js +213 -0
- package/dist/core/manifest.js +26 -10
- package/dist/core/model-discovery.js +7 -1
- package/dist/core/tracker.js +5 -33
- package/dist/learning-off/agents/code.md +7 -11
- package/dist/learning-off/agents/fix.md +5 -6
- package/dist/learning-off/agents/refactor.md +5 -6
- package/dist/learning-off/agents/review.md +2 -0
- package/dist/learning-off/commands/code-review.md +52 -44
- package/dist/learning-off/commands/debug.md +2 -2
- package/dist/learning-off/commands/dynamic-build.md +53 -61
- package/dist/learning-off/commands/explore.md +2 -2
- package/dist/learning-off/commands/implement.md +26 -31
- package/dist/learning-off/commands/plan.md +15 -25
- package/dist/learning-off/commands/resolve.md +2 -2
- package/dist/learning-off/commands/self-review.md +2 -2
- package/dist/skills/git/references/tracker/github/ensure-pr-ready.md +7 -9
- package/dist/skills/git/references/tracker/jira/ensure-pr-ready.md +7 -15
- package/dist/skills/git/references/tracker/linear/ensure-pr-ready.md +7 -15
- package/dist/targets/claude-code/learning-install.js +15 -3
- package/package.json +1 -1
- package/src/assets/agents/_partials/_code.mds +5 -6
- package/src/assets/agents/code.mds +2 -5
- package/src/assets/agents/curate.md +4 -6
- package/src/assets/agents/review.mds +2 -0
- package/src/assets/agents/synthesize.md +2 -2
- package/src/assets/commands/_partials/_settings.mds +2 -2
- package/src/assets/commands/_partials/_wave.mds +10 -17
- package/src/assets/commands/code-review.mds +50 -42
- package/src/assets/commands/dynamic-build.mds +41 -42
- package/src/assets/commands/implement.mds +24 -29
- package/src/assets/commands/plan.mds +14 -24
- package/src/assets/mds/git/_ops_steps.mds +3 -3
- package/src/assets/mds/tracker/_common.mds +23 -12
- package/src/assets/mds/tracker/_github.mds +2 -9
- package/src/assets/mds/tracker/_jira.mds +2 -15
- package/src/assets/mds/tracker/_linear.mds +2 -15
- package/src/assets/scripts/ci-wait.cjs +22 -4
- package/src/assets/scripts/claude-md-audit.cjs +66 -51
- package/src/assets/scripts/hooks/background-memory-update +404 -95
- package/src/assets/scripts/hooks/json-helper.cjs +11 -0
- package/src/assets/scripts/hooks/json-parse +18 -3
- package/src/assets/scripts/hooks/memory-permission +358 -0
- package/src/assets/scripts/hooks/session-start-context +2 -2
- package/src/assets/scripts/hooks/session-start-memory +26 -5
- package/src/assets/scripts/lib/project-config.cjs +19 -4
- package/src/assets/scripts/resolve-settings.cjs +200 -32
- package/src/assets/skills/agent-references/SKILL.md +6 -2
- package/src/assets/skills/agent-references/references/commands/code-review-levels.md +19 -0
- package/src/assets/skills/agent-references/references/commands/implement-revalidate.md +2 -2
- package/src/assets/skills/agent-references/references/commands/plan-levels.md +40 -0
- package/src/assets/skills/agent-references/references/synthesize/planning.md +9 -22
- package/src/assets/skills/agent-references/references/synthesize/review.md +11 -11
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// Operations:
|
|
13
13
|
// get-field <field> [default] Read field from stdin JSON
|
|
14
14
|
// get-string-field <field> Read field from stdin JSON only when it is a string
|
|
15
|
+
// array-length <field> Count of an array field in stdin JSON; `unknown` for any other type
|
|
15
16
|
// extract-cwd-field <field> Extract cwd + arbitrary field, SOH-byte delimited
|
|
16
17
|
// session-output <context> [message] Build SessionStart output envelope (+ systemMessage)
|
|
17
18
|
// prompt-output <context> Build UserPromptSubmit output envelope
|
|
@@ -280,6 +281,16 @@ try {
|
|
|
280
281
|
break;
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
case 'array-length': {
|
|
285
|
+
// The count of an array field: digits for an array, the word `unknown` for an
|
|
286
|
+
// absent field or any other type, so a caller can tell none from not reported.
|
|
287
|
+
// jq's `length` on an array agrees (json-parse json_array_length_file).
|
|
288
|
+
const input = JSON.parse(readStdin());
|
|
289
|
+
const val = getNestedField(input, args[0]);
|
|
290
|
+
console.log(Array.isArray(val) ? String(val.length) : 'unknown');
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
|
|
283
294
|
case 'extract-cwd-field': {
|
|
284
295
|
// Extract cwd and an arbitrary top-level field from hook JSON in one pass.
|
|
285
296
|
// Outputs: cwd + ASCII SOH (0x01) + field value (no trailing newline).
|
|
@@ -69,6 +69,21 @@ json_string_field_file() {
|
|
|
69
69
|
fi
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
# The element count of an array field in a JSON file. Usage: json_array_length_file "/path/to/file.json" "field"
|
|
73
|
+
# Prints the count as digits when the field is an array, and the word `unknown` for an
|
|
74
|
+
# absent field or any other type (a number, string, object, boolean or null), so a
|
|
75
|
+
# caller can tell "none" from "not reported". Prints nothing, and fails, when the file
|
|
76
|
+
# cannot be read or parsed. Silent on stderr and read the same way on both backends
|
|
77
|
+
# (the node path reads the file on stdin, with its stderr redirected first).
|
|
78
|
+
json_array_length_file() {
|
|
79
|
+
local file="$1" field="$2"
|
|
80
|
+
if [ "$_HAS_JQ" = "true" ]; then
|
|
81
|
+
jq -r "(try .$field catch null) | if type == \"array\" then length else \"unknown\" end" "$file" 2>/dev/null
|
|
82
|
+
else
|
|
83
|
+
node "$_JSON_HELPER" array-length "$field" 2>/dev/null < "$file"
|
|
84
|
+
fi
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
# --- Multi-field batched extraction ---
|
|
73
88
|
|
|
74
89
|
# Extract cwd and an arbitrary top-level field from stdin JSON in a single
|
|
@@ -103,9 +118,9 @@ json_extract_cwd_prompt() {
|
|
|
103
118
|
# D-SYSTEMMESSAGE-ENVELOPE: the optional second argument is a message shown to the
|
|
104
119
|
# user, carried in the top-level `systemMessage` key beside (never inside)
|
|
105
120
|
# `hookSpecificOutput`; it does not enter the model's context. With ONE argument the
|
|
106
|
-
# envelope
|
|
107
|
-
#
|
|
108
|
-
#
|
|
121
|
+
# envelope holds the context alone, byte for byte (ensure-proxy and
|
|
122
|
+
# session-start-orchestrator pass one; session-start-context and session-start-memory
|
|
123
|
+
# pass two). With two:
|
|
109
124
|
# - a message and a context -> both keys, hookSpecificOutput first;
|
|
110
125
|
# - a message and no context -> `systemMessage` alone, with NO hookSpecificOutput key;
|
|
111
126
|
# - an empty message -> the one-argument envelope for that context.
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# memory-permission — the memory worker's write permission, as one sourced helper.
|
|
4
|
+
#
|
|
5
|
+
# background-memory-update starts `claude -p` in a permission mode that denies every
|
|
6
|
+
# call no rule allows, with an allow rule for its staged file (WORKING-MEMORY.md.new),
|
|
7
|
+
# the only path the worker's write may reach, and a deny rule for every path under it.
|
|
8
|
+
# Allow rules in the user's own settings also apply to the run.
|
|
9
|
+
# This helper holds what the worker and session-start-memory share, so one bash 3.2 test
|
|
10
|
+
# run covers it (tests/shell-hooks-helpers.test.ts):
|
|
11
|
+
# path_occupied whether a file, a folder or a link, even a dangling one, stands on a path
|
|
12
|
+
# staged_path_safe whether a staged path can sit in those rules
|
|
13
|
+
# memory_settings_json the settings JSON that carries the rules
|
|
14
|
+
# memory_staged_remove the guarded removal of a folder or a link at the staged path
|
|
15
|
+
# memory_result_summary the fixed log line for a captured JSON result
|
|
16
|
+
# memory_notice_* the one-time notice: the worker writes it, a session start reads it
|
|
17
|
+
# memory_denied_seen the count of denied runs that raises the `denied` notice
|
|
18
|
+
#
|
|
19
|
+
# Source it after resolve-project-root (it needs df_no_symlink_below and df_file_below)
|
|
20
|
+
# and, for memory_result_summary, after json-parse. log() is used when the caller has one.
|
|
21
|
+
#
|
|
22
|
+
# Errexit safety: both hooks run under `set -e`, and a helper's last non-zero status
|
|
23
|
+
# aborts the caller. So each helper ends in an explicit `return 0` or a `return` with the
|
|
24
|
+
# status it means, link checks are predicates inside `if`, and a create that noclobber may
|
|
25
|
+
# refuse ends in `|| true`. Callers call a predicate inside an `if` or an `||` list.
|
|
26
|
+
#
|
|
27
|
+
# Character sets are spelled out in the patterns below: a range such as a-z collates by
|
|
28
|
+
# locale on bash 3.2.
|
|
29
|
+
|
|
30
|
+
# The reasons a notice can carry, and the file each one uses beside the memory files:
|
|
31
|
+
# path the project path cannot carry the rule, or the staged path is unusable
|
|
32
|
+
# denied Claude Code refused the worker's write in two runs with no successful update between them
|
|
33
|
+
MEMORY_NOTICE_REASONS="path denied"
|
|
34
|
+
|
|
35
|
+
# path_occupied <path> — returns 0 when a file, a folder or a link stands on <path>, and 1
|
|
36
|
+
# when nothing does. A link counts whatever it names, a dangling link included: the name is
|
|
37
|
+
# taken, and a create or a move onto it is not safe. Call it inside an `if` or an `||` list.
|
|
38
|
+
path_occupied() {
|
|
39
|
+
if [ -e "${1:-}" ] || [ -L "${1:-}" ]; then
|
|
40
|
+
return 0
|
|
41
|
+
fi
|
|
42
|
+
return 1
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# staged_path_safe <path> — returns 0 when <path> can sit in the Edit rules as it is.
|
|
46
|
+
# Sets STAGED_PATH_REFUSAL to "" when it can, `chars` when the path holds a character or
|
|
47
|
+
# a segment the rules cannot carry, and `protected` when a .git folder lies above it (the
|
|
48
|
+
# worker skips such a project and logs the reason). A .claude folder above it is fine: a
|
|
49
|
+
# checkout in .claude/worktrees gets its working memory updated. The rule text carries no
|
|
50
|
+
# quoting, so a character that has a meaning in a rule path is refused rather than quoted:
|
|
51
|
+
# * ? [ ] \ " { } and every control character, including newline, tab and DEL. A path that
|
|
52
|
+
# is not absolute, starts with //, or holds an empty, . or .. segment is refused too. ( and )
|
|
53
|
+
# are carried as they are. The path reaches a JSON string by plain concatenation, which is
|
|
54
|
+
# safe after this check: $, backtick and % are inert there, and " \ and controls cannot occur.
|
|
55
|
+
staged_path_safe() {
|
|
56
|
+
local _p="${1:-}"
|
|
57
|
+
STAGED_PATH_REFUSAL=""
|
|
58
|
+
case "$_p" in
|
|
59
|
+
/*) ;;
|
|
60
|
+
*) STAGED_PATH_REFUSAL="chars"; return 1 ;;
|
|
61
|
+
esac
|
|
62
|
+
case "$_p" in
|
|
63
|
+
//*|*//*|*/./*|*/../*|*/.|*/..) STAGED_PATH_REFUSAL="chars"; return 1 ;;
|
|
64
|
+
esac
|
|
65
|
+
case "$_p" in
|
|
66
|
+
*[[:cntrl:]]*) STAGED_PATH_REFUSAL="chars"; return 1 ;;
|
|
67
|
+
esac
|
|
68
|
+
case "$_p" in
|
|
69
|
+
*'*'*|*'?'*|*'['*|*']'*|*'\'*|*'"'*|*'{'*|*'}'*) STAGED_PATH_REFUSAL="chars"; return 1 ;;
|
|
70
|
+
esac
|
|
71
|
+
case "$_p" in
|
|
72
|
+
*/.git/*) STAGED_PATH_REFUSAL="protected"; return 1 ;;
|
|
73
|
+
esac
|
|
74
|
+
return 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# memory_settings_json <staged path> — prints the settings JSON for `claude --settings`:
|
|
78
|
+
# two rules and no hooks (// makes a rule path absolute):
|
|
79
|
+
# allow Edit(//<staged>) the staged file
|
|
80
|
+
# deny Edit(//<staged>/*) every path under the staged path
|
|
81
|
+
# Under dontAsk, any call no rule allows is refused, so the worker's write is limited to
|
|
82
|
+
# its staged file and to what allow rules in the user's own settings cover.
|
|
83
|
+
# Measured on Claude Code 2.1.269, 2.1.280, 2.1.286 and 2.1.299, both argv forms,
|
|
84
|
+
# against a local stand-in for the Messages API (2026-10-15): with these two rules
|
|
85
|
+
# the Write of the staged file succeeds, and a Write to <staged>/x, <staged>/a/b,
|
|
86
|
+
# <staged>/a/b/c/d/e, <staged>/.hidden or <staged>/../<name> is refused. The deny is
|
|
87
|
+
# `/*` and not `/**`: `/**` was measured to refuse the staged file too (2.1.269 and
|
|
88
|
+
# 2.1.299, 0 of 3 writes), and then no memory is written. A path with two pairs of ( ) in it
|
|
89
|
+
# (`obs ( )/proj (copy)`) carries both rules as they are: on 2.1.269 with the legacy argv
|
|
90
|
+
# and on 2.1.299 with the lean argv, the Write of the staged file succeeded and a Write to
|
|
91
|
+
# <staged>/x, <staged>/a/b, <staged>/.hidden, <staged>/../<name> and to a file in the
|
|
92
|
+
# project root was refused. Prints nothing and returns 1 for a path staged_path_safe
|
|
93
|
+
# refuses, so a rule is never built for an unchecked path.
|
|
94
|
+
memory_settings_json() {
|
|
95
|
+
local _p="${1:-}"
|
|
96
|
+
staged_path_safe "$_p" || return 1
|
|
97
|
+
printf '%s' '{"permissions":{"allow":["Edit(/'"$_p"')"],"deny":["Edit(/'"$_p"'/*)"]},"disableAllHooks":true}'
|
|
98
|
+
return 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# STAGED_REMOVE_MAX_LISTING — the most lines `ls -RA` may print for a folder at the staged
|
|
102
|
+
# path. A folder with a longer listing is not deleted.
|
|
103
|
+
STAGED_REMOVE_MAX_LISTING=256
|
|
104
|
+
|
|
105
|
+
# memory_staged_remove <memory dir> <root> <staged path> — makes the staged path empty
|
|
106
|
+
# when a folder or a link stands on it, with one delete of exactly that path. <root> is
|
|
107
|
+
# the project root as it resolves on disk. It deletes only when it can prove all of these,
|
|
108
|
+
# and otherwise deletes nothing, returns 1 and sets STAGED_REMOVE_REFUSAL to the keyword
|
|
109
|
+
# of the first fact it could not prove:
|
|
110
|
+
# args <memory dir>, <root> and <staged path> are all set, and both paths are absolute
|
|
111
|
+
# path <staged path> is exactly <memory dir>/WORKING-MEMORY.md.new
|
|
112
|
+
# parent <memory dir> is <root>/.devflow/memory, as a string and then on disk
|
|
113
|
+
# link no link sits on the way down from <root> to <memory dir>
|
|
114
|
+
# size a folder lists at most STAGED_REMOVE_MAX_LISTING lines of `ls -RA`
|
|
115
|
+
# rm the delete took effect: nothing stands on the staged path afterwards
|
|
116
|
+
# A link is removed as the link (`rm -f`, never `-r`), so what it names is never touched;
|
|
117
|
+
# a folder is removed with `rm -rf`, which unlinks a link inside it and never follows one.
|
|
118
|
+
# The path is a single quoted word, so no pattern expands. Sets STAGED_REMOVED to `link`,
|
|
119
|
+
# `dir`, or `none` (nothing removed). A regular file, or nothing, is left as it is and
|
|
120
|
+
# returns 0: the caller removes a stale staged file itself. Returns 0 when no folder and
|
|
121
|
+
# no link stands on the path afterwards. The checks and the delete are separate steps, so
|
|
122
|
+
# a process that swaps something in between is not stopped; such a process already runs as
|
|
123
|
+
# the user.
|
|
124
|
+
memory_staged_remove() {
|
|
125
|
+
local _dir="${1:-}" _root="${2:-}" _staged="${3:-}" _kind="" _phys="" _n=0
|
|
126
|
+
STAGED_REMOVED="none"
|
|
127
|
+
STAGED_REMOVE_REFUSAL=""
|
|
128
|
+
case "$_dir" in /?*) ;; *) STAGED_REMOVE_REFUSAL="args"; return 1 ;; esac
|
|
129
|
+
case "$_root" in /?*) ;; *) STAGED_REMOVE_REFUSAL="args"; return 1 ;; esac
|
|
130
|
+
case "$_staged" in /?*) ;; *) STAGED_REMOVE_REFUSAL="args"; return 1 ;; esac
|
|
131
|
+
if [ -L "$_staged" ]; then
|
|
132
|
+
_kind="link"
|
|
133
|
+
elif [ -d "$_staged" ]; then
|
|
134
|
+
_kind="dir"
|
|
135
|
+
else
|
|
136
|
+
return 0
|
|
137
|
+
fi
|
|
138
|
+
if [ "$_staged" != "$_dir/WORKING-MEMORY.md.new" ]; then
|
|
139
|
+
STAGED_REMOVE_REFUSAL="path"; return 1
|
|
140
|
+
fi
|
|
141
|
+
if [ "$_dir" != "$_root/.devflow/memory" ]; then
|
|
142
|
+
STAGED_REMOVE_REFUSAL="parent"; return 1
|
|
143
|
+
fi
|
|
144
|
+
if ! df_no_symlink_below "$_root" "$_dir"; then
|
|
145
|
+
STAGED_REMOVE_REFUSAL="link"; return 1
|
|
146
|
+
fi
|
|
147
|
+
_phys=$(cd -P -- "$_dir" 2>/dev/null && pwd -P) || _phys=""
|
|
148
|
+
if [ "$_phys" != "$_root/.devflow/memory" ]; then
|
|
149
|
+
STAGED_REMOVE_REFUSAL="parent"; return 1
|
|
150
|
+
fi
|
|
151
|
+
if [ "$_kind" = "dir" ]; then
|
|
152
|
+
_n=$(ls -RA -- "$_staged" 2>/dev/null | head -n $((STAGED_REMOVE_MAX_LISTING + 1)) | wc -l) || _n=0
|
|
153
|
+
_n=$((_n + 0))
|
|
154
|
+
if [ "$_n" -gt "$STAGED_REMOVE_MAX_LISTING" ]; then
|
|
155
|
+
STAGED_REMOVE_REFUSAL="size"; return 1
|
|
156
|
+
fi
|
|
157
|
+
rm -rf -- "$_staged" 2>/dev/null || true
|
|
158
|
+
else
|
|
159
|
+
rm -f -- "$_staged" 2>/dev/null || true
|
|
160
|
+
fi
|
|
161
|
+
if path_occupied "$_staged"; then
|
|
162
|
+
STAGED_REMOVE_REFUSAL="rm"; return 1
|
|
163
|
+
fi
|
|
164
|
+
STAGED_REMOVED="$_kind"
|
|
165
|
+
return 0
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# The most characters a result field may carry into the log line. A longer value reads
|
|
169
|
+
# `unknown` (a status code is left out).
|
|
170
|
+
MEMORY_RESULT_DENIALS_MAX_DIGITS=6
|
|
171
|
+
MEMORY_RESULT_TURNS_MAX_DIGITS=6
|
|
172
|
+
MEMORY_RESULT_STATUS_MAX_DIGITS=3
|
|
173
|
+
MEMORY_RESULT_SUBTYPE_MAX_CHARS=40
|
|
174
|
+
|
|
175
|
+
# _memory_field_within <digits|letters> <value> <max> — sets _MEMORY_FIELD to <value> when
|
|
176
|
+
# it is one or more characters of the named set and at most <max> of them, and to `unknown`
|
|
177
|
+
# otherwise. `digits` is 0-9; `letters` is a-z and _. Both are spelled out, since a range
|
|
178
|
+
# collates by locale on bash 3.2. A builtin only, so it forks nothing. Always returns 0.
|
|
179
|
+
_memory_field_within() {
|
|
180
|
+
local _set="${1:-}" _value="${2:-}" _max="${3:-0}"
|
|
181
|
+
_MEMORY_FIELD="unknown"
|
|
182
|
+
case "$_set" in
|
|
183
|
+
digits)
|
|
184
|
+
case "$_value" in ''|*[!0123456789]*) return 0 ;; esac
|
|
185
|
+
;;
|
|
186
|
+
letters)
|
|
187
|
+
case "$_value" in ''|*[!abcdefghijklmnopqrstuvwxyz_]*) return 0 ;; esac
|
|
188
|
+
;;
|
|
189
|
+
*) return 0 ;;
|
|
190
|
+
esac
|
|
191
|
+
if [ "${#_value}" -le "$_max" ]; then _MEMORY_FIELD="$_value"; fi
|
|
192
|
+
return 0
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# memory_result_summary <file> — reduces a `--output-format json` result file to a fixed
|
|
196
|
+
# line, and reads nothing else of it: the tool input and the result text, which can hold
|
|
197
|
+
# the memory body, are never read. Sets, in the caller's scope:
|
|
198
|
+
# MEMORY_RESULT_LINE Result: <subtype>, is_error=<true|false>, <n> turn(s),
|
|
199
|
+
# <d> permission denial(s)[, api_status=<digits>]
|
|
200
|
+
# or Result: not reported (empty|unparseable|no parser)
|
|
201
|
+
# MEMORY_RESULT_DENIALS the denial count as digits, or `unknown` when the result does
|
|
202
|
+
# not report one (an absent or non-array field is never 0)
|
|
203
|
+
# Every field is checked against its own shape, so text from the file cannot enter the
|
|
204
|
+
# line: a field that fails its check reads `unknown`. Always returns 0.
|
|
205
|
+
memory_result_summary() {
|
|
206
|
+
local _f="${1:-}" _sub="" _err="" _turns="" _den="" _status="" _api=""
|
|
207
|
+
MEMORY_RESULT_LINE=""
|
|
208
|
+
MEMORY_RESULT_DENIALS="unknown"
|
|
209
|
+
if [ "${_JSON_AVAILABLE:-false}" != "true" ]; then
|
|
210
|
+
MEMORY_RESULT_LINE="Result: not reported (no parser)"
|
|
211
|
+
return 0
|
|
212
|
+
fi
|
|
213
|
+
if [ -z "$_f" ] || [ ! -s "$_f" ]; then
|
|
214
|
+
MEMORY_RESULT_LINE="Result: not reported (empty)"
|
|
215
|
+
return 0
|
|
216
|
+
fi
|
|
217
|
+
_den=$(json_array_length_file "$_f" "permission_denials") || _den=""
|
|
218
|
+
if [ -z "$_den" ]; then
|
|
219
|
+
MEMORY_RESULT_LINE="Result: not reported (unparseable)"
|
|
220
|
+
return 0
|
|
221
|
+
fi
|
|
222
|
+
_memory_field_within digits "$_den" "$MEMORY_RESULT_DENIALS_MAX_DIGITS"; _den="$_MEMORY_FIELD"
|
|
223
|
+
_sub=$(json_string_field_file "$_f" "subtype") || _sub=""
|
|
224
|
+
_memory_field_within letters "$_sub" "$MEMORY_RESULT_SUBTYPE_MAX_CHARS"; _sub="$_MEMORY_FIELD"
|
|
225
|
+
_err=$(json_field_file "$_f" "is_error" "") || _err=""
|
|
226
|
+
case "$_err" in
|
|
227
|
+
true|false) ;;
|
|
228
|
+
*) _err="unknown" ;;
|
|
229
|
+
esac
|
|
230
|
+
_turns=$(json_field_file "$_f" "num_turns" "") || _turns=""
|
|
231
|
+
_memory_field_within digits "$_turns" "$MEMORY_RESULT_TURNS_MAX_DIGITS"; _turns="$_MEMORY_FIELD"
|
|
232
|
+
_status=$(json_field_file "$_f" "api_error_status" "") || _status=""
|
|
233
|
+
_memory_field_within digits "$_status" "$MEMORY_RESULT_STATUS_MAX_DIGITS"
|
|
234
|
+
if [ "$_MEMORY_FIELD" != "unknown" ]; then _api=", api_status=${_MEMORY_FIELD}"; fi
|
|
235
|
+
MEMORY_RESULT_LINE="Result: ${_sub}, is_error=${_err}, ${_turns} turn(s), ${_den} permission denial(s)${_api}"
|
|
236
|
+
MEMORY_RESULT_DENIALS="$_den"
|
|
237
|
+
return 0
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
# memory_notice_write <memory dir> <root> <reason> — leaves a notice for the next session
|
|
241
|
+
# start, once per reason: only where neither the notice nor its `.shown` marker stands,
|
|
242
|
+
# and where no link sits on the way down from <root>. The builtin tests come first, since
|
|
243
|
+
# noclobber alone opens a link to a FIFO or a device; noclobber then makes the create
|
|
244
|
+
# itself exclusive. Content: the reason. Best effort: a refusal leaves nothing.
|
|
245
|
+
memory_notice_write() {
|
|
246
|
+
local _dir="${1:-}" _root="${2:-}" _reason="${3:-}" _file
|
|
247
|
+
case " $MEMORY_NOTICE_REASONS " in
|
|
248
|
+
*" $_reason "*) ;;
|
|
249
|
+
*) return 0 ;;
|
|
250
|
+
esac
|
|
251
|
+
[ -d "$_dir" ] || return 0
|
|
252
|
+
_file="$_dir/.worker-notice-$_reason"
|
|
253
|
+
if ! path_occupied "$_file" && ! path_occupied "$_file.shown" \
|
|
254
|
+
&& df_no_symlink_below "$_root" "$_file" "$_file.shown"; then
|
|
255
|
+
( umask 077; set -C; printf '%s\n' "$_reason" > "$_file" ) 2>/dev/null || true
|
|
256
|
+
fi
|
|
257
|
+
return 0
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
# memory_notice_clear <memory dir> <root> <reason> — removes the notice, its `.shown`
|
|
261
|
+
# marker and, for `denied`, the one-denied-run marker, once the cause is gone. The
|
|
262
|
+
# files are removed only where no link sits on the way down from <root>.
|
|
263
|
+
memory_notice_clear() {
|
|
264
|
+
local _dir="${1:-}" _root="${2:-}" _reason="${3:-}" _file _mark
|
|
265
|
+
case " $MEMORY_NOTICE_REASONS " in
|
|
266
|
+
*" $_reason "*) ;;
|
|
267
|
+
*) return 0 ;;
|
|
268
|
+
esac
|
|
269
|
+
_file="$_dir/.worker-notice-$_reason"
|
|
270
|
+
_mark="$_dir/.worker-denied-once"
|
|
271
|
+
if path_occupied "$_file" || path_occupied "$_file.shown"; then
|
|
272
|
+
if df_no_symlink_below "$_root" "$_file" "$_file.shown"; then
|
|
273
|
+
rm -f "$_file" "$_file.shown" 2>/dev/null || true
|
|
274
|
+
fi
|
|
275
|
+
fi
|
|
276
|
+
if [ "$_reason" = "denied" ] && path_occupied "$_mark"; then
|
|
277
|
+
if df_no_symlink_below "$_root" "$_mark"; then
|
|
278
|
+
rm -f "$_mark" 2>/dev/null || true
|
|
279
|
+
fi
|
|
280
|
+
fi
|
|
281
|
+
return 0
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
# memory_denied_seen <memory dir> <root> — records one run that Claude Code refused the
|
|
285
|
+
# worker's write in. The first leaves a marker; a second, with the marker still there,
|
|
286
|
+
# raises the `denied` notice. A run that swapped the memory in clears both
|
|
287
|
+
# (memory_notice_clear denied), so only two denied runs with no successful update between
|
|
288
|
+
# them count.
|
|
289
|
+
memory_denied_seen() {
|
|
290
|
+
local _dir="${1:-}" _root="${2:-}" _mark
|
|
291
|
+
[ -d "$_dir" ] || return 0
|
|
292
|
+
_mark="$_dir/.worker-denied-once"
|
|
293
|
+
if path_occupied "$_mark"; then
|
|
294
|
+
memory_notice_write "$_dir" "$_root" "denied"
|
|
295
|
+
elif df_no_symlink_below "$_root" "$_mark"; then
|
|
296
|
+
( umask 077; set -C; : > "$_mark" ) 2>/dev/null || true
|
|
297
|
+
fi
|
|
298
|
+
return 0
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# memory_notice_text <reason> <log file> — sets MEMORY_NOTICE_TEXT to the message for a
|
|
302
|
+
# reason, naming <log file>, and to "" for a reason it has no message for. Always returns 0.
|
|
303
|
+
memory_notice_text() {
|
|
304
|
+
local _reason="${1:-}" _logfile="${2:-}"
|
|
305
|
+
local _where="The worker log is .background-memory-update.log under ~/.devflow/logs/, in the folder for the session that ran it. For this session: ${_logfile}"
|
|
306
|
+
MEMORY_NOTICE_TEXT=""
|
|
307
|
+
case "$_reason" in
|
|
308
|
+
path)
|
|
309
|
+
MEMORY_NOTICE_TEXT="Devflow: working memory is not updating because the worker cannot write its staged file at this project path. ${_where}"
|
|
310
|
+
;;
|
|
311
|
+
denied)
|
|
312
|
+
MEMORY_NOTICE_TEXT="Devflow: working memory is not updating because Claude Code refused the worker's write in two runs with no successful update between them. ${_where}"
|
|
313
|
+
;;
|
|
314
|
+
esac
|
|
315
|
+
return 0
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
# memory_notice_read <memory dir> <root> <log file> — builds the message for each pending
|
|
319
|
+
# notice and moves each to its `.shown` marker, so a reason is shown once. Sets
|
|
320
|
+
# MEMORY_NOTICE_MESSAGE (empty when nothing is pending), joined by a space when more
|
|
321
|
+
# than one reason is pending. A notice is read only where no link sits on its path; one
|
|
322
|
+
# whose content does not fit its reason is moved to `.shown` unshown and logged.
|
|
323
|
+
# <log file> is named in the messages (memory_notice_text). Always returns 0.
|
|
324
|
+
memory_notice_read() {
|
|
325
|
+
local _dir="${1:-}" _root="${2:-}" _logfile="${3:-}"
|
|
326
|
+
local _reason _file _line _tag _extra _text
|
|
327
|
+
MEMORY_NOTICE_MESSAGE=""
|
|
328
|
+
for _reason in $MEMORY_NOTICE_REASONS; do
|
|
329
|
+
_file="$_dir/.worker-notice-$_reason"
|
|
330
|
+
df_file_below "$_root" "$_file" || continue
|
|
331
|
+
_line=""; _tag=""; _extra=""; _text=""
|
|
332
|
+
# stderr is redirected before stdin, so a notice that a concurrent session start moved
|
|
333
|
+
# away since the check above fails the open in silence.
|
|
334
|
+
IFS= read -r -n 200 _line 2>/dev/null < "$_file" || true
|
|
335
|
+
read -r _tag _extra <<< "$_line" || true
|
|
336
|
+
if [ "$_tag" = "$_reason" ] && [ -z "$_extra" ]; then
|
|
337
|
+
memory_notice_text "$_reason" "$_logfile"
|
|
338
|
+
_text="$MEMORY_NOTICE_TEXT"
|
|
339
|
+
fi
|
|
340
|
+
if [ -n "$_text" ]; then
|
|
341
|
+
if [ -n "$MEMORY_NOTICE_MESSAGE" ]; then
|
|
342
|
+
MEMORY_NOTICE_MESSAGE="${MEMORY_NOTICE_MESSAGE} ${_text}"
|
|
343
|
+
else
|
|
344
|
+
MEMORY_NOTICE_MESSAGE="$_text"
|
|
345
|
+
fi
|
|
346
|
+
elif declare -F log >/dev/null 2>&1; then
|
|
347
|
+
log "Worker notice for reason ${_reason} ignored: its content does not fit the reason"
|
|
348
|
+
fi
|
|
349
|
+
if df_no_symlink_below "$_root" "$_file" "$_file.shown"; then
|
|
350
|
+
if ! path_occupied "$_file.shown"; then
|
|
351
|
+
mv "$_file" "$_file.shown" 2>/dev/null || true
|
|
352
|
+
else
|
|
353
|
+
rm -f "$_file" 2>/dev/null || true
|
|
354
|
+
fi
|
|
355
|
+
fi
|
|
356
|
+
done
|
|
357
|
+
return 0
|
|
358
|
+
}
|
|
@@ -848,7 +848,7 @@ fi
|
|
|
848
848
|
# (a) an if-clause, so it applies only when a devflow command was running, with an
|
|
849
849
|
# explicit ignore clause;
|
|
850
850
|
# (b) where the command file lives, by rule: commands/devflow/ under the Claude
|
|
851
|
-
# config directory ($CLAUDE_CONFIG_DIR, else ~/.claude);
|
|
851
|
+
# config directory ($CLAUDE_CONFIG_DIR when absolute, else ~/.claude);
|
|
852
852
|
# (c) the read mechanics: list the headings, then read from the phase in progress,
|
|
853
853
|
# never the whole file;
|
|
854
854
|
# (d) that the command's input (COMMAND_INPUT in the commands that bind it, an
|
|
@@ -862,7 +862,7 @@ fi
|
|
|
862
862
|
case "$SESSION_SOURCE" in
|
|
863
863
|
compact)
|
|
864
864
|
dbg "compaction resume directive emitted"
|
|
865
|
-
COMPACT_SECTION='If a devflow command was running:
|
|
865
|
+
COMPACT_SECTION='If a devflow command was running: read commands/devflow/<name>.md in $CLAUDE_CONFIG_DIR if absolute, else ~/.claude, list headings, read from current phase, input (COMMAND_INPUT/ARGUMENTS) from summary, resume after last finished phase. Else ignore.'
|
|
866
866
|
if [ -n "$CONTEXT" ]; then
|
|
867
867
|
CONTEXT="${CONTEXT}
|
|
868
868
|
|
|
@@ -39,6 +39,8 @@ dbg "CWD=$CWD"
|
|
|
39
39
|
# Anchor .devflow/ to the project root (prevents a stray nested .devflow/ when this
|
|
40
40
|
# hook runs with a CWD inside .devflow/...). Empty → fall back to CWD.
|
|
41
41
|
source "$SCRIPT_DIR/resolve-project-root" 2>/dev/null || true
|
|
42
|
+
# The one-time notice the memory worker leaves (needs df_file_below from resolve-project-root).
|
|
43
|
+
source "$SCRIPT_DIR/memory-permission" || { echo "session-start-memory: failed to source memory-permission" >&2; exit 1; }
|
|
42
44
|
PROJECT_ROOT="$(df_resolve_root "$CWD" 2>/dev/null || true)"
|
|
43
45
|
[ -n "$PROJECT_ROOT" ] || PROJECT_ROOT="$CWD"
|
|
44
46
|
|
|
@@ -346,17 +348,36 @@ ${COMPACT_NOTE}"
|
|
|
346
348
|
fi
|
|
347
349
|
fi
|
|
348
350
|
|
|
351
|
+
# --- One-time worker notice ---
|
|
352
|
+
# When the memory worker cannot refresh memory for a reason only the user can fix (a
|
|
353
|
+
# project path its permission rule cannot carry, the worker's write refused in two runs
|
|
354
|
+
# with no successful update between them), it leaves a notice file. The message is shown
|
|
355
|
+
# to the user once per reason, whether or not a working memory exists, and the file moves
|
|
356
|
+
# to its `.shown` marker so the next start stays quiet (memory-permission). The worker log
|
|
357
|
+
# is `.background-memory-update.log` under ~/.devflow/logs/, in the folder for the session
|
|
358
|
+
# that ran the worker; the message names this session's folder for it.
|
|
359
|
+
# D-SYSTEMMESSAGE-ENVELOPE: it travels as `systemMessage`, beside the context and never in it.
|
|
360
|
+
memory_notice_read "$MEMORY_DIR" "$PROJECT_ROOT" "$LOG_DIR/.background-memory-update.log"
|
|
361
|
+
SYSTEM_MESSAGE="$MEMORY_NOTICE_MESSAGE"
|
|
362
|
+
if [ -n "$SYSTEM_MESSAGE" ]; then
|
|
363
|
+
dbg "Worker notice shown"
|
|
364
|
+
log "Worker notice shown to the user"
|
|
365
|
+
fi
|
|
366
|
+
|
|
349
367
|
# --- Output ---
|
|
350
368
|
|
|
351
|
-
# Only output if we have something to inject
|
|
352
|
-
if [ -z "$CONTEXT" ]; then
|
|
369
|
+
# Only output if we have something to inject or to tell the user
|
|
370
|
+
if [ -z "$CONTEXT" ] && [ -z "$SYSTEM_MESSAGE" ]; then
|
|
353
371
|
dbg "EXIT: no context to inject"
|
|
354
372
|
exit 0
|
|
355
373
|
fi
|
|
356
374
|
|
|
357
375
|
dbg "OUTPUT_LENGTH=${#CONTEXT}"
|
|
358
|
-
|
|
376
|
+
if [ -n "$CONTEXT" ]; then
|
|
377
|
+
log "Injecting memory context (${#CONTEXT} chars)"
|
|
378
|
+
fi
|
|
359
379
|
dbg "=== HOOK COMPLETE ==="
|
|
360
380
|
|
|
361
|
-
# Output as additionalContext JSON envelope (Claude sees it as system context, not user-visible)
|
|
362
|
-
|
|
381
|
+
# Output as additionalContext JSON envelope (Claude sees it as system context, not user-visible);
|
|
382
|
+
# a notice adds a systemMessage the user sees.
|
|
383
|
+
json_session_output "$CONTEXT" "$SYSTEM_MESSAGE"
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
// bad value never takes its neighbours down with it (AC-26). What a malformed
|
|
22
22
|
// value MEANS is the consumer's decision, made once in each caller's fold:
|
|
23
23
|
// evidence ⇒ required, compliance ⇒ generic, tracker ⇒ TRACKER_WARN=invalid,
|
|
24
|
-
// reviewPublication ⇒ off, a feature switch ⇒ not narrowed.
|
|
24
|
+
// reviewPublication ⇒ off, a feature switch ⇒ not narrowed. The personal file
|
|
25
|
+
// alone also carries `gateLevel` ("full|standard|lean"); it is a level, not a
|
|
26
|
+
// switch, so it may raise or lower what the machine records.
|
|
25
27
|
//
|
|
26
28
|
// Whole-file rule: that per-key classification applies only INSIDE a file that
|
|
27
29
|
// reads as a JSON object. A file that exists but does not — empty, unparseable,
|
|
@@ -61,6 +63,12 @@ const POLICIES = Object.freeze(['required', 'standard']);
|
|
|
61
63
|
/** Every review-publication value, in ascending order: off < auto < full. */
|
|
62
64
|
const PUBLICATIONS = Object.freeze(['off', 'auto', 'full']);
|
|
63
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Every gate level, strictest first — transcribed from GATE_LEVELS in
|
|
68
|
+
* src/core/gate-level.ts and pinned to it by a parity test.
|
|
69
|
+
*/
|
|
70
|
+
const GATE_LEVELS = Object.freeze(['full', 'standard', 'lean']);
|
|
71
|
+
|
|
64
72
|
/**
|
|
65
73
|
* The registered tracker providers — transcribed from TRACKER_PROVIDERS in
|
|
66
74
|
* src/core/tracker.ts and pinned to it by a parity test.
|
|
@@ -101,7 +109,7 @@ const SAFE_REF_RE = /^(?![A-Za-z0-9._/-]{0,254}\.\.)[A-Za-z0-9][A-Za-z0-9._/-]{0
|
|
|
101
109
|
/** The ref namespace of origin's remote-tracking branches, as `git symbolic-ref` prints it. */
|
|
102
110
|
const ORIGIN_TRACKING_PREFIX = 'refs/remotes/origin/';
|
|
103
111
|
|
|
104
|
-
/** Largest machine manifest read, in bytes. */
|
|
112
|
+
/** Largest machine manifest read, in bytes — pinned to MAX_MANIFEST_BYTES in src/core/gate-level.ts by a parity test. */
|
|
105
113
|
const MAX_MANIFEST_BYTES = 1048576;
|
|
106
114
|
|
|
107
115
|
/** Deepest nesting the duplicate-key scan follows; deeper is invalid. */
|
|
@@ -136,9 +144,12 @@ const MAX_JSON_DEPTH = 32;
|
|
|
136
144
|
* tracker: Field<string>,
|
|
137
145
|
* reviewPublication: Field<'off' | 'auto' | 'full'>,
|
|
138
146
|
* features: Field<FeatureFields>,
|
|
147
|
+
* gateLevel: Field<'full' | 'standard' | 'lean'>,
|
|
139
148
|
* }} PersonalConfig
|
|
140
149
|
* The personal file's `tracker` is the per-repo provider override: a provider
|
|
141
150
|
* id string (an empty string reads as absent, as parseTrackerOverride does).
|
|
151
|
+
* Its `gateLevel` is one of the three level words; every other value,
|
|
152
|
+
* including an empty string and a duplicated key, is malformed.
|
|
142
153
|
*
|
|
143
154
|
* @typedef {{ kind: 'absent' } | { kind: 'refused' } | { kind: 'ok', bytes: Buffer }} BoundedRead
|
|
144
155
|
*/
|
|
@@ -585,8 +596,8 @@ function parseProjectBytes(buf) {
|
|
|
585
596
|
|
|
586
597
|
/**
|
|
587
598
|
* Classify the personal `.devflow/config.json` bytes with the same rules. Only
|
|
588
|
-
* the keys a personal file may carry are read: `reviewPublication`, `features
|
|
589
|
-
*
|
|
599
|
+
* the keys a personal file may carry are read: `reviewPublication`, `features`,
|
|
600
|
+
* the `tracker` override and `gateLevel`. The retired top-level switches (`memory`,
|
|
590
601
|
* `learning`, `knowledge`, `decisions`) are never read — `features` is a new
|
|
591
602
|
* namespace, so a stale `learning: false` left from the per-repo-install era
|
|
592
603
|
* cannot come back to life. Never throws.
|
|
@@ -607,13 +618,17 @@ function parsePersonalBytes(buf) {
|
|
|
607
618
|
tracker,
|
|
608
619
|
reviewPublication: fieldOf(obj, duplicates, [], 'reviewPublication', oneOf(PUBLICATIONS)),
|
|
609
620
|
features: featuresField(obj, duplicates),
|
|
621
|
+
// No exception for an empty string, unlike `tracker`: "" is not a level.
|
|
622
|
+
gateLevel: fieldOf(obj, duplicates, [], 'gateLevel', oneOf(GATE_LEVELS)),
|
|
610
623
|
});
|
|
611
624
|
}
|
|
612
625
|
|
|
613
626
|
module.exports = Object.freeze({
|
|
614
627
|
MAX_CONFIG_BYTES,
|
|
628
|
+
MAX_MANIFEST_BYTES,
|
|
615
629
|
POLICIES,
|
|
616
630
|
PUBLICATIONS,
|
|
631
|
+
GATE_LEVELS,
|
|
617
632
|
TRACKER_PROVIDER_IDS,
|
|
618
633
|
COMPLIANCE_IDS,
|
|
619
634
|
FEATURE_SWITCHES,
|