MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / register

Method register

src/workspaces/transcript-watcher.ts:80–173  ·  view source on GitHub ↗
(session: PersistentSession, adapter: CliAdapter)

Source from the content-addressed store, hash-verified

78 ) {}
79
80 async register(session: PersistentSession, adapter: CliAdapter): Promise<void> {
81 const discovery = adapter.capabilities.transcriptDiscovery;
82 if (discovery === 'subprocess') {
83 await this.registerSubprocess(session, adapter);
84 return;
85 }
86 if (discovery !== 'fs-watch') return;
87 if (!adapter.transcriptDir || !adapter.transcriptFileRe || !adapter.extractSessionId) {
88 this.logger.warn('transcript_watch.adapter_missing_fs_methods', { adapter: adapter.id });
89 return;
90 }
91
92 const dir = adapter.transcriptDir(session.cwd);
93 const key = watchKey(session.wsId, dir);
94
95 let existing: ReadonlySet<string>;
96 try {
97 existing = await snapshotFiles(dir, adapter.transcriptFileRe);
98 } catch (err) {
99 if (!isENOENT(err)) {
100 this.logger.warn('transcript_watch.snapshot_failed', {
101 wsId: session.wsId,
102 adapter: adapter.id,
103 dir,
104 err,
105 });
106 }
107 existing = new Set();
108 }
109
110 try {
111 await mkdir(dir, { recursive: true });
112 } catch (err) {
113 this.logger.warn('transcript_watch.mkdir_failed', {
114 wsId: session.wsId,
115 adapter: adapter.id,
116 dir,
117 err,
118 });
119 return;
120 }
121
122 let entry = this.entries.get(key);
123 if (!entry) {
124 try {
125 const w = watch(dir, (event, filename) => {
126 if (typeof filename === 'string') {
127 void this.onEvent(key, event, filename);
128 }
129 });
130 w.on('error', (err) => {
131 this.logger.warn('transcript_watch.error', {
132 wsId: session.wsId,
133 adapter: adapter.id,
134 dir,
135 err,
136 });
137 });

Callers

nothing calls this directly

Calls 12

registerSubprocessMethod · 0.95
onEventMethod · 0.95
watchKeyFunction · 0.85
snapshotFilesFunction · 0.85
warnMethod · 0.80
transcriptDirMethod · 0.80
infoMethod · 0.80
eventMethod · 0.80
isENOENTFunction · 0.70
getMethod · 0.65
setMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected