@windyroad/voice-tone 0.9.2-preview.1255 → 0.9.3-preview.1264
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.
|
@@ -88,24 +88,43 @@ print(hashlib.sha256((draft + '\n' + surface).encode('utf-8')).hexdigest())
|
|
|
88
88
|
derive_external_comms_key_from_prompt() {
|
|
89
89
|
local prompt="$1"
|
|
90
90
|
[ -n "$prompt" ] || { echo ""; return 0; }
|
|
91
|
-
# Extract SURFACE + <draft>
|
|
92
|
-
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
95
|
-
#
|
|
91
|
+
# Extract the last valid SURFACE + <draft> pair. Codex completion payloads
|
|
92
|
+
# may prefix the caller prompt with the custom agent's developer
|
|
93
|
+
# instructions, which themselves mention illustrative <draft> markers.
|
|
94
|
+
# A pair is valid only when the draft envelope follows the SURFACE line
|
|
95
|
+
# without intervening non-whitespace prose, and the SURFACE line is not
|
|
96
|
+
# itself inside another draft envelope. Scanning valid candidates from
|
|
97
|
+
# right to left selects the caller's trailing prompt rather than a decoy
|
|
98
|
+
# in the prefixed instructions.
|
|
99
|
+
#
|
|
100
|
+
# The two fields are emitted \x1f-separated (ASCII unit separator) so a
|
|
101
|
+
# body containing newlines — or an empty body — round-trips through command
|
|
102
|
+
# substitution intact (only trailing newlines are dropped, which
|
|
103
|
+
# compute_external_comms_key rstrips anyway). Empty output when no valid
|
|
104
|
+
# pair is present → empty key.
|
|
96
105
|
local extracted
|
|
97
106
|
extracted=$(printf '%s' "$prompt" | python3 -c "
|
|
98
107
|
import sys, re
|
|
99
108
|
text = sys.stdin.read()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
surface_pattern = re.compile(
|
|
110
|
+
r'^SURFACE:\s*([A-Za-z][\w-]*)[^\r\n]*(?:\r?\n|$)',
|
|
111
|
+
re.MULTILINE,
|
|
112
|
+
)
|
|
113
|
+
for surface_match in reversed(list(surface_pattern.finditer(text))):
|
|
114
|
+
prefix = text[:surface_match.start()]
|
|
115
|
+
# Reject a SURFACE line quoted inside an existing draft body.
|
|
116
|
+
if prefix.rfind('<draft>') > prefix.rfind('</draft>'):
|
|
117
|
+
continue
|
|
118
|
+
remainder = text[surface_match.end():]
|
|
119
|
+
draft_match = re.match(
|
|
120
|
+
r'[ \t\r\n]*<draft>\r?\n?(.*?)\r?\n?</draft>',
|
|
121
|
+
remainder,
|
|
122
|
+
re.DOTALL,
|
|
123
|
+
)
|
|
124
|
+
if not draft_match:
|
|
125
|
+
continue
|
|
126
|
+
sys.stdout.write(surface_match.group(1) + '\x1f' + draft_match.group(1))
|
|
127
|
+
break
|
|
109
128
|
" 2>/dev/null) || extracted=""
|
|
110
129
|
[ -n "$extracted" ] || { echo ""; return 0; }
|
|
111
130
|
local surface="${extracted%%$'\x1f'*}"
|