Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/import{ mkdirSync, rmSync }from'fs';import{ DatabaseSync }from'node:sqlite';import{ dirname }from'path';importtype{ CheckpointRow, FileRow, ISessionStore, RefRow, SearchResult, SessionRow, SessionStoreOptions, TurnRow }from'../common/sessionStore';/**
* SQLite authorizer action codes that are safe for read-only access.
* Values from https://www.sqlite.org/c3ref/c_alter_table.html
* (node:sqlite constants do not expose authorizer codes)
*/constSQLITE_OK=0;constSQLITE_DENY=1;
err markers
message err errmessage err
markersmarker messagemarker
_serviceBrand
db DatabaseSync
dbPath
remote
dbPath options SessionStoreOptions
dbPath dbPath
remote optionsremote
dbPath
DatabaseSync
db
db
err
dbPath err
err
DatabaseSync
dbPath
dbPath recursive
db dbPath
remote
db
db
db
db
db
db
db db
err
db
db
err
db
suffix
dbPath suffix force
db db
versionRow
stmt db
stmt version
currentVersion versionRowversion
currentVersion
db
ftsExists db
ftsExists
db
currentVersion currentVersion
db
currentVersion currentVersion
db
db
currentVersion
db
db
session SessionRow
db
db
sessionid
sessioncwd
sessionrepository
sessionhost_type
sessionbranch
sessionsummary
sessionagent_name
sessionagent_description
sessioncreated_at
sessionupdated_at
turn TurnRow
db
dbturnsession_id
db
turnsession_id
turnturn_index
turnuser_message
turnassistant_response
turntimestamp
content turnuser_message turnassistant_responseBoolean
content
turnId
dbturnId
db
content turnsession_id turnId
checkpoint CheckpointRow
db
dbcheckpointsession_id
db
checkpointsession_id
checkpointcheckpoint_number
checkpointtitle
checkpointoverview
checkpointhistory
checkpointwork_done
checkpointtechnical_details
checkpointimportant_files
checkpointnext_steps
checkpointcreated_at
sections
checkpointoverview
checkpointhistory
checkpointwork_done
checkpointtechnical_details
checkpointimportant_files
checkpointnext_steps
sourceType content sections
content
sourceId
dbsourceId
db
content checkpointsession_id sourceType sourceId
file FileRow
db
dbfilesession_id
db
filesession_id
filefile_path
filetool_name
fileturn_index
filefirst_seen_at
ref RefRow
db
dbrefsession_id
db
refsession_id
refref_type
refref_value
refturn_index
refcreated_at
sessionId filePath content
content
db
sourceId
dbsourceId
db
content
sessionId
sourceId
sessionId
db
dbsessionId
dbsessionId
dbsessionId
dbsessionId
dbsessionId
dbsessionId
query limit SearchResult
db
stmt db
stmtquery limit SearchResult
sessionId SessionRow
db
dbsessionId SessionRow
sessionId TurnRow
db
db
sessionId TurnRow
sessionId FileRow
db
dbsessionId FileRow
sessionId RefRow
db
dbsessionId RefRow
sql Record
db
hasAuthorizer db DatabaseSync setAuthorizer setAuthorizer
hasAuthorizer
db DatabaseSync setAuthorizer cb actionCode p1 actionCode p1
actionCode p1 p1
actionCode
actionCode p1
dbsql Record
hasAuthorizer
db DatabaseSync cb
sql Record
db
dbsql Record
sessionId
db
row db
sessionId max_idx
rowmax_idx
sessions turns checkpoints files refs
db
table
db c c
sessions
turns
checkpoints
files
refs
db
db
db
err
db
err
db DatabaseSync
db
db
db
db
/**
* Functions denied at the authorizer layer for defense-in-depth, even though the tool
* layer also blocks them by regex. Names are compared case-insensitively.
*/
const
DENIED_FUNCTIONS
=
new
Set
(
[
'load_extension'
]
)
;
/** Schema version — bump when altering tables so existing DBs get migrated. */
const
SCHEMA_VERSION
=
3
;
/**
* Substrings (matched case-insensitively) that identify a corrupt or otherwise
* unusable database file. These typically appear on non-POSIX network
* filesystems (NFS/SMB/sshfs) used by SSH-Remote workspaces, where SQLite's
* locking protocol is not honoured and the file can become permanently
* malformed.
*/
const
CORRUPTION_ERROR_MARKERS
=
[
'malformed'
,
'file is not a database'
,
'not a database'
,
'disk image'
,
'disk i/o error'
,
]
;
function
errorMessageIncludes
(
:
unknown
,
:
readonly
string
[
]
)
:
boolean
{
const
=
(
instanceof
Error
?
.
:
String
(
)
)
.
toLowerCase
(
)
;
return
.
some
(
=>
.
includes
(
)
)
;
}
/**
* Session store backed by SQLite + FTS5.
*
* Schema is identical to the copilot-agent-runtime SessionStore so that
* tooling and queries are portable across CLI and VS Code surfaces.
* The store is populated incrementally by live hooks — no background indexing.
*/
export
class
SessionStore
implements
ISessionStore
{
declare
readonly
:
undefined
;
private
:
|
null
=
null
;
private
readonly
:
string
;
private
readonly
:
boolean
;
constructor
(
:
string
,
?
:
)
{
this
.
=
;
this
.
=
?.
??
false
;
}
/**
* Get the path to the database file.
*/
getPath
(
)
:
string
{
return
this
.
;
}
/**
* Lazily open (or create) the database and ensure the schema exists.
*
* On remote workspaces the database often lives on a network filesystem
* (NFS/SMB/sshfs) that does not provide the POSIX locking guarantees WAL
* mode relies on. If the file is detected to be corrupt it is deleted and
* recreated once before giving up.
*/
private
ensureDb
(
)
:
{
if
(
this
.
)
{
return
this
.
;
}
try
{
return
this
.
openDb
(
)
;
}
catch
(
)
{
// A corrupt on-disk database is unrecoverable in place. Delete it and
// the WAL/SHM sidecar files, then try once more with a fresh file.
if
(
this
.
!==
':memory:'
&&
errorMessageIncludes
(
,
CORRUPTION_ERROR_MARKERS
)
)
{
this
.
deleteDbFiles
(
)
;
return
this
.
openDb
(
)
;
}
throw
;
}
}
/**
* Open the database, configure pragmas and ensure the schema exists.
*/
private
openDb
(
)
:
{
if
(
this
.
!==
':memory:'
)
{
mkdirSync
(
dirname
(
this
.
)
,
{
:
true
}
)
;
}
const
=
new
DatabaseSync
(
this
.
)
;
try
{
if
(
this
.
)
{
// WAL requires shared-memory (-shm) plus POSIX byte-range locking,
// neither of which network filesystems reliably provide. A rollback
// journal with a longer busy timeout is far more robust there.
.
exec
(
'PRAGMA journal_mode = DELETE'
)
;
.
exec
(
'PRAGMA busy_timeout = 10000'
)
;
.
exec
(
'PRAGMA synchronous = NORMAL'
)
;
}
else
{
.
exec
(
'PRAGMA journal_mode = WAL'
)
;
.
exec
(
'PRAGMA busy_timeout = 3000'
)
;
}
.
exec
(
'PRAGMA foreign_keys = ON'
)
;
this
.
=
;
this
.
ensureSchema
(
)
;
}
catch
(
)
{
.
close
(
)
;
this
.
=
null
;
throw
;
}
return
this
.
;
}
/**
* Best-effort deletion of the database file and its WAL/SHM sidecar files.
*/
private
deleteDbFiles
(
)
:
void
{
for
(
const
of
[
''
,
'-wal'
,
'-shm'
,
'-journal'
]
)
{
rmSync
(
this
.
+
,
{
:
true
}
)
;
}
}
/**
* Create or migrate tables to the current schema version.
*
* IMPORTANT: When bumping SCHEMA_VERSION, add explicit migration logic
* for each version step (e.g., v1→v2). CREATE TABLE IF NOT EXISTS does
* NOT alter existing tables — use ALTER TABLE for schema changes.
*/
private
ensureSchema
(
)
:
void
{
const
=
this
.
!
;
const
=
(
(
)
=>
{
try
{
const
=
.
prepare
(
'SELECT version FROM schema_version LIMIT 1'
)
;
return
.
get
(
)
as
unknown
as
{
:
number
}
|
undefined
;
}
catch
{
return
undefined
;
}
}
)
(
)
;
const
=
?.
??
0
;
if
(
>=
SCHEMA_VERSION
)
{
return
;
}
.
exec
(
`
CREATE TABLE IF NOT EXISTS schema_version (
version INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
cwd TEXT,
repository TEXT,
host_type TEXT,
branch TEXT,
summary TEXT,
agent_name TEXT,
agent_description TEXT,
created_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
updated_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
);
CREATE TABLE IF NOT EXISTS turns (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL REFERENCES sessions(id),
turn_index INTEGER NOT NULL,
user_message TEXT,
assistant_response TEXT,
timestamp TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
UNIQUE(session_id, turn_index)
);
CREATE TABLE IF NOT EXISTS checkpoints (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL REFERENCES sessions(id),
checkpoint_number INTEGER NOT NULL,
title TEXT,
overview TEXT,
history TEXT,
work_done TEXT,
technical_details TEXT,
important_files TEXT,
next_steps TEXT,
created_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
UNIQUE(session_id, checkpoint_number)
);
CREATE TABLE IF NOT EXISTS session_files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL REFERENCES sessions(id),
file_path TEXT NOT NULL,
tool_name TEXT,
turn_index INTEGER,
first_seen_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
UNIQUE(session_id, file_path)
);
CREATE TABLE IF NOT EXISTS session_refs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL REFERENCES sessions(id),
ref_type TEXT NOT NULL,
ref_value TEXT NOT NULL,
turn_index INTEGER,
created_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
UNIQUE(session_id, ref_type, ref_value)
);
CREATE INDEX IF NOT EXISTS idx_sessions_repo ON sessions(repository);
CREATE INDEX IF NOT EXISTS idx_sessions_cwd ON sessions(cwd);
CREATE INDEX IF NOT EXISTS idx_session_files_path ON session_files(file_path);
CREATE INDEX IF NOT EXISTS idx_session_refs_type_value ON session_refs(ref_type, ref_value);
CREATE INDEX IF NOT EXISTS idx_turns_session ON turns(session_id);
CREATE INDEX IF NOT EXISTS idx_checkpoints_session ON checkpoints(session_id);
`
)
;
// FTS5 virtual table — CREATE VIRTUAL TABLE doesn't support IF NOT EXISTS
// in all SQLite builds, so we guard with a check.
const
=
.
prepare
(
'SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'search_index\''
/**
* Index a workspace artifact (e.g. plan.md, context files) for full-text search.
* Content is upserted: subsequent writes to the same file replace the previous index entry.
*/
/**
* Delete a session and all associated data.
* Removes turns, checkpoints, files, refs, search index entries, and the session row.
*/
deleteSession
(
:
string
)
:
void
{
const
=
this
.
ensureDb
(
)
;
this
.
runInTransaction
(
(
)
=>
{
.
prepare
(
'DELETE FROM search_index WHERE session_id = ?'
)
.
run
(
)
;
.
prepare
(
'DELETE FROM session_refs WHERE session_id = ?'
)
.
run
(
)
;
.
prepare
(
'DELETE FROM session_files WHERE session_id = ?'
)
.
run
(
)
;
.
prepare
(
'DELETE FROM checkpoints WHERE session_id = ?'
)
.
run
(
)
;
.
prepare
(
'DELETE FROM turns WHERE session_id = ?'
)
.
run
(
)
;
.
prepare
(
'DELETE FROM sessions WHERE id = ?'
)
.
run
(
)
;
}
)
;
}
/**
* Full-text search across all indexed content (turns, checkpoint sections, and workspace artifacts).
* Uses FTS5 MATCH with BM25 ranking.
*
* @paramquery FTS5 query string (supports AND, OR, NOT, phrase "..." etc.)
* @paramlimit Maximum results to return (default 20)
*/
search
(
:
string
,
:
number
=
20
)
:
[
]
{
const
=
this
.
ensureDb
(
)
;
const
=
.
prepare
(
`
SELECT content, session_id, source_type, bm25(search_index) AS rank
FROM search_index
WHERE search_index MATCH ?
ORDER BY rank
LIMIT ?
`
)
;
return
.
all
(
,
)
as
unknown
as
[
]
;
}
/**
* Get a session by ID.
*/
getSession
(
:
string
)
:
|
undefined
{
const
=
this
.
ensureDb
(
)
;
return
.
prepare
(
'SELECT * FROM sessions WHERE id = ?'
)
.
get
(
)
as
unknown
as
|
undefined
;
}
/**
* Get all turns for a session, ordered by turn index.
*/
getTurns
(
:
string
)
:
[
]
{
const
=
this
.
ensureDb
(
)
;
return
.
prepare
(
'SELECT * FROM turns WHERE session_id = ? ORDER BY turn_index'
)
.
all
(
)
as
unknown
as
[
]
;
}
/**
* Get all files touched in a session.
*/
getFiles
(
:
string
)
:
[
]
{
const
=
this
.
ensureDb
(
)
;
return
.
prepare
(
'SELECT * FROM session_files WHERE session_id = ?'
)
.
all
(
)
as
unknown
as
[
]
;
}
/**
* Get all refs for a session.
*/
getRefs
(
:
string
)
:
[
]
{
const
=
this
.
ensureDb
(
)
;
return
.
prepare
(
'SELECT * FROM session_refs WHERE session_id = ?'
)
.
all
(
)
as
unknown
as
[
]
;
}
/**
* Execute a read-only SQL query against the store.
* When SQLite's authorizer API is available (Node.js 24.2+), installs a positive
* action-code allowlist so the engine enforces read-only. When unavailable, runs the
* prepared statement directly — callers MUST validate the SQL (allowlist + blocklist)
* before calling this method.
*/
executeReadOnly
(
:
string
)
:
<
string
,
unknown
>
[
]
{
const
=
this
.
ensureDb
(
)
;
const
=
typeof
(
as
&
{
?
:
unknown
}
)
.
===
'function'
;
if
(
)
{
(
as
&
{
:
(
:
(
(
:
number
,
:
string
|
null
)
=>
number
)
|
null
)
=>
void
}
)
.
setAuthorizer
(
(
:
number
,
:
string
|
null
)
=>
{
if
(
===
SQLITE_FUNCTION
&&
&&
DENIED_FUNCTIONS
.
has
(
.
toLowerCase
(
)
)
)
{
return
SQLITE_DENY
;
}
if
(
READ_ONLY_ACTION_CODES
.
has
(
)
)
{
return
SQLITE_OK
;
}
// FTS5 internally uses PRAGMA data_version to detect DB changes
if
(
===
SQLITE_PRAGMA
&&
===
'data_version'
)
{
return
SQLITE_OK
;
}
return
SQLITE_DENY
;
}
)
;
}
try
{
return
.
prepare
(
)
.
all
(
)
as
<
string
,
unknown
>
[
]
;
}
finally
{
if
(
)
{
(
as
&
{
setAuthorizer
:
(
:
null
)
=>
void
}
)
.
setAuthorizer
(
null
)
;
}
}
}
/**
* Execute SQL, used for hard-coded, trusted SQL composed inside the extension.
*/
executeReadOnlyFallback
(
:
string
)
:
<
string
,
unknown
>
[
]
{
const
=
this
.
ensureDb
(
)
;
return
.
prepare
(
)
.
all
(
)
as
<
string
,
unknown
>
[
]
;
}
/**
* Get the highest turn_index for a session, or -1 if no turns exist.
*/
getMaxTurnIndex
(
:
string
)
:
number
{
const
=
this
.
ensureDb
(
)
;
const
=
.
prepare
(
'SELECT MAX(turn_index) as max_idx FROM turns WHERE session_id = ?'
)
.
get
(
)
as
unknown
as
{
:
number
|
null
}
|
undefined
;
return
?.
??
-
1
;
}
/**
* Get basic stats about the store.
*/
getStats
(
)
:
{
:
number
;
:
number
;
:
number
;
:
number
;
:
number
}
{
const
=
this
.
ensureDb
(
)
;
const
count
=
(
:
string
)
=>
(
.
prepare
(
`SELECT COUNT(*) as c FROM ${table}`
)
.
get
(
)
as
unknown
as
{
:
number
}
)
.
;
return
{
:
count
(
'sessions'
)
,
:
count
(
'turns'
)
,
:
count
(
'checkpoints'
)
,
:
count
(
'session_files'
)
,
:
count
(
'session_refs'
)
,
}
;
}
/**
* Run a function inside a SQLite transaction (BEGIN/COMMIT/ROLLBACK).
* All writes are batched into a single atomic commit, which is significantly
* faster than auto-committing each individual INSERT.
*
* Transient lock contention is handled by SQLite's `busy_timeout` pragma; a
* failed transaction propagates to the caller, which re-queues the writes for
* the next flush rather than blocking here.
*/
runInTransaction
(
fn
:
(
)
=>
void
)
:
void
{
const
=
this
.
ensureDb
(
)
;
.
exec
(
'BEGIN'
)
;
try
{
fn
(
)
;
.
exec
(
'COMMIT'
)
;
}
catch
(
)
{
this
.
rollbackQuietly
(
)
;
throw
;
}
}
/**
* Roll back the active transaction, swallowing the "no transaction is active"
* error that occurs when the failure happened before BEGIN took effect.
*/
private
rollbackQuietly
(
:
)
:
void
{
try
{
.
exec
(
'ROLLBACK'
)
;
}
catch
{
// No active transaction to roll back — safe to ignore.