Skip to content

Commit 0dd0e88

Browse files
authored
Merge pull request #143 from IchenDEV/cursor/placeholder-aware-confirmation
docs(sdlc): ChatGPT composer confirmation and compatibility switch bundles
2 parents 193467f + 5eaf28d commit 0dd0e88

10 files changed

Lines changed: 453 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import AppKit
2+
import ApplicationServices
3+
4+
setvbuf(stdout, nil, _IOLBF, 0)
5+
func attr(_ el: AXUIElement, _ name: String) -> CFTypeRef? {
6+
var v: CFTypeRef?
7+
return AXUIElementCopyAttributeValue(el, name as CFString, &v) == .success ? v : nil
8+
}
9+
/// Shape only: counts per character class. The text itself is never printed or stored.
10+
func shape(_ s: String) -> String {
11+
var k: [String: Int] = [:]
12+
for c in s.unicodeScalars {
13+
let v = c.value
14+
let name: String
15+
switch v {
16+
case 0x0A: name = "LF"
17+
case 0x20: name = "SP"
18+
case 0xA0: name = "NBSP"
19+
case 0x200B...0x200D, 0xFEFF: name = "ZW"
20+
case 0xFFFC: name = "OBJ"
21+
case 0x4E00...0x9FFF: name = "CJK"
22+
case 0x3000...0x303F, 0xFF00...0xFFEF: name = "CJKP"
23+
case 0x30...0x39: name = "DIG"
24+
case 0x41...0x5A, 0x61...0x7A: name = "ASCII"
25+
case 0..<0x20: name = "CTRL"
26+
default: name = "other"
27+
}
28+
k[name, default: 0] += 1
29+
}
30+
let body = k.sorted { $0.key < $1.key }.map { "\($0.key)=\($0.value)" }.joined(separator: ",")
31+
return "u16=\((s as NSString).length){\(body)}\(s.hasPrefix("\n") ? " startLF" : "")\(s.hasSuffix("\n") ? " endLF" : "")\(s == "\n" ? " ONLY-LF" : "")"
32+
}
33+
let bundles = (CommandLine.arguments.dropFirst().first ?? "com.openai.codex").split(separator: ",").map(String.init)
34+
let minutes = Double(CommandLine.arguments.dropFirst(2).first ?? "45") ?? 45
35+
let deadline = Date().addingTimeInterval(minutes * 60)
36+
let fmt = DateFormatter(); fmt.dateFormat = "HH:mm:ss.SSS"
37+
var last = ""
38+
var prevValue: String? = nil
39+
var prevOwner = ""
40+
print("watching \(bundles) until \(fmt.string(from: deadline)); shape only, no text")
41+
func common(_ a: [UInt16], _ b: [UInt16]) -> (Int, Int) {
42+
var p = 0; while p < a.count, p < b.count, a[p] == b[p] { p += 1 }
43+
var q = 0; while q < a.count - p, q < b.count - p, a[a.count - 1 - q] == b[b.count - 1 - q] { q += 1 }
44+
return (p, q)
45+
}
46+
while Date() < deadline {
47+
RunLoop.current.run(until: Date().addingTimeInterval(0.12))
48+
guard let app = bundles.compactMap({ NSRunningApplication.runningApplications(withBundleIdentifier: $0).first }).first(where: { $0.isActive }) else {
49+
if last != "inactive" { last = "inactive"; print(fmt.string(from: Date()), "target apps not frontmost") }
50+
continue
51+
}
52+
let tag = String((app.bundleIdentifier ?? "?").suffix(8))
53+
let ax = AXUIElementCreateApplication(app.processIdentifier)
54+
guard let f = attr(ax, kAXFocusedUIElementAttribute as String) else {
55+
if last != "nofocus" { last = "nofocus"; print(fmt.string(from: Date()), tag, "no focused element") }
56+
continue
57+
}
58+
let el = f as! AXUIElement
59+
var names: CFArray?; AXUIElementCopyAttributeNames(el, &names)
60+
let list = (names as? [String]) ?? []
61+
var sel = "-"
62+
if let r = attr(el, "AXSelectedTextRange") { var cf = CFRange(); AXValueGetValue(r as! AXValue, .cfRange, &cf); sel = "\(cf.location),\(cf.length)" }
63+
let raw = attr(el, "AXValue") as? String
64+
let value = raw.map(shape) ?? "none"
65+
let ph = (attr(el, "AXPlaceholderValue") as? String).map(shape) ?? "none"
66+
var settable = DarwinBoolean(false)
67+
AXUIElementIsAttributeSettable(el, "AXSelectedText" as CFString, &settable)
68+
var line = "\(tag) role=\(attr(el, "AXRole") as? String ?? "-") chromeId=\(list.contains("ChromeAXNodeId")) selSettable=\(settable.boolValue) sel=\(sel) value=\(value) placeholder=\(ph)"
69+
if line != last {
70+
if let raw, let old = prevValue, prevOwner == tag, old != raw, settable.boolValue {
71+
let a = Array(old.utf16), b = Array(raw.utf16)
72+
let (p, q) = common(a, b)
73+
let inserted = String(utf16CodeUnits: Array(b[p..<(b.count - q)]), count: b.count - p - q)
74+
line += " DELTA oldLen=\(a.count) newLen=\(b.count) prefix=\(p) suffix=\(q) removed=\(a.count - p - q) inserted=\(shape(inserted))"
75+
}
76+
last = line; print(fmt.string(from: Date()), line)
77+
}
78+
if settable.boolValue { prevValue = raw; prevOwner = tag } else { prevValue = nil }
79+
}
80+
print("done")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Batch 0 measurements, 2026-11-03 (UTC+8). Shape only: character counts per class, never text.
2+
# Watcher: batch0-ax-shape-watcher.swift (reads the focused field of the frontmost target app; no writes).
3+
# 'DELTA' compares consecutive values of the same editable field: common prefix/suffix, removed and inserted counts.
4+
# tag ai.codex = ChatGPT desktop app, s.t3code = T3 Code (Nightly).
5+
6+
## Empty-composer shapes (before any dictation)
7+
22:21:20.050 ai.codex role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=12{ASCII=10,LF=1,SP=1} endLF placeholder=none
8+
22:18:56.725 s.t3code role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=1{LF=1} startLF endLF ONLY-LF placeholder=u16=43{ASCII=30,SP=7,other=6}
9+
10+
## Insertions (AXTextArea deltas)
11+
22:19:27.834 s.t3code role=AXTextArea chromeId=true selSettable=true sel=22,0 value=u16=22{ASCII=17,SP=4,other=1} DELTA oldLen=1 newLen=22 prefix=0 suffix=0 removed=1 inserted=u16=22{ASCII=17,SP=4,other=1}
12+
22:19:29.862 s.t3code role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=1{LF=1} startLF endLF ONLY-LF DELTA oldLen=22 newLen=1 prefix=0 suffix=0 removed=22 inserted=u16=1{LF=1} startLF endLF ONLY-LF
13+
22:19:54.812 s.t3code role=AXTextArea chromeId=true selSettable=true sel=115,0 value=u16=115{ASCII=1,CJK=104,CJKP=7,DIG=1,SP=2} DELTA oldLen=1 newLen=115 prefix=0 suffix=0 removed=1 inserted=u16=115{ASCII=1,CJK=104,CJKP=7,DIG=1,SP=2}
14+
22:19:58.488 s.t3code role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=1{LF=1} startLF endLF ONLY-LF DELTA oldLen=115 newLen=1 prefix=0 suffix=0 removed=115 inserted=u16=1{LF=1} startLF endLF ONLY-LF
15+
22:21:35.584 ai.codex role=AXTextArea chromeId=true selSettable=true sel=103,0 value=u16=103{ASCII=81,SP=17,other=5} DELTA oldLen=12 newLen=103 prefix=0 suffix=0 removed=12 inserted=u16=103{ASCII=81,SP=17,other=5}
16+
22:21:46.967 ai.codex role=AXTextArea chromeId=true selSettable=true sel=146,0 value=u16=146{ASCII=87,CJK=30,CJKP=3,SP=21,other=5} DELTA oldLen=103 newLen=146 prefix=103 suffix=0 removed=0 inserted=u16=43{ASCII=6,CJK=30,CJKP=3,SP=4}
17+
22:21:48.107 ai.codex role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=12{ASCII=10,LF=1,SP=1} endLF DELTA oldLen=146 newLen=12 prefix=0 suffix=0 removed=146 inserted=u16=12{ASCII=10,LF=1,SP=1} endLF
18+
22:22:34.374 s.t3code role=AXTextArea chromeId=true selSettable=true sel=52,0 value=u16=53{CJK=47,CJKP=4,LF=1,SP=1} DELTA oldLen=11 newLen=53 prefix=10 suffix=0 removed=1 inserted=u16=43{CJK=37,CJKP=4,LF=1,SP=1} startLF
19+
22:22:35.636 s.t3code role=AXTextArea chromeId=true selSettable=true sel=0,0 value=u16=1{LF=1} startLF endLF ONLY-LF DELTA oldLen=53 newLen=1 prefix=0 suffix=0 removed=53 inserted=u16=1{LF=1} startLF endLF ONLY-LF
20+
21+
## Utter delivery log (Utter 0.0.62, local time)
22+
2026-11-03 22:22:37.347 I Delivery completed: uncertain, confirmation: none, path: paste, target: web
23+
24+
## Input history rows for the same dictations (status, text length in UTF-16 units, units before the caret; no text)
25+
14:15:19Z (22:15:19 local) T3 Code (Nightly) status=uncertain textUnits=19 caretPrefixUnits=17
26+
14:17:06Z (22:17:06 local) T3 Code (Nightly) status=inserted textUnits=62 caretPrefixUnits=98
27+
14:17:07Z (22:17:07 local) T3 Code (Nightly) status=notDelivered textUnits=4 caretPrefixUnits=161
28+
14:17:26Z (22:17:26 local) T3 Code (Nightly) status=inserted textUnits=56 caretPrefixUnits=98
29+
14:17:41Z (22:17:41 local) T3 Code (Nightly) status=uncertain textUnits=24 caretPrefixUnits=155
30+
14:19:27Z (22:19:27 local) T3 Code (Nightly) status=inserted textUnits=22 caretPrefixUnits=none
31+
14:19:54Z (22:19:54 local) T3 Code (Nightly) status=inserted textUnits=115 caretPrefixUnits=none
32+
14:21:38Z (22:21:38 local) ChatGPT status=uncertain textUnits=103 caretPrefixUnits=none
33+
14:21:46Z (22:21:46 local) ChatGPT status=inserted textUnits=43 caretPrefixUnits=103
34+
14:22:37Z (22:22:37 local) T3 Code (Nightly) status=uncertain textUnits=41 caretPrefixUnits=10
35+
36+
## Second watcher run (edges added), 22:30-22:32 local, same shape-only rules
37+
# removedEdges/oldTailEdges/insertedEdges: first and last scalar of a segment; letters/digits/CJK only as a class, structural characters as hex.
38+
22:31:15.002 ai.codex role=AXTextArea chromeId=true selSettable=true sel=34,0 value=u16=34{ASCII=2,CJK=27,CJKP=3,SP=2} DELTA oldLen=12 newLen=34 prefix=0 suffix=0 removed=12 removedEdges=[first=alnum last=U+000A] oldTailEdges=[first=alnum last=U+000A] inserted=u16=34{ASCII=2,CJK=27,CJKP=3,SP=2} insertedEdges=[first=cjk last=U+3002]
39+
# history: 14:31:17Z ChatGPT status=uncertain textUnits=34 caretPrefixUnits=none (the delivery above)
40+
# 14:30:11Z WeChat status=notDelivered textUnits=14 (no watcher on WeChat yet; a WeChat watcher was started 22:32 for the next case)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Intent: Dictation into the ChatGPT composer must be confirmed when the text really landed
2+
3+
**Status:** approved
4+
**Approved-by:** User, chat answer "批准" to "是否批准 intent 草稿(风险档可改成中等)", 2026-11-03 22:13 UTC+8; the risk lane stays High because the owner did not downgrade it. Spec, plan, PR, merge and release remain separate decisions
5+
**Approved-date:** 2026-11-03
6+
**Upstream:** [Compact unconfirmed notice](../2026-11-03-compact-unconfirmed-notice/intent.md) (made the notice smaller; its non-goal named this root cause), [Dictated text must land in web content editors](../2026-10-25-electron-delivery-uncertain/intent.md) (introduced `isWebContentEditor` and the placeholder-aware expectation this change extends)
7+
**Risk lane:** High. It changes how the core output path decides `accepted` versus `uncertain`. Confirmation never writes, so a wrong expectation cannot insert twice, but a too-loose one can report `accepted` for text that did not land, and `accepted` creates the insertion anchor that follow-up edits and undo rely on. Independent verifier, explicit rollback and the owner's merge authorization apply. The owner may downgrade the lane; that is their decision.
8+
9+
## Problem
10+
11+
The owner reports (2026-11-03, installed Utter 0.0.62, after the compact notice shipped): the dictated text **was** inserted into the ChatGPT composer, and Utter still shows "无法确认是否已写入". The new notice looks much better, but it should not appear when the insertion succeeded.
12+
13+
### Evidence
14+
15+
- **Path and target.** Unified log, 21:56–21:59 (UTC+8) today, Utter 0.0.62: every delivery in the window is `path: paste, target: web`. Three in a row end `uncertain, confirmation: none`, then three end `accepted, confirmation: targetValue`. So paste into a Chromium web editor confirms sometimes and not other times.
16+
- **It follows the composer's state.** Input history (delivery status, app name, timestamp and the presence of text before the caret only; no dictated text was printed): in ChatGPT, dictations into an **empty** composer (no text before the caret) ended `uncertain` 5 of 5 (2026-11-02 and 2026-11-03). With text before the caret: 2 `inserted`, 2 `uncertain`. Cursor shows the same pattern before 2026-10-25 and `inserted` after the placeholder fix of the earlier bundle; T3 Code ends `inserted` in 170 of 180 records.
17+
- **What ChatGPT's empty composer reports** (read-only Accessibility probe of the focused element while ChatGPT was frontmost, shape only, 22:01 UTC+8): role `AXTextArea`, carries `ChromeAXNodeId`, `AXSelectedText` settable, selection `0,0`, and an `AXValue` of 12 UTF-16 units made of 10 ASCII characters, 1 space and 1 line feed that ends the value. That is not the lone `"\n"` that `DeliveryExpectation` knows how to expect. It is consistent with a placeholder string plus a trailing line feed, but the text was deliberately not printed, so this is **inferred, not proven**.
18+
- **What the code does with it.** `DeliveryExpectation.expectedDocument` only drops the placeholder when the document is exactly `"\n"`. For any other empty-looking value it computes "document with the text inserted at the caret". If the editor removes the placeholder once text is inserted, the real value becomes the dictated text alone, never equals the expectation, and `DeliveryTextObservation.confirm` times out after 3 s as `uncertain`.
19+
- **Not yet measured:** the value ChatGPT reports **after** a paste (whether a trailing line feed remains, how a non-empty composer reports its caret and trailing break), and the cause of the 2 `uncertain` records that had text before the caret.
20+
21+
## Outcome
22+
23+
- When the text really landed in the ChatGPT composer, delivery ends `accepted` with `confirmation: targetValue`, in an empty composer and in a composer that already has text, and the notice does not appear.
24+
- A paste that did not land, or that landed somewhere else, still ends `uncertain`. No path writes twice.
25+
26+
## Scope
27+
28+
In scope:
29+
30+
- Measure, read-only and shape-only, what the ChatGPT composer reports before and after a real Utter dictation (empty composer; composer with text, caret at the end, in the middle).
31+
- Make the expected value for web content editors match what was measured, and nothing wider.
32+
- Tests built from the measured shapes, including the negative cases below.
33+
34+
Non-goals:
35+
36+
- Removing the confirmation, the `uncertain` state, the 3 s timeout, or the compact notice from the previous change.
37+
- Targets other than web content editors. Native fields keep their behavior.
38+
- Making `uncertain` impossible for targets that expose no readable value; they stay `uncertain` because that is true.
39+
- Logging dictated text or editor text. Diagnostics, if added, carry counts and flags only.
40+
41+
## Constraints
42+
43+
- Confirmation must not become a blanket "accept anything": the observed value has to equal a value that can only exist if the text landed.
44+
- Never insert twice; no new write, retry or clipboard behavior.
45+
- No new permission. No app-name special case unless the spec shows the capability signature cannot work, and then a short, testable list.
46+
- `swift test`, `bash scripts/ci-basic-checks.sh`, `bash scripts/sdlc-checks.sh` pass.
47+
48+
## Acceptance criteria
49+
50+
1. **Empty composer.** On the reproducing machine, 10 consecutive dictations into an empty ChatGPT composer (clear it between runs) end `accepted` with `confirmation: targetValue`, the text appears once, and no unconfirmed notice shows. Recorded from the unified log and input history.
51+
2. **Composer with text.** 10 dictations with the caret at the end of existing text, and 5 with the caret in the middle, end `accepted`, text once.
52+
3. **No regression elsewhere.** Cursor, T3 Code and Dia web fields still end `accepted`; TextEdit/Notes behave as before (existing tests plus one run each).
53+
4. **Truth preserved.** Unit tests show `uncertain` when the observed value equals the original document (the paste did nothing), when it contains other text than expected, and when the target cannot be read.
54+
5. **No text in diagnostics.** Log lines added or changed contain no dictated or editor text.
55+
6. The standard checks above pass.
56+
57+
## Open questions for the spec
58+
59+
1. The post-paste shape in ChatGPT, and whether it is the same in the desktop app and in a Chromium browser tab on chatgpt.com. Decided by the measurement in the first batch.
60+
2. Whether the two `uncertain` records with text before the caret share this cause or have another one (for example a trailing line feed or whitespace normalization). Decided by the measurement.
61+
3. How to express the rule: a second accepted candidate for a caret at the start of an empty-looking editor, or a recognized placeholder shape. The spec compares both against the false-accept risk above.
62+
63+
## Request to the owner (needed for the measurement, no code is written before approval)
64+
65+
A passive watcher is running on this machine until about 22:46 UTC+8. It reads only the focused field of the ChatGPT app and prints character counts by class, never text. To fill the "not yet measured" gap, dictate normally into the ChatGPT composer a few times: first into an empty composer, then with some text already in it. Nothing else is needed.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Plan: Confirm a paste into an empty-looking web editor whose placeholder disappears
2+
3+
**Status:** approved
4+
**Approved-by:** User, chat answer "批准" (22:35 UTC+8) to the compound question "是否批准 spec 和 plan,以及是否含 D5". The reply did not say 含/不含; the spec's stated default (include D5) is applied and is open to reversal at review. PR, merge, tag and release remain separate decisions
5+
**Approved-date:** 2026-11-03
6+
**Upstream:** [spec.md](spec.md)
7+
8+
## Work items
9+
10+
| # | Item | Files | Check |
11+
|---|---|---|---|
12+
| A | `DeliveryExpectation` returns the set of values that prove the text landed (D1, D2); the lone-`"\n"` rule is kept | `Sources/UtterMacServices/DeliveryExpectation.swift`, `Tests/UtterMacServicesTests/DeliveryExpectationTests.swift` | Unit tests for the measured shapes and every negative case in the spec's test plan; existing tests unchanged except for the changed return type. |
13+
| B | `DeliveryTextObservation.confirm` accepts the set (D4) | `Sources/UtterMacServices/DeliveryTextObservation.swift`, its tests with a fake clock | Becomes-the-text confirms, stays-original and becomes-other time out; deadline and cancellation unchanged. |
14+
| C | `NativeDeliveryTarget.confirm` and `insertionAnchor` use the set, and an unchanged field is still never accepted (D3) | `Sources/UtterMacServices/Native/NativeDeliveryTarget.swift`, route tests with the fake target | Anchor accepted for either value and rejected for others; no new write paths. |
15+
| D | Counts-only diagnostic on timeout (D5), **included** (default applied after the owner's bare "批准") | `Sources/UtterMacServices/DeliveryTextObservation.swift` (or a new small file), `DeliveryRoute.swift`, tests | The line has numbers and flags only; a test asserts that none of the observed or expected text appears in it. |
16+
| E | Mutation checks: remove the extra candidate, drop `replacement != document`, drop the `(0, 0)` guard | local only, restored after | The matching tests fail each time; recorded in `verification.md`. |
17+
| F | Repo checks, release-style build, independent hardware verification, `verification.md` | `verification.md`, `evidence/` | `bash scripts/sdlc-checks.sh`, `bash scripts/ci-basic-checks.sh`, `swift test`; the hardware matrix of the spec by a verifier who is not the implementer. |
18+
| G | PR, CI, then (only with the owner's authorization) merge, tag `v0.0.63`, release | GitHub | `SDLC Gate` green; release per `release-runbook.md`; the `production` approval is the owner's. |
19+
20+
Order: A, B, C, (D), E, F, G. Run the focused tests after each item. Commit subjects become the in-app release notes, so
21+
they are written for users, for example "fix: confirm dictation into an empty ChatGPT composer instead of showing the unconfirmed notice".
22+
23+
## Verification plan
24+
25+
- **Automated:** the unit tests above, then the full suite and both scripts.
26+
- **Hardware:** the matrix in the spec, with `evidence/batch0-ax-shape-watcher.swift` recording shapes and the unified log
27+
and history rows recording results. The independent verifier is named in `verification.md`; if the owner waives
28+
independence, the waiver is recorded there.
29+
- **Runtime:** the installed Utter 0.0.62 is the owner's daily driver and shares its bundle id. The hardware run uses the
30+
release-style build of this branch only after the owner agrees to replace or stop the installed app for the run.
31+
- **Not covered, recorded:** multi-paragraph text in ChatGPT, ChatGPT in a browser tab, the second cause of `uncertain`
32+
(unless a follow-up intent covers it).
33+
34+
## Rollback
35+
36+
Revert the change commits. The previous behavior is the unconfirmed notice on empty ChatGPT composers; no settings,
37+
data or permission change is involved. Turning the web path off with the existing hidden switch
38+
`deliveryWebEditorPasteDisabled` also disables the new rule.

0 commit comments

Comments
 (0)