Skip to content

Commit 7f18adb

Browse files
committed
Track D: structure Pine Editor diagnostics summaries
1 parent 9407426 commit 7f18adb

File tree

8 files changed

+517
-9
lines changed

8 files changed

+517
-9
lines changed

docs/CHAT_CONTINUITY_IMPLEMENTATION_PLAN.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ node scripts/test-windows-observation-flow.js
15011501
- extended `src/main/tradingview/pine-workflows.js` so Pine Version History provenance requests can stay verification-first while preserving or auto-appending bounded `get_text` readback
15021502
- extended `src/main/tradingview/pine-workflows.js` so Pine Editor visible status/output requests can stay verification-first while preserving or auto-appending bounded `get_text` readback
15031503
- added Pine Editor line-budget awareness so `500-line limit` / line-count checks prefer verified Pine Editor readback and prompt guidance now explicitly treats Pine scripts as capped at 500 lines when reading/writing
1504+
- refined Pine Editor readback into explicit `compile-result` and `diagnostics` evidence modes so visible compiler status, warnings, and errors can be summarized as bounded text evidence rather than generic status text
15041505
- added dedicated Pine data-workflow regressions in `scripts/test-tradingview-pine-data-workflows.js`
15051506
- extended `scripts/test-windows-observation-flow.js` with verified Pine Logs, Pine Profiler, Pine Version History, and Pine Editor status/output readback coverage that gathers text without re-entering a screenshot loop
15061507
- updated `src/main/ai-service/system-prompt.js` so TradingView Pine output/error/provenance requests prefer verified Pine surfaces plus `get_text`, including Pine Editor visible status/output, over screenshot-only inference
@@ -1566,6 +1567,166 @@ node scripts/test-windows-observation-flow.js
15661567
**Next best slice from here**
15671568
- refine Pine Editor status/output readback into more structured visible compile-result / diagnostics summaries without implying chart-state insight
15681569

