@kyun.si/codex-hongguo 0.0.0-stage → 0.0.21
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/.codex-plugin/plugin.json +19 -0
- package/.mcp.json +11 -0
- package/LICENSE +21 -0
- package/README.en.md +131 -0
- package/README.md +129 -2
- package/bin/codex-hongguo.mjs +3 -0
- package/bin/run-node +29 -0
- package/bin/run-node.exe +0 -0
- package/dist/cli/main.mjs +8 -0
- package/dist/hooks/write.mjs +46 -0
- package/dist/server/index.mjs +147 -0
- package/dist/setup/check.mjs +47 -0
- package/dist/ui/player.html +2067 -0
- package/dist/vendor/openhongguo/GO_LICENSE +27 -0
- package/dist/vendor/openhongguo/LICENSE +202 -0
- package/dist/vendor/openhongguo/README.md +283 -0
- package/dist/vendor/openhongguo/dist/openhongguo.wasm +0 -0
- package/dist/vendor/openhongguo/dist/wasm_exec.js +575 -0
- package/dist/vendor/openhongguo/index.d.ts +212 -0
- package/dist/vendor/openhongguo/index.js +297 -0
- package/dist/vendor/openhongguo/package.json +46 -0
- package/dist/vendor/openhongguo/types.d.ts +887 -0
- package/docs/images/codex-hongguo-catalog.png +0 -0
- package/docs/images/codex-hongguo-player.png +0 -0
- package/hooks/hooks.json +40 -0
- package/licenses/@babel-runtime-LICENSE +22 -0
- package/licenses/@hono-node-server-LICENSE +21 -0
- package/licenses/@modelcontextprotocol-ext-apps-LICENSE +216 -0
- package/licenses/@modelcontextprotocol-sdk-LICENSE +21 -0
- package/licenses/@standard-schema-spec-LICENSE +21 -0
- package/licenses/@videojs-vhs-utils-LICENSE +19 -0
- package/licenses/@xmldom-xmldom-LICENSE +8 -0
- package/licenses/PROJECT-NOTICE.txt +1 -0
- package/licenses/accepts-LICENSE +23 -0
- package/licenses/ajv-LICENSE +22 -0
- package/licenses/ajv-formats-LICENSE +21 -0
- package/licenses/body-parser-LICENSE +23 -0
- package/licenses/body-parser-content-type-LICENSE +22 -0
- package/licenses/bytes-LICENSE +23 -0
- package/licenses/call-bind-apply-helpers-LICENSE +21 -0
- package/licenses/call-bound-LICENSE +21 -0
- package/licenses/content-disposition-LICENSE +22 -0
- package/licenses/content-type-LICENSE +22 -0
- package/licenses/cookie-LICENSE +24 -0
- package/licenses/cookie-signature-LICENSE +22 -0
- package/licenses/cors-LICENSE +22 -0
- package/licenses/cross-spawn-LICENSE +21 -0
- package/licenses/debug-LICENSE +20 -0
- package/licenses/depd-LICENSE +22 -0
- package/licenses/dom-walk-LICENCE +19 -0
- package/licenses/dunder-proto-LICENSE +21 -0
- package/licenses/ee-first-LICENSE +22 -0
- package/licenses/encodeurl-LICENSE +22 -0
- package/licenses/es-define-property-LICENSE +21 -0
- package/licenses/es-errors-LICENSE +21 -0
- package/licenses/es-object-atoms-LICENSE +21 -0
- package/licenses/escape-html-LICENSE +24 -0
- package/licenses/etag-LICENSE +22 -0
- package/licenses/eventsource-LICENSE +22 -0
- package/licenses/eventsource-parser-LICENSE +21 -0
- package/licenses/express-LICENSE +24 -0
- package/licenses/express-content-type-LICENSE +22 -0
- package/licenses/express-rate-limit-license +21 -0
- package/licenses/fast-deep-equal-LICENSE +21 -0
- package/licenses/fast-uri-LICENSE +30 -0
- package/licenses/finalhandler-LICENSE +22 -0
- package/licenses/forwarded-LICENSE +22 -0
- package/licenses/fresh-LICENSE +23 -0
- package/licenses/function-bind-LICENSE +20 -0
- package/licenses/get-intrinsic-LICENSE +21 -0
- package/licenses/get-proto-LICENSE +21 -0
- package/licenses/global-LICENSE +19 -0
- package/licenses/gopd-LICENSE +21 -0
- package/licenses/has-symbols-LICENSE +21 -0
- package/licenses/hasown-LICENSE +21 -0
- package/licenses/hls.js-LICENSE +28 -0
- package/licenses/hono-LICENSE +21 -0
- package/licenses/http-errors-LICENSE +23 -0
- package/licenses/iconv-lite-LICENSE +21 -0
- package/licenses/inherits-LICENSE +16 -0
- package/licenses/ip-address-LICENSE +19 -0
- package/licenses/ipaddr.js-LICENSE +19 -0
- package/licenses/is-promise-LICENSE +19 -0
- package/licenses/isexe-LICENSE +15 -0
- package/licenses/jose-LICENSE.md +21 -0
- package/licenses/json-schema-traverse-LICENSE +21 -0
- package/licenses/json-schema-typed-LICENSE.md +57 -0
- package/licenses/m3u8-parser-LICENSE +13 -0
- package/licenses/math-intrinsics-LICENSE +21 -0
- package/licenses/media-typer-LICENSE +22 -0
- package/licenses/merge-descriptors-license +11 -0
- package/licenses/mime-db-LICENSE +23 -0
- package/licenses/mime-types-LICENSE +23 -0
- package/licenses/min-document-LICENCE +19 -0
- package/licenses/mpd-parser-LICENSE +13 -0
- package/licenses/ms-license.md +21 -0
- package/licenses/negotiator-LICENSE +24 -0
- package/licenses/negotiator-content-type-LICENSE +22 -0
- package/licenses/object-assign-license +21 -0
- package/licenses/object-inspect-LICENSE +21 -0
- package/licenses/on-finished-LICENSE +23 -0
- package/licenses/once-LICENSE +15 -0
- package/licenses/openhongguo-LICENSE +202 -0
- package/licenses/parseurl-LICENSE +24 -0
- package/licenses/path-key-license +9 -0
- package/licenses/path-to-regexp-LICENSE +21 -0
- package/licenses/pkce-challenge-LICENSE +21 -0
- package/licenses/process-LICENSE +22 -0
- package/licenses/proxy-addr-LICENSE +22 -0
- package/licenses/qs-LICENSE.md +29 -0
- package/licenses/range-parser-LICENSE +23 -0
- package/licenses/raw-body-LICENSE +22 -0
- package/licenses/require-from-string-license +21 -0
- package/licenses/router-LICENSE +23 -0
- package/licenses/safer-buffer-LICENSE +21 -0
- package/licenses/send-LICENSE +23 -0
- package/licenses/serve-static-LICENSE +25 -0
- package/licenses/setprototypeof-LICENSE +13 -0
- package/licenses/shebang-command-license +9 -0
- package/licenses/shebang-regex-license +9 -0
- package/licenses/side-channel-LICENSE +21 -0
- package/licenses/side-channel-list-LICENSE +21 -0
- package/licenses/side-channel-map-LICENSE +21 -0
- package/licenses/side-channel-weakmap-LICENSE +21 -0
- package/licenses/statuses-LICENSE +23 -0
- package/licenses/toidentifier-LICENSE +21 -0
- package/licenses/type-is-LICENSE +23 -0
- package/licenses/type-is-content-type-LICENSE +22 -0
- package/licenses/unpipe-LICENSE +22 -0
- package/licenses/vary-LICENSE +22 -0
- package/licenses/which-LICENSE +15 -0
- package/licenses/wrappy-LICENSE +15 -0
- package/licenses/zod-LICENSE +21 -0
- package/licenses/zod-to-json-schema-LICENSE +15 -0
- package/package.json +37 -4
- package/skills/hongguo-setup/SKILL.md +16 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {createRequire as __cr} from 'node:module';const require=__cr(import.meta.url);
|
|
2
|
+
var Ve=Object.create;var B=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var Qe=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var O=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var m=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(s){throw e=0,s}};var tt=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ze(e))!et.call(t,n)&&n!==s&&B(t,n,{get:()=>e[n],enumerable:!(r=ze(e,n))||r.enumerable});return t};var st=(t,e,s)=>(s=t!=null?Ve(Qe(t)):{},tt(e||!t||!t.__esModule?B(s,"default",{value:t,enumerable:!0}):s,t));var Q=m((is,Z)=>{Z.exports=z;z.sync=pt;var J=O("fs");function ut(t,e){var s=e.pathExt!==void 0?e.pathExt:process.env.PATHEXT;if(!s||(s=s.split(";"),s.indexOf("")!==-1))return!0;for(var r=0;r<s.length;r++){var n=s[r].toLowerCase();if(n&&t.substr(-n.length).toLowerCase()===n)return!0}return!1}function V(t,e,s){return!t.isSymbolicLink()&&!t.isFile()?!1:ut(e,s)}function z(t,e,s){J.stat(t,function(r,n){s(r,r?!1:V(n,t,e))})}function pt(t,e){return V(J.statSync(t),t,e)}});var ne=m((os,re)=>{re.exports=te;te.sync=Et;var ee=O("fs");function te(t,e,s){ee.stat(t,function(r,n){s(r,r?!1:se(n,e))})}function Et(t,e){return se(ee.statSync(t),e)}function se(t,e){return t.isFile()&<(t,e)}function lt(t,e){var s=t.mode,r=t.uid,n=t.gid,i=e.uid!==void 0?e.uid:process.getuid&&process.getuid(),o=e.gid!==void 0?e.gid:process.getgid&&process.getgid(),a=parseInt("100",8),l=parseInt("010",8),c=parseInt("001",8),E=a|l,u=s&c||s&l&&n===o||s&a&&r===i||s&E&&i===0;return u}});var oe=m((cs,ie)=>{var as=O("fs"),x;process.platform==="win32"||global.TESTING_WINDOWS?x=Q():x=ne();ie.exports=I;I.sync=ft;function I(t,e,s){if(typeof e=="function"&&(s=e,e={}),!s){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(r,n){I(t,e||{},function(i,o){i?n(i):r(o)})})}x(t,e||{},function(r,n){r&&(r.code==="EACCES"||e&&e.ignoreErrors)&&(r=null,n=!1),s(r,n)})}function ft(t,e){try{return x.sync(t,e||{})}catch(s){if(e&&e.ignoreErrors||s.code==="EACCES")return!1;throw s}}});var le=m((ds,Ee)=>{var A=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",ae=O("path"),Tt=A?";":":",ce=oe(),de=t=>Object.assign(new Error(`not found: ${t}`),{code:"ENOENT"}),ue=(t,e)=>{let s=e.colon||Tt,r=t.match(/\//)||A&&t.match(/\\/)?[""]:[...A?[process.cwd()]:[],...(e.path||process.env.PATH||"").split(s)],n=A?e.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",i=A?n.split(s):[""];return A&&t.indexOf(".")!==-1&&i[0]!==""&&i.unshift(""),{pathEnv:r,pathExt:i,pathExtExe:n}},pe=(t,e,s)=>{typeof e=="function"&&(s=e,e={}),e||(e={});let{pathEnv:r,pathExt:n,pathExtExe:i}=ue(t,e),o=[],a=c=>new Promise((E,u)=>{if(c===r.length)return e.all&&o.length?E(o):u(de(t));let d=r[c],p=/^".*"$/.test(d)?d.slice(1,-1):d,f=ae.join(p,t),h=!p&&/^\.[\\\/]/.test(t)?t.slice(0,2)+f:f;E(l(h,c,0))}),l=(c,E,u)=>new Promise((d,p)=>{if(u===n.length)return d(a(E+1));let f=n[u];ce(c+f,{pathExt:i},(h,L)=>{if(!h&&L)if(e.all)o.push(c+f);else return d(c+f);return d(l(c,E,u+1))})});return s?a(0).then(c=>s(null,c),s):a(0)},mt=(t,e)=>{e=e||{};let{pathEnv:s,pathExt:r,pathExtExe:n}=ue(t,e),i=[];for(let o=0;o<s.length;o++){let a=s[o],l=/^".*"$/.test(a)?a.slice(1,-1):a,c=ae.join(l,t),E=!l&&/^\.[\\\/]/.test(t)?t.slice(0,2)+c:c;for(let u=0;u<r.length;u++){let d=E+r[u];try{if(ce.sync(d,{pathExt:n}))if(e.all)i.push(d);else return d}catch{}}}if(e.all&&i.length)return i;if(e.nothrow)return null;throw de(t)};Ee.exports=pe;pe.sync=mt});var Te=m((us,v)=>{"use strict";var fe=(t={})=>{let e=t.env||process.env;return(t.platform||process.platform)!=="win32"?"PATH":Object.keys(e).reverse().find(r=>r.toUpperCase()==="PATH")||"Path"};v.exports=fe;v.exports.default=fe});var Ne=m((ps,_e)=>{"use strict";var me=O("path"),ht=le(),_t=Te();function he(t,e){let s=t.options.env||process.env,r=process.cwd(),n=t.options.cwd!=null,i=n&&process.chdir!==void 0&&!process.chdir.disabled;if(i)try{process.chdir(t.options.cwd)}catch{}let o;try{o=ht.sync(t.command,{path:s[_t({env:s})],pathExt:e?me.delimiter:void 0})}catch{}finally{i&&process.chdir(r)}return o&&(o=me.resolve(n?t.options.cwd:"",o)),o}function Nt(t){return he(t)||he(t,!0)}_e.exports=Nt});var Oe=m((Es,D)=>{"use strict";var C=/([()\][%!^"`<>&|;, *?])/g;function Ot(t){return t=t.replace(C,"^$1"),t}function Rt(t,e){return t=`${t}`,t=t.replace(/(?=(\\+?)?)\1"/g,'$1$1\\"'),t=t.replace(/(?=(\\+?)?)\1$/,"$1$1"),t=`"${t}"`,t=t.replace(C,"^$1"),e&&(t=t.replace(C,"^$1")),t}D.exports.command=Ot;D.exports.argument=Rt});var Se=m((ls,Re)=>{"use strict";Re.exports=/^#!(.*)/});var Ae=m((fs,Le)=>{"use strict";var St=Se();Le.exports=(t="")=>{let e=t.match(St);if(!e)return null;let[s,r]=e[0].replace(/#! ?/,"").split(" "),n=s.split("/").pop();return n==="env"?r:r?`${n} ${r}`:n}});var be=m((Ts,we)=>{"use strict";var P=O("fs"),Lt=Ae();function At(t){let s=Buffer.alloc(150),r;try{r=P.openSync(t,"r"),P.readSync(r,s,0,150,0),P.closeSync(r)}catch{}return Lt(s.toString())}we.exports=At});var Ie=m((ms,ye)=>{"use strict";var wt=O("path"),ge=Ne(),xe=Oe(),bt=be(),gt=process.platform==="win32",xt=/\.(?:com|exe)$/i,yt=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function It(t){t.file=ge(t);let e=t.file&&bt(t.file);return e?(t.args.unshift(t.file),t.command=e,ge(t)):t.file}function vt(t){if(!gt)return t;let e=It(t),s=!xt.test(e);if(t.options.forceShell||s){let r=yt.test(e);t.command=wt.normalize(t.command),t.command=xe.command(t.command),t.args=t.args.map(i=>xe.argument(i,r));let n=[t.command].concat(t.args).join(" ");t.args=["/d","/s","/c",`"${n}"`],t.command=process.env.comspec||"cmd.exe",t.options.windowsVerbatimArguments=!0}return t}function Ct(t,e,s){e&&!Array.isArray(e)&&(s=e,e=null),e=e?e.slice(0):[],s=Object.assign({},s);let r={command:t,args:e,options:s,file:void 0,original:{command:t,args:e}};return s.shell?r:vt(r)}ye.exports=Ct});var De=m((hs,Ce)=>{"use strict";var U=process.platform==="win32";function M(t,e){return Object.assign(new Error(`${e} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${e} ${t.command}`,path:t.command,spawnargs:t.args})}function Dt(t,e){if(!U)return;let s=t.emit;t.emit=function(r,n){if(r==="exit"){let i=ve(n,e);if(i)return s.call(t,"error",i)}return s.apply(t,arguments)}}function ve(t,e){return U&&t===1&&!e.file?M(e.original,"spawn"):null}function Pt(t,e){return U&&t===1&&!e.file?M(e.original,"spawnSync"):null}Ce.exports={hookChildProcess:Dt,verifyENOENT:ve,verifyENOENTSync:Pt,notFoundError:M}});var Me=m((_s,w)=>{"use strict";var Pe=O("child_process"),F=Ie(),H=De();function Ue(t,e,s){let r=F(t,e,s),n=Pe.spawn(r.command,r.args,r.options);return H.hookChildProcess(n,r),n}function Ut(t,e,s){let r=F(t,e,s),n=Pe.spawnSync(r.command,r.args,r.options);return n.error=n.error||H.verifyENOENTSync(n.status,r),n}w.exports=Ue;w.exports.spawn=Ue;w.exports.sync=Ut;w.exports._parse=F;w.exports._enoent=H});import{spawnSync as $t}from"node:child_process";import{DatabaseSync as at}from"node:sqlite";import{mkdirSync as ct}from"node:fs";import{join as dt}from"node:path";import{homedir as rt}from"node:os";import{posix as nt,win32 as it}from"node:path";import{fileURLToPath as ot}from"node:url";var $=ot(new URL("../../",import.meta.url));function j({env:t=process.env,home:e=rt(),platform:s=process.platform}={}){let{join:r}=s==="win32"?it:nt;return t.HONGGUO_DATA_DIR?t.HONGGUO_DATA_DIR:s==="darwin"?r(e,"Library","Application Support","CodexHongguo"):s==="win32"?r(t.LOCALAPPDATA||r(e,"AppData","Local"),"CodexHongguo"):r(t.XDG_DATA_HOME||r(e,".local","share"),"codex-hongguo")}function q(t){return typeof t=="string"&&/^[A-Za-z0-9_-]{1,128}$/.test(t)}function K(t){let e=new Map;for(let{id:s,title:r}of t)if(/^hg-\d{1,32}$/.test(s)&&typeof r=="string"&&r.trim()&&!e.has(s)&&e.set(s,{id:s,title:r}),e.size===48)break;return[...e.values()]}var g=class{constructor(e=j(),s=!1){s||ct(e,{recursive:!0,mode:448}),this.persistent=!s,this.root=e,this.db=new at(s?":memory:":dt(e,"player.sqlite")),this.db.exec(`PRAGMA busy_timeout=250; PRAGMA journal_mode=WAL;
|
|
3
|
+
CREATE TABLE IF NOT EXISTS turn_state (
|
|
4
|
+
session_id TEXT NOT NULL, turn_id TEXT NOT NULL, submitted_at INTEGER,
|
|
5
|
+
stop_kind TEXT, interrupted INTEGER NOT NULL DEFAULT 0, stopped INTEGER NOT NULL DEFAULT 0,
|
|
6
|
+
observed_at INTEGER NOT NULL, revision INTEGER NOT NULL DEFAULT 1, PRIMARY KEY(session_id,turn_id));
|
|
7
|
+
CREATE INDEX IF NOT EXISTS latest_turn ON turn_state(session_id, submitted_at DESC);
|
|
8
|
+
CREATE TABLE IF NOT EXISTS waiting_card (
|
|
9
|
+
session_id TEXT NOT NULL, turn_id TEXT NOT NULL, PRIMARY KEY(session_id,turn_id));
|
|
10
|
+
CREATE TABLE IF NOT EXISTS waiting_dismissal (
|
|
11
|
+
session_id TEXT NOT NULL, turn_id TEXT NOT NULL, PRIMARY KEY(session_id,turn_id));
|
|
12
|
+
CREATE TABLE IF NOT EXISTS recommendation_feed (
|
|
13
|
+
id INTEGER PRIMARY KEY CHECK(id=1), items TEXT NOT NULL, updated_at INTEGER NOT NULL);
|
|
14
|
+
CREATE TABLE IF NOT EXISTS turn_picks (
|
|
15
|
+
session_id TEXT NOT NULL, turn_id TEXT NOT NULL, items TEXT NOT NULL,
|
|
16
|
+
reserved_at INTEGER, shown INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(session_id,turn_id));
|
|
17
|
+
CREATE INDEX IF NOT EXISTS pending_picks ON turn_picks(reserved_at) WHERE shown=0;
|
|
18
|
+
CREATE TABLE IF NOT EXISTS pick_exposure (series_id TEXT PRIMARY KEY, last_shown INTEGER NOT NULL);
|
|
19
|
+
CREATE TABLE IF NOT EXISTS visible_player (
|
|
20
|
+
session_id TEXT NOT NULL, instance TEXT NOT NULL, seen_at INTEGER NOT NULL,
|
|
21
|
+
PRIMARY KEY(session_id,instance));
|
|
22
|
+
CREATE TABLE IF NOT EXISTS player_onboarding (
|
|
23
|
+
id INTEGER PRIMARY KEY CHECK(id=1), dismissed INTEGER NOT NULL);
|
|
24
|
+
CREATE TABLE IF NOT EXISTS watch_progress (
|
|
25
|
+
series_id TEXT NOT NULL, episode_id TEXT NOT NULL, title TEXT NOT NULL, label TEXT NOT NULL,
|
|
26
|
+
position_ms INTEGER NOT NULL, duration_ms INTEGER NOT NULL, updated_at INTEGER NOT NULL,
|
|
27
|
+
PRIMARY KEY(series_id,episode_id));
|
|
28
|
+
CREATE TABLE IF NOT EXISTS watch_restart (
|
|
29
|
+
series_id TEXT NOT NULL, episode_id TEXT NOT NULL, PRIMARY KEY(series_id,episode_id));`),this.db.prepare("PRAGMA user_version").get().user_version===0&&this.db.exec(`BEGIN IMMEDIATE;
|
|
30
|
+
DELETE FROM watch_progress WHERE series_id IN ('tide','ridge');
|
|
31
|
+
PRAGMA user_version=1;
|
|
32
|
+
COMMIT;`)}preferences(){this.db.exec("CREATE TABLE IF NOT EXISTS player_preferences(id INTEGER PRIMARY KEY, body TEXT NOT NULL)");let e=this.db.prepare("SELECT body FROM player_preferences WHERE id=1").get(),s={autoPrompt:!0,autoplayNext:!0,autoPauseOnFinish:!0,autoPlayOnStart:!0,searchTerms:["\u603B\u88C1","\u91CD\u751F","\u9006\u88AD"]};return e?{...s,...JSON.parse(e.body)}:s}setupDismissed(){return this.db.prepare("SELECT dismissed FROM player_onboarding WHERE id=1").get()?.dismissed===1}setSetupDismissed(e){return this.db.prepare("INSERT OR REPLACE INTO player_onboarding VALUES(1,?)").run(Number(e)),{dismissed:e}}setPreferences(e){return this.transaction(()=>{let s=this.preferences(),r={...s,...e};return this.db.prepare("INSERT OR REPLACE INTO player_preferences VALUES(1,?)").run(JSON.stringify(r)),JSON.stringify(s.searchTerms)!==JSON.stringify(r.searchTerms)&&this.db.exec("DELETE FROM recommendation_feed"),r})}event({session_id:e,turn_id:s,hook_event_name:r},n=Date.now()){if(!q(e)||!q(s)||!["UserPromptSubmit","Stop","Interrupt"].includes(r))return;let i=+(r==="Stop"),o=+(r==="Interrupt");return this.db.prepare(`INSERT INTO turn_state(session_id,turn_id,submitted_at,stop_kind,stopped,interrupted,observed_at)
|
|
33
|
+
VALUES(?,?,?,?,?,?,?) ON CONFLICT(session_id,turn_id) DO UPDATE SET
|
|
34
|
+
submitted_at=COALESCE(submitted_at,CASE WHEN excluded.submitted_at IS NOT NULL THEN min(observed_at,excluded.submitted_at) END),
|
|
35
|
+
stop_kind=COALESCE(excluded.stop_kind,stop_kind), stopped=max(stopped,excluded.stopped),
|
|
36
|
+
interrupted=max(interrupted,excluded.interrupted), observed_at=excluded.observed_at, revision=revision+1
|
|
37
|
+
WHERE (submitted_at IS NULL AND excluded.submitted_at IS NOT NULL) OR
|
|
38
|
+
stopped<excluded.stopped OR interrupted<excluded.interrupted`).run(e,s,i||o?null:n,i||o?r:null,i,o,n).changes>0}activeTurn(e,s){let r=this.state(e);return this.persistent&&!!s&&r.turnId===s&&r.state==="submitted"}offerable(e,s){return this.activeTurn(e,s)&&this.preferences().autoPrompt&&!this.picksDismissed(e,s)&&!this.db.prepare("SELECT 1 FROM visible_player WHERE session_id=? AND seen_at>? LIMIT 1").get(e,Date.now()-6500)}picksDismissed(e,s){return!!this.db.prepare("SELECT 1 FROM waiting_dismissal WHERE session_id=? AND turn_id=?").get(e,s)}dismissPicks(e,s){return this.db.prepare("INSERT OR IGNORE INTO waiting_dismissal VALUES(?,?)").run(e,s),{dismissed:!0}}transaction(e){this.db.exec("BEGIN IMMEDIATE");try{let s=e();return this.db.exec("COMMIT"),s}catch(s){throw this.db.exec("ROLLBACK"),s}}claimCard(e,s){return this.transaction(()=>this.offerable(e,s)&&this.db.prepare("INSERT OR IGNORE INTO waiting_card VALUES(?,?)").run(e,s).changes===1)}playerVisible(e,s,r){if(!e)return;let n=Date.now();r?(this.db.prepare("DELETE FROM visible_player WHERE seen_at<=?").run(n-6500),this.db.prepare("INSERT OR REPLACE INTO visible_player VALUES(?,?,?)").run(e,s,n)):this.db.prepare("DELETE FROM visible_player WHERE session_id=? AND instance=?").run(e,s)}touchPlayer(e,s){e&&s&&this.db.prepare("UPDATE visible_player SET seen_at=? WHERE session_id=? AND instance=? AND seen_at<?").run(Date.now(),e,s,Date.now()-1800)}waitingFeed(e=!1){let s=this.db.prepare("SELECT items, updated_at FROM recommendation_feed WHERE id=1").get();return s&&!e&&s.updated_at<=Date.now()-15*6e4?[]:s?JSON.parse(s.items):[]}saveWaitingFeed(e){let s=K(e);return s.length&&this.db.prepare("INSERT OR REPLACE INTO recommendation_feed VALUES(1,?,?)").run(JSON.stringify(s),Date.now()),s}turnPicks(e,s){let r=this.db.prepare("SELECT items FROM turn_picks WHERE session_id=? AND turn_id=?").get(e,s);return r?JSON.parse(r.items):[]}allocatePicks(e,s,r,n,i,o){return this.transaction(()=>{if(!o())return[];let a=this.turnPicks(e,s);if(a.length)return a;let l=new Set,c=this.db.prepare("SELECT session_id,turn_id,items FROM turn_picks WHERE shown=0 AND reserved_at>?");for(let d of c.all(Date.now()-15e3))if(this.activeTurn(d.session_id,d.turn_id))for(let p of JSON.parse(d.items))p.episodeId||l.add(p.id);let E=this.db.prepare(`SELECT c.value->>'id' AS id, c.value->>'title' AS title
|
|
39
|
+
FROM json_each(?) c LEFT JOIN pick_exposure e ON e.series_id=c.value->>'id'
|
|
40
|
+
WHERE NOT EXISTS (SELECT 1 FROM watch_progress w WHERE w.series_id=c.value->>'id' AND
|
|
41
|
+
(w.position_ms>0 OR (w.series_id,w.episode_id) IN (SELECT series_id,episode_id FROM watch_restart)))
|
|
42
|
+
ORDER BY e.last_shown, c.key`).all(JSON.stringify(K(n))).map(({id:d,title:p})=>({id:d,title:p}));E.sort((d,p)=>Number(l.has(d.id))-Number(l.has(p.id)));let u=r?[r,...E.filter(d=>d.id!==r.id).slice(0,2)]:E.slice(0,3);return u.length&&this.db.prepare("INSERT INTO turn_picks(session_id,turn_id,items,reserved_at) VALUES(?,?,?,?)").run(e,s,JSON.stringify(u),i?Date.now():null),u})}markPicksShown(e,s,r){return this.transaction(()=>{let n=r()&&this.db.prepare("UPDATE turn_picks SET shown=1 WHERE session_id=? AND turn_id=? AND shown=0 RETURNING items").get(e,s);if(n){let i=this.db.prepare("SELECT coalesce(max(last_shown),0)+1 AS n FROM pick_exposure").get().n,o=this.db.prepare("INSERT OR REPLACE INTO pick_exposure(series_id,last_shown) VALUES(?,?)");for(let a of JSON.parse(n.items))a.episodeId||o.run(a.id,i)}return{recorded:!!n}})}state(e,s){let r=e&&(s?this.db.prepare("SELECT * FROM turn_state WHERE session_id=? AND turn_id=?").get(e,s):this.db.prepare("SELECT * FROM turn_state WHERE session_id=? ORDER BY (submitted_at IS NOT NULL) DESC,coalesce(submitted_at,observed_at) DESC,rowid DESC LIMIT 1").get(e));if(!r)return{sessionId:null,turnId:null,state:"unknown",revision:0,observedAt:null};let n=r.interrupted?"interrupted":r.stopped?"stopped":"submitted";return{sessionId:r.session_id,turnId:r.turn_id,state:n,revision:r.revision,observedAt:r.observed_at}}candidates(){return this.db.prepare("SELECT session_id, max(observed_at) AS at FROM turn_state GROUP BY session_id ORDER BY at DESC LIMIT 8").all()}save({seriesId:e,episodeId:s,title:r,label:n,positionMs:i,durationMs:o,reset:a=!1}){return i<=0&&!a?{saved:!1}:this.transaction(()=>(i===0?this.db.prepare("INSERT OR IGNORE INTO watch_restart VALUES(?,?)").run(e,s):this.db.prepare("DELETE FROM watch_restart WHERE series_id=? AND episode_id=?").run(e,s),this.db.prepare(`INSERT INTO watch_progress VALUES(?,?,?,?,?,?,max(?,coalesce((SELECT max(updated_at)+1 FROM watch_progress),0))) ON CONFLICT(series_id,episode_id) DO UPDATE SET
|
|
43
|
+
title=excluded.title,label=excluded.label,position_ms=excluded.position_ms,duration_ms=excluded.duration_ms,updated_at=excluded.updated_at`).run(e,s,r,n,Math.min(i,o),o,Date.now()),{saved:!0}))}history(e,s,r=30){let n="series_id AS seriesId,episode_id AS episodeId,title,label,position_ms AS positionMs,duration_ms AS durationMs,updated_at AS updatedAt",i="(position_ms>0 OR (series_id,episode_id) IN (SELECT series_id,episode_id FROM watch_restart))";return e&&s?this.db.prepare("SELECT "+n+" FROM watch_progress WHERE series_id=? AND episode_id=? AND "+i).all(e,s):e?this.db.prepare("SELECT "+n+" FROM watch_progress WHERE series_id=? AND "+i+" ORDER BY updated_at DESC,rowid DESC LIMIT 1").all(e):this.db.prepare("SELECT "+n+` FROM (SELECT *, row_number() OVER(PARTITION BY series_id ORDER BY updated_at DESC,rowid DESC) AS rank
|
|
44
|
+
FROM watch_progress WHERE ${i} AND series_id GLOB 'hg-*' AND episode_id GLOB 'hg-*')
|
|
45
|
+
WHERE rank=1 ORDER BY updated_at DESC LIMIT ?`).all(r)}removeHistory(e){return this.transaction(()=>(this.db.prepare("DELETE FROM watch_progress WHERE series_id=?").run(e),this.db.prepare("DELETE FROM watch_restart WHERE series_id=?").run(e),{removed:!0}))}writable(){if(!this.persistent)return!1;try{return this.db.exec("UPDATE watch_progress SET updated_at=updated_at WHERE 0"),!0}catch{return!1}}close(){this.db.close()}};import{realpathSync as Xt}from"node:fs";import{relative as Wt,resolve as Yt,isAbsolute as Bt}from"node:path";var G=st(Me(),1);import{accessSync as Mt,constants as Fe,statSync as Ft}from"node:fs";import{homedir as Ht}from"node:os";import{posix as Gt,win32 as He}from"node:path";var Ge=G.default,kt=G.default.sync;function ke(t){if(!(!t?.pid||t.exitCode!==null||t.signalCode!==null))if(t.stdin?.destroy(),process.platform==="win32"){let e=He.join(process.env.SystemRoot||"C:\\Windows","System32","taskkill.exe");kt(e,["/pid",String(t.pid),"/t","/f"],{stdio:"ignore",timeout:3e3,windowsHide:!0})}else t.kill()}function b(t,e,{env:s=process.env,home:r=Ht(),platform:n=process.platform}={}){if(e)return e;let{delimiter:i,dirname:o,join:a,isAbsolute:l,extname:c}=n==="win32"?He:Gt,E=Object.keys(s).find(f=>f.toUpperCase()==="PATH")||"PATH",u=[o(process.execPath),...(s[E]||"").split(i).filter(Boolean).map(f=>f.replace(/^"(.*)"$/,"$1"))];n!=="win32"?u.push("/opt/homebrew/bin","/usr/local/bin","/usr/bin","/bin",a(r,".volta/bin"),a(r,".local/bin")):u.push(a(s.APPDATA||a(r,"AppData","Roaming"),"npm"),a(r,".volta","bin"));let d=n!=="win32"||c(t)?[""]:[".exe",".com",".cmd",".bat"],p=u.filter(l).flatMap(f=>d.map(h=>a(f,t+h)));t==="codex"&&n==="darwin"&&p.push("/Applications/Codex.app/Contents/Resources/codex");for(let f of p)try{if(Mt(f,n==="win32"?Fe.F_OK:Fe.X_OK),Ft(f).isFile())return f}catch{}return t}var Xe=["userPromptSubmit","stop","interrupt"],R=()=>({status:"unknown",events:Xe.map(t=>({event:t,status:"unknown"}))});function We({command:t=b("codex",process.env.HONGGUO_CODEX),args:e=["app-server"],cwd:s=process.cwd(),timeoutMs:r=8e3,pluginRoot:n=$,installedId:i}={}){let o=l=>{try{return Xt(l)}catch{return Yt(l)}},a=o(n);return new Promise(l=>{let c,E=!1,u="",d=0,p=h=>{E||(E=!0,clearTimeout(f),ke(c),l(h))},f=setTimeout(()=>p(R()),r);try{c=Ge(t,e,{cwd:s,stdio:["pipe","pipe","ignore"],windowsHide:!0}),c.on("error",()=>p(R())),c.on("exit",()=>p(R())),c.stdin.on("error",()=>p(R())),c.stdout.setEncoding("utf8");let h=L=>c.stdin.write(JSON.stringify(L)+`
|
|
46
|
+
`);c.stdout.on("data",L=>{if(E)return;if(d+=Buffer.byteLength(L),d>2*1024*1024)return p(R());u+=L;let y;for(;!E&&(y=u.indexOf(`
|
|
47
|
+
`))>=0;){let Ke=u.slice(0,y);u=u.slice(y+1);let _;try{_=JSON.parse(Ke)}catch{continue}if(_.error&&[1,2].includes(_.id))return p(R());if(_.id===1&&_.result&&(h({jsonrpc:"2.0",method:"initialized"}),h({jsonrpc:"2.0",id:2,method:"hooks/list",params:{cwds:[s]}})),_.id===2&&Array.isArray(_.result?.data)){let W=_.result.data.flatMap(T=>Array.isArray(T?.hooks)?T.hooks:[]).filter(T=>typeof T?.pluginId=="string"&&T.pluginId.split("@")[0]==="codex-hongguo").filter(T=>{if(typeof T.sourcePath!="string")return!1;if(i)return T.pluginId===i;let N=Wt(a,o(T.sourcePath));return N&&!N.startsWith("..")&&!Bt(N)});if(!W.length)return p(R());let Y=Xe.map(T=>{let N=W.filter(S=>S.eventName===T),Je=N.length?N.some(S=>!S.enabled)?"disabled":N.every(S=>["trusted","managed"].includes(S.trustStatus))?"ready":N.some(S=>["untrusted","modified"].includes(S.trustStatus))?"needs_review":"unknown":"missing";return{event:T,status:Je}});p({status:Y.every(T=>T.status==="ready")?"ready":"needs_attention",events:Y})}}}),h({jsonrpc:"2.0",id:1,method:"initialize",params:{clientInfo:{name:"hongguo-setup",version:"1"},capabilities:{experimentalApi:!0}}})}catch{p(R())}})}var jt=b("ffmpeg",process.env.HONGGUO_FFMPEG),qt=b("codex",process.env.HONGGUO_CODEX),X=!1,k;try{k=new g,X=k.writable()}catch{}finally{k?.close()}var[Ye,Kt]=process.versions.node.split(".").map(Number),je={version:process.version,ready:Ye>22||Ye===22&&Kt>=16},qe=$t(jt,["-version"],{stdio:"ignore",timeout:2500,windowsHide:!0}).status===0,Be=await We({command:qt}),$e=je.ready&&X&&qe;console.log(JSON.stringify({runtime:je,database:X,ffmpeg:qe,hooks:Be,manualReady:$e,followReady:$e&&Be.status==="ready"},null,2));
|