Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .githooks/sync-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,85 @@ function updateVersionLineInSection(
return content
}

function extractTomlSectionValue(content: string, sectionName: string, key: string): string | undefined {
const lines = content.split(/\r?\n/)
let inTargetSection = false

for (const line of lines) {
const trimmed = line.trim()

if (/^\[.*\]$/.test(trimmed)) {
inTargetSection = trimmed === `[${sectionName}]`
continue
}

if (!inTargetSection) {
continue
}

const match = trimmed.match(new RegExp(`^${key}\\s*=\\s*"([^"]+)"$`, 'u'))
if (match != null) {
return match[1]
}
}

return undefined
}

function updateCargoLockPackageVersions(
content: string,
packageNames: ReadonlySet<string>,
targetVersion: string,
): string {
const lines = content.split(/\r?\n/)
let currentPackageName: string | undefined
let inPackageBlock = false

for (let index = 0; index < lines.length; index += 1) {
const line = lines[index]
const trimmed = line.trim()

if (trimmed === '[[package]]') {
inPackageBlock = true
currentPackageName = undefined
continue
}

if (/^\[\[.+\]\]$|^\[.+\]$/u.test(trimmed)) {
inPackageBlock = false
currentPackageName = undefined
continue
}

if (!inPackageBlock) {
continue
}

const nameMatch = trimmed.match(/^name\s*=\s*"([^"]+)"$/u)
if (nameMatch != null) {
currentPackageName = nameMatch[1]
continue
}

if (currentPackageName == null || !packageNames.has(currentPackageName)) {
continue
}

const versionMatch = line.match(/^(\s*version\s*=\s*")([^"]+)(".*)$/u)
if (versionMatch == null) {
continue
}

if (versionMatch[2] === targetVersion) {
continue
}

lines[index] = `${versionMatch[1]}${targetVersion}${versionMatch[3]}`
}

return lines.join('\n')
}

