@litfamily/litcodex 1.0.21 → 1.0.23
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-Ko-KR.md +9 -9
- package/README.md +9 -9
- package/dist/install/doctor-render.js +5 -0
- package/dist/install/doctor.js +9 -0
- package/dist/install/types.d.ts +4 -0
- package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
- package/marketplace/plugins/litcodex/.mcp.json +9 -1
- package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
- package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
- package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.d.ts +1 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.js +313 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-mcp.d.ts +14 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-mcp.js +141 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-server.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-server.js +38 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.d.ts +43 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.js +363 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/cli.js +5 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +14 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +76 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.d.ts +59 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.js +287 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.d.ts +30 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +113 -45
- package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
- package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
- package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
- package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
- package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
- package/marketplace/plugins/litcodex/hooks/hooks.json +20 -0
- package/node_modules/@litcodex/lit-loop/dist/card-html.d.ts +1 -0
- package/node_modules/@litcodex/lit-loop/dist/card-html.js +313 -0
- package/node_modules/@litcodex/lit-loop/dist/card-mcp.d.ts +14 -0
- package/node_modules/@litcodex/lit-loop/dist/card-mcp.js +141 -0
- package/node_modules/@litcodex/lit-loop/dist/card-server.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/card-server.js +38 -0
- package/node_modules/@litcodex/lit-loop/dist/card-status.d.ts +43 -0
- package/node_modules/@litcodex/lit-loop/dist/card-status.js +363 -0
- package/node_modules/@litcodex/lit-loop/dist/cli.js +5 -1
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +14 -0
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +76 -2
- package/node_modules/@litcodex/lit-loop/dist/live-step.d.ts +59 -0
- package/node_modules/@litcodex/lit-loop/dist/live-step.js +287 -0
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +30 -0
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +113 -45
- package/node_modules/@litcodex/lit-loop/package.json +1 -1
- package/package.json +2 -2
- package/readme-assets/badge-version.svg +1 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// src/card-html.ts — the LIT card: one self-contained HTML page for the Codex desktop app (MCP App).
|
|
2
|
+
//
|
|
3
|
+
// Inline CSS and script only; no network, fonts or images. It draws the status from `lit_card_status`
|
|
4
|
+
// (activation, workflow map, live step, context and quota use) in the LIT look: the pink-to-flame LIT
|
|
5
|
+
// pill, lowercase stage words with ✓ or ·, rails that run flame → pink → accent, the current stage as
|
|
6
|
+
// an accent pill with dark ink, and the running tool with its time.
|
|
7
|
+
//
|
|
8
|
+
// The host reports how it shows the card. Inline (in the thread) gets the compact card and tells the
|
|
9
|
+
// host its height through `notifyIntrinsicHeight`, because the host sizes inline frames from that; the
|
|
10
|
+
// side pane arrives as `fullscreen` and gets a vertical timeline with the use bars at the bottom. The
|
|
11
|
+
// card drew in a proportional face inside the app, so it pins its monospace face. Light and dark follow the
|
|
12
|
+
// host theme. It polls every 1.5 s while visible and working, slows down when idle and stops while
|
|
13
|
+
// hidden. It talks to the host through `window.openai` when present, else MCP Apps postMessage JSON-RPC.
|
|
14
|
+
export const CARD_HTML = `<!doctype html>
|
|
15
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
16
|
+
<title>LIT</title>
|
|
17
|
+
<style>
|
|
18
|
+
:root{color-scheme:dark;--bg:#10141c;--bg2:#0d1118;--ink:#e6edf3;--dim:#7d8590;--faint:#30363d;--rail:#3a434e;--flame:#ff6337;--pink:#ff2d95;--acc:#5fd7ff;--accfill:#5fd7ff;--green:#6bdb8f;--amber:#ffaf3c;--red:#ff5f5f;--pillink:#0b0f14;
|
|
19
|
+
--mono:"SF Mono",SFMono-Regular,ui-monospace,Menlo,Monaco,Consolas,"Liberation Mono",monospace}
|
|
20
|
+
:root.light{color-scheme:light;--bg:#ffffff;--bg2:#fafbfd;--ink:#1b1f27;--dim:#69717e;--faint:#dde2e8;--rail:#cfd6de;--flame:#e2521f;--pink:#d81b78;--acc:#0a87b8;--green:#1f9d55;--amber:#b86e00;--red:#d93a3a}
|
|
21
|
+
*{box-sizing:border-box}
|
|
22
|
+
html,body{margin:0;background:transparent}
|
|
23
|
+
body{color:var(--ink);font-size:12.5px;line-height:1.55;font-weight:500;-webkit-font-smoothing:antialiased}
|
|
24
|
+
.lc,.lc *{font-family:var(--mono)!important}
|
|
25
|
+
.lc{position:relative;border-radius:14px;padding:11px 14px 10px;margin:1px;
|
|
26
|
+
background:radial-gradient(110% 120% at 0% 0%,color-mix(in srgb,var(--pink) 8%,transparent),transparent 55%),radial-gradient(80% 110% at 100% 0%,color-mix(in srgb,var(--acc) 6%,transparent),transparent 60%),linear-gradient(180deg,var(--bg),var(--bg2));
|
|
27
|
+
border:1px solid color-mix(in srgb,var(--acc) 55%,transparent);box-shadow:0 0 0 1px color-mix(in srgb,var(--acc) 8%,transparent),0 10px 30px -18px color-mix(in srgb,var(--acc) 50%,transparent);animation:breathe 4.8s ease-in-out infinite}
|
|
28
|
+
.lc.is-done{border-color:color-mix(in srgb,var(--green) 55%,transparent);box-shadow:0 0 0 1px color-mix(in srgb,var(--green) 8%,transparent);animation:none}
|
|
29
|
+
.lc.is-idle{border-color:color-mix(in srgb,var(--dim) 40%,transparent);box-shadow:none;animation:none}
|
|
30
|
+
@keyframes breathe{0%,100%{border-color:color-mix(in srgb,var(--acc) 38%,transparent)}50%{border-color:color-mix(in srgb,var(--acc) 80%,transparent)}}
|
|
31
|
+
.head{display:flex;align-items:center;gap:7px;white-space:nowrap;min-height:22px}
|
|
32
|
+
.brand{position:relative;overflow:hidden;display:inline-flex;align-items:center;gap:3px;padding:1px 9px 1px 7px;border-radius:999px;background:linear-gradient(90deg,#ff2d95,#ff6337);color:#0b0f14;font-weight:800;letter-spacing:.03em;box-shadow:0 0 16px -6px rgba(255,45,149,.6)}
|
|
33
|
+
.j{color:var(--faint)}
|
|
34
|
+
.name{font-weight:700;overflow:hidden;text-overflow:ellipsis}.acc{color:var(--acc)}.dim{color:var(--dim)}.ok{color:var(--green)}
|
|
35
|
+
.right{margin-left:auto;font-weight:700;letter-spacing:.04em;display:inline-flex;align-items:center;gap:6px}
|
|
36
|
+
.dot{width:6px;height:6px;border-radius:50%;background:var(--acc);box-shadow:0 0 7px var(--acc);animation:pulse 1.6s ease-in-out infinite}
|
|
37
|
+
@keyframes pulse{50%{opacity:.35}}
|
|
38
|
+
.map{display:flex;align-items:center;gap:7px;margin:9px 0 6px;white-space:nowrap;overflow:hidden}
|
|
39
|
+
.st em{font-style:normal;margin-left:3px}.st.todo{color:var(--dim)}.st.done{font-weight:600}
|
|
40
|
+
.rail{position:relative;display:inline-block;height:2px;border-radius:2px;flex:1 1 12px;max-width:56px;min-width:10px;background:var(--rail)}
|
|
41
|
+
.rail.lead{overflow:hidden}.headfill{position:absolute;inset:0;width:40%;background:linear-gradient(90deg,var(--acc),transparent)}
|
|
42
|
+
.comet{position:absolute;top:50%;width:5px;height:5px;margin-top:-2.5px;border-radius:50%;background:#fff;box-shadow:0 0 7px 2px var(--acc);animation:comet 2.4s linear infinite}
|
|
43
|
+
:root.light .comet{background:var(--accfill);box-shadow:0 0 5px 1px var(--accfill)}
|
|
44
|
+
@keyframes comet{0%{left:-8%;opacity:0}15%,85%{opacity:1}100%{left:100%;opacity:0}}
|
|
45
|
+
.nowpill{position:relative;overflow:hidden;display:inline-flex;gap:6px;align-items:center;padding:0 9px;border-radius:999px;background:var(--accfill);color:var(--pillink);font-weight:800;box-shadow:0 0 14px -4px color-mix(in srgb,var(--accfill) 80%,transparent)}
|
|
46
|
+
.sweep{position:absolute;inset:0;background:linear-gradient(100deg,transparent 30%,rgba(255,255,255,.7) 50%,transparent 70%);transform:translateX(-120%);animation:sweep 3.2s ease-in-out infinite;pointer-events:none}
|
|
47
|
+
@keyframes sweep{0%,55%{transform:translateX(-120%)}85%,100%{transform:translateX(120%)}}
|
|
48
|
+
.is-done .sweep,.is-idle .sweep{display:none}
|
|
49
|
+
.row{display:flex;align-items:center;gap:8px;white-space:nowrap;min-height:20px}
|
|
50
|
+
.tl{display:inline-flex;align-items:center;gap:6px;overflow:hidden;min-width:0}
|
|
51
|
+
.nx{overflow:hidden;text-overflow:ellipsis}
|
|
52
|
+
.bar{display:inline-flex;gap:2px;vertical-align:middle}.seg{display:inline-block;width:6px;height:10px;border-radius:1.5px}.seg.off{background:var(--faint)}
|
|
53
|
+
.live{display:inline-flex;align-items:center;gap:6px;flex:0 0 auto}.row .tl+.live{margin-left:auto}
|
|
54
|
+
.live .tool{font-weight:700}.live .last{font-weight:600;overflow:hidden;text-overflow:ellipsis}.live.done{color:var(--green);font-weight:700}
|
|
55
|
+
.spin{color:var(--acc);animation:spin 1s linear infinite;flex:0 0 auto}@keyframes spin{to{transform:rotate(360deg)}}
|
|
56
|
+
.spin.soft{color:var(--dim)}
|
|
57
|
+
kbd{font-size:12px;color:var(--acc);background:color-mix(in srgb,var(--acc) 12%,transparent);border:1px solid color-mix(in srgb,var(--acc) 32%,transparent);border-radius:6px;padding:0 6px}
|
|
58
|
+
.foot{display:flex;align-items:center;gap:12px;margin-top:7px;padding-top:7px;border-top:1px solid color-mix(in srgb,var(--faint) 75%,transparent);font-size:11.5px;color:var(--dim);white-space:nowrap;overflow:hidden}
|
|
59
|
+
.use{display:inline-flex;align-items:center;gap:5px}.use b{font-weight:600;color:var(--ink)}
|
|
60
|
+
.mini{display:inline-flex;gap:1.5px}.mini i{display:inline-block;width:4px;height:8px;border-radius:1px;background:var(--faint)}
|
|
61
|
+
.ws{margin-left:auto;overflow:hidden;text-overflow:ellipsis}
|
|
62
|
+
/* the side pane (the host's fullscreen mode): a vertical timeline, the use bars at the bottom */
|
|
63
|
+
:root.pane .lc{min-height:calc(100vh - 2px);display:flex;flex-direction:column;padding:18px 20px 16px;font-size:13px}
|
|
64
|
+
:root.pane .brand{font-size:13.5px;padding:2px 11px 2px 9px}:root.pane .name{font-size:13.5px}
|
|
65
|
+
.tline{margin:18px 0 6px}
|
|
66
|
+
.stg{position:relative;padding:0 0 12px 24px}
|
|
67
|
+
.stg::before{content:"";position:absolute;left:4px;top:0;bottom:0;width:2px;background:var(--line,var(--rail))}
|
|
68
|
+
.stg:first-child::before{top:9px}.stg:last-child::before{bottom:auto;height:9px}.stg:last-child{padding-bottom:0}
|
|
69
|
+
.stg .pt{position:absolute;left:0;top:4px;width:10px;height:10px;border-radius:50%;border:2px solid var(--rail);background:var(--bg)}
|
|
70
|
+
.stg.done .pt{border-color:var(--c);background:var(--c)}
|
|
71
|
+
.stg.cur .pt{border-color:var(--acc);background:var(--bg);box-shadow:0 0 0 3px color-mix(in srgb,var(--acc) 25%,transparent),0 0 10px var(--acc)}
|
|
72
|
+
.stg .line1{display:flex;align-items:center;gap:8px;min-height:18px}
|
|
73
|
+
.stg .w{font-weight:600}.stg.todo .w{color:var(--dim);font-weight:500}
|
|
74
|
+
.stg .meta{margin-left:auto;color:var(--dim);font-size:12px}
|
|
75
|
+
.detail{margin-top:8px;padding:8px 11px;border-radius:10px;border:1px solid color-mix(in srgb,var(--faint) 85%,transparent);background:color-mix(in srgb,var(--bg2) 60%,transparent);display:flex;flex-direction:column;gap:3px}
|
|
76
|
+
.banner{display:flex;align-items:center;gap:8px;margin:14px 0 0;padding:7px 11px;border-radius:10px;color:var(--green);font-weight:700;background:color-mix(in srgb,var(--green) 11%,transparent);border:1px solid color-mix(in srgb,var(--green) 32%,transparent)}
|
|
77
|
+
.banner .dim{font-weight:500}
|
|
78
|
+
.usage{margin-top:auto;padding-top:14px;border-top:1px solid color-mix(in srgb,var(--faint) 75%,transparent);display:flex;flex-direction:column;gap:6px;font-size:12px;color:var(--dim)}
|
|
79
|
+
.ub{display:grid;grid-template-columns:3.2em 1fr 3.4em;align-items:center;gap:10px}.ub .pct{text-align:right;color:var(--ink);font-weight:600}
|
|
80
|
+
.track{height:5px;border-radius:3px;background:var(--faint);overflow:hidden}.track i{display:block;height:100%;border-radius:3px}
|
|
81
|
+
.hero{text-align:center;padding:36px 0 10px}.flame{font-size:40px;filter:drop-shadow(0 0 16px rgba(255,99,55,.45))}
|
|
82
|
+
.herot{font-weight:700;font-size:15px;margin-top:8px}.heros{color:var(--dim);margin:6px 0 14px}
|
|
83
|
+
.examples{display:flex;flex-direction:column;align-items:center;gap:6px}
|
|
84
|
+
@media (prefers-reduced-motion:reduce){.lc,.lc *{animation:none!important}.sweep,.comet{display:none}}
|
|
85
|
+
</style></head>
|
|
86
|
+
<body><div id="card" class="lc is-idle" role="status" aria-live="polite"><div class="head"><span class="brand">🔥 LIT</span><span class="j">·</span><span class="name dim">starting…</span></div></div>
|
|
87
|
+
<script>
|
|
88
|
+
(function(){
|
|
89
|
+
var STATUS_TOOL="lit_card_status";
|
|
90
|
+
var FAST=1500,SLOW=5000,IDLE=15000,MAX_BACKOFF=30000;
|
|
91
|
+
var root=document.documentElement,card=document.getElementById("card");
|
|
92
|
+
var status=null,thread=null,timer=null,ticker=null,failures=0,idleSince=Date.now(),bridge=null,hostMode=null;
|
|
93
|
+
var nextId=1,pending={};
|
|
94
|
+
|
|
95
|
+
function el(tag,cls,text){var n=document.createElement(tag);if(cls)n.className=cls;if(text!=null)n.textContent=String(text);return n;}
|
|
96
|
+
function add(parent){for(var i=1;i<arguments.length;i++){var c=arguments[i];if(c!=null)parent.appendChild(typeof c==="string"?document.createTextNode(c):c);}return parent;}
|
|
97
|
+
function joiner(){return el("span","j","·");}
|
|
98
|
+
|
|
99
|
+
/* linear-RGB mixing, so the flame → pink → accent ramp keeps its brightness */
|
|
100
|
+
function hex(c){c=c.trim().replace("#","");return[0,2,4].map(function(i){return parseInt(c.substr(i,2),16)/255;});}
|
|
101
|
+
function lin(v){return v<=0.04045?v/12.92:Math.pow((v+0.055)/1.055,2.4);}
|
|
102
|
+
function gam(v){return v<=0.0031308?v*12.92:1.055*Math.pow(v,1/2.4)-0.055;}
|
|
103
|
+
function mix(a,b,t){var x=hex(a),y=hex(b);return"#"+x.map(function(v,i){var m=gam(lin(v)+(lin(y[i])-lin(v))*t);return("0"+Math.round(Math.max(0,Math.min(1,m))*255).toString(16)).slice(-2);}).join("");}
|
|
104
|
+
function token(name){return getComputedStyle(root).getPropertyValue(name)||"#ffffff";}
|
|
105
|
+
function ramp(t){var f=token("--flame"),p=token("--pink"),a=token("--acc");return t<=0.5?mix(f,p,t*2):mix(p,a,(t-0.5)*2);}
|
|
106
|
+
|
|
107
|
+
function clock(ms){var s=Math.max(0,Math.floor(ms/1000));return Math.floor(s/60)+":"+("0"+(s%60)).slice(-2);}
|
|
108
|
+
function span(ms){var s=Math.max(1,Math.round(ms/1000));if(s<60)return s+"s";var m=Math.floor(s/60);if(m<60)return s%60?m+"m "+(s%60)+"s":m+"m";return Math.floor(m/60)+"h "+(m%60)+"m";}
|
|
109
|
+
function since(t){var n=el("span","dim el","· "+clock(Date.now()-t));n.setAttribute("data-since",String(t));return n;}
|
|
110
|
+
function pane(){var m=(window.openai&&window.openai.displayMode)||hostMode;return m==="fullscreen"||m==="pip";}
|
|
111
|
+
|
|
112
|
+
function bar(done,total){
|
|
113
|
+
var cells=Math.min(total,10),filled=total===0?0:Math.round(done/total*cells);
|
|
114
|
+
if(done>0&&filled===0)filled=1;if(done<total&&filled===cells)filled=cells-1;
|
|
115
|
+
var b=el("span","bar");
|
|
116
|
+
for(var i=0;i<cells;i++){var s=el("i","seg"+(i<filled?"":" off"));if(i<filled)s.style.background=mix(token("--pink"),token("--acc"),cells<=1?0:i/(cells-1));b.appendChild(s);}
|
|
117
|
+
return b;
|
|
118
|
+
}
|
|
119
|
+
function useColor(p){return p>=90?token("--red"):p>=70?token("--amber"):null;}
|
|
120
|
+
function mini(p){var b=el("span","mini"),on=Math.round(p/10),warn=useColor(p);for(var i=0;i<10;i++){var c=el("i");if(i<on)c.style.background=warn||mix(token("--pink"),token("--acc"),i/9);b.appendChild(c);}return b;}
|
|
121
|
+
function spinner(soft){
|
|
122
|
+
var ns="http://www.w3.org/2000/svg",svg=document.createElementNS(ns,"svg");
|
|
123
|
+
svg.setAttribute("class","spin"+(soft?" soft":""));svg.setAttribute("viewBox","0 0 16 16");svg.setAttribute("width","12");svg.setAttribute("height","12");svg.setAttribute("aria-hidden","true");
|
|
124
|
+
var c=document.createElementNS(ns,"circle");
|
|
125
|
+
[["cx","8"],["cy","8"],["r","5.6"],["fill","none"],["stroke","currentColor"],["stroke-width","2.2"],["stroke-dasharray","24 11.2"],["stroke-linecap","round"]].forEach(function(a){c.setAttribute(a[0],a[1]);});
|
|
126
|
+
svg.appendChild(c);return svg;
|
|
127
|
+
}
|
|
128
|
+
function currentCell(map){if(!map)return null;for(var i=0;i<map.cells.length;i++)if(map.cells[i].state==="current")return map.cells[i];return null;}
|
|
129
|
+
function progressOf(map){if(!map)return null;for(var i=0;i<map.cells.length;i++)if(map.cells[i].progress)return map.cells[i].progress;return null;}
|
|
130
|
+
function doneWord(s){return progressOf(s.map)?"COMPLETE":"DONE";}
|
|
131
|
+
function took(s){if(s.turnEndedAt)return s.turnEndedAt-(s.turnStartedAt||s.ignitedAt||s.turnEndedAt);return (s.lastStepAt||s.now)-s.ignitedAt;}
|
|
132
|
+
|
|
133
|
+
/* what LIT is doing now: the running tool, the turn's own time, or that it waits */
|
|
134
|
+
function liveNode(s){
|
|
135
|
+
var n=el("span","live");
|
|
136
|
+
if(s.step){add(n,spinner(false),el("span","tool",s.step.tool),since(s.step.startedAt));return n;}
|
|
137
|
+
if(s.state==="complete"){n.className="live done";add(n,"✓ ",el("span",null,doneWord(s)==="DONE"?"turn done":"all done"));if(s.ignitedAt)add(n,el("span","dim","in "+span(took(s))));return n;}
|
|
138
|
+
if(s.state==="ignited"&&s.working){add(n,spinner(true),el("span","dim","thinking"));if(s.turnStartedAt)n.appendChild(since(s.turnStartedAt));if(s.lastTool)add(n,el("span","dim","· last"),el("span","acc","▸"),el("span","last",s.lastTool));return n;}
|
|
139
|
+
if(s.state==="ignited"){add(n,el("span","dim","◦ waiting for you"));return n;}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
function head(s){
|
|
143
|
+
var h=el("div","head"),b=el("span","brand");add(b,el("span","sweep"),"🔥 LIT");add(h,b,joiner());
|
|
144
|
+
if(s.state==="ready"){add(h,el("span","name dim","ready"),el("span","right dim","idle"));return h;}
|
|
145
|
+
add(h,el("span","name acc",s.mode||"lit"));
|
|
146
|
+
if(s.state==="complete"){add(h,el("span","right ok",doneWord(s)+" ✓"));return h;}
|
|
147
|
+
var cur=currentCell(s.map),r=el("span","right acc",cur?(cur.label||cur.word.toUpperCase()):"IGNITED");if(s.working)r.appendChild(el("i","dot"));add(h,r);return h;
|
|
148
|
+
}
|
|
149
|
+
function pillExtra(c){var l=(c.label||"").toLowerCase(),w=c.word.toLowerCase();if(!l||l===w)return"";return l.indexOf(w+" ")===0?l.slice(w.length+1):l;}
|
|
150
|
+
function stageWord(c){var w=c.word;if(c.state==="done"&&c.label)w+=" "+c.label;else if(c.progress&&c.state!=="current")w+=" "+c.progress.done+"/"+c.progress.total;return w;}
|
|
151
|
+
function mapRow(s){
|
|
152
|
+
var m=el("div","map"),cells=s.map.cells,n=cells.length,lastColor=null;
|
|
153
|
+
cells.forEach(function(c,i){
|
|
154
|
+
var color=ramp(n<=1?0:i/(n-1)),cur=c.state==="current"&&s.state!=="complete";
|
|
155
|
+
if(i>0){
|
|
156
|
+
var r=el("span","rail");
|
|
157
|
+
if((c.state==="done"||c.state==="partial")&&cells[i-1].state!=="pending")r.style.background="linear-gradient(90deg,"+(lastColor||color)+","+color+")";
|
|
158
|
+
else if(cur){r.style.background="linear-gradient(90deg,"+(lastColor||token("--acc"))+","+token("--acc")+")";r.appendChild(el("i","comet"));}
|
|
159
|
+
else if(cells[i-1].state==="current"&&s.state!=="complete"){r.className="rail lead";r.appendChild(el("i","headfill"));}
|
|
160
|
+
m.appendChild(r);
|
|
161
|
+
}
|
|
162
|
+
if(cur){
|
|
163
|
+
var p=el("span","st nowpill");add(p,el("span","sweep"),c.word);var extra=pillExtra(c);if(extra)add(p,el("b",null,extra));if(c.progress)add(p,el("b",null,c.progress.done+"/"+c.progress.total));m.appendChild(p);lastColor=token("--acc");
|
|
164
|
+
}else if(c.state==="pending"){var t=el("span","st todo",c.word);t.appendChild(el("em",null,"·"));m.appendChild(t);}
|
|
165
|
+
else{var d=el("span","st done",stageWord(c));d.style.color=color;d.appendChild(el("em",null,c.state==="partial"?"…":"✓"));m.appendChild(d);lastColor=color;}
|
|
166
|
+
});
|
|
167
|
+
return m;
|
|
168
|
+
}
|
|
169
|
+
/* the task line: progress and next on the left, the live step on the right; just the live step otherwise */
|
|
170
|
+
function taskRow(s){
|
|
171
|
+
var row=el("div","row"),prog=progressOf(s.map),next=s.map&&s.map.next;
|
|
172
|
+
if(prog||next){
|
|
173
|
+
var left=el("span","tl");add(left,el("span","dim","└"));
|
|
174
|
+
if(prog)add(left,el("span","dim","task"),el("b",null,prog.done+"/"+prog.total),bar(prog.done,prog.total));
|
|
175
|
+
if(next){if(prog)left.appendChild(joiner());add(left,el("span","dim","next"),el("span","acc","▸"),el("span","nx",next));}
|
|
176
|
+
add(row,left,liveNode(s));return row;
|
|
177
|
+
}
|
|
178
|
+
add(row,el("span","dim","└"),liveNode(s));return row;
|
|
179
|
+
}
|
|
180
|
+
function useItems(s){
|
|
181
|
+
var u=s.usage||{},items=[];
|
|
182
|
+
[["ctx",u.ctx],["5h",u.fiveHour],["1w",u.week]].forEach(function(x){if(typeof x[1]==="number")items.push(x);});
|
|
183
|
+
return items;
|
|
184
|
+
}
|
|
185
|
+
function foot(s){
|
|
186
|
+
var f=el("div","foot");
|
|
187
|
+
useItems(s).forEach(function(x){var u=el("span","use");add(u,x[0],mini(x[1]),el("b",null,x[1]+"%"));var w=useColor(x[1]);if(w)u.lastChild.style.color=w;f.appendChild(u);});
|
|
188
|
+
if(s.branch){var g=el("span","use");add(g,"git",el("b",null,s.branch));f.appendChild(g);}
|
|
189
|
+
if(s.workspace)f.appendChild(el("span","ws",s.workspace));
|
|
190
|
+
return f.childNodes.length?f:null;
|
|
191
|
+
}
|
|
192
|
+
function timeline(s){
|
|
193
|
+
var t=el("div","tline"),cells=s.map.cells,n=cells.length;
|
|
194
|
+
cells.forEach(function(c,i){
|
|
195
|
+
var color=ramp(n<=1?0:i/(n-1)),cur=c.state==="current"&&s.state!=="complete",todo=c.state==="pending";
|
|
196
|
+
var g=el("div","stg "+(cur?"cur":todo?"todo":"done"));g.style.setProperty("--c",color);
|
|
197
|
+
var nextCell=cells[i+1];if(!todo&&!cur&&nextCell&&nextCell.state!=="pending")g.style.setProperty("--line",color);
|
|
198
|
+
var l1=el("div","line1"),w;
|
|
199
|
+
if(cur){w=el("span","st nowpill");add(w,el("span","sweep"),c.label||c.word.toUpperCase());}
|
|
200
|
+
else{w=el("span","w",c.word);if(!todo)w.style.color=color;}
|
|
201
|
+
var meta=el("span","meta");if(c.progress)meta.textContent=c.progress.done+"/"+c.progress.total;else if(!todo&&!cur)meta.textContent=c.label?c.label+" ✓":"✓";
|
|
202
|
+
add(l1,w,meta);add(g,el("span","pt"),l1);
|
|
203
|
+
if(cur){
|
|
204
|
+
var d=el("div","detail"),prog=c.progress;
|
|
205
|
+
if(prog){var r1=el("div","row");add(r1,el("span","dim","tasks"),el("b",null,prog.done+"/"+prog.total),bar(prog.done,prog.total));d.appendChild(r1);}
|
|
206
|
+
if(s.map.next){var r2=el("div","row");add(r2,el("span","dim","next"),el("span","acc","▸"),el("span","nx",s.map.next));d.appendChild(r2);}
|
|
207
|
+
var r3=el("div","row"),live=liveNode(s);if(live){r3.appendChild(live);d.appendChild(r3);}
|
|
208
|
+
g.appendChild(d);
|
|
209
|
+
}
|
|
210
|
+
t.appendChild(g);
|
|
211
|
+
});
|
|
212
|
+
return t;
|
|
213
|
+
}
|
|
214
|
+
function usageBlock(s){
|
|
215
|
+
var items=useItems(s);if(!items.length&&!s.branch&&!s.workspace)return null;
|
|
216
|
+
var u=el("div","usage");
|
|
217
|
+
items.forEach(function(x){var r=el("div","ub"),tr=el("span","track"),fill=el("i"),w=useColor(x[1]);fill.style.width=x[1]+"%";fill.style.background=w||"linear-gradient(90deg,"+token("--pink")+","+token("--acc")+")";tr.appendChild(fill);var pct=el("span","pct",x[1]+"%");if(w)pct.style.color=w;add(r,el("span",null,x[0]),tr,pct);u.appendChild(r);});
|
|
218
|
+
var g=el("div","row");if(s.branch)add(g,"git",el("b",null,s.branch));if(s.workspace){if(s.branch)g.appendChild(joiner());g.appendChild(el("span",null,s.workspace));}
|
|
219
|
+
if(g.childNodes.length)u.appendChild(g);
|
|
220
|
+
return u;
|
|
221
|
+
}
|
|
222
|
+
function renderInline(s){
|
|
223
|
+
card.appendChild(head(s));
|
|
224
|
+
if(s.state==="ready"){var hint=el("div","row");add(hint,el("span","dim","no LIT skill yet"),joiner(),el("span","dim","type"),el("kbd",null,"lit <task>"),el("span","dim","to start one"));hint.style.marginTop="6px";card.appendChild(hint);return;}
|
|
225
|
+
if(s.map)card.appendChild(mapRow(s));else card.appendChild(el("div","map"));
|
|
226
|
+
card.appendChild(taskRow(s));
|
|
227
|
+
var f=foot(s);if(f){card.appendChild(f);var ws=f.querySelector(".ws");if(ws&&ws.scrollWidth>ws.clientWidth+1)f.removeChild(ws);}
|
|
228
|
+
}
|
|
229
|
+
function renderPane(s){
|
|
230
|
+
card.appendChild(head(s));
|
|
231
|
+
if(s.state==="ready"){
|
|
232
|
+
var hero=el("div","hero"),hs=el("div","heros");add(hs,"type ",el("kbd",null,"lit <task>")," in this thread to start one");
|
|
233
|
+
var ex=el("div","examples");["lit add a --shout flag","lit plan the release note","lit-loop fix the parser"].forEach(function(t){ex.appendChild(el("kbd",null,t));});
|
|
234
|
+
add(hero,el("div","flame","🔥"),el("div","herot","no LIT skill yet"),hs,ex);card.appendChild(hero);
|
|
235
|
+
}else{
|
|
236
|
+
if(s.state==="complete"){var prog=progressOf(s.map),bn=el("div","banner",doneWord(s)+" ✓");if(prog)add(bn,el("span","dim",prog.done+"/"+prog.total+" tasks"));if(s.ignitedAt)add(bn,el("span","dim","· "+span(took(s))));card.appendChild(bn);}
|
|
237
|
+
if(s.map)card.appendChild(timeline(s));else{var r=el("div","row");r.style.marginTop="14px";add(r,liveNode(s));card.appendChild(r);}
|
|
238
|
+
}
|
|
239
|
+
var u=usageBlock(s);if(u)card.appendChild(u);
|
|
240
|
+
}
|
|
241
|
+
function render(){
|
|
242
|
+
var s=status;if(!s)return;
|
|
243
|
+
var p=pane();root.classList.toggle("pane",p);
|
|
244
|
+
card.className="lc"+(s.state==="complete"?" is-done":s.state==="ready"?" is-idle":"");
|
|
245
|
+
card.textContent="";
|
|
246
|
+
if(p)renderPane(s);else renderInline(s);
|
|
247
|
+
reportSize();
|
|
248
|
+
}
|
|
249
|
+
function tick(){
|
|
250
|
+
if(ticker){clearInterval(ticker);ticker=null;}
|
|
251
|
+
if(document.hidden||!card.querySelector("[data-since]"))return;
|
|
252
|
+
ticker=setInterval(function(){var n=card.querySelectorAll("[data-since]");for(var i=0;i<n.length;i++)n[i].textContent="· "+clock(Date.now()-Number(n[i].getAttribute("data-since")));},1000);
|
|
253
|
+
}
|
|
254
|
+
function accept(s){
|
|
255
|
+
if(!s||s.version!==1)return;
|
|
256
|
+
status=s;if(s.thread)thread=s.thread;
|
|
257
|
+
if(s.working)idleSince=Date.now();
|
|
258
|
+
render();tick();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/* host bridge: window.openai when present, else MCP Apps JSON-RPC over postMessage */
|
|
262
|
+
function rpc(method,params){return new Promise(function(resolve,reject){var id=nextId++;pending[id]={resolve:resolve,reject:reject};window.parent.postMessage({jsonrpc:"2.0",id:id,method:method,params:params},"*");setTimeout(function(){if(pending[id]){delete pending[id];reject(new Error(method+" timed out"));}},5000);});}
|
|
263
|
+
window.addEventListener("message",function(ev){
|
|
264
|
+
var m=ev.data;if(ev.source!==window.parent||!m||m.jsonrpc!=="2.0")return;
|
|
265
|
+
if(m.id!=null&&pending[m.id]){var p=pending[m.id];delete pending[m.id];if(m.error)p.reject(m.error);else p.resolve(m.result);return;}
|
|
266
|
+
if(m.method==="ui/notifications/tool-result"&&m.params)accept(m.params.structuredContent);
|
|
267
|
+
if(m.method==="ui/notifications/host-context-changed"&&m.params){if(m.params.displayMode)hostMode=m.params.displayMode;applyTheme(m.params.theme||null);}
|
|
268
|
+
});
|
|
269
|
+
window.addEventListener("openai:set_globals",function(){if(window.openai){applyTheme(window.openai.theme);if(window.openai.toolOutput&&!status)accept(window.openai.toolOutput);else render();}});
|
|
270
|
+
function callStatus(){
|
|
271
|
+
var args=thread?{thread_id:thread}:{};
|
|
272
|
+
if(bridge==="openai")return window.openai.callTool(STATUS_TOOL,args).then(function(r){return r&&(r.structuredContent||r.result&&r.result.structuredContent);});
|
|
273
|
+
return rpc("tools/call",{name:STATUS_TOOL,arguments:args}).then(function(r){return r&&r.structuredContent;});
|
|
274
|
+
}
|
|
275
|
+
var lastHeight=0;
|
|
276
|
+
function reportSize(){
|
|
277
|
+
if(pane())return;
|
|
278
|
+
var h=Math.ceil(card.getBoundingClientRect().height)+2;if(h===lastHeight)return;lastHeight=h;
|
|
279
|
+
if(bridge==="openai"&&typeof window.openai.notifyIntrinsicHeight==="function"){try{window.openai.notifyIntrinsicHeight(h);}catch(e){}}
|
|
280
|
+
else if(bridge==="mcp")window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/size-changed",params:{height:h}},"*");
|
|
281
|
+
}
|
|
282
|
+
function applyTheme(theme){
|
|
283
|
+
var dark=theme?theme==="dark":!(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches);
|
|
284
|
+
root.classList.toggle("light",!dark);if(status)render();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function delay(){
|
|
288
|
+
if(failures>0)return Math.min(MAX_BACKOFF,FAST*Math.pow(2,failures));
|
|
289
|
+
if(status&&status.working)return FAST;
|
|
290
|
+
return Date.now()-idleSince>120000?IDLE:SLOW;
|
|
291
|
+
}
|
|
292
|
+
function schedule(){if(timer)clearTimeout(timer);timer=null;if(!document.hidden)timer=setTimeout(poll,delay());}
|
|
293
|
+
function poll(){
|
|
294
|
+
callStatus().then(function(s){failures=0;accept(s);},function(){failures=Math.min(failures+1,5);}).then(schedule);
|
|
295
|
+
}
|
|
296
|
+
document.addEventListener("visibilitychange",function(){if(document.hidden){if(timer)clearTimeout(timer);timer=null;tick();}else{idleSince=Date.now();tick();poll();}});
|
|
297
|
+
window.addEventListener("resize",function(){if(status)render();});
|
|
298
|
+
|
|
299
|
+
function start(){
|
|
300
|
+
if(window.openai&&typeof window.openai.callTool==="function"){
|
|
301
|
+
bridge="openai";applyTheme(window.openai.theme);if(window.openai.toolOutput)accept(window.openai.toolOutput);poll();return;
|
|
302
|
+
}
|
|
303
|
+
bridge="mcp";applyTheme(null);
|
|
304
|
+
rpc("ui/initialize",{protocolVersion:"2026-01-26",appInfo:{name:"lit-card",version:"1"},appCapabilities:{availableDisplayModes:["inline","fullscreen"]}}).then(function(r){
|
|
305
|
+
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/initialized",params:{}},"*");
|
|
306
|
+
var ctx=r&&r.hostContext;if(ctx&&ctx.displayMode)hostMode=ctx.displayMode;applyTheme(ctx&&ctx.theme||null);poll();
|
|
307
|
+
},function(){poll();});
|
|
308
|
+
}
|
|
309
|
+
if(window.matchMedia)window.matchMedia("(prefers-color-scheme: light)").addEventListener("change",function(){if(!(window.openai&&window.openai.theme))applyTheme(null);});
|
|
310
|
+
start();
|
|
311
|
+
})();
|
|
312
|
+
</script></body></html>
|
|
313
|
+
`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const CARD_TOOL = "lit_card";
|
|
2
|
+
export declare const CARD_STATUS_TOOL = "lit_card_status";
|
|
3
|
+
export declare const CARD_MIME = "text/html;profile=mcp-app";
|
|
4
|
+
/** The card's `ui://` URI. Hosts cache by URI, so it carries a hash of the HTML and changes with it. */
|
|
5
|
+
export declare function cardResourceUri(): string;
|
|
6
|
+
export interface CardContext {
|
|
7
|
+
readonly env: NodeJS.ProcessEnv;
|
|
8
|
+
readonly now: () => number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Answer one parsed JSON-RPC message. Returns the reply, or null for a notification (no `id`). Never
|
|
12
|
+
* throws: a failure inside a handler becomes an internal-error reply.
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleCardMessage(message: unknown, context: CardContext): unknown;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/card-mcp.ts — the JSON-RPC side of the LIT card server (MCP over stdio, no dependencies).
|
|
2
|
+
//
|
|
3
|
+
// Two tools. `lit_card` is for the model: it opens the card (an MCP App: `_meta.ui.resourceUri` plus
|
|
4
|
+
// the `openai/outputTemplate` alias the Codex desktop app also reads) and returns the text map, so a
|
|
5
|
+
// host that draws no card still gets something useful. `lit_card_status` is for the card only
|
|
6
|
+
// (`visibility: ["app"]`, so the model and the terminal never list it); the card polls it with the
|
|
7
|
+
// thread id the host adds to `_meta`. Both are read-only. The module has no side effects at import.
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { CARD_HTML } from "./card-html.js";
|
|
10
|
+
import { cardStatusText, readCardStatus } from "./card-status.js";
|
|
11
|
+
export const CARD_TOOL = "lit_card";
|
|
12
|
+
export const CARD_STATUS_TOOL = "lit_card_status";
|
|
13
|
+
export const CARD_MIME = "text/html;profile=mcp-app";
|
|
14
|
+
const SERVER_INFO = { name: "litcodex", title: "LIT card", version: "1" };
|
|
15
|
+
const PROTOCOL_VERSIONS = new Set(["2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"]);
|
|
16
|
+
const DEFAULT_PROTOCOL = "2025-06-18";
|
|
17
|
+
/** Without a thread id nothing is known about the thread, so the text claims nothing about it. */
|
|
18
|
+
const NO_THREAD_TEXT = "🔥 LIT · the host did not name the thread, so there is no LIT state to show here.";
|
|
19
|
+
let resourceUri = null;
|
|
20
|
+
/** The card's `ui://` URI. Hosts cache by URI, so it carries a hash of the HTML and changes with it. */
|
|
21
|
+
export function cardResourceUri() {
|
|
22
|
+
resourceUri ??= `ui://litcodex/lit-card-${createHash("sha256").update(CARD_HTML).digest("hex").slice(0, 12)}.html`;
|
|
23
|
+
return resourceUri;
|
|
24
|
+
}
|
|
25
|
+
function isRecord(value) {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
function tools() {
|
|
29
|
+
const uri = cardResourceUri();
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
name: CARD_TOOL,
|
|
33
|
+
title: "LIT card",
|
|
34
|
+
description: "Opens the live LIT card for this thread: the LIT activation, the workflow map and the step running now. It updates by itself. Call it once per thread, when the LIT activation context asks for it. In a host without cards it returns the same map as text.",
|
|
35
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
36
|
+
annotations: { title: "LIT card", readOnlyHint: true, destructiveHint: false, openWorldHint: false },
|
|
37
|
+
_meta: { ui: { resourceUri: uri, visibility: ["model", "app"] }, "openai/outputTemplate": uri },
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: CARD_STATUS_TOOL,
|
|
41
|
+
title: "LIT card status",
|
|
42
|
+
description: "Current LIT state for the card's thread. Used by the LIT card only.",
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: { thread_id: { type: "string", maxLength: 128 } },
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
annotations: { title: "LIT card status", readOnlyHint: true, destructiveHint: false, openWorldHint: false },
|
|
49
|
+
_meta: { ui: { visibility: ["app"] } },
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
/** The thread id from the host's `_meta` (poll or model call), else the card's own argument. */
|
|
54
|
+
function threadOf(params) {
|
|
55
|
+
const meta = isRecord(params["_meta"]) ? params["_meta"] : {};
|
|
56
|
+
const turn = isRecord(meta["x-codex-turn-metadata"]) ? meta["x-codex-turn-metadata"] : {};
|
|
57
|
+
const args = isRecord(params["arguments"]) ? params["arguments"] : {};
|
|
58
|
+
for (const value of [
|
|
59
|
+
meta["thread_id"],
|
|
60
|
+
meta["threadId"],
|
|
61
|
+
turn["thread_id"],
|
|
62
|
+
turn["session_id"],
|
|
63
|
+
args["thread_id"],
|
|
64
|
+
]) {
|
|
65
|
+
if (typeof value === "string" && value !== "" && value.length <= 128)
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function callTool(params, context) {
|
|
71
|
+
const thread = threadOf(params);
|
|
72
|
+
const status = readCardStatus(thread, context.env, context.now());
|
|
73
|
+
if (params["name"] === CARD_STATUS_TOOL) {
|
|
74
|
+
return { content: [{ type: "text", text: JSON.stringify(status) }], structuredContent: status };
|
|
75
|
+
}
|
|
76
|
+
const text = thread === null ? NO_THREAD_TEXT : cardStatusText(status);
|
|
77
|
+
return { content: [{ type: "text", text }], structuredContent: status };
|
|
78
|
+
}
|
|
79
|
+
function result(id, value) {
|
|
80
|
+
return { jsonrpc: "2.0", id, result: value };
|
|
81
|
+
}
|
|
82
|
+
function failure(id, code, message) {
|
|
83
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Answer one parsed JSON-RPC message. Returns the reply, or null for a notification (no `id`). Never
|
|
87
|
+
* throws: a failure inside a handler becomes an internal-error reply.
|
|
88
|
+
*/
|
|
89
|
+
export function handleCardMessage(message, context) {
|
|
90
|
+
if (!isRecord(message) || message["jsonrpc"] !== "2.0" || typeof message["method"] !== "string") {
|
|
91
|
+
return failure(null, -32600, "invalid request");
|
|
92
|
+
}
|
|
93
|
+
const rawId = message["id"];
|
|
94
|
+
if (rawId === undefined)
|
|
95
|
+
return null;
|
|
96
|
+
const id = typeof rawId === "string" || typeof rawId === "number" ? rawId : null;
|
|
97
|
+
const params = isRecord(message["params"]) ? message["params"] : {};
|
|
98
|
+
try {
|
|
99
|
+
switch (message["method"]) {
|
|
100
|
+
case "initialize": {
|
|
101
|
+
const asked = params["protocolVersion"];
|
|
102
|
+
return result(id, {
|
|
103
|
+
protocolVersion: typeof asked === "string" && PROTOCOL_VERSIONS.has(asked) ? asked : DEFAULT_PROTOCOL,
|
|
104
|
+
capabilities: { tools: {}, resources: {}, extensions: { "io.modelcontextprotocol/ui": {} } },
|
|
105
|
+
serverInfo: SERVER_INFO,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
case "ping":
|
|
109
|
+
return result(id, {});
|
|
110
|
+
case "tools/list":
|
|
111
|
+
return result(id, { tools: tools() });
|
|
112
|
+
case "tools/call":
|
|
113
|
+
if (params["name"] !== CARD_TOOL && params["name"] !== CARD_STATUS_TOOL) {
|
|
114
|
+
return failure(id, -32602, "unknown tool");
|
|
115
|
+
}
|
|
116
|
+
return result(id, callTool(params, context));
|
|
117
|
+
case "resources/list":
|
|
118
|
+
return result(id, { resources: [{ uri: cardResourceUri(), name: "LIT card", mimeType: CARD_MIME }] });
|
|
119
|
+
case "resources/templates/list":
|
|
120
|
+
return result(id, { resourceTemplates: [] });
|
|
121
|
+
case "resources/read":
|
|
122
|
+
if (params["uri"] !== cardResourceUri())
|
|
123
|
+
return failure(id, -32602, "unknown resource");
|
|
124
|
+
return result(id, {
|
|
125
|
+
contents: [
|
|
126
|
+
{
|
|
127
|
+
uri: cardResourceUri(),
|
|
128
|
+
mimeType: CARD_MIME,
|
|
129
|
+
text: CARD_HTML,
|
|
130
|
+
_meta: { ui: { prefersBorder: false } },
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
default:
|
|
135
|
+
return failure(id, -32601, "method not found");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return failure(id, -32603, "internal error");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/card-server.ts — stdio entry of the LIT card MCP server (`.mcp.json` starts it in the plugin folder).
|
|
3
|
+
//
|
|
4
|
+
// The desktop app may start dozens of copies in one launch, so the process does nothing until a request
|
|
5
|
+
// arrives: no state reads, timers, locks, ports or files. It answers newline-delimited JSON-RPC, writes
|
|
6
|
+
// only to stdout, and ends when stdin closes. `LITCODEX_CARD_DEBUG=1` adds one stderr line per request.
|
|
7
|
+
import { createInterface } from "node:readline";
|
|
8
|
+
import { handleCardMessage } from "./card-mcp.js";
|
|
9
|
+
/** Requests are small; a longer line is refused with a parse error instead of being parsed. */
|
|
10
|
+
const MAX_LINE_BYTES = 1_000_000;
|
|
11
|
+
const debug = process.env["LITCODEX_CARD_DEBUG"] === "1";
|
|
12
|
+
const context = { env: process.env, now: () => Date.now() };
|
|
13
|
+
// A host that stops reading ends the conversation; the process leaves instead of crashing on EPIPE.
|
|
14
|
+
process.stdout.on("error", () => process.exit(0));
|
|
15
|
+
const lines = createInterface({ input: process.stdin, crlfDelay: Number.POSITIVE_INFINITY });
|
|
16
|
+
lines.on("line", (line) => {
|
|
17
|
+
if (line.trim() === "")
|
|
18
|
+
return;
|
|
19
|
+
let reply;
|
|
20
|
+
if (Buffer.byteLength(line, "utf8") > MAX_LINE_BYTES) {
|
|
21
|
+
reply = { jsonrpc: "2.0", id: null, error: { code: -32700, message: "request too large" } };
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
try {
|
|
25
|
+
reply = handleCardMessage(JSON.parse(line), context);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
reply = { jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (debug)
|
|
32
|
+
process.stderr.write(`[lit-card] ${line.slice(0, 300)}\n`);
|
|
33
|
+
if (reply !== null)
|
|
34
|
+
process.stdout.write(`${JSON.stringify(reply)}\n`);
|
|
35
|
+
});
|
|
36
|
+
lines.on("close", () => {
|
|
37
|
+
process.exitCode = 0;
|
|
38
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type WorkflowMap } from "./workflow-map.js";
|
|
2
|
+
export interface CardStatus {
|
|
3
|
+
readonly version: 1;
|
|
4
|
+
/** The normalized thread id, so the card can name its thread when the host does not. */
|
|
5
|
+
readonly thread: string | null;
|
|
6
|
+
readonly state: "ready" | "ignited" | "complete";
|
|
7
|
+
readonly mode: string | null;
|
|
8
|
+
readonly ignitedAt: number | null;
|
|
9
|
+
readonly map: WorkflowMap | null;
|
|
10
|
+
readonly step: {
|
|
11
|
+
readonly tool: string;
|
|
12
|
+
readonly startedAt: number;
|
|
13
|
+
} | null;
|
|
14
|
+
readonly lastStepAt: number | null;
|
|
15
|
+
/** The tool that finished last in this turn, named the way the step is. */
|
|
16
|
+
readonly lastTool: string | null;
|
|
17
|
+
/** When the current turn began, so the card can count the turn's time while no tool runs. */
|
|
18
|
+
readonly turnStartedAt: number | null;
|
|
19
|
+
/** When the current turn ended, so a finished turn shows its own length. */
|
|
20
|
+
readonly turnEndedAt: number | null;
|
|
21
|
+
readonly working: boolean;
|
|
22
|
+
/** Percent of the context window and of each quota window in use, from the thread's last token count. */
|
|
23
|
+
readonly usage: Usage | null;
|
|
24
|
+
/** The workspace's checked-out branch, or a short commit when detached. */
|
|
25
|
+
readonly branch: string | null;
|
|
26
|
+
/** Folder name of the workspace only; the full path stays out of the card. */
|
|
27
|
+
readonly workspace: string | null;
|
|
28
|
+
readonly now: number;
|
|
29
|
+
}
|
|
30
|
+
export interface Usage {
|
|
31
|
+
readonly ctx: number | null;
|
|
32
|
+
readonly fiveHour: number | null;
|
|
33
|
+
readonly week: number | null;
|
|
34
|
+
}
|
|
35
|
+
/** The workspace a thread runs in: the hook pointer, else the rollout header; null when unknown. */
|
|
36
|
+
export declare function resolveThreadCwd(threadId: string | null, env: NodeJS.ProcessEnv): string | null;
|
|
37
|
+
/** Context and quota use from the newest token count in a rollout tail; null when there is none. */
|
|
38
|
+
export declare function usageFromRollout(text: string): Usage | null;
|
|
39
|
+
/** A tool name as the card shows it: an MCP tool reads `server · tool` rather than its joined id. */
|
|
40
|
+
export declare function toolDisplayName(tool: string): string;
|
|
41
|
+
export declare function readCardStatus(threadId: string | null, env: NodeJS.ProcessEnv, now?: number): CardStatus;
|
|
42
|
+
/** The card as plain text, for hosts that cannot draw it (the terminal `codex`). */
|
|
43
|
+
export declare function cardStatusText(status: CardStatus): string;
|