1570+
**Concrete next Pine slice — structured diagnostics and provenance summaries**
1571+
1572+
This is the next Pine-facing implementation slice after the current Logs / Profiler / Version History / Pine Editor readback foundation.
1573+
1574+
**Grounded status of recent Pine follow-ups**
1575+
- broader visible Pine status/output surfaces beyond Logs / Profiler / Version History are now implemented via verified `pine-editor` readback with bounded `get_text`
1576+
- script-audit / provenance refinement is only partially complete:
1577+
- verified Pine Version History opening plus raw visible text readback is implemented
1578+
- structural extraction of the top visible revision metadata (for example revision label, relative time, author/source hints when visible, and compact summary formatting) is not implemented yet
1579+
1580+
**Immediate next objective**
1581+
- turn generic Pine Editor text readback into explicit visible diagnostics summaries
1582+
- turn generic Pine Version History text readback into explicit visible revision/provenance summaries
1583+
1584+
**Priority order**
1585+
1. **Slice D-next-1 — Pine Editor compile-result / diagnostics summaries**
1586+
2. **Slice D-next-2 — Pine Version History top visible revision metadata summaries**
1587+
1588+
#### Slice D-next-1 — Pine Editor compile-result / diagnostics summaries
1589+
1590+
**Status:** First slice completed in working tree
1591+
1592+
**Delivered so far**
1593+
- extended `src/main/tradingview/pine-workflows.js` so Pine Editor readback requests can classify bounded evidence modes:
1594+
- `compile-result`
1595+
- `diagnostics`
1596+
- `line-budget`
1597+
- `generic-status`
1598+
- refined Pine Editor `get_text` readback reasons and mode metadata so compile-result and diagnostics requests carry explicit bounded-summary intent instead of generic status wording
1599+
- updated `src/main/ai-service/system-prompt.js` with Pine diagnostics guidance that:
1600+
- prefers visible compiler/diagnostic text over screenshot interpretation
1601+
- treats `no errors` / compile success as compiler evidence only
1602+
- mentions Pine execution-model caveats before inferring runtime or strategy behavior
1603+
- updated `src/main/ai-service/message-builder.js` to inject `## Pine Evidence Bounds` for Pine diagnostics-oriented requests
1604+
- added focused prompt coverage in `scripts/test-pine-diagnostics-bounds.js`
1605+
- extended workflow, seam, and execution regressions in:
1606+
- `scripts/test-tradingview-pine-data-workflows.js`
1607+
- `scripts/test-windows-observation-flow.js`
1608+
- `scripts/test-bug-fixes.js`
1609+
1610+
**Why this slice should go first**
1611+
- the current `pine-editor` workflow already opens the correct surface and gathers bounded text evidence
1612+
- the remaining gap is interpretation structure, not UI access
1613+
- this is the highest-value next step for Pine debugging because compile/result state is more actionable than generic visible text
1614+
1615+
**Goal**
1616+
- summarize visible Pine Editor output into bounded categories such as:
1617+
- compile success / no errors
1618+
- compile errors
1619+
- warnings / status-only output
1620+
- line-budget proximity hints
1621+
- do this without claiming chart-state or runtime behavior that is not directly visible in the text evidence
1622+
1623+
**Primary files**
1624+
- `src/main/tradingview/pine-workflows.js`
1625+
- `src/main/ai-service/system-prompt.js`
1626+
- `src/main/ai-service/message-builder.js`
1627+
- `scripts/test-tradingview-pine-data-workflows.js`
1628+
- `scripts/test-windows-observation-flow.js`
1629+
- `scripts/test-bug-fixes.js`
1630+
1631+
**Exact changes to map in**
1632+
- `src/main/tradingview/pine-workflows.js`
1633+
- extend Pine evidence-read intent shaping so requests such as:
1634+
- `summarize compile result`
1635+
- `read compiler errors`
1636+
- `check diagnostics`
1637+
- `summarize warnings`
1638+
route to `pine-editor` bounded readback with stronger compile/diagnostic wording
1639+
- add a small helper for Pine Editor evidence modes, for example:
1640+
- `diagnostics`
1641+
- `compile-result`
1642+
- `line-budget`
1643+
- `generic-status`
1644+
- preserve existing verification-first open/read behavior and only refine the `get_text.reason` / mode metadata
1645+
- `src/main/ai-service/system-prompt.js`
1646+
- add explicit Pine diagnostics guidance:
1647+
- prefer visible compiler/diagnostic text over screenshot interpretation
1648+
- separate visible compile status from inferred runtime/chart conclusions
1649+
- mention Pine execution-model caveats when the user asks for strategy/runtime diagnosis
1650+
- keep Pine 500-line awareness as a practical guardrail, but avoid treating it as the only limit
1651+
- `src/main/ai-service/message-builder.js`
1652+
- add a compact Pine evidence guard block when the active app capability is TradingView and the user request is Pine-diagnostic in nature
1653+
- include rules like:
1654+
- summarize only what the visible text proves
1655+
- do not turn `no errors` into market insight
1656+
- do not infer runtime correctness from compile success alone
1657+
1658+
**Regression additions**
1659+
- `scripts/test-tradingview-pine-data-workflows.js`
1660+
- `pine workflow recognizes compile-result requests`
1661+
- `pine workflow recognizes diagnostics requests`
1662+
- `open pine editor and summarize compile result stays verification-first`
1663+
- `open pine editor and summarize diagnostics preserves bounded get_text readback`
1664+
- `scripts/test-windows-observation-flow.js`
1665+
- `verified pine editor diagnostics workflow gathers compile text without screenshot loop`
1666+
- `verified pine editor no-errors workflow preserves visible success text for bounded summary`
1667+
- `scripts/test-bug-fixes.js`
1668+
- seam assertions that Pine prompt guidance includes compiler/diagnostic wording and that Pine workflows encode the new diagnostics mode hints
1669+
1670+
**Acceptance criteria**
1671+
- Liku can distinguish visible Pine Editor diagnostics from generic status text
1672+
- compile success is summarized honestly without implying runtime/market validity
1673+
- compile errors/warnings are surfaced as bounded evidence rather than screenshot-only speculation
1674+
1675+
#### Slice D-next-2 — Pine Version History top visible revision metadata summaries
1676+
1677+
**Why this is second**
1678+
- the UI access path is already implemented, but the current behavior is still just raw visible text gathering
1679+
- the next value is structural summarization of the top visible revisions, not merely reopening the panel
1680+
1681+
**Goal**
1682+
- summarize the top visible Pine Version History entries into compact provenance facts such as:
1683+
- latest visible revision label/number
1684+
- relative save time when visible
1685+
- count of visible revisions in the current panel snapshot
1686+
- whether the visible text implies recent churn or a stable revision list
1687+
1688+
**Primary files**
1689+
- `src/main/tradingview/pine-workflows.js`
1690+
- `src/main/ai-service/system-prompt.js`
1691+
- `src/main/ai-service/message-builder.js`
1692+
- `scripts/test-tradingview-pine-data-workflows.js`
1693+
- `scripts/test-windows-observation-flow.js`
1694+
- `scripts/test-bug-fixes.js`
1695+
1696+
**Exact changes to map in**
1697+
- `src/main/tradingview/pine-workflows.js`
1698+
- extend evidence-read intent shaping so requests such as:
1699+
- `summarize latest revision metadata`
1700+
- `read top visible revisions`
1701+
- `show visible provenance details`
1702+
explicitly mark Version History as a provenance-summary workflow instead of a generic text readback
1703+
- add a `provenance-summary` evidence mode for `pine-version-history`
1704+
- `src/main/ai-service/system-prompt.js`
1705+
- add explicit provenance guidance:
1706+
- summarize only visible revision metadata
1707+
- do not infer hidden diffs or full script history from the visible list alone
1708+
- treat Version History as audit/provenance evidence, not runtime/chart evidence
1709+
- `src/main/ai-service/message-builder.js`
1710+
- add a compact Pine provenance guard block when the request is revision/history focused
1711+
- reinforce that visible history entries are bounded UI evidence only
1712+
1713+
**Regression additions**
1714+
- `scripts/test-tradingview-pine-data-workflows.js`
1715+
- `pine workflow recognizes visible revision metadata requests`
1716+
- `pine version history provenance-summary workflow stays verification-first`
1717+
- `scripts/test-windows-observation-flow.js`
1718+
- `verified pine version history workflow preserves top visible revision metadata text for bounded provenance summary`
1719+
- `scripts/test-bug-fixes.js`
1720+
- seam assertions that Version History prompt guidance distinguishes provenance from runtime/chart evidence
1721+
1722+
**Acceptance criteria**
1723+
- Liku can summarize top visible revision metadata without overclaiming hidden history
1724+
- Version History output is framed as provenance/audit evidence only
1725+
1726+
**Recommended commit order from here**
1727+
1. `Track D: structure Pine Editor diagnostics summaries`
1728+
2. `Track D: structure Pine Version History provenance summaries`
1729+
15691730
### Track E — Honest drawing capability framing
15701731