function runGit(rootDir: string, args: readonly string[]): string {
return execFileSync('git', args, {
cwd: rootDir,
Expand Down Expand Up @@ -168,6 +247,49 @@ function syncCargoVersion(
}
}

function collectCargoPackageNames(cargoTomlPaths: readonly string[]): Set<string> {
const packageNames = new Set<string>()

for (const filePath of cargoTomlPaths) {
try {
const content = readFileSync(filePath, 'utf-8')
const packageName = extractTomlSectionValue(content, 'package', 'name')
if (packageName != null && packageName !== '') {
packageNames.add(packageName)
}
} catch {
console.log(`⚠️ ${filePath} not found or invalid, skipping`)
}
}

return packageNames
}

function syncCargoLockVersion(
filePath: string,
packageNames: ReadonlySet<string>,
targetVersion: string,
changedPaths: Set<string>,
): void {
if (packageNames.size === 0) {
return
}

try {
const originalContent = readFileSync(filePath, 'utf-8')
const updatedContent = updateCargoLockPackageVersions(originalContent, packageNames, targetVersion)

if (updatedContent === originalContent) {
return
}

writeFileSync(filePath, updatedContent, 'utf-8')
changedPaths.add(filePath)
} catch {
console.log(`⚠️ ${filePath} not found or invalid, skipping`)
}
}

function getStagedPackageVersionCandidates(rootDir: string, rootVersion: string): Map<string, string[]> {
const stagedFiles = runGit(rootDir, ['diff', '--cached', '--name-only', '--diff-filter=ACMR'])
.split(/\r?\n/)
Expand Down Expand Up @@ -253,6 +375,7 @@ export function runSyncVersions(options: SyncVersionsOptions = {}): SyncVersions
const rootDir = resolve(options.rootDir ?? '.')
const rootPackagePath = resolve(rootDir, 'package.json')
const rootCargoPath = resolve(rootDir, 'Cargo.toml')
const cargoLockPath = resolve(rootDir, 'Cargo.lock')
const rootPkg = readJsonFile(rootPackagePath)
const currentRootVersion = typeof rootPkg.version === 'string' ? rootPkg.version.trim() : ''

Expand Down Expand Up @@ -284,11 +407,14 @@ export function runSyncVersions(options: SyncVersionsOptions = {}): SyncVersions
const cargoTomlPaths = discoverFilesByName(rootDir, 'Cargo.toml')
.filter(filePath => resolve(filePath) !== rootCargoPath)
.sort()
const cargoPackageNames = collectCargoPackageNames([rootCargoPath, ...cargoTomlPaths])

for (const filePath of cargoTomlPaths) {
syncCargoVersion(filePath, 'package', target.version, changedPaths)
}

syncCargoLockVersion(cargoLockPath, cargoPackageNames, target.version, changedPaths)

for (const filePath of discoverFilesByName(rootDir, 'tauri.conf.json').sort()) {
syncJsonVersion(filePath, target.version, changedPaths)
}
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
]

[workspace.package]
version = "2026.10402.109"
version = "2026.10402.110"
edition = "2024"
rust-version = "1.88"
license = "AGPL-3.0-only"
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-darwin-arm64",
"version": "2026.10402.109",
"version": "2026.10402.110",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-darwin-x64",
"version": "2026.10402.109",
"version": "2026.10402.110",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-linux-arm64-gnu",
"version": "2026.10402.109",
"version": "2026.10402.110",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-linux-x64-gnu",
"version": "2026.10402.109",
"version": "2026.10402.110",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-cli-win32-x64-msvc",
"version": "2026.10402.109",
"version": "2026.10402.110",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@truenine/memory-sync-cli",
"type": "module",
"version": "2026.10402.109",
"version": "2026.10402.110",
"description": "TrueNine Memory Synchronization CLI shell",
"author": "TrueNine",
"license": "AGPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion doc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-docs",
"version": "2026.10402.109",
"version": "2026.10402.110",
"private": true,
"description": "Chinese-first manifesto-led documentation site for @truenine/memory-sync.",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion gui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@truenine/memory-sync-gui",
"version": "2026.10402.109",
"version": "2026.10402.110",
"private": true,
"engines": {
"node": ">=25.2.1",
Expand Down
2 changes: 1 addition & 1 deletion gui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "memory-sync-gui"
version = "2026.10402.109"
version = "2026.10402.110"
description = "Memory Sync desktop GUI application"
authors.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion gui/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://schema.tauri.app/config/2",
"version": "2026.10402.109",
"version": "2026.10402.110",
"productName": "Memory Sync",
"identifier": "org.truenine.memory-sync",
"build": {
Expand Down
2 changes: 1 addition & 1 deletion libraries/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@truenine/logger",
"type": "module",
"version": "2026.10402.109",
"version": "2026.10402.110",
"private": true,
"description": "Rust-powered AI-friendly Markdown logger for Node.js via N-API",
"license": "AGPL-3.0-only",
Expand Down
42 changes: 36 additions & 6 deletions libraries/logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,9 @@ fn output_worker(receiver: Receiver<OutputCommand>) {
match command {
OutputCommand::Write { use_stderr, output } => {
if use_stderr {
if stderr_writer.write_all(output.as_bytes()).is_ok() {
let _ = stderr_writer.write_all(b"\n");
}
let _ = write_output_line(&mut stderr_writer, &output);
} else {
if stdout_writer.write_all(output.as_bytes()).is_ok() {
let _ = stdout_writer.write_all(b"\n");
}
let _ = write_output_line(&mut stdout_writer, &output);
}
}
OutputCommand::Flush { ack } => {
Expand All @@ -713,6 +709,12 @@ fn output_worker(receiver: Receiver<OutputCommand>) {
let _ = stderr_writer.flush();
}

fn write_output_line(writer: &mut impl Write, output: &str) -> std::io::Result<()> {
writer.write_all(output.as_bytes())?;
writer.write_all(b"\n")?;
writer.flush()
}

fn print_output_direct(use_stderr: bool, output: &str) {
if use_stderr {
let mut stderr = std::io::stderr().lock();
Expand Down Expand Up @@ -1222,4 +1224,32 @@ mod tests {
assert_eq!(drained.len(), 1);
assert_eq!(drained[0].code, "BUFFERED_WARN");
}

#[derive(Default)]
struct FlushTrackingWriter {
writes: Vec<u8>,
flush_count: usize,
}

impl Write for FlushTrackingWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.writes.extend_from_slice(buf);
Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
self.flush_count += 1;
Ok(())
}
}

#[test]
fn test_write_output_line_flushes_each_message() {
let mut writer = FlushTrackingWriter::default();

write_output_line(&mut writer, "**INFO** `logger-test` hello").unwrap();

assert_eq!(String::from_utf8(writer.writes).unwrap(), "**INFO** `logger-test` hello\n");
assert_eq!(writer.flush_count, 1);
}
}
2 changes: 1 addition & 1 deletion libraries/md-compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@truenine/md-compiler",
"type": "module",
"version": "2026.10402.109",
"version": "2026.10402.110",
"private": true,
"description": "Rust-powered MDX→Markdown compiler for Node.js with pure-TS fallback",
"license": "AGPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion libraries/script-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@truenine/script-runtime",
"type": "module",
"version": "2026.10402.109",
"version": "2026.10402.110",
"private": true,
"description": "Rust-backed TypeScript proxy runtime for tnmsc",
"license": "AGPL-3.0-only",
Expand Down
Loading
Loading