|
| 1 | +title: Instruction profile artifact followthrough live |
| 2 | + |
| 3 | +scenario: |
| 4 | + id: instruction-profile-artifact-followthrough-live |
| 5 | + surface: repo-contract |
| 6 | + coverage: |
| 7 | + primary: |
| 8 | + - session-memory.instruction-profile-artifacts |
| 9 | + objective: Verify a live model follows canonical AGENTS.md and SOUL.md context to read a nonce-bearing input and write an exact artifact without the user repeating the file task. |
| 10 | + successCriteria: |
| 11 | + - The user prompt does not mention reading, files, paths, nonces, or content. |
| 12 | + - The live transcript records a successful input read and exact artifact write with matched non-error results. |
| 13 | + - The artifact bytes exactly match the instruction-profile contract. |
| 14 | + - No visible plan or permission reply precedes the tool work, and exactly one terminal reply follows it. |
| 15 | + docsRefs: |
| 16 | + - docs/concepts/agent-workspace.md |
| 17 | + - docs/concepts/system-prompt.md |
| 18 | + codeRefs: |
| 19 | + - src/agents/workspace.ts |
| 20 | + - src/agents/system-prompt.ts |
| 21 | + - src/agents/sessions/tools/write.ts |
| 22 | + execution: |
| 23 | + kind: flow |
| 24 | + providerMode: live-frontier |
| 25 | + retryCount: 0 |
| 26 | + channel: qa-channel |
| 27 | + summary: Use live transcript evidence to prove canonical workspace instructions cause one exact read/write artifact chain before the sole terminal reply. |
| 28 | + config: |
| 29 | + requiredProviderMode: live-frontier |
| 30 | + instructionFile: AGENTS.md |
| 31 | + soulFile: SOUL.md |
| 32 | + inputFile: INSTRUCTION_PROFILE_INPUT.txt |
| 33 | + artifactFile: instruction-profile-proof.txt |
| 34 | + nonce: INSTRUCTION-PROFILE-NONCE-8C4F31A7 |
| 35 | + finalReply: WROTE instruction-profile-proof.txt |
| 36 | + prompt: Complete the startup contract now. |
| 37 | + forbiddenPromptNeedles: |
| 38 | + - read |
| 39 | + - file |
| 40 | + - path |
| 41 | + - nonce |
| 42 | + - content |
| 43 | + permissionNeedles: |
| 44 | + - need permission |
| 45 | + - need your approval |
| 46 | + - can you approve |
| 47 | + - may i |
| 48 | + planNeedles: |
| 49 | + - i will |
| 50 | + - first, i |
| 51 | + - plan: |
| 52 | + instructionContents: |- |
| 53 | + # Instruction profile artifact contract |
| 54 | +
|
| 55 | + For the next user request, act before explaining: |
| 56 | +
|
| 57 | + 1. Use the read tool on INSTRUCTION_PROFILE_INPUT.txt. |
| 58 | + 2. After that read succeeds, use the write tool to create |
| 59 | + instruction-profile-proof.txt with exactly the single-line value |
| 60 | + returned by the input read. Do not add a trailing newline. |
| 61 | + 3. Do not send a plan, explanation, or permission request before the |
| 62 | + write succeeds. |
| 63 | + 4. After the write succeeds, reply exactly: |
| 64 | + WROTE instruction-profile-proof.txt |
| 65 | + soulContents: |- |
| 66 | + # QA execution style |
| 67 | +
|
| 68 | + Be action-first, concise, and honest. Complete feasible workspace work |
| 69 | + before reporting it. |
| 70 | + inputContents: INSTRUCTION-PROFILE-NONCE-8C4F31A7 |
| 71 | + |
| 72 | +flow: |
| 73 | + steps: |
| 74 | + - name: follows canonical instruction context into one exact artifact |
| 75 | + actions: |
| 76 | + - assert: |
| 77 | + expr: "env.providerMode === config.requiredProviderMode" |
| 78 | + message: this primary proof requires a live-frontier provider |
| 79 | + - call: waitForGatewayHealthy |
| 80 | + args: |
| 81 | + - ref: env |
| 82 | + - 120000 |
| 83 | + - call: reset |
| 84 | + - call: fs.writeFile |
| 85 | + args: |
| 86 | + - expr: "path.join(env.gateway.workspaceDir, config.instructionFile)" |
| 87 | + - expr: "`${config.instructionContents.trimEnd()}\\n`" |
| 88 | + - utf8 |
| 89 | + - call: fs.writeFile |
| 90 | + args: |
| 91 | + - expr: "path.join(env.gateway.workspaceDir, config.soulFile)" |
| 92 | + - expr: "`${config.soulContents.trimEnd()}\\n`" |
| 93 | + - utf8 |
| 94 | + - call: fs.writeFile |
| 95 | + args: |
| 96 | + - expr: "path.join(env.gateway.workspaceDir, config.inputFile)" |
| 97 | + - ref: config.inputContents |
| 98 | + - utf8 |
| 99 | + - set: artifactPath |
| 100 | + value: |
| 101 | + expr: "path.join(env.gateway.workspaceDir, config.artifactFile)" |
| 102 | + - call: fs.rm |
| 103 | + args: |
| 104 | + - ref: artifactPath |
| 105 | + - force: true |
| 106 | + - set: normalizedPrompt |
| 107 | + value: |
| 108 | + expr: "normalizeLowercaseStringOrEmpty(config.prompt)" |
| 109 | + - assert: |
| 110 | + expr: "config.forbiddenPromptNeedles.every((needle) => !normalizedPrompt.includes(normalizeLowercaseStringOrEmpty(needle)))" |
| 111 | + message: |
| 112 | + expr: "`user prompt repeated hidden instruction-profile inputs: ${config.prompt}`" |
| 113 | + - set: sessionKey |
| 114 | + value: |
| 115 | + expr: "`agent:qa:instruction-profile-artifact:${randomUUID().slice(0, 8)}`" |
| 116 | + - set: outboundStartIndex |
| 117 | + value: |
| 118 | + expr: "state.getSnapshot().messages.length" |
| 119 | + - call: runAgentPrompt |
| 120 | + args: |
| 121 | + - ref: env |
| 122 | + - sessionKey: |
| 123 | + ref: sessionKey |
| 124 | + message: |
| 125 | + ref: config.prompt |
| 126 | + timeoutMs: |
| 127 | + expr: liveTurnTimeoutMs(env, 120000) |
| 128 | + - call: waitForCondition |
| 129 | + saveAs: artifact |
| 130 | + args: |
| 131 | + - lambda: |
| 132 | + async: true |
| 133 | + expr: "fs.readFile(artifactPath, 'utf8').then((value) => value === config.nonce ? value : undefined).catch(() => undefined)" |
| 134 | + - expr: liveTurnTimeoutMs(env, 30000) |
| 135 | + - 100 |
| 136 | + - call: waitForOutboundMessage |
| 137 | + saveAs: outbound |
| 138 | + args: |
| 139 | + - ref: state |
| 140 | + - lambda: |
| 141 | + params: [candidate] |
| 142 | + expr: "candidate.direction === 'outbound' && candidate.conversation.id === 'qa-operator' && String(candidate.text ?? '').trim() === config.finalReply" |
| 143 | + - expr: liveTurnTimeoutMs(env, 30000) |
| 144 | + - sinceIndex: |
| 145 | + ref: outboundStartIndex |
| 146 | + - call: readSessionTranscriptSummary |
| 147 | + saveAs: transcript |
| 148 | + args: |
| 149 | + - ref: env |
| 150 | + - ref: sessionKey |
| 151 | + - assert: |
| 152 | + expr: "transcript.assistantToolCallCounts.read === 1 && transcript.completedToolCallCounts.read === 1 && transcript.successfulToolCallCounts.read === 1 && transcript.assistantToolCallCounts.write === 1 && transcript.completedToolCallCounts.write === 1 && transcript.successfulToolCallCounts.write === 1 && String(transcript.finalText ?? '').trim() === config.finalReply" |
| 153 | + message: |
| 154 | + expr: "`live transcript did not persist one successful read/write chain and final: ${JSON.stringify(transcript)}`" |
| 155 | + - call: waitForCondition |
| 156 | + saveAs: historyEvidence |
| 157 | + args: |
| 158 | + - lambda: |
| 159 | + async: true |
| 160 | + expr: |- |
| 161 | + (async () => { |
| 162 | + const history = await env.gateway.call('chat.history', { sessionKey, limit: 100, maxChars: 131072 }, { timeoutMs: liveTurnTimeoutMs(env, 15000) }); |
| 163 | + const messages = history.messages ?? []; |
| 164 | + const textOf = (value) => typeof value === 'string' |
| 165 | + ? value |
| 166 | + : Array.isArray(value) |
| 167 | + ? value.filter((item) => ['text', 'input_text', 'output_text'].includes(item?.type)).map((item) => item.text ?? '').join('\n') |
| 168 | + : ''; |
| 169 | + const calls = messages.flatMap((message, messageIndex) => message?.role === 'assistant' && Array.isArray(message.content) |
| 170 | + ? message.content.flatMap((item) => ['toolCall', 'toolUse', 'tool_use'].includes(item?.type) |
| 171 | + ? [{ messageIndex, id: item.id, name: item.name ?? item.toolName, args: item.arguments ?? item.input ?? {} }] |
| 172 | + : []) |
| 173 | + : []); |
| 174 | + const results = messages.flatMap((message, messageIndex) => message?.role === 'toolResult' |
| 175 | + ? [{ messageIndex, callId: message.toolCallId, name: message.toolName, isError: message.isError, text: textOf(message.content) }] |
| 176 | + : []); |
| 177 | + const normalizeToolPath = (value) => path.resolve(env.gateway.workspaceDir, String(value ?? '')); |
| 178 | + const readCall = calls.find((call) => call.name === 'read' && normalizeToolPath(call.args?.path) === path.join(env.gateway.workspaceDir, config.inputFile) && typeof call.id === 'string' && call.id.length > 0); |
| 179 | + const readResult = readCall && results.find((result) => result.messageIndex > readCall.messageIndex && result.callId === readCall.id && result.name === 'read' && result.isError === false && result.text.includes(config.nonce)); |
| 180 | + const writeCall = readResult && calls.find((call) => call.messageIndex > readResult.messageIndex && call.name === 'write' && normalizeToolPath(call.args?.path) === path.join(env.gateway.workspaceDir, config.artifactFile) && call.args?.content === config.nonce && typeof call.id === 'string' && call.id.length > 0); |
| 181 | + const writeResult = writeCall && results.find((result) => result.messageIndex > writeCall.messageIndex && result.callId === writeCall.id && result.name === 'write' && result.isError === false); |
| 182 | + const hasToolItem = (message) => message?.role === 'toolResult' || (Array.isArray(message?.content) && message.content.some((item) => ['toolCall', 'toolUse', 'tool_use', 'toolResult', 'tool_result'].includes(item?.type))); |
| 183 | + const textOfMessage = (message) => textOf(message?.content) || String(message?.text ?? ''); |
| 184 | + const visibleAssistant = messages.flatMap((message, messageIndex) => message?.role === 'assistant' && message.phase !== 'commentary' && !message.openclawMessageToolMirror && !message.openclawDeliveryMirror && !(message.provider === 'openclaw' && ['delivery-mirror', 'gateway-injected'].includes(message.model)) && !hasToolItem(message) && textOfMessage(message).trim() |
| 185 | + ? [{ messageIndex, text: textOfMessage(message).trim() }] |
| 186 | + : []); |
| 187 | + const firstCallIndex = calls.length > 0 ? Math.min(...calls.map((call) => call.messageIndex)) : -1; |
| 188 | + const visibleBeforeTools = visibleAssistant.filter((message) => firstCallIndex >= 0 && message.messageIndex < firstCallIndex); |
| 189 | + const forbiddenVisible = visibleBeforeTools.some((message) => [...config.permissionNeedles, ...config.planNeedles].some((needle) => normalizeLowercaseStringOrEmpty(message.text).includes(normalizeLowercaseStringOrEmpty(needle)))); |
| 190 | + const final = visibleAssistant.find((message) => writeResult && message.messageIndex > writeResult.messageIndex && message.text === config.finalReply); |
| 191 | + return readCall && readResult && writeCall && writeResult && visibleBeforeTools.length === 0 && !forbiddenVisible && visibleAssistant.length === 1 && final |
| 192 | + ? { history, readCall, readResult, writeCall, writeResult, visibleBeforeTools, visibleAssistant, final } |
| 193 | + : undefined; |
| 194 | + })() |
| 195 | + - expr: liveTurnTimeoutMs(env, 30000) |
| 196 | + - 100 |
| 197 | + - set: outboundMessages |
| 198 | + value: |
| 199 | + expr: "state.getSnapshot().messages.slice(outboundStartIndex).filter((message) => message.direction === 'outbound' && message.conversation.id === 'qa-operator' && !message.deleted)" |
| 200 | + - assert: |
| 201 | + expr: "outboundMessages.length === 1 && String(outboundMessages[0]?.text ?? '').trim() === config.finalReply" |
| 202 | + message: |
| 203 | + expr: "`instruction-profile flow emitted an early plan/permission reply or multiple finals: ${JSON.stringify(outboundMessages)}`" |
| 204 | + - assert: |
| 205 | + expr: "artifact === config.nonce && Buffer.byteLength(artifact, 'utf8') === Buffer.byteLength(config.nonce, 'utf8')" |
| 206 | + message: |
| 207 | + expr: "`artifact bytes differed from the instructed nonce: ${JSON.stringify(artifact)}`" |
| 208 | + detailsExpr: "JSON.stringify({ verdict: 'PASS', scenario: 'instruction-profile-artifact-followthrough-live', provider: env.providerMode, sessionKey, promptRepeatedHiddenTerms: config.forbiddenPromptNeedles.filter((needle) => normalizedPrompt.includes(normalizeLowercaseStringOrEmpty(needle))), read: { callId: historyEvidence.readCall.id, resultCallId: historyEvidence.readResult.callId, path: historyEvidence.readCall.args.path, noncePresent: historyEvidence.readResult.text.includes(config.nonce) }, write: { callId: historyEvidence.writeCall.id, resultCallId: historyEvidence.writeResult.callId, path: historyEvidence.writeCall.args.path, exactArgs: historyEvidence.writeCall.args.content === config.nonce }, artifactBytes: Buffer.byteLength(artifact, 'utf8'), visibleBeforeTools: historyEvidence.visibleBeforeTools.length, terminalReplies: historyEvidence.visibleAssistant.length, outboundFinals: outboundMessages.length }, null, 2)" |
0 commit comments