teamsmith 0.1.2 → 0.2.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/README.md +13 -7
- package/package.json +1 -1
- package/skills/teamsmith/CHANGELOG.md +39 -0
- package/skills/teamsmith/SKILL.md +18 -7
- package/skills/teamsmith/references/agent-adapters.md +7 -7
- package/skills/teamsmith/references/config.md +29 -15
- package/skills/teamsmith/references/migration.md +38 -2
- package/skills/teamsmith/references/protocol.md +81 -13
- package/skills/teamsmith/references/workflows.md +31 -19
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +210 -70
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +70 -9
- package/skills/teamsmith/scripts/lib/cmd-config.sh +222 -70
- package/skills/teamsmith/scripts/lib/cmd-death.sh +2 -15
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +6 -3
- package/skills/teamsmith/scripts/lib/cmd-project.sh +134 -17
- package/skills/teamsmith/scripts/lib/cmd-reply.sh +96 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +13 -10
- package/skills/teamsmith/scripts/lib/cmd-status.sh +42 -13
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +75 -13
- package/skills/teamsmith/scripts/lib/common.sh +797 -71
- package/skills/teamsmith/scripts/monitor.mjs +34 -3
- package/skills/teamsmith/scripts/panel/README.md +22 -11
- package/skills/teamsmith/scripts/panel/panel.js +217 -215
- package/skills/teamsmith/scripts/panel/src/App.tsx +421 -164
- package/skills/teamsmith/scripts/panel/src/data.ts +84 -4
- package/skills/teamsmith/scripts/panel/src/layout.ts +502 -91
- package/skills/teamsmith/scripts/panel/src/main.tsx +97 -12
- package/skills/teamsmith/scripts/panel/src/settings.ts +1 -1
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +56 -21
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +56 -21
- package/skills/teamsmith/scripts/panel/src/types.ts +178 -16
- package/skills/teamsmith/scripts/replies.mjs +893 -0
- package/skills/teamsmith/scripts/team +1 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +15 -2
- package/skills/teamsmith/templates/BOARD.md.tmpl +2 -2
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +7 -3
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +17 -0
- package/skills/teamsmith/templates/config.sh.tmpl +10 -5
- package/skills/teamsmith/templates/memory-seed.md.tmpl +3 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +20 -1
- package/skills/teamsmith/templates/report.md.tmpl +12 -0
- package/skills/teamsmith/templates/task.md.tmpl +4 -0
- package/skills/teamsmith/tests/config-cli.sh +162 -288
- package/skills/teamsmith/tests/death-cause.sh +5 -2
- package/skills/teamsmith/tests/install-shape.sh +4 -2
- package/skills/teamsmith/tests/key-replies-pty.sh +375 -0
- package/skills/teamsmith/tests/key-replies-ui.sh +332 -0
- package/skills/teamsmith/tests/key-replies.sh +1075 -0
- package/skills/teamsmith/tests/ledger-ban.sh +4 -4
- package/skills/teamsmith/tests/ledger-claim.sh +247 -0
- package/skills/teamsmith/tests/lib/model-policy.sh +26 -0
- package/skills/teamsmith/tests/lib/model-routing-boundary.sh +420 -0
- package/skills/teamsmith/tests/lib/model-routing-expansion.sh +155 -0
- package/skills/teamsmith/tests/lib/model-routing-flips.py +136 -0
- package/skills/teamsmith/tests/lib/model-routing-roles.sh +250 -0
- package/skills/teamsmith/tests/lib/proc-io.sh +103 -0
- package/skills/teamsmith/tests/lib/reply-fixture.sh +372 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +8 -0
- package/skills/teamsmith/tests/panel-b2.sh +1 -1
- package/skills/teamsmith/tests/panel-b3-stub.sh +27 -0
- package/skills/teamsmith/tests/panel-b3.sh +14 -10
- package/skills/teamsmith/tests/panel-choices.sh +74 -61
- package/skills/teamsmith/tests/panel-cpu.sh +1 -1
- package/skills/teamsmith/tests/panel-p21.sh +311 -190
- package/skills/teamsmith/tests/perf.sh +1 -1
- package/skills/teamsmith/tests/pm-box-real.sh +1 -1
- package/skills/teamsmith/tests/pulse-nudge-key.sh +1 -1
- package/skills/teamsmith/tests/routes.sh +43 -22
- package/skills/teamsmith/tests/section-budgets.tsv +8 -4
- package/skills/teamsmith/tests/section-paths.tsv +26 -16
- package/skills/teamsmith/tests/section-select.sh +82 -6
- package/skills/teamsmith/tests/smoke.sh +782 -180
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +9 -9
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +1 -1
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +5 -5
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +2 -2
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +5 -5
- package/skills/teamsmith/tests/task-header-model.sh +2 -1
- package/skills/teamsmith/tests/task-model-routing.sh +1014 -0
- package/skills/teamsmith-init/SKILL.md +38 -38
- package/skills/teamsmith-init/references/bootstrap.md +6 -4
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +9 -5
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""P228 scratch-only mutations; print exact byte hashes and require one target."""
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import pathlib
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
root = pathlib.Path(sys.argv[1]).resolve()
|
|
9
|
+
name = sys.argv[2]
|
|
10
|
+
assert (root / '.routing-mutant').is_file(), 'not a marked owned scratch tree'
|
|
11
|
+
lib = root / 'skills/teamsmith/scripts/lib'
|
|
12
|
+
changes = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def replace(path, old, new):
|
|
16
|
+
text = path.read_text()
|
|
17
|
+
assert text.count(old) == 1, (name, str(path), text.count(old))
|
|
18
|
+
before = hashlib.sha256(text.encode()).hexdigest()
|
|
19
|
+
text = text.replace(old, new)
|
|
20
|
+
assert text.count(new) == 1
|
|
21
|
+
path.write_text(text)
|
|
22
|
+
after = hashlib.sha256(text.encode()).hexdigest()
|
|
23
|
+
assert before != after
|
|
24
|
+
changes.append(dict(file=str(path), matched=1, before=before, after=after))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def function(path, symbol, body):
|
|
28
|
+
text = path.read_text()
|
|
29
|
+
begin = text.index(symbol + '() {')
|
|
30
|
+
line_end = text.index('\n', begin)
|
|
31
|
+
end = line_end if text[begin:line_end].rstrip().endswith('}') else text.index('\n}', begin) + 2
|
|
32
|
+
old = text[begin:end]
|
|
33
|
+
replace(path, old, '# P228_FLIP_' + name + '\n' + symbol + '() {\n' + body + '\n}')
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if name == 'unmapped-override':
|
|
37
|
+
replace(lib / 'cmd-agents.sh',
|
|
38
|
+
' local policy_model; policy_model="$(team_task_policy_model "$category")" || { team_err "category 未映射:$category;config set-task-model $category <model>(override 仍须映射)"; return 1; }',
|
|
39
|
+
' # P228_FLIP_unmapped-override\n local policy_model; policy_model="${override:-$(team_task_policy_model "$category" || true)}"')
|
|
40
|
+
elif name == 'required-categories':
|
|
41
|
+
# F6 red side: restore the hardcoded analysis/verify requirement the contract forbids.
|
|
42
|
+
replace(lib / 'common.sh',
|
|
43
|
+
' # 唯一非法的映射是**空映射**',
|
|
44
|
+
' for cat in analysis verify; do\n case "$seen" in *" $cat "*) ;; *) printf \'required category missing: %s\\n\' "$cat"; return 1 ;; esac\n done # P228_FLIP_required-categories\n # 唯一非法的映射是**空映射**')
|
|
45
|
+
elif name == 'identity-overclaim':
|
|
46
|
+
# R6/OBS1 red side: publish the complete identity no matter what the template delivered.
|
|
47
|
+
function(lib / 'common.sh', 'team_launch_identity_fields', " printf 'provider,model,session_id\\n'")
|
|
48
|
+
elif name == 'fingerprint':
|
|
49
|
+
function(lib / 'cmd-config.sh', 'team_config_fingerprint', " printf '%064d\\n' 0")
|
|
50
|
+
elif name == 'expanding-quote':
|
|
51
|
+
replace(lib / 'cmd-bootstrap.sh', 'newline="${form}${k}=\'${quoted}\'${comment}"',
|
|
52
|
+
'newline="${form}${k}=\\"${v}\\"${comment}" # P228_FLIP_expanding-quote')
|
|
53
|
+
replace(lib / 'cmd-bootstrap.sh', 'newline="${form}${k}=\'${quoted}\'"',
|
|
54
|
+
'newline="${form}${k}=\\"${v}\\"" # P228_FLIP_expanding-quote')
|
|
55
|
+
elif name == 'recovery-drift':
|
|
56
|
+
replace(lib / 'cmd-agents.sh', 'TEAM_SELECTED_MODEL="$oldmodel"; TEAM_SELECTED_SID="$oldsid";',
|
|
57
|
+
'TEAM_SELECTED_MODEL="$(team_task_policy_model "$category" || true)"; TEAM_SELECTED_SID="$TEAM_SESSION-$agent";')
|
|
58
|
+
elif name == 'partial-publication':
|
|
59
|
+
replace(lib / 'cmd-agents.sh', ' TEAM_ASSIGN_TMP="$TEAM_STATE_DIR/.assignment-$seat-$nonce"',
|
|
60
|
+
' TEAM_ASSIGN_TMP="$TEAM_STATE_DIR/.assignment-$seat-$nonce"\n printf "model=forbidden/partial\\n" > "$TEAM_STATE_DIR/$seat.env" # P228_FLIP_partial-publication')
|
|
61
|
+
elif name == 'unknown-as-zero':
|
|
62
|
+
replace(lib / 'common.sh', ' running="$TEAM_MODEL_KNOWN_COUNT"; rule="$(team_model_limit_pattern_for "$model")"',
|
|
63
|
+
' running="$TEAM_MODEL_KNOWN_COUNT"; rule="$(team_model_limit_pattern_for "$model")"\n TEAM_MODEL_UNKNOWN="" # P228_FLIP_unknown-as-zero')
|
|
64
|
+
elif name == 'latest-shell':
|
|
65
|
+
function(lib / 'common.sh', 'team_session_file',
|
|
66
|
+
' local d; d="$(team_pi_session_dir "$2")"\n find "$d" -maxdepth 1 -type f -name "*.jsonl" -print 2>/dev/null | sort | tail -1')
|
|
67
|
+
elif name == 'latest-monitor':
|
|
68
|
+
replace(root / 'skills/teamsmith/scripts/monitor.mjs', '(!match || f.endsWith(match))', 'true /* P228_FLIP_latest-monitor */')
|
|
69
|
+
elif name == 'pm-fallback':
|
|
70
|
+
function(lib / 'common.sh', 'team_pm_model_resolve', " printf '%s\\n' vendor/routine")
|
|
71
|
+
elif name == 'pm-publication':
|
|
72
|
+
function(lib / 'common.sh', 'team_pm_abort_uncommitted', ' return 0 # leave uncommitted process and proof alive')
|
|
73
|
+
elif name == 'extra-shadow':
|
|
74
|
+
function(lib / 'common.sh', 'team_identity_extra_guard', ' return 0 # identity shadow accepted')
|
|
75
|
+
elif name == 'template-shadow':
|
|
76
|
+
function(lib / 'common.sh', 'team_template_identity_guard', ' return 0 # hardcoded template identity accepted')
|
|
77
|
+
elif name == 'literal-shell-expansion':
|
|
78
|
+
path = lib / 'common.sh'
|
|
79
|
+
text = path.read_text()
|
|
80
|
+
start = text.index(" '*'|'?'|'['|']'|'~')\n")
|
|
81
|
+
end = text.index(" ' '|$'\\t')", start)
|
|
82
|
+
replace(path, text[start:end], ' # P228_FLIP_literal-shell-expansion: launch shell expands unchecked argv\n')
|
|
83
|
+
elif name == 'init-legacy-proceeds':
|
|
84
|
+
# P235 red side: the legacy-model gate is removed, so init/bootstrap migrate by overwrite.
|
|
85
|
+
function(lib / 'cmd-project.sh', 'team_config_legacy_model_keys', ' return 0 # P235_FLIP_init-legacy-proceeds')
|
|
86
|
+
# P238: 拆掉退休键闸门后,plain 路径仍被 P235 的模型策略解析器独立拦住(这份夹具没有合法新策略
|
|
87
|
+
# → 拒绝),于是 `init-legacy-plain-refused` 永远不红 —— 臂头的命名期望形同虚设(P238 实测:
|
|
88
|
+
# 8 条红里没有它,且改前改后一模一样)。把解析器也一并短路,才真的是「闸门被拆掉」:
|
|
89
|
+
# plain / force / bootstrap 三条都按覆盖式迁移红出来。
|
|
90
|
+
function(lib / 'cmd-project.sh', 'team_init_model_policy_resolve',
|
|
91
|
+
' printf \'%s\\n\' vendor/light; printf \'%s\\n\' vendor/pm:high # P238_FLIP_init-legacy-proceeds-policy')
|
|
92
|
+
elif name == 'template-retired-key':
|
|
93
|
+
# P235 red side: the shipped template carries the retired worker key again.
|
|
94
|
+
replace(root / 'skills/teamsmith/templates/config.sh.tmpl',
|
|
95
|
+
'TEAM_TASK_MODELS=""',
|
|
96
|
+
'TEAM_DEFAULT_MODEL="{{PROJECT}}" # P235_FLIP_template-retired-key\nTEAM_TASK_MODELS=""')
|
|
97
|
+
elif name == 'worker-literal-resplit':
|
|
98
|
+
replace(lib / 'cmd-agents.sh',
|
|
99
|
+
' team_literal_argv "$TEAM_EXTRA_PI_ARGS" || return 1\n piargs+=("${TEAM_LITERAL_TOKENS[@]}")',
|
|
100
|
+
' piargs+=($TEAM_EXTRA_PI_ARGS) # P228_FLIP_worker-literal-resplit')
|
|
101
|
+
elif name == 'pm-literal-resplit':
|
|
102
|
+
replace(lib / 'common.sh',
|
|
103
|
+
' team_literal_argv "$TEAM_PM_RESUME_ARGS" || return 1\n args+=("${TEAM_LITERAL_TOKENS[@]}")',
|
|
104
|
+
' args+=($TEAM_PM_RESUME_ARGS) # P228_FLIP_pm-literal-resplit-resume')
|
|
105
|
+
replace(lib / 'common.sh',
|
|
106
|
+
' team_literal_argv "$TEAM_PM_EXTRA_PI_ARGS" || return 1\n args+=("${TEAM_LITERAL_TOKENS[@]}")',
|
|
107
|
+
' args+=($TEAM_PM_EXTRA_PI_ARGS) # P228_FLIP_pm-literal-resplit-extra')
|
|
108
|
+
elif name == 'template-roles':
|
|
109
|
+
# Restore F5's lexical-only walk on a real copied source, including the
|
|
110
|
+
# resume selector-as-data path. No assertion/test code is changed.
|
|
111
|
+
function(lib / 'common.sh', 'team_argv_roles_guard', ' return 0 # argv roles ignored')
|
|
112
|
+
replace(lib / 'common.sh',
|
|
113
|
+
' -e|--skill) i=$((i+1)); continue ;; # proved scalar data, never a selector',
|
|
114
|
+
' # P228_FLIP_template-roles: tool data mistaken for selectors')
|
|
115
|
+
replace(lib / 'common.sh',
|
|
116
|
+
' -e|--skill) i=$((i+1)) ;; # scalar role already proved; its data is not continuity',
|
|
117
|
+
' # P228_FLIP_template-roles: tool data mistaken for continuity')
|
|
118
|
+
elif name == 'template-unbound':
|
|
119
|
+
# Restore F4: occurrence is mistaken for an owned selector binding.
|
|
120
|
+
# The new surrounding-role proof independently refuses identity-as-tool-data,
|
|
121
|
+
# so restore that part of the older source as well; leave tests untouched.
|
|
122
|
+
function(lib / 'common.sh', 'team_argv_roles_guard', ' return 0 # old unbound data walk')
|
|
123
|
+
path = lib / 'common.sh'
|
|
124
|
+
text = path.read_text()
|
|
125
|
+
start = text.index(' # Presence is not ownership:')
|
|
126
|
+
end = text.index(' if [ "$mode" = continued ]; then', start)
|
|
127
|
+
replace(path, text[start:end], ' # P228_FLIP_template-unbound: no binding proof\n')
|
|
128
|
+
replace(path, '[ "${seen[$token]:-0}" = 1 ] || { team_err',
|
|
129
|
+
'[ "${refs[$token]:-0}" = 1 ] || { team_err')
|
|
130
|
+
elif name == 'monitor-record-drift':
|
|
131
|
+
replace(root / 'skills/teamsmith/scripts/monitor.mjs',
|
|
132
|
+
' team_assignment_parse "$2" "$data" || exit 1',
|
|
133
|
+
' data="$(printf "%s" "$data" | sed "s/malformed nonce/fixture-nonce/")" # P228_FLIP_monitor-record-drift\n team_assignment_parse "$2" "$data" || exit 1')
|
|
134
|
+
else:
|
|
135
|
+
raise SystemExit('unknown mutation: ' + name)
|
|
136
|
+
print(json.dumps(dict(mutation=name, changes=changes), ensure_ascii=False))
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# F5: isolated parameter-role controls; no runtime Pi/parser dependency.
|
|
3
|
+
# Uses only the routing front door's real recorder/repo/HOME/private socket.
|
|
4
|
+
routing_role_probes() { # worker|pm
|
|
5
|
+
local seat="$1" oldmap tag body mode before sid='' field tool good
|
|
6
|
+
oldmap="$(team_config_file_value "$CONFIG" TEAM_TASK_MODELS)"
|
|
7
|
+
run config set-task-model routine vendor/routine
|
|
8
|
+
check "$seat-role-category-ready" eq "$RC" 0
|
|
9
|
+
if [ "$seat" = worker ]; then
|
|
10
|
+
run config set TEAM_AGENT_CMD '' --yes
|
|
11
|
+
run config set TEAM_EXTRA_PI_ARGS '' --yes
|
|
12
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md --model vendor/deep/model:high --fresh
|
|
13
|
+
check worker-role-assignment-ready eq "$RC" 0
|
|
14
|
+
team_assignment_load dev; sid="${TEAM_ASSIGN[sid]}"; stop_fixture_seat dev
|
|
15
|
+
good='--provider {provider} --model {model} --session-id {session_id}'
|
|
16
|
+
else
|
|
17
|
+
routing_fixture_tmux new-window -d -t routing-fixture -n role-anchor 'sleep 1200'
|
|
18
|
+
stop_fixture_seat pm
|
|
19
|
+
run config set TEAM_PM_EXTRA_PI_ARGS '' --yes
|
|
20
|
+
# config set 的前门拒收 `-` 开头的值:按既有夹具惯例用前导空格写入(读取侧 team_trim)。
|
|
21
|
+
run config set TEAM_PM_RESUME_ARGS ' --continue' --yes
|
|
22
|
+
(TEAM_PM_MODEL=vendor/pm:high; TEAM_PM_RESUME_ARGS=--continue; TEAM_PM_FRESH_LAUNCH=0; team_pm_metadata_publish fixture-role-control)
|
|
23
|
+
cp -p "$STATE/pm-launch.env" "$TMP/role-pm-trusted"
|
|
24
|
+
good='--provider {provider} --model {model} {resume_args}'
|
|
25
|
+
fi
|
|
26
|
+
local -a faults=()
|
|
27
|
+
# Both emitted tool scalar roles, every identity selector and argv-list seam.
|
|
28
|
+
# Unknown arity is NOT guessed, including unknown equals/quoted option forms.
|
|
29
|
+
for tool in '--skill' '-e' '--unknown' '--unknown=value' '"--unknown"'; do
|
|
30
|
+
faults+=("provider:$tool|$tool --provider {provider} --model {model}")
|
|
31
|
+
faults+=("model:$tool|--provider {provider} $tool --model {model}")
|
|
32
|
+
if [ "$seat" = worker ]; then
|
|
33
|
+
faults[${#faults[@]}-2]+=' --session-id {session_id}'
|
|
34
|
+
faults[${#faults[@]}-1]+=' --session-id {session_id}'
|
|
35
|
+
faults+=("sid:$tool|--provider {provider} --model {model} $tool --session-id {session_id}")
|
|
36
|
+
else
|
|
37
|
+
faults[${#faults[@]}-2]+=' {resume_args}'
|
|
38
|
+
faults[${#faults[@]}-1]+=' {resume_args}'
|
|
39
|
+
faults+=("resume-list:$tool|--provider {provider} --model {model} $tool {resume_args}")
|
|
40
|
+
fi
|
|
41
|
+
faults+=("extra-list:$tool|$good $tool {extra_args}")
|
|
42
|
+
done
|
|
43
|
+
faults+=("unknown-scalar-prefix|--unknown harmless $good" "unknown-equals-prefix|--unknown=harmless $good" "quoted-unknown-prefix|\"--unknown\" harmless $good")
|
|
44
|
+
if [ "$seat" = pm ]; then
|
|
45
|
+
faults+=('extra-consumes-resume|--provider {provider} --model {model} {extra_args} {resume_args}'
|
|
46
|
+
'extra-unknown-before-resume|--provider {provider} --model {model} {extra_args} {resume_args}'
|
|
47
|
+
'resume-unknown-before-model|{resume_args} --provider {provider} --model {model}')
|
|
48
|
+
else
|
|
49
|
+
faults+=('extra-consumes-model|--provider {provider} {extra_args} --model {model} --session-id {session_id}'
|
|
50
|
+
'extra-unknown-before-model|--provider {provider} {extra_args} --model {model} --session-id {session_id}')
|
|
51
|
+
fi
|
|
52
|
+
for body in "${faults[@]}"; do
|
|
53
|
+
tag="${body%%|*}"; body="${body#*|}"
|
|
54
|
+
if [ "$seat" = worker ]; then
|
|
55
|
+
run config set TEAM_AGENT_CMD "$TMP/recording-pi $body {prompt}" --yes
|
|
56
|
+
case "$tag" in extra-consumes-*) run config set TEAM_EXTRA_PI_ARGS ' --skill' --yes ;; extra-unknown-*) run config set TEAM_EXTRA_PI_ARGS ' --unknown harmless' --yes ;; esac
|
|
57
|
+
else
|
|
58
|
+
run config set TEAM_PM_CMD "$TMP/recording-pi $body {prompt}" --yes
|
|
59
|
+
case "$tag" in
|
|
60
|
+
extra-consumes-*) run config set TEAM_PM_EXTRA_PI_ARGS ' --skill' --yes ;;
|
|
61
|
+
extra-unknown-*) run config set TEAM_PM_EXTRA_PI_ARGS ' --unknown harmless' --yes ;;
|
|
62
|
+
resume-unknown-*) run config set TEAM_PM_RESUME_ARGS ' --continue --unknown' --yes ;;
|
|
63
|
+
esac
|
|
64
|
+
(TEAM_PM_MODEL=vendor/pm:high; TEAM_PM_RESUME_ARGS="$(team_config_file_value "$CONFIG" TEAM_PM_RESUME_ARGS)"; TEAM_PM_FRESH_LAUNCH=0; team_pm_metadata_publish fixture-role-control)
|
|
65
|
+
cp -p "$STATE/pm-launch.env" "$TMP/role-pm-trusted"
|
|
66
|
+
fi
|
|
67
|
+
check "$seat-role-template-config:$tag" eq "$RC" 0
|
|
68
|
+
for mode in preview launch fresh-preview fresh-launch; do
|
|
69
|
+
[ "$seat" != pm ] || cp -p "$TMP/role-pm-trusted" "$STATE/pm-launch.env"
|
|
70
|
+
before="$(routing_observable_snapshot)"
|
|
71
|
+
check "role-capture:$seat:$tag:$mode:before" routing_binding_capture "$seat-role" "$tag" "$mode" before
|
|
72
|
+
if [ "$seat" = worker ]; then
|
|
73
|
+
case "$mode" in
|
|
74
|
+
preview) run dispatch dev T1 docs/team/tasks/T1-fixture.md --print ;;
|
|
75
|
+
launch) run dispatch dev T1 docs/team/tasks/T1-fixture.md ;;
|
|
76
|
+
fresh-preview) run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh --print ;;
|
|
77
|
+
fresh-launch) run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh ;;
|
|
78
|
+
esac
|
|
79
|
+
else
|
|
80
|
+
case "$mode" in preview) run up --print ;; launch) run up ;; fresh-preview) run up --fresh-pm --print ;; fresh-launch) run up --fresh-pm ;; esac
|
|
81
|
+
fi
|
|
82
|
+
check "$seat-role-refused:$tag:$mode" eq "$RC" 1
|
|
83
|
+
check "$seat-role-pure:$tag:$mode" eq "$(routing_observable_snapshot)" "$before"
|
|
84
|
+
check "role-capture:$seat:$tag:$mode:after" routing_binding_capture "$seat-role" "$tag" "$mode" after
|
|
85
|
+
if [ "$seat" = worker ]; then stop_fixture_seat dev; else stop_fixture_seat pm; fi
|
|
86
|
+
done
|
|
87
|
+
if [ "$seat" = worker ]; then run config set TEAM_EXTRA_PI_ARGS '' --yes
|
|
88
|
+
else run config set TEAM_PM_EXTRA_PI_ARGS '' --yes; run config set TEAM_PM_RESUME_ARGS ' --continue' --yes; fi
|
|
89
|
+
done
|
|
90
|
+
if [ "$seat" = pm ]; then
|
|
91
|
+
(TEAM_PM_MODEL=vendor/pm:high; TEAM_PM_RESUME_ARGS=--continue; TEAM_PM_FRESH_LAUNCH=0; team_pm_metadata_publish fixture-role-control)
|
|
92
|
+
cp -p "$STATE/pm-launch.env" "$TMP/role-pm-trusted"
|
|
93
|
+
fi
|
|
94
|
+
# Prefix tool data has a proved scalar role. Unknown options/literal quoted
|
|
95
|
+
# data are a suffix after ALL protected groups, not guessed zero-arity flags.
|
|
96
|
+
for field in tool-prefix unknown-suffix extra-prefix; do
|
|
97
|
+
body="--skill harmless -e 'literal extension' $good --unknown 'two words'"
|
|
98
|
+
[ "$field" != unknown-suffix ] || body="$good --unknown 'two words'"
|
|
99
|
+
if [ "$field" = extra-prefix ]; then
|
|
100
|
+
body="{extra_args} $body"
|
|
101
|
+
if [ "$seat" = worker ]; then run config set TEAM_EXTRA_PI_ARGS ' --skill harmless -e "literal extension" --no-tools' --yes
|
|
102
|
+
else run config set TEAM_PM_EXTRA_PI_ARGS ' --skill harmless -e "literal extension" --no-tools' --yes; fi
|
|
103
|
+
fi
|
|
104
|
+
if [ "$seat" = worker ]; then run config set TEAM_AGENT_CMD "$TMP/recording-pi $body {prompt}" --yes
|
|
105
|
+
else run config set TEAM_PM_CMD "$TMP/recording-pi $body {prompt}" --yes; fi
|
|
106
|
+
check "$seat-role-legal-config:$field" eq "$RC" 0
|
|
107
|
+
for mode in preview launch fresh-preview fresh-launch; do
|
|
108
|
+
[ "$seat" != pm ] || cp -p "$TMP/role-pm-trusted" "$STATE/pm-launch.env"
|
|
109
|
+
before="$(routing_observable_snapshot)"
|
|
110
|
+
if [ "$seat" = worker ]; then
|
|
111
|
+
case "$mode" in preview) run dispatch dev T1 docs/team/tasks/T1-fixture.md --print ;; launch) run dispatch dev T1 docs/team/tasks/T1-fixture.md ;; fresh-preview) run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh --print ;; fresh-launch) run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh ;; esac
|
|
112
|
+
else
|
|
113
|
+
case "$mode" in preview) run up --print ;; launch) run up ;; fresh-preview) run up --fresh-pm --print ;; fresh-launch) run up --fresh-pm ;; esac
|
|
114
|
+
fi
|
|
115
|
+
check "$seat-role-legal:$field:$mode" eq "$RC" 0
|
|
116
|
+
case "$mode" in
|
|
117
|
+
*preview) check "$seat-role-legal-pure:$field:$mode" eq "$(routing_observable_snapshot)" "$before" ;;
|
|
118
|
+
*)
|
|
119
|
+
if [ "$seat" = worker ]; then
|
|
120
|
+
team_assignment_load dev; sid="${TEAM_ASSIGN[sid]}"
|
|
121
|
+
check "$seat-role-actual:$field:$mode" routing_identity_argv_check "$TMP/argv-jsonl" vendor deep/model:high "$sid" -
|
|
122
|
+
else
|
|
123
|
+
local continuation=--continue; [ "$mode" != fresh-launch ] || continuation=-
|
|
124
|
+
check "$seat-role-actual:$field:$mode" routing_identity_argv_check "$TMP/argv-jsonl" vendor pm:high - "$continuation"
|
|
125
|
+
fi
|
|
126
|
+
if [ "$seat" = worker ]; then stop_fixture_seat dev; else stop_fixture_seat pm; fi ;;
|
|
127
|
+
esac
|
|
128
|
+
done
|
|
129
|
+
if [ "$seat" = worker ]; then run config set TEAM_EXTRA_PI_ARGS '' --yes; else run config set TEAM_PM_EXTRA_PI_ARGS '' --yes; fi
|
|
130
|
+
done
|
|
131
|
+
if [ "$seat" = worker ]; then run config set TEAM_AGENT_CMD '' --yes
|
|
132
|
+
else run config set TEAM_PM_CMD '' --yes; run config set TEAM_PM_RESUME_ARGS '' --yes; fi
|
|
133
|
+
run config set TEAM_TASK_MODELS "$oldmap" --yes
|
|
134
|
+
check "$seat-role-policy-restored" eq "$RC" 0
|
|
135
|
+
}
|
|
136
|
+
routing_resume_role_probes() {
|
|
137
|
+
local field bad mode before
|
|
138
|
+
for field in builtin custom; do
|
|
139
|
+
if [ "$field" = builtin ]; then run config set TEAM_PM_CMD '' --yes
|
|
140
|
+
else run config set TEAM_PM_CMD "$TMP/recording-pi --provider {provider} --model {model} {resume_args} {prompt}" --yes; fi
|
|
141
|
+
for bad in '--skill --continue' '-e -c' '--unknown --continue' '--unknown harmless --continue' '--skill --session-id fixture-sid' '-e -s fixture-sid' '--unknown --session-id fixture-sid'; do
|
|
142
|
+
run config set TEAM_PM_RESUME_ARGS " $bad" --yes
|
|
143
|
+
check "pm-role-resume-config:$field:$bad" eq "$RC" 0
|
|
144
|
+
(TEAM_PM_MODEL=vendor/pm:high; TEAM_PM_FRESH_LAUNCH=0; TEAM_PM_RESUME_ARGS="$bad"; team_pm_metadata_publish fixture-role-resume)
|
|
145
|
+
for mode in preview launch fresh-preview fresh-launch; do
|
|
146
|
+
before="$(routing_observable_snapshot)"
|
|
147
|
+
case "$mode" in preview) run up --print ;; launch) run up ;; fresh-preview) run up --fresh-pm --print ;; fresh-launch) run up --fresh-pm ;; esac
|
|
148
|
+
check "pm-role-resume-refused:$field:$bad:$mode" eq "$RC" 1
|
|
149
|
+
check "pm-role-resume-pure:$field:$bad:$mode" eq "$(routing_observable_snapshot)" "$before"
|
|
150
|
+
stop_fixture_seat pm
|
|
151
|
+
done
|
|
152
|
+
done
|
|
153
|
+
done
|
|
154
|
+
run config set TEAM_PM_RESUME_ARGS '' --yes
|
|
155
|
+
run config set TEAM_PM_CMD '' --yes
|
|
156
|
+
}
|
|
157
|
+
routing_identity_argv_fields() { # <argv-jsonl>:最后一行的 argv 里真实的身份 selector 集合(逗号,规范顺序)
|
|
158
|
+
python3 - "$@" <<'PY'
|
|
159
|
+
import json, sys
|
|
160
|
+
args = json.loads(open(sys.argv[1]).readlines()[-1])
|
|
161
|
+
found = set(); i = 0
|
|
162
|
+
while i < len(args):
|
|
163
|
+
a = args[i]; i += 1
|
|
164
|
+
if a in ('--provider', '--model', '-m', '--session-id', '--session', '-s'):
|
|
165
|
+
key = {'--provider': 'provider', '--model': 'model', '-m': 'model',
|
|
166
|
+
'--session-id': 'session_id', '--session': 'session_id', '-s': 'session_id'}[a]
|
|
167
|
+
found.add(key); continue
|
|
168
|
+
for opt, key in (('--provider=', 'provider'), ('--model=', 'model'), ('--session-id=', 'session_id'), ('--session=', 'session_id')):
|
|
169
|
+
if a.startswith(opt):
|
|
170
|
+
found.add(key); break
|
|
171
|
+
else:
|
|
172
|
+
if a.startswith('-m') and len(a) > 2: found.add('model')
|
|
173
|
+
elif a.startswith('-s') and len(a) > 2: found.add('session_id')
|
|
174
|
+
print(','.join(f for f in ('provider', 'model', 'session_id') if f in found))
|
|
175
|
+
PY
|
|
176
|
+
}
|
|
177
|
+
routing_publication_probes() {
|
|
178
|
+
# P228/R6(OBS1):三态(全绑 / 只绑 model / 全不绑)—— 发布不得多于 argv 实际交付。
|
|
179
|
+
# ① 记录 identity_via == argv 里真实的身份 selector 集合(逐条对账,不是「包含」)
|
|
180
|
+
# ② 横幅/预览行只声明已交付的字段,未交付的显式点名
|
|
181
|
+
# ③ 同任务续跑对未交付身份仍如实拒绝(F5 的 guarded continuation 规则不许被这轮放松)
|
|
182
|
+
local oldmap tag body sid before
|
|
183
|
+
oldmap="$(team_config_file_value "$CONFIG" TEAM_TASK_MODELS)"
|
|
184
|
+
# 本组自己建前提(如 pre-resume 组删过 routine,新选择必须是当前已映射类别)
|
|
185
|
+
run config set TEAM_TASK_MODELS 'routine=vendor/routine analysis=vendor/analysis verify=vendor/verify' --yes
|
|
186
|
+
check publication-map-ready eq "$RC" 0
|
|
187
|
+
stop_fixture_seat dev
|
|
188
|
+
run config set TEAM_AGENT_CMD '' --yes
|
|
189
|
+
run config set TEAM_EXTRA_PI_ARGS '' --yes
|
|
190
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md --model vendor/deep/model:high --fresh
|
|
191
|
+
check publication-setup-recorded eq "$RC" 0
|
|
192
|
+
team_assignment_load dev; sid="${TEAM_ASSIGN[sid]:-missing}"; stop_fixture_seat dev
|
|
193
|
+
local -a arms=('builtin|' 'all-bound|--provider {provider} --model {model} --session-id {session_id}' \
|
|
194
|
+
'model-only|--model {model}' 'opaque|--ask {prompt}')
|
|
195
|
+
for body in "${arms[@]}"; do
|
|
196
|
+
tag="${body%%|*}"; body="${body#*|}"
|
|
197
|
+
if [ "$tag" = builtin ]; then run config set TEAM_AGENT_CMD '' --yes
|
|
198
|
+
else run config set TEAM_AGENT_CMD "$TMP/recording-pi $body" --yes; fi
|
|
199
|
+
check "publication-config:$tag" eq "$RC" 0
|
|
200
|
+
before="$(routing_observable_snapshot)"
|
|
201
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh --print
|
|
202
|
+
check "publication-preview:$tag" eq "$RC" 0
|
|
203
|
+
check "publication-preview-pure:$tag" eq "$(routing_observable_snapshot)" "$before"
|
|
204
|
+
case "$tag" in
|
|
205
|
+
builtin|all-bound)
|
|
206
|
+
check "publication-preview-sid:$tag" contains "$OUT" 'sid='
|
|
207
|
+
check "publication-preview-no-gap:$tag" bash -c '! [[ "$1" == *identity-delivery* ]]' _ "$OUT" ;;
|
|
208
|
+
model-only)
|
|
209
|
+
check "publication-preview-no-sid:$tag" bash -c '! [[ "$1" == *"sid="* ]]' _ "$OUT"
|
|
210
|
+
check "publication-preview-gap:$tag" contains "$OUT" 'identity-delivery: 未交付 provider,session_id' ;;
|
|
211
|
+
opaque)
|
|
212
|
+
check "publication-preview-no-model:$tag" bash -c '! [[ "$1" == *"model="* ]]' _ "$OUT"
|
|
213
|
+
check "publication-preview-gap:$tag" contains "$OUT" 'identity-delivery: 未交付 provider,model,session_id' ;;
|
|
214
|
+
esac
|
|
215
|
+
# 真启动:横幅里的身份声明只含已交付字段(与上面的 argv 对账)
|
|
216
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh
|
|
217
|
+
check "publication-launch:$tag" eq "$RC" 0
|
|
218
|
+
team_assignment_load dev
|
|
219
|
+
case "$tag" in
|
|
220
|
+
builtin|all-bound)
|
|
221
|
+
check "publication-record:$tag" eq "${TEAM_ASSIGN[identity_via]:-}" 'provider,model,session_id'
|
|
222
|
+
check "publication-claim-full:$tag" contains "$OUT" "provider=vendor model=${TEAM_ASSIGN[model]#*/} session=${TEAM_ASSIGN[sid]}" ;;
|
|
223
|
+
model-only)
|
|
224
|
+
check "publication-record:$tag" eq "${TEAM_ASSIGN[identity_via]:-}" 'model'
|
|
225
|
+
check "publication-claim-gap:$tag" contains "$OUT" '模板未交付 provider,session_id'
|
|
226
|
+
check "publication-claim-no-provider:$tag" bash -c '! [[ "$1" == *"provider=vendor"* ]]' _ "$OUT" ;;
|
|
227
|
+
opaque)
|
|
228
|
+
check "publication-record:$tag" eq "${TEAM_ASSIGN[identity_via]:-}" ''
|
|
229
|
+
check "publication-claim-gap:$tag" contains "$OUT" '模板未交付 provider,model,session_id'
|
|
230
|
+
check "publication-claim-no-model:$tag" bash -c '! [[ "$1" == *"model=${TEAM_ASSIGN[model]#*/}"* ]]' _ "$OUT" ;;
|
|
231
|
+
esac
|
|
232
|
+
check "publication-record-equals-argv:$tag" eq "$(routing_identity_argv_fields "$TMP/argv-jsonl")" "${TEAM_ASSIGN[identity_via]:-}"
|
|
233
|
+
stop_fixture_seat dev
|
|
234
|
+
done
|
|
235
|
+
# 读侧:模板没把模型交给 CLI 的席位,ps 列不得把它当「在跑的模型」
|
|
236
|
+
run config set TEAM_AGENT_CMD "$TMP/recording-pi --ask {prompt}" --yes
|
|
237
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md --fresh
|
|
238
|
+
check publication-reader-launch eq "$RC" 0
|
|
239
|
+
check publication-reader-unavailable contains "$(team_agent_session_cols dev)" '(未交付)'
|
|
240
|
+
stop_fixture_seat dev
|
|
241
|
+
# 同任务续跑(未 --fresh)对未交付身份如实拒绝:模型只绑一半 → 不是完整 Pi 身份
|
|
242
|
+
run config set TEAM_AGENT_CMD "$TMP/recording-pi --ask {prompt}" --yes
|
|
243
|
+
run dispatch dev T1 docs/team/tasks/T1-fixture.md
|
|
244
|
+
check publication-continuation-refused eq "$RC" 1
|
|
245
|
+
check publication-continuation-named contains "$OUT" 'guarded continuation'
|
|
246
|
+
stop_fixture_seat dev
|
|
247
|
+
run config set TEAM_AGENT_CMD '' --yes
|
|
248
|
+
run config set TEAM_TASK_MODELS "$oldmap" --yes
|
|
249
|
+
check publication-policy-restored eq "$RC" 0
|
|
250
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# proc-io.sh — 无编译器依赖的进程观测器(key-replies.sh 与 panel 的 reply-fixture.sh 共用)。
|
|
4
|
+
#
|
|
5
|
+
# ---------------------------------------------------------------- 内核观测器(无编译器依赖)
|
|
6
|
+
# 为什么不用 LD_PRELOAD 计数:门禁镜像 `ci/Containerfile` 按 M47 在编译完 tmux 后 purge 掉
|
|
7
|
+
# build-essential —— 镜像里永远没有编译器,shim 编不出来,本 change 登记的段在门禁环境里就会红
|
|
8
|
+
# (V27 的 M3)。这里改用**内核自己给出的**两个只读接口,宿主与容器一致可用:
|
|
9
|
+
# /proc/<pid>/io rchar(read 类系统调用搬进的字节数)/ syscr(read 类调用次数)
|
|
10
|
+
# /proc/<pid>/fd{,info} 进程真正打开过哪些路径、以什么 flags 打开(O_PATH 在内核里不能 getdents)
|
|
11
|
+
# 采样在子进程存活期间**紧循环**进行(不 sleep):读取量断言靠「最后一刻的快照」,紧循环把丢失
|
|
12
|
+
# 末次读的窗口压到微秒级;观测器不可用时按项目约定**可见跳过并点名**,绝不静默通过。
|
|
13
|
+
kr_io_why() { # 观测器不可用的原因(点名)
|
|
14
|
+
if [ "${TEAM_REPLY_NO_PROC_IO:-}" = "1" ]; then printf '%s' 'TEAM_REPLY_NO_PROC_IO=1(夹具模拟缺工具)'
|
|
15
|
+
elif [ ! -r /proc/self/io ]; then printf '%s' '/proc/self/io 不可读(hidepid/非 Linux?)'
|
|
16
|
+
else printf '%s' 'rchar/syscr 字段不在 /proc/<pid>/io 里'
|
|
17
|
+
fi
|
|
18
|
+
}
|
|
19
|
+
kr_io_supported() {
|
|
20
|
+
[ "${TEAM_REPLY_NO_PROC_IO:-}" = "1" ] && return 1
|
|
21
|
+
[ -r /proc/self/io ] || return 1
|
|
22
|
+
grep -q '^rchar:' /proc/self/io 2>/dev/null || return 1
|
|
23
|
+
return 0
|
|
24
|
+
}
|
|
25
|
+
kr_observe_py() { # 惰性写:source 时 $TMP 还不存在
|
|
26
|
+
KR_OBS_PY="${TMP:?kr_observe 需要先建临时根}/kr_observe.py"
|
|
27
|
+
[ -f "$KR_OBS_PY" ] && return 0
|
|
28
|
+
cat >"$KR_OBS_PY" <<'PYOBS'
|
|
29
|
+
"""Sample /proc/<pid>/io and /proc/<pid>/fd{,info} while a child runs.
|
|
30
|
+
|
|
31
|
+
Writes <prefix>.rc, <prefix>.io (last snapshot), <prefix>.fds (one row per fd target seen:
|
|
32
|
+
count, flags, target) and keeps the child's stdout/stderr in <prefix>.out / <prefix>.err.
|
|
33
|
+
The sampling loop is tight (no sleep) so the final reads are not missed; it costs one busy
|
|
34
|
+
core for the duration of the observed command, which is why only the IO fixtures use it.
|
|
35
|
+
"""
|
|
36
|
+
import os, subprocess, sys
|
|
37
|
+
|
|
38
|
+
rcf, iof, fdf = (sys.argv[1], sys.argv[2], sys.argv[3])
|
|
39
|
+
cmd = sys.argv[4:]
|
|
40
|
+
child = subprocess.Popen(cmd, stdout=open(rcf + ".out", "wb"), stderr=open(rcf + ".err", "wb"))
|
|
41
|
+
last_io = b""
|
|
42
|
+
seen = {}
|
|
43
|
+
|
|
44
|
+
def sample():
|
|
45
|
+
global last_io
|
|
46
|
+
try:
|
|
47
|
+
with open("/proc/%d/io" % child.pid, "rb") as f:
|
|
48
|
+
last_io = f.read()
|
|
49
|
+
except OSError:
|
|
50
|
+
pass
|
|
51
|
+
try:
|
|
52
|
+
names = os.listdir("/proc/%d/fd" % child.pid)
|
|
53
|
+
except OSError:
|
|
54
|
+
return
|
|
55
|
+
for name in names:
|
|
56
|
+
try:
|
|
57
|
+
target = os.readlink("/proc/%d/fd/%s" % (child.pid, name))
|
|
58
|
+
except OSError:
|
|
59
|
+
continue
|
|
60
|
+
if target.startswith(("/proc", "/dev", "pipe:", "socket:", "anon_inode:", "/memfd")):
|
|
61
|
+
continue
|
|
62
|
+
flags = ""
|
|
63
|
+
try:
|
|
64
|
+
with open("/proc/%d/fdinfo/%s" % (child.pid, name)) as f:
|
|
65
|
+
for line in f:
|
|
66
|
+
if line.startswith("flags:"):
|
|
67
|
+
flags = line.split(":", 1)[1].strip()
|
|
68
|
+
break
|
|
69
|
+
except OSError:
|
|
70
|
+
pass
|
|
71
|
+
row = seen.setdefault(target, {"n": 0, "flags": flags})
|
|
72
|
+
row["n"] += 1
|
|
73
|
+
if flags and not row["flags"]:
|
|
74
|
+
row["flags"] = flags
|
|
75
|
+
|
|
76
|
+
while child.poll() is None:
|
|
77
|
+
sample()
|
|
78
|
+
rc = child.wait()
|
|
79
|
+
open(rcf, "w").write("%d\n" % rc)
|
|
80
|
+
open(iof, "wb").write(last_io)
|
|
81
|
+
with open(fdf, "w") as f:
|
|
82
|
+
for target, row in sorted(seen.items()):
|
|
83
|
+
f.write("%d\t%s\t%s\n" % (row["n"], row["flags"], target))
|
|
84
|
+
PYOBS
|
|
85
|
+
}
|
|
86
|
+
kr_observe() { # <前缀> <命令…>:跑命令并把内核计数器/打开证据落到 <前缀>.{rc,io,fds,out,err}
|
|
87
|
+
kr_observe_py
|
|
88
|
+
python3 "$KR_OBS_PY" "$1" "$1.io" "$1.fds" "${@:2}"
|
|
89
|
+
return $?
|
|
90
|
+
}
|
|
91
|
+
kr_obs_rc() { cat "$1.rc" 2>/dev/null | tr -d '\n'; }
|
|
92
|
+
kr_obs_field() { # <前缀> <rchar|syscr|…>
|
|
93
|
+
awk -v k="$2:" '$1 == k { print $2 }' "$1.io" 2>/dev/null | tr -d '\n'
|
|
94
|
+
}
|
|
95
|
+
kr_obs_rchar() { local v; v="$(kr_obs_field "$1" rchar)"; printf '%s' "${v:-0}"; }
|
|
96
|
+
kr_obs_syscr() { local v; v="$(kr_obs_field "$1" syscr)"; printf '%s' "${v:-0}"; }
|
|
97
|
+
kr_obs_fd_count() { # <前缀> <路径正则> → 命中的 fd 目标个数(0 = 没看见)
|
|
98
|
+
awk -F'\t' -v re="$2" '$3 ~ re { n++ } END { print n+0 }' "$1.fds" 2>/dev/null
|
|
99
|
+
}
|
|
100
|
+
kr_obs_fd_flags() { # <前缀> <路径正则> → 第一个命中目标的 flags(八进制字符串)
|
|
101
|
+
awk -F'\t' -v re="$2" '$3 ~ re { print $2; exit }' "$1.fds" 2>/dev/null
|
|
102
|
+
}
|
|
103
|
+
|