KnowledgeStore/Tools/Support.pm

filter: Statementstmt 60.0% 3 / 5 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 71.4% 5 / 7 CC 1 SCAR 1.4
CC
1
Cov
60%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« KnowledgeStore/Tools/Revisioned.pm ↑ Summary
1 package MCP::Server::KnowledgeStore::Tools::Support;
2 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use Mojo::Base -strict, -signatures;
Subroutine BEGIN: called CC=1 SCAR=2.6
4  
5 our $VERSION = '0.001';
6  
7 # ABSTRACT: Shared helpers every MCP::Server::KnowledgeStore::Tools::* plugin uses
8  
9 use Exporter qw(import);
10  
11 our @EXPORT_OK = qw(
12 name_pattern summary author revision_property author_property
13 project_property
14 );
15  
16 use constant NAME_PATTERN => '^[A-Za-z0-9][A-Za-z0-9_:-]*$';
17  
18 sub name_pattern () { return NAME_PATTERN }
19  
20 # Tools return structured results rather than prose, so a client gets a
21 # list it can filter instead of a paragraph it has to parse. The store's
22 # `body` is dropped from list/search output - it is what get_* is for,
23 # and including it would make a listing as expensive as reading
24 # everything.
25 sub summary ($entry) {
26 return {
27 name => $entry->{name},
28 description => $entry->{description},
29 revision => $entry->{revision},
30 view_count => $entry->{view_count} // 0,
31 useful_count => $entry->{useful_count} // 0,
32  
33 # `projects`: memory/skill's tags (may be several). `project`: a
34 # spec's single required one - absent for memory/skill going
35 # forward, since they no longer write that column.
36 projects => $entry->{projects} // [],
37 map { defined $entry->{$_} ? ($_ => $entry->{$_}) : () }
38 qw(type project last_viewed_at),
39 };
40 }
41  
42 # A save records who claims to have made it. The token is shared, so this
43 # is not an authenticated identity - it is git's user.name, not a login.
44 sub author ($tool, $args) {
45 return $args->{author} // $tool->context->principal;
46 }
47  
48 sub revision_property () {
49 return {
50 revision => {
51 type => 'integer',
52 minimum => 1,
53 description =>
54 'Read this revision instead of the current one. Omit for current.',
55 },
56 };
57 }
58  
59 sub author_property () {
60 return {
61 author => {
62 type => 'string',
63 description => 'Who to record as having made this revision',
64 },
65 };
66 }
67  
68 sub project_property () {
69 return {
70 project => {
71 type => 'string',
72 description =>
73 'Only entries tagged with this project (a spec\'s single required '
74 . 'project; a memory/skill/agent may be tagged with several)',
75 },
76 };
77 }
78  
79 1;
80  
81 __END__
« KnowledgeStore/Tools/Revisioned.pm ↑ Summary