15711732
**Why this track exists**

scripts/test-bug-fixes.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ test('message-builder injects active app capability context', () => {
195195
assert(messageBuilderContent.includes('uia-rich'), 'Capability context should recognize UIA-rich apps');
196196
assert(messageBuilderContent.includes('namedInteractiveElementCount'), 'Capability context should include UIA inventory counts');
197197
assert(messageBuilderContent.includes('answer-shape:'), 'Capability context should shape control-surface answers');
198+
assert(messageBuilderContent.includes('## Pine Evidence Bounds'), 'Message builder should inject a bounded Pine diagnostics evidence block when relevant');
199+
assert(messageBuilderContent.includes('inferPineEvidenceRequestKind'), 'Message builder should classify Pine evidence request kinds');
200+
assert(messageBuilderContent.includes('runtime correctness, strategy validity, profitability, or market insight'), 'Pine evidence bounds should prevent compile success from being overclaimed');
198201
});
199202

200203
test('ai-service verifies focus continuity after action execution', () => {
@@ -234,6 +237,31 @@ test('rewriteActionsForReliability normalizes typoed app launches', () => {
234237
assert(launchAction.verifyTarget.domKeywords.includes('depth of market'), 'verifyTarget should include TradingView DOM keywords');
235238
});
236239

240+
test('pine workflow encodes diagnostics and compile-result evidence modes', () => {
241+
const pineWorkflowPath = path.join(__dirname, '..', 'src', 'main', 'tradingview', 'pine-workflows.js');
242+
const fs = require('fs');
243+
244+
const pineWorkflowContent = fs.readFileSync(pineWorkflowPath, 'utf8');
245+
246+
assert(pineWorkflowContent.includes('function inferPineEditorEvidenceMode'), 'Pine workflows should classify Pine Editor evidence modes');
247+
assert(pineWorkflowContent.includes("return 'compile-result'"), 'Pine workflows should support compile-result evidence mode');
248+
assert(pineWorkflowContent.includes("return 'diagnostics'"), 'Pine workflows should support diagnostics evidence mode');
249+
assert(pineWorkflowContent.includes('pineEvidenceMode'), 'Pine get_text steps should preserve evidence mode metadata');
250+
assert(pineWorkflowContent.includes('compile-result text for a bounded diagnostics summary'), 'Pine workflows should use compile-result-specific readback wording');
251+
assert(pineWorkflowContent.includes('diagnostics and warnings text'), 'Pine workflows should use diagnostics-specific readback wording');
252+
});
253+
254+
test('system prompt includes Pine diagnostics guidance', () => {
255+
const systemPromptPath = path.join(__dirname, '..', 'src', 'main', 'ai-service', 'system-prompt.js');
256+
const fs = require('fs');
257+
258+
const systemPromptContent = fs.readFileSync(systemPromptPath, 'utf8');
259+
260+
assert(systemPromptContent.includes('TradingView Pine diagnostics rule'), 'System prompt should include Pine diagnostics guidance');
261+
assert(systemPromptContent.includes('compile success'), 'System prompt should mention compile success bounds');
262+
assert(systemPromptContent.includes('realtime rollback'), 'System prompt should mention Pine execution-model caveats');
263+
});
264+
237265
test('rewriteActionsForReliability does not reinterpret passive TradingView open-state prompts as app launches', () => {
238266
const aiServicePath = path.join(__dirname, '..', 'src', 'main', 'ai-service.js');
239267
const aiService = require(aiServicePath);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env node
2+
3+
const assert = require('assert');
4+
const path = require('path');
5+
6+
const { createMessageBuilder } = require(path.join(__dirname, '..', 'src', 'main', 'ai-service', 'message-builder.js'));
7+
8+
function createBuilder({ foreground } = {}) {
9+
return createMessageBuilder({
10+
getBrowserSessionState: () => ({ lastUpdated: null }),
11+
getCurrentProvider: () => 'copilot',
12+
getForegroundWindowInfo: async () => foreground || null,
13+
getInspectService: () => ({ isInspectModeActive: () => false }),
14+
getLatestVisualContext: () => null,
15+
getPreferencesSystemContext: () => '',
16+
getPreferencesSystemContextForApp: () => '',
17+
getRecentConversationHistory: () => [],
18+
getSemanticDOMContextText: () => '',
19+
getUIWatcher: () => ({ isPolling: false, getCapabilitySnapshot: () => null, getContextForAI: () => '' }),
20+
maxHistory: 0,
21+
systemPrompt: 'base system prompt'
22+
});
23+
}
24+
25+
async function test(name, fn) {
26+
try {
27+
await fn();
28+
console.log(`PASS ${name}`);
29+
} catch (error) {
30+
console.error(`FAIL ${name}`);
31+
console.error(error.stack || error.message);
32+
process.exitCode = 1;
33+
}
34+
}
35+
36+
async function buildPineEvidenceMessage(userMessage) {
37+
const builder = createBuilder({
38+
foreground: {
39+
success: true,
40+
processName: 'tradingview',
41+
title: 'TradingView - Pine Editor'
42+
}
43+
});
44+
const messages = await builder.buildMessages(userMessage, false);
45+
return messages.find((entry) => entry.role === 'system' && entry.content.includes('## Pine Evidence Bounds'));
46+
}
47+
48+
async function main() {
49+
await test('pine compile-result prompt bounds compile success claims', async () => {
50+
const evidenceMessage = await buildPineEvidenceMessage('open pine editor in tradingview and summarize the compile result');
51+
52+
assert(evidenceMessage, 'pine evidence block should be injected');
53+
assert(evidenceMessage.content.includes('requestKind: compile-result'));
54+
assert(evidenceMessage.content.includes('Rule: Prefer visible Pine Editor compiler/diagnostic text over screenshot interpretation for Pine compile and diagnostics requests.'));
55+
assert(evidenceMessage.content.includes('compiler/editor evidence only, not proof of runtime correctness, strategy validity, profitability, or market insight'));
56+
});
57+
58+
await test('pine diagnostics prompt bounds warning and runtime inferences', async () => {
59+
const evidenceMessage = await buildPineEvidenceMessage('open pine editor in tradingview and check diagnostics');
60+
61+
assert(evidenceMessage, 'pine evidence block should be injected');
62+
assert(evidenceMessage.content.includes('requestKind: diagnostics'));
63+
assert(evidenceMessage.content.includes('Rule: Surface visible compiler errors and warnings as bounded diagnostics evidence; do not infer hidden causes or chart-state effects unless the visible text states them.'));
64+
assert(evidenceMessage.content.includes('mention Pine execution-model caveats such as realtime rollback, confirmed vs unconfirmed bars, and indicator vs strategy recalculation differences'));
65+
});
66+
}
67+
68+
main().catch((error) => {
69+
console.error('FAIL pine diagnostics bounds');
70+
console.error(error.stack || error.message);
71+
process.exit(1);
72+
});

0 commit comments

Comments
 (0)