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
1 change: 0 additions & 1 deletion .claude/scheduled_tasks.lock

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.0.0
## 1.0.1

Plugin-based command knowledge base.

Expand Down
5 changes: 5 additions & 0 deletions lib/command_shield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ export 'src/capabilities/knowledge/command_knowledge.dart';
export 'src/capabilities/knowledge/command_knowledge_plugin.dart';
export 'src/capabilities/knowledge/command_knowledge_result.dart';
export 'src/capabilities/knowledge/plugins/archive_knowledge.dart';
export 'src/capabilities/knowledge/plugins/compression_knowledge.dart';
export 'src/capabilities/knowledge/plugins/container_knowledge.dart';
export 'src/capabilities/knowledge/plugins/crypto_knowledge.dart';
export 'src/capabilities/knowledge/plugins/dart_flutter_knowledge.dart';
export 'src/capabilities/knowledge/plugins/database_knowledge.dart';
export 'src/capabilities/knowledge/plugins/default_plugins.dart';
export 'src/capabilities/knowledge/plugins/editor_knowledge.dart';
export 'src/capabilities/knowledge/plugins/environment_knowledge.dart';
export 'src/capabilities/knowledge/plugins/filesystem_knowledge.dart';
export 'src/capabilities/knowledge/plugins/git_knowledge.dart';
export 'src/capabilities/knowledge/plugins/hash_knowledge.dart';
export 'src/capabilities/knowledge/plugins/network_knowledge.dart';
export 'src/capabilities/knowledge/plugins/package_manager_knowledge.dart';
export 'src/capabilities/knowledge/plugins/process_knowledge.dart';
Expand Down
17 changes: 16 additions & 1 deletion lib/src/capabilities/knowledge/command_knowledge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ enum KnowledgeCategory {
/// Filesystem manipulation (`ls`, `cp`, `rm`, …).
filesystem,

/// Archive and compression tools (`tar`, `zip`, `gzip`, …).
/// Archive and bundling tools (`tar`, `7z`, `cpio`, …).
archive,

/// Single-stream compressors and zip tools (`gzip`, `zip`, `xz`, …).
compression,

/// Checksum and digest tools (`md5sum`, `sha256sum`, `cksum`, …).
hash,

/// Encryption, signing and encoding tools (`openssl`, `gpg`, `base64`, …).
crypto,

/// Database clients and dump/restore tools (`psql`, `mysql`, `sqlite3`, …).
database,

/// Interactive text editors (`vim`, `nano`, `emacs`, …).
editor,

/// Software package managers (`npm`, `pip`, `apt`, `brew`, …).
packageManager,

Expand Down
24 changes: 5 additions & 19 deletions lib/src/capabilities/knowledge/plugins/archive_knowledge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import '../../capability.dart';
import '../command_knowledge.dart';
import '../command_knowledge_plugin.dart';

/// Knowledge about archive and compression tools.
/// Knowledge about archive and bundling tools.
///
/// These both read inputs and write outputs, so they carry read + write
/// filesystem capabilities; extraction-only or list-only modes are still
/// conservatively reported as read + write.
/// conservatively reported as read + write. Single-stream compressors live in
/// the compression plugin.
final class ArchiveKnowledge implements CommandKnowledgePlugin {
/// Creates the archive knowledge plugin.
const ArchiveKnowledge();
Expand All @@ -16,26 +17,11 @@ final class ArchiveKnowledge implements CommandKnowledgePlugin {

@override
List<CommandKnowledge> get entries => [
for (final tool in const [
'tar',
'zip',
'unzip',
'gzip',
'gunzip',
'bzip2',
'bunzip2',
'xz',
'unxz',
'zstd',
'7z',
'7za',
'compress',
'uncompress',
])
for (final tool in const ['tar', '7z', '7za', 'cpio', 'ar', 'pax'])
CommandKnowledge(
executable: tool,
category: KnowledgeCategory.archive,
description: 'Archive/compression tool (reads inputs, writes outputs).',
description: 'Archive/bundling tool (reads inputs, writes outputs).',
baseCapabilities: const {
CommandCapability.readFilesystem,
CommandCapability.writeFilesystem,
Expand Down
52 changes: 52 additions & 0 deletions lib/src/capabilities/knowledge/plugins/compression_knowledge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import '../../capability.dart';
import '../command_knowledge.dart';
import '../command_knowledge_plugin.dart';

/// Knowledge about single-stream compressors and zip tools.
///
/// These both read inputs and write outputs, so they carry read + write
/// filesystem capabilities; decompression-only or list-only modes are still
/// conservatively reported as read + write.
final class CompressionKnowledge implements CommandKnowledgePlugin {
/// Creates the compression knowledge plugin.
const CompressionKnowledge();

@override
String get name => 'compression';

@override
List<CommandKnowledge> get entries => [
for (final tool in const [
'gzip',
'gunzip',
'zcat',
'zip',
'unzip',
'bzip2',
'bunzip2',
'bzcat',
'xz',
'unxz',
'xzcat',
'zstd',
'unzstd',
'zstdcat',
'lz4',
'lzma',
'unlzma',
'compress',
'uncompress',
'brotli',
'pigz',
])
CommandKnowledge(
executable: tool,
category: KnowledgeCategory.compression,
description: 'Compression tool (reads inputs, writes outputs).',
baseCapabilities: const {
CommandCapability.readFilesystem,
CommandCapability.writeFilesystem,
},
),
];
}
69 changes: 69 additions & 0 deletions lib/src/capabilities/knowledge/plugins/crypto_knowledge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import '../../capability.dart';
import '../command_knowledge.dart';
import '../command_knowledge_plugin.dart';
import 'knowledge_builders.dart';

/// Knowledge about encryption, signing and encoding tools.
final class CryptoKnowledge implements CommandKnowledgePlugin {
/// Creates the crypto knowledge plugin.
const CryptoKnowledge();

@override
String get name => 'crypto';

static const _crypto = KnowledgeCategory.crypto;

@override
List<CommandKnowledge> get entries => [
// openssl reads/writes files; the s_client/s_server/ocsp commands talk to
// the network.
const CommandKnowledge(
executable: 'openssl',
category: _crypto,
description: 'Cryptography toolkit (keys, certs, encryption, TLS).',
baseCapabilities: {
CommandCapability.readFilesystem,
CommandCapability.writeFilesystem,
},
subcommands: [
SubcommandRule(
{'s_client', 's_server', 'ocsp'},
{CommandCapability.networkRead, CommandCapability.networkWrite},
description: 'Opens a network connection to a TLS/OCSP endpoint.',
),
],
),

// gpg reads/writes files; keyserver operations talk to the network.
for (final g in const ['gpg', 'gpg2'])
CommandKnowledge(
executable: g,
category: _crypto,
description: 'OpenPGP encryption and signing tool.',
baseCapabilities: const {
CommandCapability.readFilesystem,
CommandCapability.writeFilesystem,
},
argumentRules: const [
ArgumentRule(
ExactFlag({
'--recv-keys',
'--send-keys',
'--refresh-keys',
'--keyserver',
}),
{CommandCapability.networkRead, CommandCapability.networkWrite},
description: 'Keyserver operations transfer keys over the network.',
),
],
),

// base64/base32 read an input file (or stdin) and write the result to
// stdout.
...simpleEntries(
const ['base64', 'base32'],
_crypto,
const {CommandCapability.readFilesystem},
),
];
}
68 changes: 68 additions & 0 deletions lib/src/capabilities/knowledge/plugins/database_knowledge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import '../../capability.dart';
import '../command_knowledge.dart';
import '../command_knowledge_plugin.dart';
import 'knowledge_builders.dart';

/// Knowledge about database clients and dump/restore tools.
final class DatabaseKnowledge implements CommandKnowledgePlugin {
/// Creates the database knowledge plugin.
const DatabaseKnowledge();

@override
String get name => 'database';

static const _db = KnowledgeCategory.database;

@override
List<CommandKnowledge> get entries => [
// --- network clients (connect to a database server) ---
...simpleEntries(
const [
'psql',
'mysql',
'mariadb',
'mongo',
'mongosh',
'redis-cli',
'cqlsh',
'influx',
],
_db,
const {CommandCapability.networkRead, CommandCapability.networkWrite},
),

// --- local file database ---
const CommandKnowledge(
executable: 'sqlite3',
category: _db,
description: 'Operates on a local SQLite database file.',
baseCapabilities: {
CommandCapability.readFilesystem,
CommandCapability.writeFilesystem,
},
),

// --- dump tools: read from the server, write a dump file ---
for (final d in const ['pg_dump', 'mysqldump'])
CommandKnowledge(
executable: d,
category: _db,
description: 'Dumps a database to a file (reads server, writes file).',
baseCapabilities: const {
CommandCapability.networkRead,
CommandCapability.writeFilesystem,
},
),

// --- restore tool: read a dump file, write to the server ---
const CommandKnowledge(
executable: 'pg_restore',
category: _db,
description: 'Restores a dump file into a database server.',
baseCapabilities: {
CommandCapability.readFilesystem,
CommandCapability.networkWrite,
},
),
];
}
10 changes: 10 additions & 0 deletions lib/src/capabilities/knowledge/plugins/default_plugins.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import '../command_knowledge_plugin.dart';
import 'archive_knowledge.dart';
import 'compression_knowledge.dart';
import 'container_knowledge.dart';
import 'crypto_knowledge.dart';
import 'dart_flutter_knowledge.dart';
import 'database_knowledge.dart';
import 'editor_knowledge.dart';
import 'environment_knowledge.dart';
import 'filesystem_knowledge.dart';
import 'git_knowledge.dart';
import 'hash_knowledge.dart';
import 'network_knowledge.dart';
import 'package_manager_knowledge.dart';
import 'process_knowledge.dart';
Expand All @@ -21,12 +26,17 @@ import 'windows_knowledge.dart';
const List<CommandKnowledgePlugin> defaultKnowledgePlugins =
<CommandKnowledgePlugin>[
FilesystemKnowledge(),
HashKnowledge(),
ArchiveKnowledge(),
CompressionKnowledge(),
CryptoKnowledge(),
EditorKnowledge(),
ShellKnowledge(),
EnvironmentKnowledge(),
ProcessKnowledge(),
SystemConfigKnowledge(),
NetworkKnowledge(),
DatabaseKnowledge(),
ContainerKnowledge(),
PackageManagerKnowledge(),
DartFlutterKnowledge(),
Expand Down
35 changes: 35 additions & 0 deletions lib/src/capabilities/knowledge/plugins/editor_knowledge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import '../../capability.dart';
import '../command_knowledge.dart';
import '../command_knowledge_plugin.dart';
import 'knowledge_builders.dart';

/// Knowledge about interactive text editors.
///
/// Editors open files for reading and can write them back, so they carry
/// read + write filesystem capabilities.
final class EditorKnowledge implements CommandKnowledgePlugin {
/// Creates the editor knowledge plugin.
const EditorKnowledge();

@override
String get name => 'editor';

@override
List<CommandKnowledge> get entries => simpleEntries(
const [
'vim',
'vi',
'nvim',
'vimdiff',
'nano',
'emacs',
'ed',
'ex',
'pico',
'joe',
'micro',
],
KnowledgeCategory.editor,
const {CommandCapability.readFilesystem, CommandCapability.writeFilesystem},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ final class FilesystemKnowledge implements CommandKnowledgePlugin {
'nl',
'tac',
'strings',
'md5sum',
'sha256sum',
'sha1sum',
'cksum',
],
_fs,
const {CommandCapability.readFilesystem},
Expand Down
Loading